Skip to content

Commit 8770d80

Browse files
committed
Add writable 'Key' properties matching writable server-side properties.
Addresses part of #314.
1 parent d194aeb commit 8770d80

File tree

2 files changed

+389
-2
lines changed

2 files changed

+389
-2
lines changed

gcloud/storage/key.py

Lines changed: 181 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Create / interact with gcloud storage keys."""
22

3+
import copy
34
import mimetypes
45
import os
56
from StringIO import StringIO
@@ -15,6 +16,11 @@ class Key(_PropertyMixin):
1516

1617
CUSTOM_PROPERTY_ACCESSORS = {
1718
'acl': 'get_acl()',
19+
'cacheControl': 'cache_control',
20+
'contentDisposition': 'content_disposition',
21+
'contentEncoding': 'content_encoding',
22+
'contentLanguage': 'content_language',
23+
'contentType': 'content_type',
1824
'componentCount': 'component_count',
1925
'etag': 'etag',
2026
'generation': 'generation',
@@ -372,6 +378,138 @@ def make_public(self):
372378
self.acl.save()
373379
return self
374380

381+
@property
382+
def cache_control(self):
383+
"""Retrieve HTTP 'Cache-Control' header for this object.
384+
385+
See: https://tools.ietf.org/html/rfc7234#section-5.2 and
386+
https://cloud.google.com/storage/docs/json_api/v1/objects
387+
388+
:rtype: string
389+
"""
390+
return self.properties['cacheControl']
391+
392+
@cache_control.setter
393+
def cache_control(self, value):
394+
"""Update HTTP 'Cache-Control' header for this object.
395+
396+
See: https://tools.ietf.org/html/rfc7234#section-5.2 and
397+
https://cloud.google.com/storage/docs/json_api/v1/objects
398+
399+
:type value: string
400+
"""
401+
self._patch_properties({'cacheControl': value})
402+
403+
@property
404+
def content_disposition(self):
405+
"""Retrieve HTTP 'Content-Disposition' header for this object.
406+
407+
See: https://tools.ietf.org/html/rfc6266 and
408+
https://cloud.google.com/storage/docs/json_api/v1/objects
409+
410+
:rtype: string
411+
"""
412+
return self.properties['contentDisposition']
413+
414+
@content_disposition.setter
415+
def content_disposition(self, value):
416+
"""Update HTTP 'Content-Disposition' header for this object.
417+
418+
See: https://tools.ietf.org/html/rfc6266 and
419+
https://cloud.google.com/storage/docs/json_api/v1/objects
420+
421+
:type value: string
422+
"""
423+
self._patch_properties({'contentDisposition': value})
424+
425+
@property
426+
def content_encoding(self):
427+
"""Retrieve HTTP 'Content-Encoding' header for this object.
428+
429+
See: https://tools.ietf.org/html/rfc7231#section-3.1.2.2 and
430+
https://cloud.google.com/storage/docs/json_api/v1/objects
431+
432+
:rtype: string
433+
"""
434+
return self.properties['contentEncoding']
435+
436+
@content_encoding.setter
437+
def content_encoding(self, value):
438+
"""Update HTTP 'Content-Encoding' header for this object.
439+
440+
See: https://tools.ietf.org/html/rfc7231#section-3.1.2.2 and
441+
https://cloud.google.com/storage/docs/json_api/v1/objects
442+
443+
:type value: string
444+
"""
445+
self._patch_properties({'contentEncoding': value})
446+
447+
@property
448+
def content_language(self):
449+
"""Retrieve HTTP 'Content-Language' header for this object.
450+
451+
See: http://tools.ietf.org/html/bcp47 and
452+
https://cloud.google.com/storage/docs/json_api/v1/objects
453+
454+
:rtype: string
455+
"""
456+
return self.properties['contentLanguage']
457+
458+
@content_language.setter
459+
def content_language(self, value):
460+
"""Update HTTP 'Content-Language' header for this object.
461+
462+
See: http://tools.ietf.org/html/bcp47 and
463+
https://cloud.google.com/storage/docs/json_api/v1/objects
464+
465+
:type value: string
466+
"""
467+
self._patch_properties({'contentLanguage': value})
468+
469+
@property
470+
def content_type(self):
471+
"""Retrieve HTTP 'Content-Type' header for this object.
472+
473+
See: https://tools.ietf.org/html/rfc2616#section-14.17 and
474+
https://cloud.google.com/storage/docs/json_api/v1/objects
475+
476+
:rtype: string
477+
"""
478+
return self.properties['contentType']
479+
480+
@content_type.setter
481+
def content_type(self, value):
482+
"""Update HTTP 'Content-Type' header for this object.
483+
484+
See: https://tools.ietf.org/html/rfc2616#section-14.17 and
485+
https://cloud.google.com/storage/docs/json_api/v1/objects
486+
487+
:type value: string
488+
"""
489+
self._patch_properties({'contentType': value})
490+
491+
@property
492+
def crc32c(self):
493+
"""Retrieve CRC32C checksum for this object.
494+
495+
See: http://tools.ietf.org/html/rfc4960#appendix-B and
496+
https://cloud.google.com/storage/docs/json_api/v1/objects
497+
498+
:rtype: string
499+
"""
500+
return self.properties['crc32c']
501+
502+
@crc32c.setter
503+
def crc32c(self, value):
504+
"""Update CRC32C checksum for this object.
505+
506+
See: http://tools.ietf.org/html/rfc4960#appendix-B and
507+
https://cloud.google.com/storage/docs/json_api/v1/objects
508+
509+
:type value: string
510+
"""
511+
self._patch_properties({'crc32c': value})
512+
375513
@property
376514
def component_count(self):
377515
"""Number of underlying components that make up this object.
@@ -413,6 +551,28 @@ def id(self):
413551
"""
414552
return self.properties['id']
415553

554+
@property
555+
def md5_hash(self):
556+
"""Retrieve MD5 hash for this object.
557+
558+
See: http://tools.ietf.org/html/rfc4960#appendix-B and
559+
https://cloud.google.com/storage/docs/json_api/v1/objects
560+
561+
:rtype: string
562+
"""
563+
return self.properties['md5Hash']
564+
565+
@md5_hash.setter
566+
def md5_hash(self, value):
567+
"""Update MD5 hash for this object.
568+
569+
See: http://tools.ietf.org/html/rfc4960#appendix-B and
570+
https://cloud.google.com/storage/docs/json_api/v1/objects
571+
572+
:type value: string
573+
"""
574+
self._patch_properties({'md5Hash': value})
575+
416576
@property
417577
def media_link(self):
418578
"""Retrieve the media download URI for the object.
@@ -421,7 +581,27 @@ def media_link(self):
421581
422582
:rtype: string
423583
"""
424-
return self.properties['selfLink']
584+
return self.properties['mediaLink']
585+
586+
@property
587+
def metadata(self):
588+
"""Retrieve arbitrary/application specific metadata for the object.
589+
590+
See: https://cloud.google.com/storage/docs/json_api/v1/objects
591+
592+
:rtype: dict
593+
"""
594+
return copy.deepcopy(self.properties['metadata'])
595+
596+
@metadata.setter
597+
def metadata(self, value):
598+
"""Update arbitrary/application specific metadata for the object.
599+
600+
See: https://cloud.google.com/storage/docs/json_api/v1/objects
601+
602+
:type value: dict
603+
"""
604+
self._patch_properties({'metadata': value})
425605

426606
@property
427607
def metageneration(self):

0 commit comments

Comments
 (0)