How to use list_policy_tags method in localstack

Best Python code snippet using localstack_python

policy_tag_operation.py

Source:policy_tag_operation.py Github

copy

Full Screen

...14 policy_tag.parent_policy_tag = parent_policy_tag15 policy_tag = client.create_policy_tag(parent = taxonomy, policy_tag = policy_tag)16 print(f"""Policy tag "{policy_tag.name}" created.""")17 return policy_tag18def list_policy_tags(taxonomy):19 client = datacatalog.PolicyTagManagerClient()20 request = datacatalog.ListPolicyTagsRequest()21 request.parent = taxonomy22 policy_tag = client.list_policy_tags(request=request)23 result = []24 for pt in policy_tag:25 result.append(pt)26 return result27def get_policy_tag(taxonomy, display_name):28 policy_tags = list_policy_tags(taxonomy)29 result = ""30 for pt in policy_tags:31 if pt.display_name == display_name:32 result = pt.name33 return result34def attach_policy_tag(project_id, dataset_name, table_name, column_list, policy_tag):35 client = bigquery.Client(project=project_id)36 table_id = f"{project_id}.{dataset_name}.{table_name}"37 table = client.get_table(table_id)38 # get the original schema of the table39 original_schema = table.schema40 # update the original schema with policy tag41 new_schema = []42 attached_columns = []...

Full Screen

Full Screen

iam.py

Source:iam.py Github

copy

Full Screen

...28def _process_create_policy(event: dict, set_tag: bool = False) -> list:29 """ Process CreatePolicy event. """30 if set_tag is True:31 policy_arn = event['responseElements']['policy']['arn']32 tags = iam.list_policy_tags(PolicyArn=policy_arn)['Tags']33 if check_contain_mandatory_tag_list(tags) is False:34 iam.tag_policy(PolicyArn=policy_arn,35 Tags=[{36 'Key': 'User',37 'Value': get_user_identity(event)38 }])39 return [event['responseElements']['policy']['policyName']]40def _process_create_instance_profile(event: dict, set_tag: bool = False) -> list:41 """ Process CreateInstanceProfile event. """42 instance_profile_name = event['responseElements']['instanceProfile']['instanceProfileName']43 if set_tag is True:44 tags = iam.list_instance_profile_tags(InstanceProfileName=instance_profile_name)['Tags']45 if check_contain_mandatory_tag_list(tags) is False:46 iam.tag_instance_profile(InstanceProfileName=instance_profile_name,...

Full Screen

Full Screen

IAM policy.py

Source:IAM policy.py Github

copy

Full Screen

...39 iam = boto3.client("iam")40 response = iam.list_policies(Scope='Local')41 for policy in response['Policies']:42 if policy['AttachmentCount'] ==0 :43 tags = iam.list_policy_tags(PolicyArn=policy['Arn'])44 for tag in tags['Tags']:45 if(tag.get("Key") ==key ):46 unused_fdate = tag.get("Value")47 user = [tag.get("Value").split('@')[0] for tag in tags['Tags'] if tag.get("Key") =="CreatedBy"]48 if user:49 user_name = user[0]50 else:51 user_name = None52 termination_time = (datetime.strptime(unused_fdate, "%Y-%m-%d") + timedelta(days=5)).date()53 if current_time >= termination_time:54 try:55 response = iam.list_policy_versions(PolicyArn=policy['Arn'])56 for version in response['Versions']:57 if version['IsDefaultVersion'] != True:58 iam.delete_policy_version(PolicyArn=policy['Arn'],VersionId=version['VersionId'])59 iam.delete_policy(PolicyArn=policy['Arn'])60 except Exception as e:61 logging.info(f"Unable to delete policy {policy['Arn']}" +str(e))62 elif poli == "":63 poli = poli + "\nUnused policy: \n" 64 poli = poli + f"User: {user_name}, policy name: {policy['PolicyName']}, Termination Date: {termination_time} \n"65 else:66 poli = poli + f"User: {user_name}, policy name: {policy['PolicyName']}, Termination Da: {termination_time} \n"67 68 if not any(tag.get('Key') == key for tag in tags['Tags']):69 iam.tag_policy(PolicyArn=policy['Arn'] , Tags=[{'Key': key, 'Value': value} ])70 logging.info(f"Tag created for the policy-{policy['PolicyName']}")71 else :72 tags = iam.list_policy_tags(PolicyArn=policy['Arn'])73 if(tag.get("Key") ==key for tag in tags['Tags']):74 iam.untag_policy(PolicyArn=policy['Arn'],TagKeys=[key]) ...

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