Best Python code snippet using localstack_python
client.pyi
Source:client.pyi  
...1339        (SAML) identity provider in IAM.1340        [Show boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/1.24.58/reference/services/iam.html#IAM.Client.untag_saml_provider)1341        [Show boto3-stubs documentation](https://vemel.github.io/boto3_stubs_docs/mypy_boto3_iam/client.html#untag_saml_provider)1342        """1343    def untag_server_certificate(self, *, ServerCertificateName: str, TagKeys: List[str]) -> None:1344        """1345        Removes the specified tags from the IAM server certificate.1346        [Show boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/1.24.58/reference/services/iam.html#IAM.Client.untag_server_certificate)1347        [Show boto3-stubs documentation](https://vemel.github.io/boto3_stubs_docs/mypy_boto3_iam/client.html#untag_server_certificate)1348        """1349    def untag_user(self, *, UserName: str, TagKeys: List[str]) -> None:1350        """1351        Removes the specified tags from the user.1352        [Show boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/1.24.58/reference/services/iam.html#IAM.Client.untag_user)1353        [Show boto3-stubs documentation](https://vemel.github.io/boto3_stubs_docs/mypy_boto3_iam/client.html#untag_user)1354        """1355    def update_access_key(1356        self, *, AccessKeyId: str, Status: statusTypeType, UserName: str = None1357    ) -> None:...iam.py
Source:iam.py  
1from datetime import datetime2from typing import ClassVar, Dict, Optional, Type, List, Any3from attrs import define, field4from resoto_plugin_aws.resource.base import AwsResource, GraphBuilder, AwsApiSpec5from resoto_plugin_aws.resource.ec2 import AwsEc2IamInstanceProfile6from resoto_plugin_aws.utils import ToDict7from resotolib.baseresources import (  # noqa: F4018    BaseCertificate,9    BasePolicy,10    BaseGroup,11    BaseAccount,12    BaseAccessKey,13    BaseUser,14    BaseInstanceProfile,15    EdgeType,16    ModelReference,17)18from resotolib.json import from_json19from resotolib.json_bender import Bender, S, Bend, AsDate, Sort, bend, ForallBend20from resotolib.types import Json21from resotolib.graph import Graph22from resoto_plugin_aws.aws_client import AwsClient23def iam_update_tag(resource: AwsResource, client: AwsClient, action: str, key: str, value: str, **kwargs: Any) -> bool:24    if spec := resource.api_spec:25        client.call(26            aws_service=spec.service,27            action=action,28            result_name=None,29            Tags=[{"Key": key, "Value": value}],30            **kwargs,31        )32        return True33    return False34def iam_delete_tag(resource: AwsResource, client: AwsClient, action: str, key: str, **kwargs: Any) -> bool:35    if spec := resource.api_spec:36        client.call(37            aws_service=spec.service,38            action=action,39            result_name=None,40            TagKeys=[key],41            **kwargs,42        )43        return True44    return False45@define(eq=False, slots=False)46class AwsIamPolicyDetail:47    kind: ClassVar[str] = "aws_iam_policy_detail"48    mapping: ClassVar[Dict[str, Bender]] = {"policy_name": S("PolicyName"), "policy_document": S("PolicyDocument")}49    policy_name: Optional[str] = field(default=None)50    policy_document: Optional[str] = field(default=None)51@define(eq=False, slots=False)52class AwsIamAttachedPermissionsBoundary:53    kind: ClassVar[str] = "aws_iam_attached_permissions_boundary"54    mapping: ClassVar[Dict[str, Bender]] = {55        "permissions_boundary_type": S("PermissionsBoundaryType"),56        "permissions_boundary_arn": S("PermissionsBoundaryArn"),57    }58    permissions_boundary_type: Optional[str] = field(default=None)59    permissions_boundary_arn: Optional[str] = field(default=None)60@define(eq=False, slots=False)61class AwsIamRoleLastUsed:62    kind: ClassVar[str] = "aws_iam_role_last_used"63    mapping: ClassVar[Dict[str, Bender]] = {"last_used_date": S("LastUsedDate"), "region": S("Region")}64    last_used_date: Optional[datetime] = field(default=None)65    region: Optional[str] = field(default=None)66@define(eq=False, slots=False)67class AwsIamRole(AwsResource):68    # Note: this resource is collected via AwsIamUser.collect.69    kind: ClassVar[str] = "aws_iam_role"70    reference_kinds: ClassVar[ModelReference] = {71        "successors": {72            "default": ["aws_iam_policy", "aws_iam_instance_profile"],73            "delete": ["aws_iam_policy", "aws_iam_instance_profile"],74        },75    }76    mapping: ClassVar[Dict[str, Bender]] = {77        "id": S("RoleId"),78        "tags": S("Tags", default=[]) >> ToDict(),79        "name": S("RoleName"),80        "ctime": S("CreateDate"),81        "atime": (S("RoleLastUsed") >> Sort(S("LastUsedDate") >> AsDate()))[-1]["LastUsedDate"],82        "path": S("Path"),83        "arn": S("Arn"),84        "role_assume_role_policy_document": S("AssumeRolePolicyDocument"),85        "description": S("Description"),86        "role_max_session_duration": S("MaxSessionDuration"),87        "role_permissions_boundary": S("PermissionsBoundary") >> Bend(AwsIamAttachedPermissionsBoundary.mapping),88        "role_last_used": S("RoleLastUsed") >> Bend(AwsIamRoleLastUsed.mapping),89        "role_policies": S("RolePolicyList", default=[]) >> ForallBend(AwsIamPolicyDetail.mapping),90    }91    path: Optional[str] = field(default=None)92    description: Optional[str] = field(default=None)93    role_assume_role_policy_document: Optional[Any] = field(default=None)94    role_max_session_duration: Optional[int] = field(default=None)95    role_permissions_boundary: Optional[AwsIamAttachedPermissionsBoundary] = field(default=None)96    role_last_used: Optional[AwsIamRoleLastUsed] = field(default=None)97    role_policies: List[AwsIamPolicyDetail] = field(factory=list)98    def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:99        # connect to instance profiles for this role100        for profile in bend(S("InstanceProfileList", default=[]), source):101            builder.dependant_node(102                self, clazz=AwsEc2IamInstanceProfile, delete_same_as_default=True, arn=profile["Arn"]103            )104        # connect to attached policies for this role105        for profile in bend(S("AttachedManagedPolicies", default=[]), source):106            builder.dependant_node(self, clazz=AwsIamPolicy, delete_same_as_default=True, arn=profile["PolicyArn"])107    def update_resource_tag(self, client: AwsClient, key: str, value: str) -> bool:108        return iam_update_tag(109            resource=self,110            client=client,111            action="tag_role",112            key=key,113            value=value,114            RoleName=self.name,115        )116    def delete_resource_tag(self, client: AwsClient, key: str) -> bool:117        return iam_delete_tag(118            resource=self,119            client=client,120            action="untag_role",121            key=key,122            RoleName=self.name,123        )124    def pre_delete_resource(self, client: AwsClient, graph: Graph) -> bool:125        for successor in self.successors(graph, edge_type=EdgeType.delete):126            if isinstance(successor, AwsIamPolicy):127                log_msg = f"Detaching {successor.rtdname}"128                self.log(log_msg)129                client.call(130                    aws_service="iam",131                    action="detach_role_policy",132                    result_name=None,133                    PolicyArn=successor.arn,134                    RoleName=self.name,135                )136        for role_policy in self.role_policies:137            log_msg = f"Deleting inline policy {role_policy}"138            self.log(log_msg)139            client.call(140                aws_service="iam",141                action="delete_role_policy",142                result_name=None,143                PolicyName=role_policy.policy_name,144                RoleName=self.name,145            )146        return True147    def delete_resource(self, client: AwsClient) -> bool:148        client.call(aws_service="iam", action="delete_role", result_name=None, RoleName=self.name)149        return True150@define(eq=False, slots=False)151class AwsIamServerCertificate(AwsResource, BaseCertificate):152    kind: ClassVar[str] = "aws_iam_server_certificate"153    api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("iam", "list-server-certificates", "ServerCertificateMetadataList")154    mapping: ClassVar[Dict[str, Bender]] = {155        "id": S("ServerCertificateId"),156        "arn": S("Arn"),157        "tags": S("Tags", default=[]) >> ToDict(),158        "name": S("ServerCertificateName"),159        "ctime": S("UploadDate"),160        "path": S("Path"),161        "expires": S("Expiration"),162    }163    path: Optional[str] = field(default=None)164    def update_resource_tag(self, client: AwsClient, key: str, value: str) -> bool:165        return iam_update_tag(166            resource=self,167            client=client,168            action="tag_server_certificate",169            key=key,170            value=value,171            ServerCertificateName=self.name,172        )173    def delete_resource_tag(self, client: AwsClient, key: str) -> bool:174        return iam_delete_tag(175            resource=self,176            client=client,177            action="untag_server_certificate",178            key=key,179            ServerCertificateName=self.name,180        )181    def delete_resource(self, client: AwsClient) -> bool:182        client.call(183            aws_service=self.api_spec.service,184            action="delete_server_certificate",185            result_name=None,186            ServerCertificateName=self.name,187        )188        return True189@define(eq=False, slots=False)190class AwsIamPolicy(AwsResource, BasePolicy):191    # Note: this resource is collected via AwsIamUser.collect.192    kind: ClassVar[str] = "aws_iam_policy"193    mapping: ClassVar[Dict[str, Bender]] = {194        "id": S("PolicyId"),195        "tags": S("Tags", default=[]) >> ToDict(),196        "name": S("PolicyName"),197        "ctime": S("CreateDate"),198        "mtime": S("UpdateDate"),199        "arn": S("Arn"),200        "path": S("Path"),201        "policy_default_version_id": S("DefaultVersionId"),202        "policy_attachment_count": S("AttachmentCount"),203        "policy_permissions_boundary_usage_count": S("PermissionsBoundaryUsageCount"),204        "policy_is_attachable": S("IsAttachable"),205        "policy_description": S("Description"),206    }207    path: Optional[str] = field(default=None)208    policy_default_version_id: Optional[str] = field(default=None)209    policy_attachment_count: Optional[int] = field(default=None)210    policy_permissions_boundary_usage_count: Optional[int] = field(default=None)211    policy_is_attachable: Optional[bool] = field(default=None)212    policy_description: Optional[str] = field(default=None)213    def update_resource_tag(self, client: AwsClient, key: str, value: str) -> bool:214        return iam_update_tag(215            resource=self,216            client=client,217            action="tag_policy",218            key=key,219            value=value,220            PolicyArn=self.arn,221        )222    def delete_resource_tag(self, client: AwsClient, key: str) -> bool:223        return iam_delete_tag(224            resource=self,225            client=client,226            action="untag_policy",227            key=key,228            PolicyArn=self.arn,229        )230    def delete_resource(self, client: AwsClient) -> bool:231        client.call(232            aws_service="iam",233            action="delete_policy",234            result_name=None,235            PolicyArn=self.arn,236        )237        return True238@define(eq=False, slots=False)239class AwsIamGroup(AwsResource, BaseGroup):240    # Note: this resource is collected via AwsIamUser.collect.241    kind: ClassVar[str] = "aws_iam_group"242    reference_kinds: ClassVar[ModelReference] = {243        "successors": {"default": ["aws_iam_policy"], "delete": ["aws_iam_policy"]},244    }245    mapping: ClassVar[Dict[str, Bender]] = {246        "id": S("GroupId"),247        "tags": S("Tags", default=[]) >> ToDict(),248        "name": S("GroupName"),249        "ctime": S("CreateDate"),250        "path": S("Path"),251        "arn": S("Arn"),252        "group_policies": S("GroupPolicyList", default=[]) >> ForallBend(AwsIamPolicyDetail.mapping),253    }254    path: Optional[str] = field(default=None)255    group_policies: List[AwsIamPolicyDetail] = field(factory=list)256    def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:257        for policy in bend(S("AttachedManagedPolicies", default=[]), source):258            builder.dependant_node(self, clazz=AwsIamPolicy, delete_same_as_default=True, arn=policy.get("PolicyArn"))259    def pre_delete_resource(self, client: AwsClient, graph: Graph) -> bool:260        for successor in self.successors(graph, edge_type=EdgeType.delete):261            if isinstance(successor, AwsIamPolicy):262                log_msg = f"Detaching {successor.rtdname}"263                self.log(log_msg)264                client.call(265                    aws_service="iam",266                    action="detach_group_policy",267                    result_name=None,268                    GroupName=self.name,269                    PolicyArn=successor.arn,270                )271        for group_policy in self.group_policies:272            log_msg = f"Deleting inline policy {group_policy}"273            self.log(log_msg)274            client.call(275                aws_service="iam",276                action="delete_group_policy",277                result_name=None,278                GroupName=self.name,279                PolicyName=group_policy,280            )281        return True282    def delete_resource(self, client: AwsClient) -> bool:283        client.call(284            aws_service="iam",285            action="delete_group",286            result_name=None,287            GroupName=self.name,288        )289        return True290@define(eq=False, slots=False)291class AwsIamAccessKeyLastUsed:292    kind: ClassVar[str] = "aws_iam_access_key_last_used"293    mapping: ClassVar[Dict[str, Bender]] = {294        "last_used_date": S("LastUsedDate"),295        "service_name": S("ServiceName"),296        "region": S("Region"),297    }298    last_used_date: Optional[datetime] = field(default=None)299    service_name: Optional[str] = field(default=None)300    region: Optional[str] = field(default=None)301    @staticmethod302    def from_api(js: Json) -> "AwsIamAccessKeyLastUsed":303        mapped = bend(AwsIamAccessKeyLastUsed.mapping, js)304        return from_json(mapped, AwsIamAccessKeyLastUsed)305@define(eq=False, slots=False)306class AwsIamAccessKey(AwsResource, BaseAccessKey):307    # Note: this resource is collected via AwsIamUser.collect.308    kind: ClassVar[str] = "aws_iam_access_key"309    mapping: ClassVar[Dict[str, Bender]] = {310        "id": S("AccessKeyId"),311        "tags": S("Tags", default=[]) >> ToDict(),312        "name": S("UserName"),313        "ctime": S("CreateDate"),314        "access_key_status": S("Status"),315    }316    access_key_last_used: Optional[AwsIamAccessKeyLastUsed] = field(default=None)317@define(eq=False, slots=False)318class AwsIamUser(AwsResource, BaseUser):319    kind: ClassVar[str] = "aws_iam_user"320    api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("iam", "get-account-authorization-details")321    reference_kinds: ClassVar[ModelReference] = {322        "predecessors": {"default": ["aws_iam_group"]},323        "successors": {"default": ["aws_iam_policy"], "delete": ["aws_iam_policy"]},324    }325    mapping: ClassVar[Dict[str, Bender]] = {326        "id": S("UserId"),327        "tags": S("Tags", default=[]) >> ToDict(),328        "name": S("UserName"),329        "ctime": S("CreateDate"),330        "atime": S("PasswordLastUsed"),331        "path": S("Path"),332        "arn": S("Arn"),333        "user_policies": S("UserPolicyList", default=[]) >> ForallBend(AwsIamPolicyDetail.mapping),334        "user_permissions_boundary": S("PermissionsBoundary") >> Bend(AwsIamAttachedPermissionsBoundary.mapping),335    }336    path: Optional[str] = field(default=None)337    user_policies: List[AwsIamPolicyDetail] = field(factory=list)338    user_permissions_boundary: Optional[AwsIamAttachedPermissionsBoundary] = field(default=None)339    @classmethod340    def called_apis(cls) -> List[AwsApiSpec]:341        return [cls.api_spec, AwsApiSpec("iam", "list-access-keys"), AwsApiSpec("iam", "get-access-key-last-used")]342    @classmethod343    def collect(cls: Type[AwsResource], json_list: List[Json], builder: GraphBuilder) -> None:344        for json in json_list:345            for js in json.get("GroupDetailList", []):346                builder.add_node(AwsIamGroup.from_api(js), js)347            for js in json.get("RoleDetailList", []):348                builder.add_node(AwsIamRole.from_api(js), js)349            for js in json.get("Policies", []):350                builder.add_node(AwsIamPolicy.from_api(js), js)351            for js in json.get("UserDetailList", []):352                user = AwsIamUser.from_api(js)353                builder.add_node(user, js)354                # add all iam access keys for this user355                for ak in builder.client.list("iam", "list-access-keys", "AccessKeyMetadata", UserName=user.name):356                    key = AwsIamAccessKey.from_api(ak)357                    # get last used date for this key358                    if lu := builder.client.get(359                        "iam", "get-access-key-last-used", "AccessKeyLastUsed", AccessKeyId=key.id360                    ):361                        key.access_key_last_used = AwsIamAccessKeyLastUsed.from_api(lu)362                        key.atime = key.access_key_last_used.last_used_date if key.access_key_last_used else None363                    builder.add_node(key, ak)364                    builder.dependant_node(user, node=key)365    def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:366        for p in bend(S("AttachedManagedPolicies", default=[]), source):367            builder.dependant_node(self, clazz=AwsIamPolicy, delete_same_as_default=True, arn=p.get("PolicyArn"))368        for arn in bend(S("GroupList", default=[]), source):369            builder.add_edge(self, reverse=True, clazz=AwsIamGroup, arn=arn)370    def update_resource_tag(self, client: AwsClient, key: str, value: str) -> bool:371        return iam_update_tag(resource=self, client=client, action="tag_user", key=key, value=value, UserName=self.name)372    def delete_resource_tag(self, client: AwsClient, key: str) -> bool:373        return iam_delete_tag(resource=self, client=client, action="untag_user", key=key, UserName=self.name)374    def pre_delete_resource(self, client: AwsClient, graph: Graph) -> bool:375        for successor in self.successors(graph, edge_type=EdgeType.delete):376            if isinstance(successor, AwsIamPolicy):377                log_msg = f"Detaching {successor.rtdname}"378                self.log(log_msg)379                client.call(380                    aws_service="iam",381                    action="detach_user_policy",382                    result_name=None,383                    UserName=self.name,384                    PolicyArn=successor.arn,385                )386        for user_policy in self.user_policies:387            log_msg = f"Deleting inline policy {user_policy}"388            self.log(log_msg)389            client.call(390                aws_service="iam",391                action="delete_user_policy",392                result_name=None,393                UserName=self.name,394                PolicyName=user_policy.policy_name,395            )396        return True397    def delete_resource(self, client: AwsClient) -> bool:398        client.call(aws_service="iam", action="delete_user", result_name=None, UserName=self.name)399        return True400@define(eq=False, slots=False)401class AwsIamInstanceProfile(AwsResource, BaseInstanceProfile):402    kind: ClassVar[str] = "aws_iam_instance_profile"403    api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("iam", "list-instance-profiles", "InstanceProfiles")404    mapping: ClassVar[Dict[str, Bender]] = {405        "id": S("InstanceProfileId"),406        "name": S("InstanceProfileName"),407        "ctime": S("CreateDate"),408        "arn": S("Arn"),409        "instance_profile_path": S("Path"),410    }411    instance_profile_path: Optional[str] = field(default=None)412    def update_resource_tag(self, client: AwsClient, key: str, value: str) -> bool:413        return iam_update_tag(414            resource=self,415            client=client,416            action="tag_instance_profile",417            key=key,418            value=value,419            InstanceProfileName=self.name,420        )421    def delete_resource_tag(self, client: AwsClient, key: str) -> bool:422        return iam_delete_tag(423            resource=self, client=client, action="untag_instance_profile", key=key, InstanceProfileName=self.name424        )425    def pre_delete_resource(self, client: AwsClient, graph: Graph) -> bool:426        for predecessor in self.predecessors(graph, edge_type=EdgeType.delete):427            if isinstance(predecessor, AwsIamRole):428                log_msg = f"Detaching {predecessor.rtdname}"429                self.log(log_msg)430                client.call(431                    aws_service="iam",432                    action="remove_role_from_instance_profile",433                    result_name=None,434                    RoleName=predecessor.name,435                    InstanceProfileName=self.name,436                )437        return True438    def delete_resource(self, client: AwsClient) -> bool:439        client.call(440            aws_service="iam", action="delete_instance_profile", result_name=None, InstanceProfileName=self.name441        )442        return True443resources: List[Type[AwsResource]] = [444    AwsIamServerCertificate,445    AwsIamPolicy,446    AwsIamGroup,447    AwsIamRole,448    AwsIamUser,449    AwsIamInstanceProfile,...iam_test.py
Source:iam_test.py  
1from resoto_plugin_aws.resource.iam import (2    AwsIamPolicy,3    AwsIamGroup,4    AwsIamServerCertificate,5    AwsIamRole,6    AwsIamUser,7    AwsIamAccessKey,8    AwsIamInstanceProfile,9)10from test.resources import round_trip_for11from typing import Any, cast12from types import SimpleNamespace13from resoto_plugin_aws.aws_client import AwsClient14def test_server_certificates() -> None:15    round_trip_for(AwsIamServerCertificate, "dns_names", "sha1_fingerprint")16def test_instance_profiles() -> None:17    round_trip_for(AwsIamInstanceProfile)18def test_user_roles_groups_policies_keys() -> None:19    _, builder = round_trip_for(AwsIamUser)20    # users ------------21    assert len(builder.resources_of(AwsIamUser)) == 322    assert (test_user := builder.node(clazz=AwsIamUser, name="test_user")) is not None23    assert [p.policy_name for p in test_user.user_policies] == ["stsAssumeRole"]24    # keys ------------25    assert len(builder.resources_of(AwsIamAccessKey)) == 226    assert (ak_test := builder.node(clazz=AwsIamAccessKey, id="ak_test")) is not None27    assert len(builder.graph.nodes) == 1228    # make sure access keys are created and connected as part of the user29    assert builder.graph.has_edge(test_user, ak_test)30    # groups ------------31    assert len(builder.resources_of(AwsIamGroup)) == 132    assert (group := builder.node(clazz=AwsIamGroup, name="test_group")) is not None33    assert [p.policy_name for p in group.group_policies] == ["stsAssumeRole"]34    # policies ------------35    assert len(builder.resources_of(AwsIamPolicy)) == 436    assert (policy := builder.node(clazz=AwsIamPolicy, name="master-elb")) is not None37    assert policy.policy_attachment_count == 138    # roles39    assert len(builder.resources_of(AwsIamRole)) == 240    assert (role := builder.node(clazz=AwsIamRole, name="role1")) is not None41    assert len(role.role_policies) == 142def test_server_certificate_deletion() -> None:43    res, _ = round_trip_for(AwsIamServerCertificate, "dns_names", "sha1_fingerprint")44    def validate_update_args(**kwargs: Any) -> None:45        assert kwargs["action"] == "delete_server_certificate"46        assert kwargs["ServerCertificateName"] == res.name47    client = cast(AwsClient, SimpleNamespace(call=validate_update_args))48    res.delete_resource(client)49def test_aws_iam_policy_deletion() -> None:50    _, builder = round_trip_for(AwsIamUser)51    res = builder.resources_of(AwsIamPolicy)[0]52    def validate_update_args(**kwargs: Any) -> None:53        assert kwargs["action"] == "delete_policy"54        assert kwargs["PolicyArn"] == res.arn55    client = cast(AwsClient, SimpleNamespace(call=validate_update_args))56    res.delete_resource(client)57def test_aws_iam_group_deletion() -> None:58    _, builder = round_trip_for(AwsIamUser)59    res = builder.resources_of(AwsIamGroup)[0]60    def validate_update_args(**kwargs: Any) -> None:61        assert kwargs["action"] == "delete_group"62        assert kwargs["GroupName"] == res.name63    client = cast(AwsClient, SimpleNamespace(call=validate_update_args))64    res.delete_resource(client)65def test_aws_iam_role_deletion() -> None:66    _, builder = round_trip_for(AwsIamUser)67    res = builder.resources_of(AwsIamRole)[0]68    def validate_update_args(**kwargs: Any) -> None:69        assert kwargs["action"] == "delete_role"70        assert kwargs["RoleName"] == res.name71    client = cast(AwsClient, SimpleNamespace(call=validate_update_args))72    res.delete_resource(client)73def test_aws_iam_user_deletion() -> None:74    _, builder = round_trip_for(AwsIamUser)75    res = builder.resources_of(AwsIamUser)[0]76    def validate_update_args(**kwargs: Any) -> None:77        assert kwargs["action"] == "delete_user"78        assert kwargs["UserName"] == res.name79    client = cast(AwsClient, SimpleNamespace(call=validate_update_args))80    res.delete_resource(client)81def test_aws_iam_instance_profile_deletion() -> None:82    res, _ = round_trip_for(AwsIamInstanceProfile)83    def validate_update_args(**kwargs: Any) -> None:84        assert kwargs["action"] == "delete_instance_profile"85        assert kwargs["InstanceProfileName"] == res.name86    client = cast(AwsClient, SimpleNamespace(call=validate_update_args))87    res.delete_resource(client)88def test_tagging() -> None:89    res, _ = round_trip_for(AwsIamServerCertificate, "dns_names", "sha1_fingerprint")90    def validate_update_args(**kwargs: Any) -> None:91        assert kwargs["action"] == "tag_server_certificate"92        assert kwargs["Tags"] == [{"Key": "foo", "Value": "bar"}]93        assert kwargs["ServerCertificateName"] == res.name94    def validate_delete_args(**kwargs: Any) -> None:95        assert kwargs["action"] == "untag_server_certificate"96        assert kwargs["TagKeys"] == ["foo"]97        assert kwargs["ServerCertificateName"] == res.name98    client = cast(AwsClient, SimpleNamespace(call=validate_update_args))99    res.update_resource_tag(client, "foo", "bar")100    client = cast(AwsClient, SimpleNamespace(call=validate_delete_args))...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
