Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ecd5f1f

Browse filesBrowse files
ryanmatsJon Wayne Parrott
authored andcommitted
Edited upload/download to perform encryption properly (GoogleCloudPlatform#667)
1 parent 0b364bc commit ecd5f1f
Copy full SHA for ecd5f1f

File tree

Expand file treeCollapse file tree

1 file changed

+8
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-9
lines changed

‎storage/cloud-client/encryption.py

Copy file name to clipboardExpand all lines: storage/cloud-client/encryption.py
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import os
3333

3434
from google.cloud import storage
35+
from google.cloud.storage import Blob
3536

3637

3738
def 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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.