How to use get_policy_version method in localstack

Best Python code snippet using localstack_python

test-hdfs-policy.py

Source:test-hdfs-policy.py Github

copy

Full Screen

...52admin_delete_grp_url_template = "{}/service/xusers/secure/groups/{}?forceDelete=true".format(args.host.rstrip('/'), "{}")53admin_delete_rol_url_template = "{}/service/roles/roles/name/{}".format(args.host.rstrip('/'), "{}")54def log(log_group, message):55 print(str(datetime.now()) + " [" + log_group + "] " + message)56def get_policy_version():57 resp = session.get(admin_get_service_url)58 assert resp.status_code == 200, "Failed to fetch policy version"59 return resp.json()["policyVersion"]60def test_create_policy(log_group, policy_json):61 log(log_group, " Create policy URL: " + str(admin_create_url))62 policy_version_v1 = get_policy_version()63 resp = session.post(admin_create_url, data=json.dumps(policy_json))64 policy_version_v2 = get_policy_version()65 assert resp.status_code == 200, "Create policy request failed"66 assert policy_version_v1 != policy_version_v2, "Policy version did not updated after create. policyVersion=" + policy_version_v267 policy_id = resp.json()["id"]68 log(log_group, " Policy ID: " + str(policy_id))69 log(log_group, " Waiting for {} milliseconds".format(wait_between_commands))70 time.sleep(wait_between_commands/1000)71 return policy_id72def test_get_policy(log_group, policy_id, flag=True):73 log(log_group, " Get policy URL: " + str(admin_get_url))74 resp = session.get(admin_get_url)75 assert resp.status_code == 200, "Get policy request failed"76 resp_text = resp.text77 if flag:78 assert '"id":{}'.format(policy_id) in resp_text, resp_text79 else:80 assert not '"id":{}'.format(policy_id) in resp_text, resp_text81def test_update_policy(log_group, policy_json, policy_id):82 policy_json['description'] = "This is a test policy created to test policy cache functionality."83 policy_json['id'] = policy_id84 update_url = admin_update_url_template.format(policy_id)85 log(log_group, " Update policy URL: " + str(update_url))86 policy_version_v1 = get_policy_version()87 resp = session.put(update_url, data=json.dumps(policy_json))88 policy_version_v2 = get_policy_version()89 assert resp.status_code == 200, "Update policy request failed"90 assert policy_version_v1 != policy_version_v2, "Policy version did not updated after create. policyVersion=" + policy_version_v291 log(log_group, " Waiting for {} milliseconds".format(wait_between_commands))92 time.sleep(wait_between_commands/1000)93def test_delete_policy(log_group, policy_id):94 delete_url = admin_delete_url_template.format(policy_id)95 log(log_group, " Delete policy URL: " + str(delete_url))96 policy_version_v1 = get_policy_version()97 resp = session.delete(delete_url)98 policy_version_v2 = get_policy_version()99 assert resp.status_code == 204, "Delete policy request failed"100 assert policy_version_v1 != policy_version_v2, "Policy version did not updated after create. policyVersion=" + policy_version_v2101def test_policy(log_group, policy_json):102 log(log_group, "[START] LastKnownPolicyVersion=" + str(get_policy_version()))103 # Create Policy104 policy_id = test_create_policy(log_group, policy_json)105 # Get Policy106 test_get_policy(log_group, policy_id)107 # Update Policy108 test_update_policy(log_group, policy_json, policy_id)109 # Get Policy110 test_get_policy(log_group, policy_id)111 # Delete Policy112 test_delete_policy(log_group, policy_id)113 # Get Policy114 test_get_policy(log_group, policy_id, False)115 log(log_group, "[END] LastKnownPolicyVersion=" + str(get_policy_version()))116 log(log_group, "test_policy function finished, waiting for {} milliseconds".format(wait_between_commands))117 time.sleep(wait_between_commands/1000)118def get_policy_json(in_fix=""):119 json_data = json.loads(admin_create_data_template)120 json_data['name'] = "test-{}-{}".format(in_fix, currentIndex)121 json_data['service'] = args.serviceName122 json_data['resources']['path']['values'] = ["/dummy-hdfs-path-{}-{}".format(in_fix, currentIndex)]123 return json_data124def test_delete_user(log_group, uname):125 delete_user_url = admin_delete_usr_url_template.format(uname)126 log(log_group, "Delete user URL: " + str(delete_user_url))127 resp = session.delete(delete_user_url)128 assert resp.status_code == 204, "Delete user request failed. [User=" + str(uname) + " ,, response code=" + str(resp.status_code) + "]"129def test_delete_group(log_group, gname):...

Full Screen

Full Screen

get_policy_version.py

Source:get_policy_version.py Github

copy

Full Screen

...2526version_id = get_policy_response['Policy']['DefaultVersionId']2728# Get default version of policy29get_policy_version_response = iam.get_policy_version(30 PolicyArn=policy_arn,31 VersionId=version_id,32)3334policy_document = get_policy_version_response['PolicyVersion']['Document']3536print("IAM Policy Version: " + policy_document['Version'])37print("Statements: ")38for statement in policy_document['Statement']:39 print(statement)4041print("\n\rUnformatted Policy Document: \n\r" + str(policy_document))4243# snippet-end:[iam.python.get_policy_version.complete] ...

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