How to use retire_grant method in localstack

Best Python code snippet using localstack_python

grant_management.py

Source:grant_management.py Github

copy

Full Screen

...61 pprint(grants)62 return grants63# snippet-end:[python.example_code.kms.ListGrants]64# snippet-start:[python.example_code.kms.RetireGrant]65 def retire_grant(self, grant):66 """67 Retires a grant so that it can no longer be used.68 :param grant: The grant to retire.69 """70 try:71 self.kms_client.retire_grant(GrantToken=grant['GrantToken'])72 except ClientError as err:73 logger.error(74 "Couldn't retire grant %s. Here's why: %s",75 grant['GrantId'], err.response['Error']['Message'])76 else:77 print(f"Grant {grant['GrantId']} retired.")78# snippet-end:[python.example_code.kms.RetireGrant]79# snippet-start:[python.example_code.kms.RevokeGrant]80 def revoke_grant(self, key_id, grant):81 """82 Revokes a grant so that it can no longer be used.83 :param key_id: The ARN or ID of the key associated with the grant.84 :param grant: The grant to revoke.85 """86 try:87 self.kms_client.revoke_grant(KeyId=key_id, GrantId=grant['GrantId'])88 except ClientError as err:89 logger.error(90 "Couldn't revoke grant %s. Here's why: %s",91 grant['GrantId'], err.response['Error']['Message'])92 else:93 print(f"Grant {grant['GrantId']} revoked.")94# snippet-end:[python.example_code.kms.RevokeGrant]95def grant_management(kms_client):96 logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')97 print('-'*88)98 print("Welcome to the AWS Key Management Service (AWS KMS) grant management demo.")99 print('-'*88)100 key_id = input("Enter a key ID or ARN to start the demo: ")101 if key_id == '':102 print("A key is required to run this demo.")103 return104 grant_manager = GrantManager(kms_client)105 grant = grant_manager.create_grant(key_id)106 print('-'*88)107 grant_manager.list_grants(key_id)108 print('-'*88)109 if grant is not None:110 action = input("Let's remove the demo grant. Enter 'retire' or 'revoke': ")111 if action == 'retire':112 grant_manager.retire_grant(grant)113 elif action == 'revoke':114 grant_manager.revoke_grant(key_id, grant)115 else:116 print("Skipping grant removal.")117 print("\nThanks for watching!")118 print('-'*88)119if __name__ == '__main__':120 try:121 grant_management(boto3.client('kms'))122 except Exception:123 logging.exception("Something went wrong with the demo!")...

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