From ed1edb2699a1e84812cdabd2da5381b57a07bef3 Mon Sep 17 00:00:00 2001 From: Kelvin Salton do Prado Date: Sat, 19 Jan 2019 09:46:09 -0200 Subject: [PATCH 1/2] Improve generate_signed_url documentation --- storage/google/cloud/storage/_signing.py | 16 ++++++++++++---- storage/google/cloud/storage/blob.py | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/storage/google/cloud/storage/_signing.py b/storage/google/cloud/storage/_signing.py index 6f0bf4d5f39f..02fe8496b4ab 100644 --- a/storage/google/cloud/storage/_signing.py +++ b/storage/google/cloud/storage/_signing.py @@ -28,9 +28,12 @@ def ensure_signed_credentials(credentials): """Raise AttributeError if the credentials are unsigned. - :type credentials: :class:`google.auth.credentials.Signer` + :type credentials: :class:`google.auth.credentials.Signing` :param credentials: The credentials used to create a private key for signing text. + + :raises :exc:`AttributeError` if credentials is not an instance + of :class:`google.auth.credentials.Signing`. """ if not isinstance(credentials, google.auth.credentials.Signing): auth_uri = ( @@ -49,7 +52,7 @@ def ensure_signed_credentials(credentials): def get_signed_query_params(credentials, expiration, string_to_sign): """Gets query parameters for creating a signed URL. - :type credentials: :class:`google.auth.credentials.Signer` + :type credentials: :class:`google.auth.credentials.Signing` :param credentials: The credentials used to create a private key for signing text. @@ -59,7 +62,8 @@ def get_signed_query_params(credentials, expiration, string_to_sign): :type string_to_sign: str :param string_to_sign: The string to be signed by the credentials. - :raises AttributeError: If :meth: sign_blob is unavailable. + :raises :exc:`AttributeError` if credentials is not an instance + of :class:`google.auth.credentials.Signing`. :rtype: dict :returns: Query parameters matching the signing credentials with a @@ -82,7 +86,7 @@ def get_expiration_seconds(expiration): :type expiration: int, long, datetime.datetime, datetime.timedelta :param expiration: When the signed URL should expire. - :raises TypeError: When expiration is not an integer. + :raises :exc:`TypeError` when expiration is not a valid type. :rtype: int :returns: a timestamp as an absolute number of seconds. @@ -184,6 +188,10 @@ def generate_signed_url( :param generation: (Optional) A value that indicates which generation of the resource to fetch. + :raises :exc:`TypeError` when expiration is not a valid type. + :raises :exc:`AttributeError` if credentials is not an instance + of :class:`google.auth.credentials.Signing`. + :rtype: str :returns: A signed URL you can use to access the resource until expiration. diff --git a/storage/google/cloud/storage/blob.py b/storage/google/cloud/storage/blob.py index 58d25e5d9a02..49a69582ee26 100644 --- a/storage/google/cloud/storage/blob.py +++ b/storage/google/cloud/storage/blob.py @@ -344,6 +344,10 @@ def generate_signed_url( the URL. Defaults to the credentials stored on the client used. + :raises :exc:`TypeError` when expiration is not a valid type. + :raises :exc:`AttributeError` if credentials is not an instance + of :class:`google.auth.credentials.Signing`. + :rtype: str :returns: A signed URL you can use to access the resource until expiration. From 69257279a4fe938227f1969cb0191dc84cbd4798 Mon Sep 17 00:00:00 2001 From: Kelvin Salton do Prado Date: Sat, 19 Jan 2019 10:06:37 -0200 Subject: [PATCH 2/2] Add missing colon to the raise --- storage/google/cloud/storage/_signing.py | 10 +++++----- storage/google/cloud/storage/blob.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/storage/google/cloud/storage/_signing.py b/storage/google/cloud/storage/_signing.py index 02fe8496b4ab..92703107421d 100644 --- a/storage/google/cloud/storage/_signing.py +++ b/storage/google/cloud/storage/_signing.py @@ -32,7 +32,7 @@ def ensure_signed_credentials(credentials): :param credentials: The credentials used to create a private key for signing text. - :raises :exc:`AttributeError` if credentials is not an instance + :raises: :exc:`AttributeError` if credentials is not an instance of :class:`google.auth.credentials.Signing`. """ if not isinstance(credentials, google.auth.credentials.Signing): @@ -62,7 +62,7 @@ def get_signed_query_params(credentials, expiration, string_to_sign): :type string_to_sign: str :param string_to_sign: The string to be signed by the credentials. - :raises :exc:`AttributeError` if credentials is not an instance + :raises: :exc:`AttributeError` if credentials is not an instance of :class:`google.auth.credentials.Signing`. :rtype: dict @@ -86,7 +86,7 @@ def get_expiration_seconds(expiration): :type expiration: int, long, datetime.datetime, datetime.timedelta :param expiration: When the signed URL should expire. - :raises :exc:`TypeError` when expiration is not a valid type. + :raises: :exc:`TypeError` when expiration is not a valid type. :rtype: int :returns: a timestamp as an absolute number of seconds. @@ -188,8 +188,8 @@ def generate_signed_url( :param generation: (Optional) A value that indicates which generation of the resource to fetch. - :raises :exc:`TypeError` when expiration is not a valid type. - :raises :exc:`AttributeError` if credentials is not an instance + :raises: :exc:`TypeError` when expiration is not a valid type. + :raises: :exc:`AttributeError` if credentials is not an instance of :class:`google.auth.credentials.Signing`. :rtype: str diff --git a/storage/google/cloud/storage/blob.py b/storage/google/cloud/storage/blob.py index 49a69582ee26..0e4a6a6f789e 100644 --- a/storage/google/cloud/storage/blob.py +++ b/storage/google/cloud/storage/blob.py @@ -344,8 +344,8 @@ def generate_signed_url( the URL. Defaults to the credentials stored on the client used. - :raises :exc:`TypeError` when expiration is not a valid type. - :raises :exc:`AttributeError` if credentials is not an instance + :raises: :exc:`TypeError` when expiration is not a valid type. + :raises: :exc:`AttributeError` if credentials is not an instance of :class:`google.auth.credentials.Signing`. :rtype: str