How to use secretsmanager_secret_arn method in localstack

Best Python code snippet using localstack_python

secretsmanager.py

Source:secretsmanager.py Github

copy

Full Screen

...15 def cloudformation_type():16 return "AWS::SecretsManager::Secret"17 def get_physical_resource_id(self, attribute, **kwargs):18 props = self.props19 result = props.get("Arn") or aws_stack.secretsmanager_secret_arn(props["Name"])20 return result21 def get_cfn_attribute(self, attribute_name):22 if attribute_name in (REF_ARN_ATTRS + REF_ID_ATTRS):23 return self.get_physical_resource_id(attribute_name)24 return super(SecretsManagerSecret, self).get_cfn_attribute(attribute_name)25 def fetch_state(self, stack_name, resources):26 secret_name = self.props.get("Name") or self.resource_id27 secret_name = self.resolve_refs_recursively(stack_name, secret_name, resources)28 result = aws_stack.connect_to_service("secretsmanager").describe_secret(29 SecretId=secret_name30 )31 return result32 @staticmethod33 def generate_secret_value(34 length: int,35 excl_lower: bool,36 excl_upper: bool,37 excl_chars: str,38 excl_numbers: bool,39 excl_punct: bool,40 incl_spaces: bool,41 req_each: bool,42 ) -> str:43 """WARN: This is NOT a secure way to generate secrets - use only for testing and not in production use cases!"""44 # TODO: add a couple of unit tests for this function ...45 punctuation = r"!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"46 alphabet = ""47 if not excl_punct:48 alphabet += punctuation49 if not excl_upper:50 alphabet += string.ascii_uppercase51 if not excl_lower:52 alphabet += string.ascii_lowercase53 if not excl_numbers:54 alphabet += "".join([str(i) for i in list(range(10))])55 if incl_spaces:56 alphabet += " "57 if req_each:58 LOG.info("Secret generation option 'RequireEachIncludedType' not yet supported")59 for char in excl_chars:60 alphabet = alphabet.replace(char, "")61 result = [alphabet[random.randrange(len(alphabet))] for _ in range(length)]62 result = "".join(result)63 return result64 @classmethod65 def get_deploy_templates(cls):66 def _create_params(params, **kwargs):67 attributes = ["Name", "Description", "KmsKeyId", "SecretString", "Tags"]68 result = select_attributes(params, attributes)69 gen_secret = params.get("GenerateSecretString")70 if gen_secret:71 excl_lower = gen_secret.get("ExcludeLowercase")72 excl_upper = gen_secret.get("ExcludeUppercase")73 excl_chars = gen_secret.get("ExcludeCharacters") or ""74 excl_numbers = gen_secret.get("ExcludeNumbers")75 excl_punct = gen_secret.get("ExcludePunctuation")76 incl_spaces = gen_secret.get("IncludeSpace")77 length = gen_secret.get("PasswordLength") or 3278 req_each = gen_secret.get("RequireEachIncludedType")79 secret_value = cls.generate_secret_value(80 length=length,81 excl_lower=excl_lower,82 excl_upper=excl_upper,83 excl_punct=excl_punct,84 incl_spaces=incl_spaces,85 excl_chars=excl_chars,86 excl_numbers=excl_numbers,87 req_each=req_each,88 )89 template = gen_secret.get("SecretStringTemplate")90 if template:91 gen_key = gen_secret.get("GenerateStringKey") or "secret"92 template = json.loads(template)93 template[gen_key] = secret_value94 secret_value = json.dumps(template)95 result["SecretString"] = secret_value96 return result97 return {98 "create": {99 "function": "create_secret",100 "parameters": _create_params,101 },102 "delete": {"function": "delete_secret", "parameters": {"SecretId": "Name"}},103 }104class SecretsManagerSecretTargetAttachment(GenericBaseModel):105 @staticmethod106 def cloudformation_type():107 return "AWS::SecretsManager::SecretTargetAttachment"108 def get_physical_resource_id(self, attribute, **kwargs):109 return aws_stack.secretsmanager_secret_arn(self.props.get("SecretId"))110 def fetch_state(self, stack_name, resources):111 # TODO implement?112 return {"state": "dummy"}113class SecretsManagerRotationSchedule(GenericBaseModel):114 @staticmethod115 def cloudformation_type():116 return "AWS::SecretsManager::RotationSchedule"117 def get_physical_resource_id(self, attribute, **kwargs):118 return aws_stack.secretsmanager_secret_arn(self.props.get("SecretId"))119 def fetch_state(self, stack_name, resources):120 # TODO implement?121 return {"state": "dummy"}122class SecretsManagerResourcePolicy(GenericBaseModel):123 @staticmethod124 def cloudformation_type():125 return "AWS::SecretsManager::ResourcePolicy"126 def get_physical_resource_id(self, attribute, **kwargs):127 return aws_stack.secretsmanager_secret_arn(self.props.get("SecretId"))128 def fetch_state(self, stack_name, resources):129 secret_id = self.resolve_refs_recursively(stack_name, self.props.get("SecretId"), resources)130 result = aws_stack.connect_to_service("secretsmanager").get_resource_policy(131 SecretId=secret_id132 )133 return result134 @staticmethod135 def get_deploy_templates():136 def create_params(params, **kwargs):137 return {138 "SecretId": params["SecretId"].split(":")[-1],139 "ResourcePolicy": json.dumps(params["ResourcePolicy"]),140 "BlockPublicPolicy": params.get("BlockPublicPolicy"),141 }...

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