How to use finish_secret method in localstack

Best Python code snippet using localstack_python

windows_rotation.py

Source: windows_rotation.py Github

copy

Full Screen

...20 set_secret(service_client, arn, token)21 elif step == "testSecret":22 test_secret(service_client, arn, token)23 elif step == "finishSecret":24 finish_secret(service_client, arn, token)25 else:26 raise ValueError("Invalid step parameter")27def create_secret(service_client, arn, token):28 print('------ Inside create_secret ------')29 mysecretresponse = service_client.describe_secret(SecretId=arn)30 print("mysecretresponse",mysecretresponse)31 # we need this unicode conversion because the tags are in unicode and we have back errors32 for tag in mysecretresponse['Tags']:33 if tag['Key'] == 'instanceid':34 instance = tag['Value']35 print('working on instnaceid ' + str(instance))36 client = boto3.client('ssm')37 try:38 # Generate a random password39 print('Generating new password')40 # create a parameter store to pass the new generated password in a secure way41 ssm = "alias/​aws/​ssm"42 print('Send command to change the password to the instance')43 response = client.send_command(DocumentName="AWSSupport-RunEC2RescueForWindowsTool",44 Targets=[{"Key": "InstanceIds", "Values": [instance]}],45 Parameters={"Command": ["ResetAccess"], "Parameters": [ssm]}, TimeoutSeconds=600,46 MaxConcurrency="50", MaxErrors="0")47 print("send_command : ", response)48 print('sleepping')49 time.sleep(60)50 response = client.get_parameter(51 Name="/​EC2Rescue/​Passwords/​"+instance,52 WithDecryption=True53 )54 print(response)55 print('Put the new password in a secret')56 secure_string = '{ \"Administrator\": \"' + response['Parameter']['Value'] + '\"\n }'57 print('password :' + response['Parameter']["Value"])58 service_client.put_secret_value(SecretId=arn, ClientRequestToken=token, SecretString=secure_string,59 VersionStages=['AWSCURRENT'])60 logger.info("createSecret: Successfully put secret for ARN %s and version %s." % (arn, token))61 # Before delete the parameter we need to wait some seconds that the powershell will be executed62 # the above send_command is asyncronous63 print('Delete parameter')64 response = client.delete_parameter(65 Name="/​EC2Rescue/​Passwords/​"+instance,66 )67 time.sleep(20)68 return True69 except Exception as e:70 print("Error")71 print(e)72 return False73def set_secret(service_client, arn, token):74 print('------ Inside set_secret ------')75 print('nothing to be done here left because secret manager needs to call this')76 return True77def test_secret(service_client, arn, token):78 print('------ Inside test_secret ------')79 print('nothing to be done here left because secret manager needs to call this')80 return True81def finish_secret(service_client, arn, token):82 print('------ Inside finish_secret ------')83 print('nothing to be done here left because secret manager needs to call this')...

Full Screen

Full Screen

17_rotate_secrets.py

Source: 17_rotate_secrets.py Github

copy

Full Screen

...16 set_secret(service_client, arn, token)17 elif step == "testSecret":18 test_secret(service_client, arn, token)19 elif step == "finishSecret":20 finish_secret(service_client, arn, token)21 else:22 raise ValueError("Invalid step parameter")23def create_secret(service_client, arn, token):24 service_client.get_secret_value(SecretId=arn, VersionStage="AWSCURRENT")25 # Now try to get the secret version, if that fails, put a new secret26 try:27 service_client.get_secret_value(SecretId=arn, VersionId=token, VersionStage="AWSPENDING")28 except service_client.exceptions.ResourceNotFoundException:29 # Generate a random password30 passwd = service_client.get_random_password(ExcludeCharacters='/​@"\'\\')31 # Put the secret32 service_client.put_secret_value(SecretId=arn, ClientRequestToken=token, SecretString=passwd['RandomPassword'], VersionStages=['AWSPENDING'])33def set_secret(service_client, arn, token):34 print("No database user credentials to update...")35def test_secret(service_client, arn, token):36 print("No need to testing against any service...")37def finish_secret(service_client, arn, token):38 39 # First describe the secret to get the current version40 metadata = service_client.describe_secret(SecretId=arn)41 for version in metadata["VersionIdsToStages"]:42 if "AWSCURRENT" in metadata["VersionIdsToStages"][version]:43 if version == token:44 # The correct version is already marked as current, return45 return46 # Finalize by staging the secret version current47 service_client.update_secret_version_stage(SecretId=arn, VersionStage="AWSCURRENT", MoveToVersionId=token, RemoveFromVersionId=version)48 break...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

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