How to use _raise_if_invalid_secret_id method in localstack

Best Python code snippet using localstack_python

provider.py

Source:provider.py Github

copy

Full Screen

...93 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(127 self, context: RequestContext, request: CreateSecretRequest128 ) -> CreateSecretResponse:129 self._raise_if_invalid_secret_id(request["Name"])130 return call_moto(context)131 @handler("DeleteResourcePolicy", expand=False)132 def delete_resource_policy(133 self, context: RequestContext, request: DeleteResourcePolicyRequest134 ) -> DeleteResourcePolicyResponse:135 self._raise_if_invalid_secret_id(request["SecretId"])136 return self._call_moto_with_request_secret_id(context, request)137 @handler("DeleteSecret", expand=False)138 def delete_secret(139 self, context: RequestContext, request: DeleteSecretRequest140 ) -> DeleteSecretResponse:141 self._raise_if_invalid_secret_id(request["SecretId"])142 return self._call_moto_with_request_secret_id(context, request)143 @handler("DescribeSecret", expand=False)144 def describe_secret(145 self, context: RequestContext, request: DescribeSecretRequest146 ) -> DescribeSecretResponse:147 self._raise_if_invalid_secret_id(request["SecretId"])148 res = self._call_moto_with_request_secret_id(context, request)149 return res150 @handler("GetResourcePolicy", expand=False)151 def get_resource_policy(152 self, context: RequestContext, request: GetResourcePolicyRequest153 ) -> GetResourcePolicyResponse:154 self._raise_if_invalid_secret_id(request["SecretId"])155 return self._call_moto_with_request_secret_id(context, request)156 @handler("GetSecretValue", expand=False)157 def get_secret_value(158 self, context: RequestContext, request: GetSecretValueRequest159 ) -> GetSecretValueResponse:160 self._raise_if_invalid_secret_id(request["SecretId"])161 return self._call_moto_with_request_secret_id(context, request)162 @handler("ListSecretVersionIds", expand=False)163 def list_secret_version_ids(164 self, context: RequestContext, request: ListSecretVersionIdsRequest165 ) -> ListSecretVersionIdsResponse:166 self._raise_if_invalid_secret_id(request["SecretId"])167 return self._call_moto_with_request_secret_id(context, request)168 @handler("PutResourcePolicy", expand=False)169 def put_resource_policy(170 self, context: RequestContext, request: PutResourcePolicyRequest171 ) -> PutResourcePolicyResponse:172 self._raise_if_invalid_secret_id(request["SecretId"])173 return self._call_moto_with_request_secret_id(context, request)174 @handler("PutSecretValue", expand=False)175 def put_secret_value(176 self, context: RequestContext, request: PutSecretValueRequest177 ) -> PutSecretValueResponse:178 self._raise_if_invalid_secret_id(request["SecretId"])179 return self._call_moto_with_request_secret_id(context, request)180 @handler("RemoveRegionsFromReplication", expand=False)181 def remove_regions_from_replication(182 self, context: RequestContext, request: RemoveRegionsFromReplicationRequest183 ) -> RemoveRegionsFromReplicationResponse:184 self._raise_if_invalid_secret_id(request["SecretId"])185 return self._call_moto_with_request_secret_id(context, request)186 @handler("ReplicateSecretToRegions", expand=False)187 def replicate_secret_to_regions(188 self, context: RequestContext, request: ReplicateSecretToRegionsRequest189 ) -> ReplicateSecretToRegionsResponse:190 self._raise_if_invalid_secret_id(request["SecretId"])191 return self._call_moto_with_request_secret_id(context, request)192 @handler("RestoreSecret", expand=False)193 def restore_secret(194 self, context: RequestContext, request: RestoreSecretRequest195 ) -> RestoreSecretResponse:196 self._raise_if_invalid_secret_id(request["SecretId"])197 return self._call_moto_with_request_secret_id(context, request)198 @handler("RotateSecret", expand=False)199 def rotate_secret(200 self, context: RequestContext, request: RotateSecretRequest201 ) -> RotateSecretResponse:202 self._raise_if_invalid_secret_id(request["SecretId"])203 return self._call_moto_with_request_secret_id(context, request)204 @handler("StopReplicationToReplica", expand=False)205 def stop_replication_to_replica(206 self, context: RequestContext, request: StopReplicationToReplicaRequest207 ) -> StopReplicationToReplicaResponse:208 self._raise_if_invalid_secret_id(request["SecretId"])209 return self._call_moto_with_request_secret_id(context, request)210 @handler("TagResource", expand=False)211 def tag_resource(self, context: RequestContext, request: TagResourceRequest) -> None:212 self._raise_if_invalid_secret_id(request["SecretId"])213 return self._call_moto_with_request_secret_id(context, request)214 @handler("UntagResource", expand=False)215 def untag_resource(self, context: RequestContext, request: UntagResourceRequest) -> None:216 self._raise_if_invalid_secret_id(request["SecretId"])217 return self._call_moto_with_request_secret_id(context, request)218 @handler("UpdateSecret", expand=False)219 def update_secret(220 self, context: RequestContext, request: UpdateSecretRequest221 ) -> UpdateSecretResponse:222 self._raise_if_invalid_secret_id(request["SecretId"])223 return self._call_moto_with_request_secret_id(context, request)224 @handler("UpdateSecretVersionStage", expand=False)225 def update_secret_version_stage(226 self, context: RequestContext, request: UpdateSecretVersionStageRequest227 ) -> UpdateSecretVersionStageResponse:228 self._raise_if_invalid_secret_id(request["SecretId"])229 return self._call_moto_with_request_secret_id(context, request)230 @handler("ValidateResourcePolicy", expand=False)231 def validate_resource_policy(232 self, context: RequestContext, request: ValidateResourcePolicyRequest233 ) -> ValidateResourcePolicyResponse:234 self._raise_if_invalid_secret_id(request["SecretId"])235 return self._call_moto_with_request_secret_id(context, request)236@patch(FakeSecret.__init__)237def fake_secret__init__(fn, self, **kwargs):238 fn(self, **kwargs)239 # Fix time not including millis.240 time_now = time.time()241 if kwargs.get("last_changed_date", None):242 self.last_changed_date = time_now243 if kwargs.get("created_date", None):244 self.created_date = time_now245 # The last date that the secret value was retrieved.246 # This value does not include the time.247 # This field is omitted if the secret has never been retrieved.248 self.last_accessed_date = None...

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