Best Python code snippet using localstack_python
acl.py
Source:acl.py
...25 elif self.arn.resource_type == "assumed-role":26 self.get_role_permissions()27 def get_user_permissions(self):28 try:29 policies = self.client.list_policies_granting_service_access(30 Arn=self.arn.full,31 ServiceNamespaces=[32 "apigateway",33 "dynamodb",34 "kms",35 "lambda",36 "iam",37 "s3",38 "sns",39 "sqs",40 "sts",41 ],42 )["PoliciesGrantingServiceAccess"]43 for item in policies:...
iam_rule_helpers.py
Source:iam_rule_helpers.py
...18 if 'LastAuthenticated' not in x19 ]20 if len(never_accessed) == 0:21 return 'COMPLIANT', 'IAM entity has accessed all allowed services'22 policies_by_service = iam.list_policies_granting_service_access(23 Arn=arn, ServiceNamespaces=[s['ServiceNamespace'] for s in never_accessed]24 )['PoliciesGrantingServiceAccess']25 never_accessed_and_not_readonly = [26 g for g in policies_by_service27 if not all(p['PolicyName'] == 'ReadOnlyAccess' for p in g['Policies'])28 ]29 if len(never_accessed_and_not_readonly) > 0:30 return (31 'NON_COMPLIANT',32 "Services " + ', '.join(x['ServiceNamespace'] for x in never_accessed_and_not_readonly)[:220] + " have never been accessed"33 )34 return 'COMPLIANT', 'IAM entity has accessed all allowed services'35def no_access_in_180_days_check(iam, arn):36 import pytz...
find_admins.py
Source:find_admins.py
...15 client = boto3.client('iam', **credentials)16 users = get_paginated_results('iam', 'list_users', 'Users', credentials)17 admins = []18 for user in users:19 response = client.list_policies_granting_service_access(20 Arn=user['Arn'],21 ServiceNamespaces=[SUPER_ESOTERIC_AWS_NAMESPACE]22 )23 if len(response['PoliciesGrantingServiceAccess'][0]['Policies']) > 0:24 last_used = user.get('PasswordLastUsed', datetime.datetime.utcfromtimestamp(0))25 admins.append((user['UserName'], str(last_used)))26 return admins27if __name__ == "__main__":...
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!!