#NEWLINE# def rotate_key( bucket , obj , current_encryption_key , current_key_hash , new_encryption_key , new_key_hash ) : #NEWLINE# #INDENT# 'Changes the encryption key used to store an existing object.' #NEWLINE# service = create_service ( ) #NEWLINE# request = service . objects ( ) . rewrite ( sourceBucket = bucket , sourceObject = obj , destinationBucket = bucket , destinationObject = obj , body = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# while True : #NEWLINE# #INDENT# request . headers . update ( { #NEWLINE# #INDENT# 'x-goog-copy-source-encryption-algorithm' : 'AES256' , #NEWLINE# 'x-goog-copy-source-encryption-key' : current_encryption_key , #NEWLINE# 'x-goog-copy-source-encryption-key-sha256' : current_key_hash , #NEWLINE# 'x-goog-encryption-algorithm' : 'AES256' , #NEWLINE# 'x-goog-encryption-key' : new_encryption_key , #NEWLINE# 'x-goog-encryption-key-sha256' : new_key_hash , #NEWLINE# #UNINDENT# } ) #NEWLINE# rewrite_response = request . execute ( ) #NEWLINE# if rewrite_response [ 'done' ] : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# print ( 'Continuing rewrite call...' ) #NEWLINE# request = service . objects ( ) . rewrite ( source_bucket = bucket , source_object = obj , destination_bucket = bucket , destination_object = obj , rewriteToken = rewrite_response [ 'rewriteToken' ] ) #NEWLINE# rewrite_response . execute ( )