-
Notifications
You must be signed in to change notification settings - Fork 167
feat: add support for 'Blob.custom_time' and lifecycle rules #199
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
Changes from all commits
c03d6ae
7347cf2
ef32ca2
0212ca4
a6c830c
3dbda6a
04e3a10
75e6067
7ee2796
e2793ce
43f1f5a
0bd9bf4
fee993f
76457b1
ae71f29
d99fcb9
62781a3
0fcf160
39a12f0
285e15b
780a616
e76b8bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ | |
| from google.api_core.iam import Policy | ||
| from google.cloud import exceptions | ||
| from google.cloud._helpers import _bytes_to_unicode | ||
| from google.cloud._helpers import _datetime_to_rfc3339 | ||
| from google.cloud._helpers import _rfc3339_to_datetime | ||
| from google.cloud._helpers import _to_bytes | ||
| from google.cloud.exceptions import NotFound | ||
|
|
@@ -3348,6 +3349,39 @@ def updated(self): | |
| if value is not None: | ||
| return _rfc3339_to_datetime(value) | ||
|
|
||
| @property | ||
| def custom_time(self): | ||
| """Retrieve the custom time for the object. | ||
|
|
||
| See https://cloud.google.com/storage/docs/json_api/v1/objects | ||
|
|
||
| :rtype: :class:`datetime.datetime` or ``NoneType`` | ||
| :returns: Datetime object parsed from RFC3339 valid timestamp, or | ||
| ``None`` if the blob's resource has not been loaded from | ||
| the server (see :meth:`reload`). | ||
| """ | ||
| value = self._properties.get("customTime") | ||
| if value is not None: | ||
| return _rfc3339_to_datetime(value) | ||
|
|
||
| @custom_time.setter | ||
| def custom_time(self, value): | ||
| """Set the custom time for the object. Once set it can't be unset | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow PEP 257 for Multi-line docstrings, i.e., move the non-summary down below. |
||
| 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These semantics are not enforced by the method. |
||
|
|
||
| See https://cloud.google.com/storage/docs/json_api/v1/objects | ||
|
|
||
| :type value: :class:`datetime.datetime` | ||
| :param value: (Optional) Set the custom time of blob. Datetime object | ||
| parsed from RFC3339 valid timestamp. | ||
| """ | ||
| if value is not None: | ||
| value = _datetime_to_rfc3339(value) | ||
|
|
||
| self._properties["customTime"] = value | ||
|
|
||
|
|
||
| def _get_encryption_headers(key, source=False): | ||
| """Builds customer encryption key headers | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,18 @@ class LifecycleRuleConditions(dict): | |
| :param number_of_newer_versions: (Optional) Apply rule action to versioned | ||
| items having N newer versions. | ||
|
|
||
| :type days_since_custom_time: int | ||
| :param days_since_custom_time: (Optional) Apply rule action to items whose number of days | ||
| elapsed since the custom timestamp. This condition is relevant | ||
| only for versioned objects. The value of the field must be a non | ||
| negative integer. If it's zero, the object version will become | ||
| eligible for lifecycle action as soon as it becomes custom. | ||
|
|
||
| :type custom_time_before: :class:`datetime.date` | ||
| :param custom_time_before: (Optional) Date object parsed from RFC3339 valid date, apply rule action | ||
| to items whose custom time is before this date. This condition is relevant | ||
| only for versioned objects, e.g., 2019-03-16. | ||
|
|
||
| :type days_since_noncurrent_time: int | ||
| :param days_since_noncurrent_time: (Optional) Apply rule action to items whose number of days | ||
| elapsed since the non current timestamp. This condition | ||
|
|
@@ -193,6 +205,8 @@ def __init__( | |
| is_live=None, | ||
| matches_storage_class=None, | ||
| number_of_newer_versions=None, | ||
| days_since_custom_time=None, | ||
| custom_time_before=None, | ||
| days_since_noncurrent_time=None, | ||
| noncurrent_time_before=None, | ||
| _factory=False, | ||
|
|
@@ -214,6 +228,12 @@ def __init__( | |
| if number_of_newer_versions is not None: | ||
| conditions["numNewerVersions"] = number_of_newer_versions | ||
|
|
||
| if days_since_custom_time is not None: | ||
| conditions["daysSinceCustomTime"] = days_since_custom_time | ||
|
|
||
| if custom_time_before is not None: | ||
| conditions["customTimeBefore"] = custom_time_before.isoformat() | ||
|
|
||
| if not _factory and not conditions: | ||
| raise ValueError("Supply at least one condition") | ||
|
|
||
|
|
@@ -266,6 +286,18 @@ def number_of_newer_versions(self): | |
| """Conditon's 'number_of_newer_versions' value.""" | ||
| return self.get("numNewerVersions") | ||
|
|
||
| @property | ||
| def days_since_custom_time(self): | ||
| """Conditon's 'days_since_custom_time' value.""" | ||
| return self.get("daysSinceCustomTime") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setter for this property? |
||
|
|
||
| @property | ||
| def custom_time_before(self): | ||
| """Conditon's 'custom_time_before' value.""" | ||
| before = self.get("customTimeBefore") | ||
| if before is not None: | ||
| return datetime_helpers.from_iso8601_date(before) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setter for this property?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about the setter method for all this properties, because we don't have a method for other properties as well which defined before. Please let me know if needed, so need to create setter method for all the properties of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks both, looks like setters weren't defined at this level. It will be filed as a feature request for now. It doesn't block customers from using the feature. |
||
|
|
||
| @property | ||
| def days_since_noncurrent_time(self): | ||
| """Conditon's 'days_since_noncurrent_time' value.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.