How to use kms_create_alias method in localstack

Best Python code snippet using localstack_python

fixtures.py

Source:fixtures.py Github

copy

Full Screen

...624# kms_create_key fixture is used here not just to be able to create aliases without a key specified,625# but also to make sure that kms_create_key gets executed before and teared down after kms_create_alias -626# to make sure that we clean up aliases before keys get cleaned up.627@pytest.fixture()628def kms_create_alias(kms_client, kms_create_key):629 aliases = []630 def _create_alias(**kwargs):631 if "AliasName" not in kwargs:632 kwargs["AliasName"] = f"alias/{short_uid()}"633 if "TargetKeyId" not in kwargs:634 kwargs["TargetKeyId"] = kms_create_key()["KeyId"]635 kms_client.create_alias(**kwargs)636 aliases.append(kwargs["AliasName"])637 return kwargs["AliasName"]638 yield _create_alias639 for alias in aliases:640 try:641 kms_client.delete_alias(AliasName=alias)642 except Exception as e:...

Full Screen

Full Screen

test_kms.py

Source:test_kms.py Github

copy

Full Screen

...189 return alias_list_entry["AliasArn"]190 key_metadata = kms_create_key()191 key_arn = key_metadata["Arn"]192 key_id = key_metadata["KeyId"]193 alias_name = kms_create_alias(TargetKeyId=key_id)194 alias_arn = get_alias_arn_by_alias_name(kms_client, alias_name)195 assert alias_arn196 kms_client.encrypt(KeyId=key_arn, Plaintext="encrypt-me")197 kms_client.encrypt(KeyId=key_id, Plaintext="encrypt-me")198 kms_client.encrypt(KeyId=alias_arn, Plaintext="encrypt-me")...

Full Screen

Full Screen

kms.py

Source:kms.py Github

copy

Full Screen

...37 create_key_params['Policy'] = policy38 logger.debug({'create_key_params': create_key_params})39 return client.create_key(**create_key_params).get('KeyMetadata')40@boto_client('kms')41def kms_create_alias(alias_name, key_id, region=None, client=None):42 alias_name = __alias_name(alias_name)43 create_alias_params = {44 'AliasName': alias_name,45 'TargetKeyId': key_id46 }47 logger.debug({'create_alias_params': create_alias_params})48 try:49 client.create_alias(**create_alias_params)50 except Exception as e:51 logger.error(str(e))52 return False53 return True54def kms_ensure_key(alias_name, description=None, policy=None, bypass_policy_lockout_safety_check=False,55 key_usage='ENCRYPT_DECRYPT', origin='AWS_KMS', tags=[], region=None):56 alias_name = __alias_name(alias_name)57 key_alias = get_alias_attr(alias_name, region=region)58 if not key_alias:59 logger.debug('[kms_ensure_key] key does not exist... creating it...')60 if description is None:61 description = alias_name62 key = kms_create_key(63 description=description,64 policy=policy,65 bypass_policy_lockout_safety_check=bypass_policy_lockout_safety_check,66 key_usage=key_usage,67 origin=origin,68 tags=tags,69 region=region70 )71 if kms_create_alias(alias_name, key['KeyId'], region=region):72 # need to get the new alias arn73 key_alias = get_alias_attr(alias_name, region=region)...

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