From 1e2f14824eff7d2ab2816bb7077ca35bec586357 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 27 May 2022 13:01:07 -0400 Subject: [PATCH 1/3] chore: fix release script on v1 branch (#391) * chore: fix release script on v1 branch * build: switch to release-please for tagging * build: switch to release-please for tagging --- .github/release-please.yml | 1 + .github/release-trigger.yml | 1 + .kokoro/release.sh | 2 +- .kokoro/release/common.cfg | 12 +++++++++++- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .github/release-trigger.yml diff --git a/.github/release-please.yml b/.github/release-please.yml index 4507ad05..466597e5 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1 +1,2 @@ releaseType: python +handleGHRelease: true diff --git a/.github/release-trigger.yml b/.github/release-trigger.yml new file mode 100644 index 00000000..d4ca9418 --- /dev/null +++ b/.github/release-trigger.yml @@ -0,0 +1 @@ +enabled: true diff --git a/.kokoro/release.sh b/.kokoro/release.sh index 0728ce11..a00f93ec 100755 --- a/.kokoro/release.sh +++ b/.kokoro/release.sh @@ -26,7 +26,7 @@ python3 -m pip install --upgrade twine wheel setuptools export PYTHONUNBUFFERED=1 # Move into the package, build the distribution and upload. -TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token") +TWINE_PASSWORD=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google-cloud-pypi-token-keystore-1") cd github/python-api-core python3 setup.py sdist bdist_wheel twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/* diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index 586e7649..de4f6f89 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,8 +23,18 @@ env_vars: { value: "github/python-api-core/.kokoro/release.sh" } +# Fetch PyPI password +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "google-cloud-pypi-token-keystore-1" + } + } +} + # Tokens needed to report release status back to GitHub env_vars: { key: "SECRET_MANAGER_KEYS" - value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,google-cloud-pypi-token" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" } From 483422487129fe4a0d2e30637cbea02bc0f370bf Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Wed, 13 Jul 2022 10:10:37 -0400 Subject: [PATCH 2/3] feat: adds support for audience in client_options in v1 branch (#411) feat: add api_key to client options in v1 branch --- google/api_core/client_options.py | 16 ++++++++++++- tests/unit/test_client_options.py | 39 +++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/google/api_core/client_options.py b/google/api_core/client_options.py index 57000e95..0d9afc39 100644 --- a/google/api_core/client_options.py +++ b/google/api_core/client_options.py @@ -66,11 +66,19 @@ class ClientOptions(object): quota_project_id (Optional[str]): A project name that a client's quota belongs to. credentials_file (Optional[str]): A path to a file storing credentials. + ``credentials_file` and ``api_key`` are mutually exclusive. scopes (Optional[Sequence[str]]): OAuth access token override scopes. + api_key (Optional[str]): Google API key. ``credentials_file`` and + ``api_key`` are mutually exclusive. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the service endpoint value will be used as a default. + An example of a valid ``api_audience`` is: "https://language.googleapis.com". Raises: ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source`` - are provided. + are provided, or both ``credentials_file`` and ``api_key`` are provided. """ def __init__( @@ -81,17 +89,23 @@ def __init__( quota_project_id=None, credentials_file=None, scopes=None, + api_key=None, + api_audience=None, ): if client_cert_source and client_encrypted_cert_source: raise ValueError( "client_cert_source and client_encrypted_cert_source are mutually exclusive" ) + if api_key and credentials_file: + raise ValueError("api_key and credentials_file are mutually exclusive") self.api_endpoint = api_endpoint self.client_cert_source = client_cert_source self.client_encrypted_cert_source = client_encrypted_cert_source self.quota_project_id = quota_project_id self.credentials_file = credentials_file self.scopes = scopes + self.api_key = api_key + self.api_audience = api_audience def __repr__(self): return "ClientOptions: " + repr(self.__dict__) diff --git a/tests/unit/test_client_options.py b/tests/unit/test_client_options.py index 38b9ad0a..40edcc19 100644 --- a/tests/unit/test_client_options.py +++ b/tests/unit/test_client_options.py @@ -36,6 +36,7 @@ def test_constructor(): "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloud-platform.read-only", ], + api_audience="foo2.googleapis.com", ) assert options.api_endpoint == "foo.googleapis.com" @@ -46,6 +47,7 @@ def test_constructor(): "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloud-platform.read-only", ] + assert options.api_audience == "foo2.googleapis.com" def test_constructor_with_encrypted_cert_source(): @@ -72,6 +74,36 @@ def test_constructor_with_both_cert_sources(): ) +def test_constructor_with_api_key(): + + options = client_options.ClientOptions( + api_endpoint="foo.googleapis.com", + client_cert_source=get_client_cert, + quota_project_id="quote-proj", + api_key="api-key", + scopes=[ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ], + ) + + assert options.api_endpoint == "foo.googleapis.com" + assert options.client_cert_source() == (b"cert", b"key") + assert options.quota_project_id == "quote-proj" + assert options.api_key == "api-key" + assert options.scopes == [ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ] + + +def test_constructor_with_both_api_key_and_credentials_file(): + with pytest.raises(ValueError): + client_options.ClientOptions( + api_key="api-key", credentials_file="path/to/credentials.json", + ) + + def test_from_dict(): options = client_options.from_dict( { @@ -83,6 +115,7 @@ def test_from_dict(): "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloud-platform.read-only", ], + "api_audience": "foo2.googleapis.com", } ) @@ -94,6 +127,8 @@ def test_from_dict(): "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/cloud-platform.read-only", ] + assert options.api_key is None + assert options.api_audience == "foo2.googleapis.com" def test_from_dict_bad_argument(): @@ -112,6 +147,6 @@ def test_repr(): assert ( repr(options) - == "ClientOptions: {'api_endpoint': 'foo.googleapis.com', 'client_cert_source': None, 'client_encrypted_cert_source': None}" - or "ClientOptions: {'client_encrypted_cert_source': None, 'client_cert_source': None, 'api_endpoint': 'foo.googleapis.com'}" + == "ClientOptions: {'api_endpoint': 'foo.googleapis.com', 'client_cert_source': None, 'client_encrypted_cert_source': None, 'api_key': None}" + or "ClientOptions: {'client_encrypted_cert_source': None, 'client_cert_source': None, 'api_endpoint': 'foo.googleapis.com', 'api_key': None}" ) From a1d83359516834d535a1783adeafedc6f5248d62 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 13 Jul 2022 10:11:12 -0400 Subject: [PATCH 3/3] chore(v1): release 1.32.0 (#412) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 8 ++++++++ google/api_core/version.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a73af3d..df8c7819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ [1]: https://pypi.org/project/google-api-core/#history +## [1.32.0](https://github.com/googleapis/python-api-core/compare/v1.31.6...v1.32.0) (2022-07-13) + + +### Features + +* add api_key to client options in v1 branch ([4834224](https://github.com/googleapis/python-api-core/commit/483422487129fe4a0d2e30637cbea02bc0f370bf)) +* adds support for audience in client_options in v1 branch ([#411](https://github.com/googleapis/python-api-core/issues/411)) ([4834224](https://github.com/googleapis/python-api-core/commit/483422487129fe4a0d2e30637cbea02bc0f370bf)) + ### [1.31.6](https://github.com/googleapis/python-api-core/compare/v1.31.5...v1.31.6) (2022-05-27) diff --git a/google/api_core/version.py b/google/api_core/version.py index 678ded5b..687ca554 100644 --- a/google/api_core/version.py +++ b/google/api_core/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.31.6" +__version__ = "1.32.0"