3232import os
3333
3434from google .cloud import storage
35+ from google .cloud .storage import Blob
3536
3637
3738def generate_encryption_key ():
@@ -57,12 +58,11 @@ def upload_encrypted_blob(bucket_name, source_file_name,
5758 """
5859 storage_client = storage .Client ()
5960 bucket = storage_client .get_bucket (bucket_name )
60- blob = bucket .blob (destination_blob_name )
61-
6261 # Encryption key must be an AES256 key represented as a bytestring with
6362 # 32 bytes. Since it's passed in as a base64 encoded string, it needs
6463 # to be decoded.
65- blob .encryption_key = base64 .b64decode (base64_encryption_key )
64+ encryption_key = base64 .b64decode (base64_encryption_key )
65+ blob = Blob (destination_blob_name , bucket , encryption_key = encryption_key )
6666
6767 blob .upload_from_filename (source_file_name )
6868
@@ -80,12 +80,11 @@ def download_encrypted_blob(bucket_name, source_blob_name,
8080 """
8181 storage_client = storage .Client ()
8282 bucket = storage_client .get_bucket (bucket_name )
83- blob = bucket .blob (source_blob_name )
84-
8583 # Encryption key must be an AES256 key represented as a bytestring with
8684 # 32 bytes. Since it's passed in as a base64 encoded string, it needs
8785 # to be decoded.
88- blob .encryption_key = base64 .b64decode (base64_encryption_key )
86+ encryption_key = base64 .b64decode (base64_encryption_key )
87+ blob = Blob (source_blob_name , bucket , encryption_key = encryption_key )
8988
9089 blob .download_to_filename (destination_file_name )
9190
@@ -131,9 +130,9 @@ def rotate_encryption_key(bucket_name, blob_name, base64_encryption_key,
131130 'rotate' , help = rotate_encryption_key .__doc__ )
132131 rotate_parser .add_argument (
133132 'bucket_name' , help = 'Your cloud storage bucket.' )
134- download_parser .add_argument ('blob_name' )
135- download_parser .add_argument ('base64_encryption_key' )
136- download_parser .add_argument ('base64_new_encryption_key' )
133+ rotate_parser .add_argument ('blob_name' )
134+ rotate_parser .add_argument ('base64_encryption_key' )
135+ rotate_parser .add_argument ('base64_new_encryption_key' )
137136
138137 args = parser .parse_args ()
139138
0 commit comments