From 9d5a9a9884fecbd698a602d2a9fd9bec6b987de7 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Wed, 3 Jun 2020 10:47:36 -0700 Subject: [PATCH 1/3] fix: fix impersonated cred exception doc (#521) --- google/auth/impersonated_credentials.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/google/auth/impersonated_credentials.py b/google/auth/impersonated_credentials.py index c6822776b..58e1bab06 100644 --- a/google/auth/impersonated_credentials.py +++ b/google/auth/impersonated_credentials.py @@ -75,12 +75,12 @@ def _make_iam_token_request(request, principal, headers, body): API call. Raises: - TransportError: Raised if there is an underlying HTTP connection - Error - DefaultCredentialsError: Raised if the impersonated credentials - are not available. Common reasons are - `iamcredentials.googleapis.com` is not enabled or the - `Service Account Token Creator` is not assigned + google.auth.exceptions.TransportError: Raised if there is an underlying + HTTP connection error + google.auth.exceptions.RefreshError: Raised if the impersonated + credentials are not available. Common reasons are + `iamcredentials.googleapis.com` is not enabled or the + `Service Account Token Creator` is not assigned """ iam_endpoint = _IAM_ENDPOINT.format(principal) From 8ffb4d3e832607869026444e5a071c5f3e225fd2 Mon Sep 17 00:00:00 2001 From: chenyumic Date: Thu, 4 Jun 2020 10:14:05 -0700 Subject: [PATCH 2/3] fix: replace environment variable GCE_METADATA_ROOT with GCE_METADATA_HOST (#433) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …_HOST * keeps consistent naming across auth packages of all languages. The package will now check GCE_METADATA_HOST (the new name) first; if not present, it falls back to GCE_METADATA_ROOT (the old name), then the default value. closes [#339](https://github.com/googleapis/google-auth-library-python/issues/339). --- google/auth/compute_engine/_metadata.py | 13 ++++++++++--- google/auth/environment_vars.py | 8 +++++++- tests/compute_engine/test__metadata.py | 22 +++++++++++++++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/google/auth/compute_engine/_metadata.py b/google/auth/compute_engine/_metadata.py index 2861192d0..cba426fb2 100644 --- a/google/auth/compute_engine/_metadata.py +++ b/google/auth/compute_engine/_metadata.py @@ -32,9 +32,16 @@ _LOGGER = logging.getLogger(__name__) -_METADATA_ROOT = "http://{}/computeMetadata/v1/".format( - os.getenv(environment_vars.GCE_METADATA_ROOT, "metadata.google.internal") -) +# Environment variable GCE_METADATA_HOST is originally named +# GCE_METADATA_ROOT. For compatiblity reasons, here it checks +# the new variable first; if not set, the system falls back +# to the old variable. +_GCE_METADATA_HOST = os.getenv(environment_vars.GCE_METADATA_HOST, None) +if not _GCE_METADATA_HOST: + _GCE_METADATA_HOST = os.getenv( + environment_vars.GCE_METADATA_ROOT, "metadata.google.internal" + ) +_METADATA_ROOT = "http://{}/computeMetadata/v1/".format(_GCE_METADATA_HOST) # This is used to ping the metadata server, it avoids the cost of a DNS # lookup. diff --git a/google/auth/environment_vars.py b/google/auth/environment_vars.py index 6a596f22d..9c1367f52 100644 --- a/google/auth/environment_vars.py +++ b/google/auth/environment_vars.py @@ -40,9 +40,15 @@ # These two variables allow for customization of the addresses used when # contacting the GCE metadata service. +GCE_METADATA_HOST = "GCE_METADATA_HOST" GCE_METADATA_ROOT = "GCE_METADATA_ROOT" """Environment variable providing an alternate hostname or host:port to be -used for GCE metadata requests.""" +used for GCE metadata requests. + +This environment variable is originally named GCE_METADATA_ROOT. System will +check the new variable first; should there be no value present, +the system falls back to the old variable. +""" GCE_METADATA_IP = "GCE_METADATA_IP" """Environment variable providing an alternate ip:port to be used for ip-only diff --git a/tests/compute_engine/test__metadata.py b/tests/compute_engine/test__metadata.py index 8b5eece7a..d9b039a32 100644 --- a/tests/compute_engine/test__metadata.py +++ b/tests/compute_engine/test__metadata.py @@ -155,7 +155,27 @@ def test_get_success_text(): assert result == data -def test_get_success_custom_root(): +def test_get_success_custom_root_new_variable(): + request = make_request("{}", headers={"content-type": "application/json"}) + + fake_root = "another.metadata.service" + os.environ[environment_vars.GCE_METADATA_HOST] = fake_root + reload_module(_metadata) + + try: + _metadata.get(request, PATH) + finally: + del os.environ[environment_vars.GCE_METADATA_HOST] + reload_module(_metadata) + + request.assert_called_once_with( + method="GET", + url="http://{}/computeMetadata/v1/{}".format(fake_root, PATH), + headers=_metadata._METADATA_HEADERS, + ) + + +def test_get_success_custom_root_old_variable(): request = make_request("{}", headers={"content-type": "application/json"}) fake_root = "another.metadata.service" From 16df8a3b7e461b939b1602d8ce4851152bb82bc9 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 4 Jun 2020 17:30:05 +0000 Subject: [PATCH 3/3] chore: release 1.16.1 (#522) :robot: I have created a release \*beep\* \*boop\* --- ### [1.16.1](https://www.github.com/googleapis/google-auth-library-python/compare/v1.16.0...v1.16.1) (2020-06-04) ### Bug Fixes * fix impersonated cred exception doc ([#521](https://www.github.com/googleapis/google-auth-library-python/issues/521)) ([9d5a9a9](https://www.github.com/googleapis/google-auth-library-python/commit/9d5a9a9884fecbd698a602d2a9fd9bec6b987de7)) * replace environment variable GCE_METADATA_ROOT with GCE_METADATA_HOST ([#433](https://www.github.com/googleapis/google-auth-library-python/issues/433)) ([8ffb4d3](https://www.github.com/googleapis/google-auth-library-python/commit/8ffb4d3e832607869026444e5a071c5f3e225fd2)), closes [#339](https://www.github.com/googleapis/google-auth-library-python/issues/339) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). --- CHANGELOG.md | 8 ++++++++ setup.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11f1a4d0a..945f8ea9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ [1]: https://pypi.org/project/google-auth/#history +### [1.16.1](https://www.github.com/googleapis/google-auth-library-python/compare/v1.16.0...v1.16.1) (2020-06-04) + + +### Bug Fixes + +* fix impersonated cred exception doc ([#521](https://www.github.com/googleapis/google-auth-library-python/issues/521)) ([9d5a9a9](https://www.github.com/googleapis/google-auth-library-python/commit/9d5a9a9884fecbd698a602d2a9fd9bec6b987de7)) +* replace environment variable GCE_METADATA_ROOT with GCE_METADATA_HOST ([#433](https://www.github.com/googleapis/google-auth-library-python/issues/433)) ([8ffb4d3](https://www.github.com/googleapis/google-auth-library-python/commit/8ffb4d3e832607869026444e5a071c5f3e225fd2)), closes [#339](https://www.github.com/googleapis/google-auth-library-python/issues/339) + ## [1.16.0](https://www.github.com/googleapis/google-auth-library-python/compare/v1.15.0...v1.16.0) (2020-05-28) diff --git a/setup.py b/setup.py index 212228d12..e02e9f9c5 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ with io.open("README.rst", "r") as fh: long_description = fh.read() -version = "1.16.0" +version = "1.16.1" setup( name="google-auth",