Best Python code snippet using localstack_python
lambda_function.py
Source:lambda_function.py
...148 return149 current_version = version150 break151 # Finalize by staging the secret version current152 service_client.update_secret_version_stage(SecretId=arn, VersionStage="AWSCURRENT", MoveToVersionId=token, RemoveFromVersionId=current_version)153 logger.info("finishSecret: Successfully set AWSCURRENT stage to version %s for secret %s. Removed AWSCURRENT from version %s." % (token, arn, current_version))154 # Bump all the previous versions as required by the configuration155 metadata = service_client.describe_secret(SecretId=arn)156 sorted_versions = sorted(metadata["VersionIdsToStages"].items(),key=sort_by_tag)157 max_versions = int(os.environ['SEALER_KEY_VERSION_COUNT'])158 while (len(sorted_versions) > max_versions):159 prune_version_id = sorted_versions[len(sorted_versions)-1][0]160 prune_version_stage = sorted_versions[len(sorted_versions)-1][1][0]161 service_client.update_secret_version_stage(SecretId=arn, VersionStage=prune_version_stage, RemoveFromVersionId=prune_version_id)162 del sorted_versions[-1]163 logger.info("finishSecret: REMOVED Stage %s from version %s" % (prune_version_stage, prune_version_id))164 for offset, version in reversed_enumerate(sorted_versions, start=1):165 version_stage = "AWSPREVIOUS-CUSTOM_"+str(offset)166 if((offset < len(sorted_versions)-1) and (offset < max_versions) and (len(sorted_versions) > offset-1) and (version_stage in sorted_versions[offset+1][1])):167 logger.info("finishSecret: Moving %s stage to version %s from version %s for secret %s." % (version_stage, sorted_versions[offset][0], sorted_versions[offset+1][0], arn))168 service_client.update_secret_version_stage(SecretId=arn, VersionStage=version_stage, MoveToVersionId=sorted_versions[offset][0], RemoveFromVersionId=sorted_versions[offset+1][0])169 logger.info("finishSecret: Successfully set %s stage to version %s for secret %s. Removed %s from version %s." % (version_stage, sorted_versions[offset][0], arn, version_stage, sorted_versions[offset+1][0]))170 elif(offset < len(sorted_versions)):171 logger.info("finishSecret: Setting %s stage to version %s for secret %s." % (version_stage, sorted_versions[offset][0], arn))172 service_client.update_secret_version_stage(SecretId=arn, VersionStage=version_stage, MoveToVersionId=sorted_versions[offset][0])173 logger.info("finishSecret: Successfully set %s stage to version %s for secret %s." % (version_stage, sorted_versions[offset][0], arn))174 metadata = service_client.describe_secret(SecretId=arn)175 sorted_versions = sorted(metadata["VersionIdsToStages"].items(),key=sort_by_tag)...
secretsmanager.py
Source:secretsmanager.py
...182 SecretString=SecretString,183 KmsKeyId=KmsKeyId184 )185 return response186 def update_secret_version_stage(self, SecretId, VersionStage, MoveToVersionId):187 response = self.smClient.update_secret_version_stage(188 SecretId=SecretId,189 VersionStage=VersionStage,190 MoveToVersionId=MoveToVersionId191 )192 return response["ARN"], response["Name"]193 194 def generate_tags(self, name):195 tags = [196 {197 'Key': 'Name',198 'Value': name199 }200 ]201 return tags
rotate_secret_lambda_snippet_parse_output.py
Source:rotate_secret_lambda_snippet_parse_output.py
...6 else:7 ssm_run_command_stderr = ssm_run_command_response['StandardErrorContent']8 publish_sns(sns_topic_arn, "db_rotate_secret: Lambda: Secret rotations has failed",9 "setSecret: RunPowerShellScript has failed with %s." % ssm_run_command_stderr)10 service_client.update_secret_version_stage(SecretId=arn, VersionStage="AWSPENDING",11 RemoveFromVersionId=token)...
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!!