Best Python code snippet using localstack_python
provider.py
Source:provider.py  
...74    def __init__(self):75        super().__init__()76        apply_patches()77    @staticmethod78    def _transform_context_secret_id(secret_id: SecretIdType) -> Optional[SecretIdType]:79        # If secret ARN ends with "-<randomId>" this is removed from the request for upstream compatibility.80        t_secret_id = secret_id81        if secret_id and re.match(r"^arn:", secret_id):82            arn = aws_stack.parse_arn(secret_id)83            aws_region = aws_stack.get_region()84            if arn["region"] != aws_region:85                LOG.info(f'Expected request region "{aws_region}" for secret "{secret_id}"')86            resource_id = arn["resource"].split(":")[-1]87            if resource_id[-7] == "-":88                t_secret_id = resource_id[:-7]89            elif resource_id[-1] != "-":90                t_secret_id += "-"91        return None if secret_id == t_secret_id else t_secret_id92    @staticmethod93    def _validate_secret_id(secret_id: SecretIdType) -> bool:94        # The secret name can contain ASCII letters, numbers, and the following characters: /_+=.@-95        return bool(re.match(r"^[A-Za-z0-9/_+=.@-]+\Z", secret_id))96    @staticmethod97    def _raise_if_invalid_secret_id(secret_id: Union[SecretIdType, NameType]):98        # Patches moto's implementation for which secret_ids are not validated, by raising a ValidationException.99        # Skips this check if the secret_id provided appears to be an arn (starting with 'arn:').100        if not re.match(101            r"^arn:", secret_id102        ):  # Check if it appears to be an arn: so to skip secret_id check: delegate parsing of arn to handlers.103            if not SecretsmanagerProvider._validate_secret_id(secret_id):104                raise ValidationException(105                    "Invalid name. Must be a valid name containing alphanumeric "106                    "characters, or any of the following: -/_+=.@!"107                )108    @staticmethod109    def _call_moto_with_request_secret_id(110        context: RequestContext, request: Dict111    ) -> ServiceResponse:112        t_secret_id = SecretsmanagerProvider._transform_context_secret_id(113            request.get("SecretId", None)114        )115        if t_secret_id:116            request.update({"SecretId": t_secret_id})117            return call_moto_with_request(context, request)118        return call_moto(context)119    @handler("CancelRotateSecret", expand=False)120    def cancel_rotate_secret(121        self, context: RequestContext, request: CancelRotateSecretRequest122    ) -> CancelRotateSecretResponse:123        self._raise_if_invalid_secret_id(request["SecretId"])124        return self._call_moto_with_request_secret_id(context, request)125    @handler("CreateSecret", expand=False)126    def create_secret(...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!!
