Skip to content

Commit 944ab18

Browse files
HemangChothanifrankyntseaver
authored
docs: add docs signed_url expiration take default utc (#250)
Co-authored-by: Frank Natividad <[email protected]> Co-authored-by: Tres Seaver <[email protected]>
1 parent 22eeb2f commit 944ab18

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

google/cloud/storage/_signing.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def get_expiration_seconds_v2(expiration):
9191
"""Convert 'expiration' to a number of seconds in the future.
9292
9393
:type expiration: Union[Integer, datetime.datetime, datetime.timedelta]
94-
:param expiration: Point in time when the signed URL should expire.
94+
:param expiration: Point in time when the signed URL should expire. If
95+
a ``datetime`` instance is passed without an explicit
96+
``tzinfo`` set, it will be assumed to be ``UTC``.
9597
9698
:raises: :exc:`TypeError` when expiration is not a valid type.
9799
@@ -123,7 +125,9 @@ def get_expiration_seconds_v4(expiration):
123125
"""Convert 'expiration' to a number of seconds offset from the current time.
124126
125127
:type expiration: Union[Integer, datetime.datetime, datetime.timedelta]
126-
:param expiration: Point in time when the signed URL should expire.
128+
:param expiration: Point in time when the signed URL should expire. If
129+
a ``datetime`` instance is passed without an explicit
130+
``tzinfo`` set, it will be assumed to be ``UTC``.
127131
128132
:raises: :exc:`TypeError` when expiration is not a valid type.
129133
:raises: :exc:`ValueError` when expiration is too large.
@@ -299,7 +303,9 @@ def generate_signed_url_v2(
299303
Caller should have already URL-encoded the value.
300304
301305
:type expiration: Union[Integer, datetime.datetime, datetime.timedelta]
302-
:param expiration: Point in time when the signed URL should expire.
306+
:param expiration: Point in time when the signed URL should expire. If
307+
a ``datetime`` instance is passed without an explicit
308+
``tzinfo`` set, it will be assumed to be ``UTC``.
303309
304310
:type api_access_endpoint: str
305311
:param api_access_endpoint: (Optional) URI base. Defaults to empty string.
@@ -461,7 +467,9 @@ def generate_signed_url_v4(
461467
Caller should have already URL-encoded the value.
462468
463469
:type expiration: Union[Integer, datetime.datetime, datetime.timedelta]
464-
:param expiration: Point in time when the signed URL should expire.
470+
:param expiration: Point in time when the signed URL should expire. If
471+
a ``datetime`` instance is passed without an explicit
472+
``tzinfo`` set, it will be assumed to be ``UTC``.
465473
466474
:type api_access_endpoint: str
467475
:param api_access_endpoint: (Optional) URI base. Defaults to

google/cloud/storage/blob.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ def generate_signed_url(
418418
log in.
419419
420420
:type expiration: Union[Integer, datetime.datetime, datetime.timedelta]
421-
:param expiration: Point in time when the signed URL should expire.
421+
:param expiration: Point in time when the signed URL should expire. If
422+
a ``datetime`` instance is passed without an explicit
423+
``tzinfo`` set, it will be assumed to be ``UTC``.
422424
423425
:type api_access_endpoint: str
424426
:param api_access_endpoint: (Optional) URI base.

google/cloud/storage/bucket.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3020,7 +3020,9 @@ def generate_signed_url(
30203020
log in.
30213021
30223022
:type expiration: Union[Integer, datetime.datetime, datetime.timedelta]
3023-
:param expiration: Point in time when the signed URL should expire.
3023+
:param expiration: Point in time when the signed URL should expire. If
3024+
a ``datetime`` instance is passed without an explicit
3025+
``tzinfo`` set, it will be assumed to be ``UTC``.
30243026
30253027
:type api_access_endpoint: str
30263028
:param api_access_endpoint: (Optional) URI base.

google/cloud/storage/client.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,9 @@ def generate_signed_post_policy_v4(
962962
:param blob_name: Object name.
963963
964964
:type expiration: Union[Integer, datetime.datetime, datetime.timedelta]
965-
:param expiration: Policy expiration time.
965+
:param expiration: Policy expiration time. If a ``datetime`` instance is
966+
passed without an explicit ``tzinfo`` set, it will be
967+
assumed to be ``UTC``.
966968
967969
:type conditions: list
968970
:param conditions: (Optional) List of POST policy conditions, which are
@@ -1004,11 +1006,13 @@ def generate_signed_post_policy_v4(
10041006
Generate signed POST policy and upload a file.
10051007
10061008
>>> from google.cloud import storage
1009+
>>> import pytz
10071010
>>> client = storage.Client()
1011+
>>> tz = pytz.timezone('America/New_York')
10081012
>>> policy = client.generate_signed_post_policy_v4(
10091013
"bucket-name",
10101014
"blob-name",
1011-
expiration=datetime.datetime(2020, 3, 17),
1015+
expiration=datetime.datetime(2020, 3, 17, tzinfo=tz),
10121016
conditions=[
10131017
["content-length-range", 0, 255]
10141018
],

0 commit comments

Comments
 (0)