Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for 'Blob.custom_time' and lifecycle rules #199

Merged
merged 22 commits into from Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c03d6ae
feat(storage): add support of custom time metadata and timestamp
HemangChothani Jul 1, 2020
7347cf2
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Jul 1, 2020
ef32ca2
Merge branch 'master' into storage_issue_196
jkwlui Jul 13, 2020
0212ca4
feat(storage): change the return type of custom_time_before
HemangChothani Jul 17, 2020
a6c830c
feat(storage): add setter method
HemangChothani Jul 24, 2020
3dbda6a
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Jul 24, 2020
04e3a10
Merge branch 'master' into storage_issue_196
tseaver Jul 24, 2020
75e6067
feat(storage): add test for None value
HemangChothani Jul 27, 2020
7ee2796
Merge branch 'storage_issue_196' of https://github.com/q-logic/python…
HemangChothani Jul 27, 2020
e2793ce
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Jul 27, 2020
43f1f5a
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Aug 5, 2020
0bd9bf4
feat(storage): changes in unittest
HemangChothani Aug 5, 2020
fee993f
feat(storage): change custom_time type to date
HemangChothani Aug 5, 2020
76457b1
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Aug 13, 2020
ae71f29
feat: change custom_time to datetime
HemangChothani Aug 17, 2020
d99fcb9
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Aug 17, 2020
62781a3
Merge branch 'master' into storage_issue_196
frankyn Aug 24, 2020
0fcf160
Merge branch 'master' into storage_issue_196
frankyn Aug 24, 2020
39a12f0
feat: nit
HemangChothani Aug 25, 2020
285e15b
Merge branch 'storage_issue_196' of https://github.com/q-logic/python…
HemangChothani Aug 25, 2020
780a616
feat: resolve conflict and nit
HemangChothani Aug 26, 2020
e76b8bb
Merge branch 'master' into storage_issue_196
frankyn Aug 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions google/cloud/storage/blob.py
Expand Up @@ -3196,11 +3196,14 @@ def custom_time(self, value):

See https://cloud.google.com/storage/docs/json_api/v1/objects

:type value: :class:`datetime.datetime`
:type value: :class:`datetime.datetime` or ``NoneType``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once set it can't be unset and only changed to a custom datetime in the future. If the custom_time must be unset, you must either perform a rewrite operation or upload the data again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd state that setter can only be datetime.datetime to not confuse folks.

:param value: (Optional) Set the custom time of blob. Datetime object parsed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document the semantics of None value (which should be to clear any existing property value).

from RFC3339 valid timestamp.
"""
self._properties["customTime"] = _datetime_to_rfc3339(value)
if value is not None:
value = _datetime_to_rfc3339(value)

self._properties["customTime"] = value


def _get_encryption_headers(key, source=False):
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_blob.py
Expand Up @@ -4152,6 +4152,14 @@ def test_custom_time_setter(self):
blob.custom_time = TIMESTAMP
self.assertEqual(blob.custom_time, TIMESTAMP)
tseaver marked this conversation as resolved.
Show resolved Hide resolved

def test_custom_time_setter_none_value(self):
BLOB_NAME = "blob-name"
bucket = _Bucket()
TIMESTAMP = None
blob = self._make_one(BLOB_NAME, bucket=bucket)
blob.custom_time = TIMESTAMP
self.assertIsNone(blob.custom_time)
tseaver marked this conversation as resolved.
Show resolved Hide resolved

def test_custom_time_unset(self):
BUCKET = object()
blob = self._make_one("blob-name", bucket=BUCKET)
Expand Down