Best Python code snippet using localstack_python
provider.py
Source:provider.py
...36 if "/" in param_name:37 param_name = "/%s" % param_name38 return param_name39 @staticmethod40 def _get_secrets_information(41 name: ParameterName, resource_name: str42 ) -> Optional[GetParameterResult]:43 client = aws_stack.connect_to_service("secretsmanager")44 try:45 secret_info = client.get_secret_value(SecretId=resource_name)46 del secret_info["ResponseMetadata"]47 created_date_timestamp = time.mktime(secret_info["CreatedDate"].timetuple())48 secret_info["CreatedDate"] = created_date_timestamp49 result = {50 "Parameter": {51 "SourceResult": json.dumps(secret_info, default=str),52 "Name": name,53 "Value": secret_info.get("SecretString"),54 "Type": "SecureString",55 "LastModifiedDate": created_date_timestamp,56 }57 }58 return GetParameterResult(**result)59 except client.exceptions.ResourceNotFoundException:60 return None61 @staticmethod62 def _get_params_and_secrets(names: ParameterNameList) -> GetParametersResult:63 ssm_client = aws_stack.connect_to_service("ssm")64 result = {"Parameters": [], "InvalidParameters": []}65 for name in names:66 if name.startswith(PARAM_PREFIX_SECRETSMANAGER):67 secret = SsmProvider._get_secrets_information(68 name, name[len(PARAM_PREFIX_SECRETSMANAGER) + 1 :]69 )70 if secret is not None:71 secret = secret["Parameter"]72 result["Parameters"].append(secret)73 else:74 result["InvalidParameters"].append(name)75 else:76 try:77 param = ssm_client.get_parameter(Name=name)78 param["Parameter"]["LastModifiedDate"] = time.mktime(79 param["Parameter"]["LastModifiedDate"].timetuple()80 )81 result["Parameters"].append(param["Parameter"])82 except ssm_client.exceptions.ParameterNotFound:83 result["InvalidParameters"].append(name)84 return GetParametersResult(**result)85 @staticmethod86 def _notify_event_subscribers(name: ParameterName, operation: str):87 """Publish an EventBridge event to notify subscribers of changes."""88 if not is_api_enabled("events"):89 return90 events = aws_stack.connect_to_service("events")91 detail = {"name": name, "operation": operation}92 event = {93 "Source": "aws.ssm",94 "Detail": json.dumps(detail),95 "DetailType": "Parameter Store Change",96 }97 events.put_events(Entries=[event])98 def get_parameters(99 self,100 context: RequestContext,101 names: ParameterNameList,102 with_decryption: Boolean = None,103 ) -> GetParametersResult:104 if SsmProvider._has_secrets(names):105 return SsmProvider._get_params_and_secrets(names)106 names = list([SsmProvider._normalize_name(name) for name in names])107 request = {"Names": names, "WithDecryption": bool(with_decryption)}108 res = call_moto_with_request(context, request)109 return GetParametersResult(**res)110 def put_parameter(111 self, context: RequestContext, request: PutParameterRequest112 ) -> PutParameterResult:113 name = request["Name"]114 nname = SsmProvider._normalize_name(name)115 if name != nname:116 request.update({"Name": nname})117 moto_res = call_moto_with_request(context, request)118 else:119 moto_res = call_moto(context)120 SsmProvider._notify_event_subscribers(nname, "Create")121 return PutParameterResult(**moto_res)122 def get_parameter(123 self,124 context: RequestContext,125 name: PSParameterName,126 with_decryption: Boolean = None,127 ) -> GetParameterResult:128 result = None129 #130 name = SsmProvider._normalize_name(name)131 details = name.split("/")132 if len(details) > 4:133 service = details[3]134 if service == "secretsmanager":135 resource_name = "/".join(details[4:])136 result = SsmProvider._get_secrets_information(name, resource_name)137 #138 if not result:139 result = call_moto_with_request(140 context, {"Name": name, "WithDecryption": bool(with_decryption)}141 )142 #143 return GetParameterResult(**result)144 def delete_parameter(145 self, context: RequestContext, name: PSParameterName146 ) -> DeleteParameterResult:147 SsmProvider._notify_event_subscribers(name, "Delete")148 call_moto(context) # Return type is an emtpy type.149 return DeleteParameterResult()150 def label_parameter_version(...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!