32
32
import os
33
33
34
34
from google .cloud import storage
35
+ from google .cloud .storage import Blob
35
36
36
37
37
38
def generate_encryption_key ():
@@ -57,12 +58,11 @@ def upload_encrypted_blob(bucket_name, source_file_name,
57
58
"""
58
59
storage_client = storage .Client ()
59
60
bucket = storage_client .get_bucket (bucket_name )
60
- blob = bucket .blob (destination_blob_name )
61
-
62
61
# Encryption key must be an AES256 key represented as a bytestring with
63
62
# 32 bytes. Since it's passed in as a base64 encoded string, it needs
64
63
# 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 )
66
66
67
67
blob .upload_from_filename (source_file_name )
68
68
@@ -80,12 +80,11 @@ def download_encrypted_blob(bucket_name, source_blob_name,
80
80
"""
81
81
storage_client = storage .Client ()
82
82
bucket = storage_client .get_bucket (bucket_name )
83
- blob = bucket .blob (source_blob_name )
84
-
85
83
# Encryption key must be an AES256 key represented as a bytestring with
86
84
# 32 bytes. Since it's passed in as a base64 encoded string, it needs
87
85
# 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 )
89
88
90
89
blob .download_to_filename (destination_file_name )
91
90
@@ -131,9 +130,9 @@ def rotate_encryption_key(bucket_name, blob_name, base64_encryption_key,
131
130
'rotate' , help = rotate_encryption_key .__doc__ )
132
131
rotate_parser .add_argument (
133
132
'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' )
137
136
138
137
args = parser .parse_args ()
139
138
0 commit comments