How to use list_user_tags method in localstack

Best Python code snippet using localstack_python

iam_access_key_age_function.py

Source:iam_access_key_age_function.py Github

copy

Full Screen

...22 #print ("datetime details are: ", datetime.timedelta(days=15))23 24 # if Access key age is greater then or equal to 70 days, send warning25 if active_days == datetime.timedelta(days=int(os.environ['days_70'])):26 userTags = iam.list_user_tags(UserName=keyValue['UserName'])27 email_tag = list(filter(lambda tag: tag['Key'] == 'email', userTags['Tags']))28 if(len(email_tag) == 1):29 email = email_tag[0]['Value']30 email_70_list.append(email)31 print("This User: ", IAMUserName, ", with the email: ", email, ", is having access key age is 70 days") 32 33 email_unique = list(set(email_70_list))34 print("Email list: ", email_unique)35 RECIPIENTS = email_unique36 SENDER = os.environ['sender_email']37 AWS_REGION = os.environ['region']38 SUBJECT_70 = os.environ['SUBJECT_70']39 BODY_TEXT_70 = os.environ['BODY_TEXT_70']40 BODY_HTML_70 = os.environ['BODY_HTML_70'] 41 CHARSET = "UTF-8"42 client = boto3.client('ses',region_name=AWS_REGION)43 try:44 response = client.send_email(45 Destination={46 'ToAddresses': RECIPIENTS,47 },48 Message={49 'Body': {50 'Html': {51 'Charset': CHARSET,52 'Data': BODY_HTML_70,53 },54 'Text': {55 'Charset': CHARSET,56 'Data': BODY_TEXT_70,57 },58 },59 'Subject': {60 'Charset': CHARSET,61 'Data': SUBJECT_70,62 },63 },64 Source=SENDER,65 )66 except ClientError as e:67 print(e.response['Error']['Message'])68 else:69 print("Email sent! Message ID:"),70 print(response['MessageId'])71 72 # if Access Key Age is greater then 80 days, send email alert73 if active_days == datetime.timedelta(days=int(os.environ['days_80'])):74 userTags = iam.list_user_tags(UserName=keyValue['UserName'])75 email_tag = list(filter(lambda tag: tag['Key'] == 'email', userTags['Tags']))76 if(len(email_tag) == 1):77 email = email_tag[0]['Value']78 email_80_list.append(email)79 print("The User: ", IAMUserName, ", with the email: ", email, ", is having access key age is 80 days")80 81 email_unique = list(set(email_80_list))82 print("Email list: ", email_unique)83 RECIPIENTS = email_unique84 SENDER = os.environ['sender_email']85 print("Sender: ", SENDER)86 AWS_REGION = os.environ['region']87 SUBJECT_80 = os.environ['SUBJECT_80']88 BODY_TEXT_80 = os.environ['BODY_TEXT_80']89 BODY_HTML_80 = os.environ['BODY_HTML_80'] 90 CHARSET = "UTF-8"91 client = boto3.client('ses',region_name=AWS_REGION)92 try:93 response = client.send_email(94 Destination={95 'ToAddresses': RECIPIENTS,96 },97 Message={98 'Body': {99 'Html': {100 'Charset': CHARSET,101 'Data': BODY_HTML_80,102 },103 'Text': {104 'Charset': CHARSET,105 'Data': BODY_TEXT_80,106 },107 },108 'Subject': {109 'Charset': CHARSET,110 'Data': SUBJECT_80,111 },112 },113 Source=SENDER,114 )115 except ClientError as e:116 print(e.response['Error']['Message'])117 else:118 print("Email sent! Message ID:"),119 print(response['MessageId'])120 121 # if Access Key Age is greater then 90 days, send email alert and inactive access keys122 if active_days >= datetime.timedelta(days=int(os.environ['days_90'])):123 userTags = iam.list_user_tags(UserName=keyValue['UserName'])124 email_tag = list(filter(lambda tag: tag['Key'] == 'email', userTags['Tags']))125 user1_tag = list(filter(lambda tag: tag['Key'] == 'UserType', userTags['Tags']))126 if(len(email_tag) == 1):127 email = email_tag[0]['Value']128 email_90_list.append(email)129 print("The User: ", IAMUserName, ", with the email: ", email, ", is having access key age is greater then 90 days")130 131 if(len(user1_tag) == 1):132 user1tag = user1_tag[0]['Value']133 if user1tag == "Employee":134 iam.update_access_key(AccessKeyId=UserAccessKeyID,Status='Inactive',UserName=IAMUserName)135 print("Status has been updated to Inactive")136 137 email_unique = list(set(email_90_list))...

Full Screen

Full Screen

app.py

Source:app.py Github

copy

Full Screen

...187 ) 188 return json.dumps(response, default=datetime_handler)189 except botocore.exceptions.ClientError as e:190 return f'{e}' 191 def list_user_tags(self, access_key, secret_key, region, user_name, marker, max_items):192 self.iam = self.auth_iam(access_key, secret_key, region)193 client = self.iam.meta.client194 try:195 response = client.list_user_tags(196 UserName = str(user_name)197 )198 if marker:199 response = client.list_user_tags(200 UserName = str(user_name),201 Marker = str(marker)202 )203 if max_items:204 response = client.list_user_tags(205 UserName = str(user_name),206 MaxItems = int(max_items)207 ) 208 if marker and max_items:209 response = client.list_user_tags(210 UserName = str(user_name),211 MaxItems = int(max_items),212 Marker = str(marker) 213 ) 214 return json.dumps(response, default=datetime_handler)215 except botocore.exceptions.ClientError as e:216 return f'{e}'217if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful