@@ -254,6 +254,31 @@ def chunk_size(self, value):
254
254
)
255
255
self ._chunk_size = value
256
256
257
+ @property
258
+ def encryption_key (self ):
259
+ """Retrieve the customer-supplied encryption key for the object.
260
+
261
+ :rtype: bytes or ``NoneType``
262
+ :returns:
263
+ The encryption key or ``None`` if no customer-supplied encryption key was used,
264
+ or the blob's resource has not been loaded from the server.
265
+ """
266
+ return self ._encryption_key
267
+
268
+ @encryption_key .setter
269
+ def encryption_key (self , value ):
270
+ """Set the blob's encryption key.
271
+
272
+ See https://cloud.google.com/storage/docs/encryption#customer-supplied
273
+
274
+ To perform a key rotation for an encrypted blob, use :meth:`rewrite`.
275
+ See https://cloud.google.com/storage/docs/encryption/using-customer-supplied-keys?hl=ca#rotating
276
+
277
+ :type value: bytes
278
+ :param value: 32 byte encryption key for customer-supplied encryption.
279
+ """
280
+ self ._encryption_key = value
281
+
257
282
@staticmethod
258
283
def path_helper (bucket_path , blob_name ):
259
284
"""Relative URL path for a blob.
@@ -347,25 +372,25 @@ def public_url(self):
347
372
def from_string (cls , uri , client = None ):
348
373
"""Get a constructor for blob object by URI.
349
374
350
- :type uri: str
351
- :param uri: The blob uri pass to get blob object.
375
+ :type uri: str
376
+ :param uri: The blob uri pass to get blob object.
352
377
353
378
:type client: :class:`~google.cloud.storage.client.Client`
354
379
:param client:
355
380
(Optional) The client to use. If not passed, falls back to the
356
381
``client`` stored on the blob's bucket.
357
382
358
- :rtype: :class:`google.cloud.storage.blob.Blob`
359
- :returns: The blob object created.
383
+ :rtype: :class:`google.cloud.storage.blob.Blob`
384
+ :returns: The blob object created.
360
385
361
- Example:
362
- Get a constructor for blob object by URI..
386
+ Example:
387
+ Get a constructor for blob object by URI.
363
388
364
389
>>> from google.cloud import storage
365
390
>>> from google.cloud.storage.blob import Blob
366
391
>>> client = storage.Client()
367
392
>>> blob = Blob.from_string("gs://bucket/object")
368
- """
393
+ """
369
394
from google .cloud .storage .bucket import Bucket
370
395
371
396
scheme , netloc , path , query , frag = urlsplit (uri )
@@ -3839,6 +3864,15 @@ def kms_key_name(self):
3839
3864
"""
3840
3865
return self ._properties .get ("kmsKeyName" )
3841
3866
3867
+ @kms_key_name .setter
3868
+ def kms_key_name (self , value ):
3869
+ """Set KMS encryption key for object.
3870
+
3871
+ :type value: str or ``NoneType``
3872
+ :param value: new KMS key name (None to clear any existing key).
3873
+ """
3874
+ self ._patch_property ("kmsKeyName" , value )
3875
+
3842
3876
storage_class = _scalar_property ("storageClass" )
3843
3877
"""Retrieve the storage class for the object.
3844
3878
0 commit comments