Best Python code snippet using localstack_python
storage_rotate_encryption_key.py
Source:storage_rotate_encryption_key.py
...17# [END storage_rotate_encryption_key]18import sys19# [START storage_rotate_encryption_key]20from google.cloud import storage21def rotate_encryption_key(22 bucket_name, blob_name, base64_encryption_key, base64_new_encryption_key23):24 """Performs a key rotation by re-writing an encrypted blob with a new25 encryption key."""26 storage_client = storage.Client()27 bucket = storage_client.bucket(bucket_name)28 current_encryption_key = base64.b64decode(base64_encryption_key)29 new_encryption_key = base64.b64decode(base64_new_encryption_key)30 # Both source_blob and destination_blob refer to the same storage object,31 # but destination_blob has the new encryption key.32 source_blob = bucket.blob(33 blob_name, encryption_key=current_encryption_key34 )35 destination_blob = bucket.blob(36 blob_name, encryption_key=new_encryption_key37 )38 token = None39 while True:40 token, bytes_rewritten, total_bytes = destination_blob.rewrite(41 source_blob, token=token42 )43 if token is None:44 break45 print("Key rotation complete for Blob {}".format(blob_name))46# [END storage_rotate_encryption_key]47if __name__ == "__main__":48 rotate_encryption_key(49 bucket_name=sys.argv[1],50 blob_name=sys.argv[2],51 base64_encryption_key=sys.argv[3],52 base64_new_encryption_key=sys.argv[4],...
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!!