Skip to content

Commit cf451cf

Browse files
committed
Pass 'encryption_key' through 'Bucket.blob' factory.
1 parent 2da75d4 commit cf451cf

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

storage/google/cloud/storage/bucket.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def client(self):
111111
"""The client bound to this bucket."""
112112
return self._client
113113

114-
def blob(self, blob_name, chunk_size=None):
114+
def blob(self, blob_name, chunk_size=None, encryption_key=None):
115115
"""Factory constructor for blob object.
116116
117117
.. note::
@@ -126,10 +126,15 @@ def blob(self, blob_name, chunk_size=None):
126126
(1 MB). This must be a multiple of 256 KB per the
127127
API specification.
128128
129+
:type encryption_key: bytes
130+
:param encryption_key:
131+
Optional 32 byte encryption key for customer-supplied encryption.
132+
129133
:rtype: :class:`google.cloud.storage.blob.Blob`
130134
:returns: The blob object created.
131135
"""
132-
return Blob(name=blob_name, bucket=self, chunk_size=chunk_size)
136+
return Blob(name=blob_name, bucket=self, chunk_size=chunk_size,
137+
encryption_key=encryption_key)
133138

134139
def exists(self, client=None):
135140
"""Determines whether or not this bucket exists.

storage/unit_tests/test_bucket.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,17 @@ def test_blob(self):
113113
BUCKET_NAME = 'BUCKET_NAME'
114114
BLOB_NAME = 'BLOB_NAME'
115115
CHUNK_SIZE = 1024 * 1024
116+
KEY = b'01234567890123456789012345678901' # 32 bytes
116117

117118
bucket = self._makeOne(name=BUCKET_NAME)
118-
blob = bucket.blob(BLOB_NAME, chunk_size=CHUNK_SIZE)
119+
blob = bucket.blob(
120+
BLOB_NAME, chunk_size=CHUNK_SIZE, encryption_key=KEY)
119121
self.assertIsInstance(blob, Blob)
120122
self.assertIs(blob.bucket, bucket)
121123
self.assertIs(blob.client, bucket.client)
122124
self.assertEqual(blob.name, BLOB_NAME)
123125
self.assertEqual(blob.chunk_size, CHUNK_SIZE)
126+
self.assertEqual(blob._encryption_key, KEY)
124127

125128
def test_exists_miss(self):
126129
from google.cloud.exceptions import NotFound

0 commit comments

Comments
 (0)