diff --git a/.github/header-checker-lint.yml b/.github/header-checker-lint.yml new file mode 100644 index 00000000..fc281c05 --- /dev/null +++ b/.github/header-checker-lint.yml @@ -0,0 +1,15 @@ +{"allowedCopyrightHolders": ["Google LLC"], + "allowedLicenses": ["Apache-2.0", "MIT", "BSD-3"], + "ignoreFiles": ["**/requirements.txt", "**/requirements-test.txt"], + "sourceFileExtensions": [ + "ts", + "js", + "java", + "sh", + "Dockerfile", + "yaml", + "py", + "html", + "txt" + ] +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index b9daa52f..b4243ced 100644 --- a/.gitignore +++ b/.gitignore @@ -50,8 +50,10 @@ docs.metadata # Virtual environment env/ + +# Test logs coverage.xml -sponge_log.xml +*sponge_log.xml # System test environment variables. system_tests/local_test_setup diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 5d03ac70..86c97c06 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -15,7 +15,11 @@ set -eo pipefail -cd github/python-game-servers +if [[ -z "${PROJECT_ROOT:-}" ]]; then + PROJECT_ROOT="github/python-game-servers" +fi + +cd "${PROJECT_ROOT}" # Disable buffering, so that the logs stream through. export PYTHONUNBUFFERED=1 @@ -30,16 +34,26 @@ export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json") # Remove old nox -python3.6 -m pip uninstall --yes --quiet nox-automation +python3 -m pip uninstall --yes --quiet nox-automation # Install nox -python3.6 -m pip install --upgrade --quiet nox -python3.6 -m nox --version +python3 -m pip install --upgrade --quiet nox +python3 -m nox --version + +# If this is a continuous build, send the test log to the FlakyBot. +# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. +if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then + cleanup() { + chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot + $KOKORO_GFILE_DIR/linux_amd64/flakybot + } + trap cleanup EXIT HUP +fi # If NOX_SESSION is set, it only runs the specified session, # otherwise run all the sessions. if [[ -n "${NOX_SESSION:-}" ]]; then - python3.6 -m nox -s "${NOX_SESSION:-}" + python3 -m nox -s ${NOX_SESSION:-} else - python3.6 -m nox + python3 -m nox fi diff --git a/.kokoro/docs/docs-presubmit.cfg b/.kokoro/docs/docs-presubmit.cfg index 11181078..d4dad531 100644 --- a/.kokoro/docs/docs-presubmit.cfg +++ b/.kokoro/docs/docs-presubmit.cfg @@ -15,3 +15,14 @@ env_vars: { key: "TRAMPOLINE_IMAGE_UPLOAD" value: "false" } + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-game-servers/.kokoro/build.sh" +} + +# Only run this nox session. +env_vars: { + key: "NOX_SESSION" + value: "docs docfx" +} diff --git a/.kokoro/samples/python3.6/periodic-head.cfg b/.kokoro/samples/python3.6/periodic-head.cfg new file mode 100644 index 00000000..f9cfcd33 --- /dev/null +++ b/.kokoro/samples/python3.6/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-pubsub/.kokoro/test-samples-against-head.sh" +} diff --git a/.kokoro/samples/python3.7/periodic-head.cfg b/.kokoro/samples/python3.7/periodic-head.cfg new file mode 100644 index 00000000..f9cfcd33 --- /dev/null +++ b/.kokoro/samples/python3.7/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-pubsub/.kokoro/test-samples-against-head.sh" +} diff --git a/.kokoro/samples/python3.8/periodic-head.cfg b/.kokoro/samples/python3.8/periodic-head.cfg new file mode 100644 index 00000000..f9cfcd33 --- /dev/null +++ b/.kokoro/samples/python3.8/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-pubsub/.kokoro/test-samples-against-head.sh" +} diff --git a/.kokoro/test-samples-against-head.sh b/.kokoro/test-samples-against-head.sh new file mode 100755 index 00000000..9ad74a95 --- /dev/null +++ b/.kokoro/test-samples-against-head.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A customized test runner for samples. +# +# For periodic builds, you can specify this file for testing against head. + +# `-e` enables the script to automatically fail when a command fails +# `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero +set -eo pipefail +# Enables `**` to include files nested inside sub-folders +shopt -s globstar + +cd github/python-game-servers + +exec .kokoro/test-samples-impl.sh diff --git a/.kokoro/test-samples-impl.sh b/.kokoro/test-samples-impl.sh new file mode 100755 index 00000000..cf5de74c --- /dev/null +++ b/.kokoro/test-samples-impl.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# `-e` enables the script to automatically fail when a command fails +# `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero +set -eo pipefail +# Enables `**` to include files nested inside sub-folders +shopt -s globstar + +# Exit early if samples directory doesn't exist +if [ ! -d "./samples" ]; then + echo "No tests run. `./samples` not found" + exit 0 +fi + +# Disable buffering, so that the logs stream through. +export PYTHONUNBUFFERED=1 + +# Debug: show build environment +env | grep KOKORO + +# Install nox +python3.6 -m pip install --upgrade --quiet nox + +# Use secrets acessor service account to get secrets +if [[ -f "${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" ]]; then + gcloud auth activate-service-account \ + --key-file="${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" \ + --project="cloud-devrel-kokoro-resources" +fi + +# This script will create 3 files: +# - testing/test-env.sh +# - testing/service-account.json +# - testing/client-secrets.json +./scripts/decrypt-secrets.sh + +source ./testing/test-env.sh +export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/testing/service-account.json + +# For cloud-run session, we activate the service account for gcloud sdk. +gcloud auth activate-service-account \ + --key-file "${GOOGLE_APPLICATION_CREDENTIALS}" + +export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json + +echo -e "\n******************** TESTING PROJECTS ********************" + +# Switch to 'fail at end' to allow all tests to complete before exiting. +set +e +# Use RTN to return a non-zero value if the test fails. +RTN=0 +ROOT=$(pwd) +# Find all requirements.txt in the samples directory (may break on whitespace). +for file in samples/**/requirements.txt; do + cd "$ROOT" + # Navigate to the project folder. + file=$(dirname "$file") + cd "$file" + + echo "------------------------------------------------------------" + echo "- testing $file" + echo "------------------------------------------------------------" + + # Use nox to execute the tests for the project. + python3.6 -m nox -s "$RUN_TESTS_SESSION" + EXIT=$? + + # If this is a periodic build, send the test log to the FlakyBot. + # See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. + if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then + chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot + $KOKORO_GFILE_DIR/linux_amd64/flakybot + fi + + if [[ $EXIT -ne 0 ]]; then + RTN=1 + echo -e "\n Testing failed: Nox returned a non-zero exit code. \n" + else + echo -e "\n Testing completed.\n" + fi + +done +cd "$ROOT" + +# Workaround for Kokoro permissions issue: delete secrets +rm testing/{test-env.sh,client-secrets.json,service-account.json} + +exit "$RTN" diff --git a/.kokoro/test-samples.sh b/.kokoro/test-samples.sh index 042b950e..cdaf0153 100755 --- a/.kokoro/test-samples.sh +++ b/.kokoro/test-samples.sh @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +# The default test runner for samples. +# +# For periodic builds, we rewinds the repo to the latest release, and +# run test-samples-impl.sh. # `-e` enables the script to automatically fail when a command fails # `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero @@ -24,87 +28,19 @@ cd github/python-game-servers # Run periodic samples tests at latest release if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then + # preserving the test runner implementation. + cp .kokoro/test-samples-impl.sh "${TMPDIR}/test-samples-impl.sh" + echo "--- IMPORTANT IMPORTANT IMPORTANT ---" + echo "Now we rewind the repo back to the latest release..." LATEST_RELEASE=$(git describe --abbrev=0 --tags) git checkout $LATEST_RELEASE -fi - -# Exit early if samples directory doesn't exist -if [ ! -d "./samples" ]; then - echo "No tests run. `./samples` not found" - exit 0 -fi - -# Disable buffering, so that the logs stream through. -export PYTHONUNBUFFERED=1 - -# Debug: show build environment -env | grep KOKORO - -# Install nox -python3.6 -m pip install --upgrade --quiet nox - -# Use secrets acessor service account to get secrets -if [[ -f "${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" ]]; then - gcloud auth activate-service-account \ - --key-file="${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" \ - --project="cloud-devrel-kokoro-resources" -fi - -# This script will create 3 files: -# - testing/test-env.sh -# - testing/service-account.json -# - testing/client-secrets.json -./scripts/decrypt-secrets.sh - -source ./testing/test-env.sh -export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/testing/service-account.json - -# For cloud-run session, we activate the service account for gcloud sdk. -gcloud auth activate-service-account \ - --key-file "${GOOGLE_APPLICATION_CREDENTIALS}" - -export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json - -echo -e "\n******************** TESTING PROJECTS ********************" - -# Switch to 'fail at end' to allow all tests to complete before exiting. -set +e -# Use RTN to return a non-zero value if the test fails. -RTN=0 -ROOT=$(pwd) -# Find all requirements.txt in the samples directory (may break on whitespace). -for file in samples/**/requirements.txt; do - cd "$ROOT" - # Navigate to the project folder. - file=$(dirname "$file") - cd "$file" - - echo "------------------------------------------------------------" - echo "- testing $file" - echo "------------------------------------------------------------" - - # Use nox to execute the tests for the project. - python3.6 -m nox -s "$RUN_TESTS_SESSION" - EXIT=$? - - # If this is a periodic build, send the test log to the Build Cop Bot. - # See https://github.com/googleapis/repo-automation-bots/tree/master/packages/buildcop. - if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then - chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop - $KOKORO_GFILE_DIR/linux_amd64/buildcop + echo "The current head is: " + echo $(git rev-parse --verify HEAD) + echo "--- IMPORTANT IMPORTANT IMPORTANT ---" + # move back the test runner implementation if there's no file. + if [ ! -f .kokoro/test-samples-impl.sh ]; then + cp "${TMPDIR}/test-samples-impl.sh" .kokoro/test-samples-impl.sh fi +fi - if [[ $EXIT -ne 0 ]]; then - RTN=1 - echo -e "\n Testing failed: Nox returned a non-zero exit code. \n" - else - echo -e "\n Testing completed.\n" - fi - -done -cd "$ROOT" - -# Workaround for Kokoro permissions issue: delete secrets -rm testing/{test-env.sh,client-secrets.json,service-account.json} - -exit "$RTN" +exec .kokoro/test-samples-impl.sh diff --git a/.kokoro/trampoline_v2.sh b/.kokoro/trampoline_v2.sh index 719bcd5b..4af6cdc2 100755 --- a/.kokoro/trampoline_v2.sh +++ b/.kokoro/trampoline_v2.sh @@ -159,7 +159,7 @@ if [[ -n "${KOKORO_BUILD_ID:-}" ]]; then "KOKORO_GITHUB_COMMIT" "KOKORO_GITHUB_PULL_REQUEST_NUMBER" "KOKORO_GITHUB_PULL_REQUEST_COMMIT" - # For Build Cop Bot + # For FlakyBot "KOKORO_GITHUB_COMMIT_URL" "KOKORO_GITHUB_PULL_REQUEST_URL" ) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a9024b15..32302e48 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,6 +12,6 @@ repos: hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + rev: 3.9.0 hooks: - id: flake8 diff --git a/.trampolinerc b/.trampolinerc index 995ee291..383b6ec8 100644 --- a/.trampolinerc +++ b/.trampolinerc @@ -24,6 +24,7 @@ required_envvars+=( pass_down_envvars+=( "STAGING_BUCKET" "V2_STAGING_BUCKET" + "NOX_SESSION" ) # Prevent unintentional override on the default image. diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b14583a8..fcd772fd 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -70,9 +70,14 @@ We use `nox `__ to instrument our tests. - To test your changes, run unit tests with ``nox``:: $ nox -s unit-2.7 - $ nox -s unit-3.7 + $ nox -s unit-3.8 $ ... +- Args to pytest can be passed through the nox command separated by a `--`. For + example, to run a single test:: + + $ nox -s unit-3.8 -- -k + .. note:: The unit tests and system tests are described in the @@ -93,8 +98,12 @@ On Debian/Ubuntu:: ************ Coding Style ************ +- We use the automatic code formatter ``black``. You can run it using + the nox session ``blacken``. This will eliminate many lint errors. Run via:: + + $ nox -s blacken -- PEP8 compliance, with exceptions defined in the linter configuration. +- PEP8 compliance is required, with exceptions defined in the linter configuration. If you have ``nox`` installed, you can test that you have not introduced any non-compliant code via:: @@ -133,13 +142,18 @@ Running System Tests - To run system tests, you can execute:: - $ nox -s system-3.7 + # Run all system tests + $ nox -s system-3.8 $ nox -s system-2.7 + # Run a single system test + $ nox -s system-3.8 -- -k + + .. note:: System tests are only configured to run under Python 2.7 and - Python 3.7. For expediency, we do not run them in older versions + Python 3.8. For expediency, we do not run them in older versions of Python 3. This alone will not run the tests. You'll need to change some local diff --git a/MANIFEST.in b/MANIFEST.in index e9e29d12..e783f4c6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -16,10 +16,10 @@ # Generated by synthtool. DO NOT EDIT! include README.rst LICENSE -recursive-include google *.json *.proto +recursive-include google *.json *.proto py.typed recursive-include tests * global-exclude *.py[co] global-exclude __pycache__ # Exclude scripts for samples readmegen -prune scripts/readme-gen \ No newline at end of file +prune scripts/readme-gen diff --git a/docs/gaming_v1/game_server_clusters_service.rst b/docs/gaming_v1/game_server_clusters_service.rst new file mode 100644 index 00000000..252f5e38 --- /dev/null +++ b/docs/gaming_v1/game_server_clusters_service.rst @@ -0,0 +1,11 @@ +GameServerClustersService +------------------------------------------- + +.. automodule:: google.cloud.gaming_v1.services.game_server_clusters_service + :members: + :inherited-members: + + +.. automodule:: google.cloud.gaming_v1.services.game_server_clusters_service.pagers + :members: + :inherited-members: diff --git a/docs/gaming_v1/game_server_configs_service.rst b/docs/gaming_v1/game_server_configs_service.rst new file mode 100644 index 00000000..ce8eb52a --- /dev/null +++ b/docs/gaming_v1/game_server_configs_service.rst @@ -0,0 +1,11 @@ +GameServerConfigsService +------------------------------------------ + +.. automodule:: google.cloud.gaming_v1.services.game_server_configs_service + :members: + :inherited-members: + + +.. automodule:: google.cloud.gaming_v1.services.game_server_configs_service.pagers + :members: + :inherited-members: diff --git a/docs/gaming_v1/game_server_deployments_service.rst b/docs/gaming_v1/game_server_deployments_service.rst new file mode 100644 index 00000000..0dc31f40 --- /dev/null +++ b/docs/gaming_v1/game_server_deployments_service.rst @@ -0,0 +1,11 @@ +GameServerDeploymentsService +---------------------------------------------- + +.. automodule:: google.cloud.gaming_v1.services.game_server_deployments_service + :members: + :inherited-members: + + +.. automodule:: google.cloud.gaming_v1.services.game_server_deployments_service.pagers + :members: + :inherited-members: diff --git a/docs/gaming_v1/realms_service.rst b/docs/gaming_v1/realms_service.rst new file mode 100644 index 00000000..642eaf79 --- /dev/null +++ b/docs/gaming_v1/realms_service.rst @@ -0,0 +1,11 @@ +RealmsService +------------------------------- + +.. automodule:: google.cloud.gaming_v1.services.realms_service + :members: + :inherited-members: + + +.. automodule:: google.cloud.gaming_v1.services.realms_service.pagers + :members: + :inherited-members: diff --git a/docs/gaming_v1/services.rst b/docs/gaming_v1/services.rst index 8b09a196..0a08e641 100644 --- a/docs/gaming_v1/services.rst +++ b/docs/gaming_v1/services.rst @@ -1,15 +1,9 @@ Services for Google Cloud Gaming v1 API ======================================= +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.gaming_v1.services.game_server_clusters_service - :members: - :inherited-members: -.. automodule:: google.cloud.gaming_v1.services.game_server_configs_service - :members: - :inherited-members: -.. automodule:: google.cloud.gaming_v1.services.game_server_deployments_service - :members: - :inherited-members: -.. automodule:: google.cloud.gaming_v1.services.realms_service - :members: - :inherited-members: + game_server_clusters_service + game_server_configs_service + game_server_deployments_service + realms_service diff --git a/docs/gaming_v1/types.rst b/docs/gaming_v1/types.rst index dfd145a1..1948e8ea 100644 --- a/docs/gaming_v1/types.rst +++ b/docs/gaming_v1/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Gaming v1 API .. automodule:: google.cloud.gaming_v1.types :members: + :undoc-members: :show-inheritance: diff --git a/docs/gaming_v1beta/game_server_clusters_service.rst b/docs/gaming_v1beta/game_server_clusters_service.rst new file mode 100644 index 00000000..5eea9895 --- /dev/null +++ b/docs/gaming_v1beta/game_server_clusters_service.rst @@ -0,0 +1,11 @@ +GameServerClustersService +------------------------------------------- + +.. automodule:: google.cloud.gaming_v1beta.services.game_server_clusters_service + :members: + :inherited-members: + + +.. automodule:: google.cloud.gaming_v1beta.services.game_server_clusters_service.pagers + :members: + :inherited-members: diff --git a/docs/gaming_v1beta/game_server_configs_service.rst b/docs/gaming_v1beta/game_server_configs_service.rst new file mode 100644 index 00000000..f99089f7 --- /dev/null +++ b/docs/gaming_v1beta/game_server_configs_service.rst @@ -0,0 +1,11 @@ +GameServerConfigsService +------------------------------------------ + +.. automodule:: google.cloud.gaming_v1beta.services.game_server_configs_service + :members: + :inherited-members: + + +.. automodule:: google.cloud.gaming_v1beta.services.game_server_configs_service.pagers + :members: + :inherited-members: diff --git a/docs/gaming_v1beta/game_server_deployments_service.rst b/docs/gaming_v1beta/game_server_deployments_service.rst new file mode 100644 index 00000000..a0f9d6c6 --- /dev/null +++ b/docs/gaming_v1beta/game_server_deployments_service.rst @@ -0,0 +1,11 @@ +GameServerDeploymentsService +---------------------------------------------- + +.. automodule:: google.cloud.gaming_v1beta.services.game_server_deployments_service + :members: + :inherited-members: + + +.. automodule:: google.cloud.gaming_v1beta.services.game_server_deployments_service.pagers + :members: + :inherited-members: diff --git a/docs/gaming_v1beta/realms_service.rst b/docs/gaming_v1beta/realms_service.rst new file mode 100644 index 00000000..54fbb60b --- /dev/null +++ b/docs/gaming_v1beta/realms_service.rst @@ -0,0 +1,11 @@ +RealmsService +------------------------------- + +.. automodule:: google.cloud.gaming_v1beta.services.realms_service + :members: + :inherited-members: + + +.. automodule:: google.cloud.gaming_v1beta.services.realms_service.pagers + :members: + :inherited-members: diff --git a/docs/gaming_v1beta/services.rst b/docs/gaming_v1beta/services.rst index 70c98979..98f3751f 100644 --- a/docs/gaming_v1beta/services.rst +++ b/docs/gaming_v1beta/services.rst @@ -1,15 +1,9 @@ Services for Google Cloud Gaming v1beta API =========================================== +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.gaming_v1beta.services.game_server_clusters_service - :members: - :inherited-members: -.. automodule:: google.cloud.gaming_v1beta.services.game_server_configs_service - :members: - :inherited-members: -.. automodule:: google.cloud.gaming_v1beta.services.game_server_deployments_service - :members: - :inherited-members: -.. automodule:: google.cloud.gaming_v1beta.services.realms_service - :members: - :inherited-members: + game_server_clusters_service + game_server_configs_service + game_server_deployments_service + realms_service diff --git a/docs/gaming_v1beta/types.rst b/docs/gaming_v1beta/types.rst index 0d4debed..93b2a0bd 100644 --- a/docs/gaming_v1beta/types.rst +++ b/docs/gaming_v1beta/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Gaming v1beta API .. automodule:: google.cloud.gaming_v1beta.types :members: + :undoc-members: :show-inheritance: diff --git a/gaming-v1beta-py.tar.gz b/gaming-v1beta-py.tar.gz deleted file mode 100644 index e69de29b..00000000 diff --git a/google/cloud/gaming_v1/__init__.py b/google/cloud/gaming_v1/__init__.py index d565585b..cddeaeec 100644 --- a/google/cloud/gaming_v1/__init__.py +++ b/google/cloud/gaming_v1/__init__.py @@ -92,6 +92,7 @@ "FleetConfig", "GameServerCluster", "GameServerClusterConnectionInfo", + "GameServerClustersServiceClient", "GameServerConfig", "GameServerConfigOverride", "GameServerConfigsServiceClient", @@ -127,7 +128,6 @@ "PreviewUpdateGameServerClusterResponse", "Realm", "RealmSelector", - "RealmsServiceClient", "ScalingConfig", "Schedule", "SpecSource", @@ -137,5 +137,5 @@ "UpdateGameServerDeploymentRequest", "UpdateGameServerDeploymentRolloutRequest", "UpdateRealmRequest", - "GameServerClustersServiceClient", + "RealmsServiceClient", ) diff --git a/google/cloud/gaming_v1/services/game_server_clusters_service/async_client.py b/google/cloud/gaming_v1/services/game_server_clusters_service/async_client.py index 9e6f157c..b2e6c26c 100644 --- a/google/cloud/gaming_v1/services/game_server_clusters_service/async_client.py +++ b/google/cloud/gaming_v1/services/game_server_clusters_service/async_client.py @@ -94,9 +94,36 @@ class GameServerClustersServiceAsyncClient: GameServerClustersServiceClient.parse_common_location_path ) - from_service_account_file = ( - GameServerClustersServiceClient.from_service_account_file - ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerClustersServiceAsyncClient: The constructed client. + """ + return GameServerClustersServiceClient.from_service_account_info.__func__(GameServerClustersServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerClustersServiceAsyncClient: The constructed client. + """ + return GameServerClustersServiceClient.from_service_account_file.__func__(GameServerClustersServiceAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -174,13 +201,14 @@ async def list_game_server_clusters( location. Args: - request (:class:`~.game_server_clusters.ListGameServerClustersRequest`): + request (:class:`google.cloud.gaming_v1.types.ListGameServerClustersRequest`): The request object. Request message for GameServerClustersService.ListGameServerClusters. parent (:class:`str`): Required. The parent resource name. Uses the form: "projects/{project}/locations/{location}/realms/{realm}". + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -192,7 +220,7 @@ async def list_game_server_clusters( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerClustersAsyncPager: + google.cloud.gaming_v1.services.game_server_clusters_service.pagers.ListGameServerClustersAsyncPager: Response message for GameServerClustersService.ListGameServerClusters. Iterating over this object will yield @@ -227,6 +255,7 @@ async def list_game_server_clusters( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -262,7 +291,7 @@ async def get_game_server_cluster( r"""Gets details of a single game server cluster. Args: - request (:class:`~.game_server_clusters.GetGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1.types.GetGameServerClusterRequest`): The request object. Request message for GameServerClustersService.GetGameServerCluster. name (:class:`str`): @@ -270,6 +299,7 @@ async def get_game_server_cluster( retrieve. Uses the form: ``projects/{project}/locations/{location}/realms/{realm-id}/gameServerClusters/{cluster}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -281,7 +311,7 @@ async def get_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.GameServerCluster: + google.cloud.gaming_v1.types.GameServerCluster: A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -311,6 +341,7 @@ async def get_game_server_cluster( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -343,24 +374,27 @@ async def create_game_server_cluster( and location. Args: - request (:class:`~.game_server_clusters.CreateGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1.types.CreateGameServerClusterRequest`): The request object. Request message for GameServerClustersService.CreateGameServerCluster. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/realms/{realm-id}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_cluster (:class:`~.game_server_clusters.GameServerCluster`): + game_server_cluster (:class:`google.cloud.gaming_v1.types.GameServerCluster`): Required. The game server cluster resource to be created. + This corresponds to the ``game_server_cluster`` field on the ``request`` instance; if ``request`` is provided, this should not be set. game_server_cluster_id (:class:`str`): Required. The ID of the game server cluster resource to be created. + This corresponds to the ``game_server_cluster_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -372,12 +406,12 @@ async def create_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_clusters.GameServerCluster``: A - game server cluster resource. + :class:`google.cloud.gaming_v1.types.GameServerCluster` + A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -444,7 +478,7 @@ async def preview_create_game_server_cluster( given project and location. Args: - request (:class:`~.game_server_clusters.PreviewCreateGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1.types.PreviewCreateGameServerClusterRequest`): The request object. Request message for GameServerClustersService.PreviewCreateGameServerCluster. @@ -455,7 +489,7 @@ async def preview_create_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewCreateGameServerClusterResponse: + google.cloud.gaming_v1.types.PreviewCreateGameServerClusterResponse: Response message for GameServerClustersService.PreviewCreateGameServerCluster. @@ -473,6 +507,7 @@ async def preview_create_game_server_cluster( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -502,13 +537,14 @@ async def delete_game_server_cluster( r"""Deletes a single game server cluster. Args: - request (:class:`~.game_server_clusters.DeleteGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1.types.DeleteGameServerClusterRequest`): The request object. Request message for GameServerClustersService.DeleteGameServerCluster. name (:class:`str`): Required. The name of the game server cluster to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerClusters/{cluster}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -520,24 +556,22 @@ async def delete_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -597,7 +631,7 @@ async def preview_delete_game_server_cluster( r"""Previews deletion of a single game server cluster. Args: - request (:class:`~.game_server_clusters.PreviewDeleteGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1.types.PreviewDeleteGameServerClusterRequest`): The request object. Request message for GameServerClustersService.PreviewDeleteGameServerCluster. @@ -608,7 +642,7 @@ async def preview_delete_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewDeleteGameServerClusterResponse: + google.cloud.gaming_v1.types.PreviewDeleteGameServerClusterResponse: Response message for GameServerClustersService.PreviewDeleteGameServerCluster. @@ -626,6 +660,7 @@ async def preview_delete_game_server_cluster( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -656,22 +691,24 @@ async def update_game_server_cluster( r"""Patches a single game server cluster. Args: - request (:class:`~.game_server_clusters.UpdateGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1.types.UpdateGameServerClusterRequest`): The request object. Request message for GameServerClustersService.UpdateGameServerCluster. - game_server_cluster (:class:`~.game_server_clusters.GameServerCluster`): + game_server_cluster (:class:`google.cloud.gaming_v1.types.GameServerCluster`): Required. The game server cluster to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``game_server_cluster`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -683,12 +720,12 @@ async def update_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_clusters.GameServerCluster``: A - game server cluster resource. + :class:`google.cloud.gaming_v1.types.GameServerCluster` + A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -752,7 +789,7 @@ async def preview_update_game_server_cluster( r"""Previews updating a GameServerCluster. Args: - request (:class:`~.game_server_clusters.PreviewUpdateGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1.types.PreviewUpdateGameServerClusterRequest`): The request object. Request message for GameServerClustersService.UpdateGameServerCluster. @@ -763,7 +800,7 @@ async def preview_update_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewUpdateGameServerClusterResponse: + google.cloud.gaming_v1.types.PreviewUpdateGameServerClusterResponse: Response message for GameServerClustersService.PreviewUpdateGameServerCluster @@ -781,6 +818,7 @@ async def preview_update_game_server_cluster( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/google/cloud/gaming_v1/services/game_server_clusters_service/client.py b/google/cloud/gaming_v1/services/game_server_clusters_service/client.py index 356ad140..ea2baca7 100644 --- a/google/cloud/gaming_v1/services/game_server_clusters_service/client.py +++ b/google/cloud/gaming_v1/services/game_server_clusters_service/client.py @@ -120,6 +120,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerClustersServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -132,7 +148,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + GameServerClustersServiceClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -242,10 +258,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.GameServerClustersServiceTransport]): The + transport (Union[str, GameServerClustersServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -281,21 +297,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -338,7 +350,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -356,13 +368,14 @@ def list_game_server_clusters( location. Args: - request (:class:`~.game_server_clusters.ListGameServerClustersRequest`): + request (google.cloud.gaming_v1.types.ListGameServerClustersRequest): The request object. Request message for GameServerClustersService.ListGameServerClusters. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: "projects/{project}/locations/{location}/realms/{realm}". + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -374,7 +387,7 @@ def list_game_server_clusters( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerClustersPager: + google.cloud.gaming_v1.services.game_server_clusters_service.pagers.ListGameServerClustersPager: Response message for GameServerClustersService.ListGameServerClusters. Iterating over this object will yield @@ -441,14 +454,15 @@ def get_game_server_cluster( r"""Gets details of a single game server cluster. Args: - request (:class:`~.game_server_clusters.GetGameServerClusterRequest`): + request (google.cloud.gaming_v1.types.GetGameServerClusterRequest): The request object. Request message for GameServerClustersService.GetGameServerCluster. - name (:class:`str`): + name (str): Required. The name of the game server cluster to retrieve. Uses the form: ``projects/{project}/locations/{location}/realms/{realm-id}/gameServerClusters/{cluster}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -460,7 +474,7 @@ def get_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.GameServerCluster: + google.cloud.gaming_v1.types.GameServerCluster: A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -517,24 +531,27 @@ def create_game_server_cluster( and location. Args: - request (:class:`~.game_server_clusters.CreateGameServerClusterRequest`): + request (google.cloud.gaming_v1.types.CreateGameServerClusterRequest): The request object. Request message for GameServerClustersService.CreateGameServerCluster. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/realms/{realm-id}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_cluster (:class:`~.game_server_clusters.GameServerCluster`): + game_server_cluster (google.cloud.gaming_v1.types.GameServerCluster): Required. The game server cluster resource to be created. + This corresponds to the ``game_server_cluster`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_cluster_id (:class:`str`): + game_server_cluster_id (str): Required. The ID of the game server cluster resource to be created. + This corresponds to the ``game_server_cluster_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -546,12 +563,12 @@ def create_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_clusters.GameServerCluster``: A - game server cluster resource. + :class:`google.cloud.gaming_v1.types.GameServerCluster` + A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -621,7 +638,7 @@ def preview_create_game_server_cluster( given project and location. Args: - request (:class:`~.game_server_clusters.PreviewCreateGameServerClusterRequest`): + request (google.cloud.gaming_v1.types.PreviewCreateGameServerClusterRequest): The request object. Request message for GameServerClustersService.PreviewCreateGameServerCluster. @@ -632,7 +649,7 @@ def preview_create_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewCreateGameServerClusterResponse: + google.cloud.gaming_v1.types.PreviewCreateGameServerClusterResponse: Response message for GameServerClustersService.PreviewCreateGameServerCluster. @@ -680,13 +697,14 @@ def delete_game_server_cluster( r"""Deletes a single game server cluster. Args: - request (:class:`~.game_server_clusters.DeleteGameServerClusterRequest`): + request (google.cloud.gaming_v1.types.DeleteGameServerClusterRequest): The request object. Request message for GameServerClustersService.DeleteGameServerCluster. - name (:class:`str`): + name (str): Required. The name of the game server cluster to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerClusters/{cluster}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -698,24 +716,22 @@ def delete_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -778,7 +794,7 @@ def preview_delete_game_server_cluster( r"""Previews deletion of a single game server cluster. Args: - request (:class:`~.game_server_clusters.PreviewDeleteGameServerClusterRequest`): + request (google.cloud.gaming_v1.types.PreviewDeleteGameServerClusterRequest): The request object. Request message for GameServerClustersService.PreviewDeleteGameServerCluster. @@ -789,7 +805,7 @@ def preview_delete_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewDeleteGameServerClusterResponse: + google.cloud.gaming_v1.types.PreviewDeleteGameServerClusterResponse: Response message for GameServerClustersService.PreviewDeleteGameServerCluster. @@ -838,22 +854,24 @@ def update_game_server_cluster( r"""Patches a single game server cluster. Args: - request (:class:`~.game_server_clusters.UpdateGameServerClusterRequest`): + request (google.cloud.gaming_v1.types.UpdateGameServerClusterRequest): The request object. Request message for GameServerClustersService.UpdateGameServerCluster. - game_server_cluster (:class:`~.game_server_clusters.GameServerCluster`): + game_server_cluster (google.cloud.gaming_v1.types.GameServerCluster): Required. The game server cluster to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``game_server_cluster`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -865,12 +883,12 @@ def update_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_clusters.GameServerCluster``: A - game server cluster resource. + :class:`google.cloud.gaming_v1.types.GameServerCluster` + A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -937,7 +955,7 @@ def preview_update_game_server_cluster( r"""Previews updating a GameServerCluster. Args: - request (:class:`~.game_server_clusters.PreviewUpdateGameServerClusterRequest`): + request (google.cloud.gaming_v1.types.PreviewUpdateGameServerClusterRequest): The request object. Request message for GameServerClustersService.UpdateGameServerCluster. @@ -948,7 +966,7 @@ def preview_update_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewUpdateGameServerClusterResponse: + google.cloud.gaming_v1.types.PreviewUpdateGameServerClusterResponse: Response message for GameServerClustersService.PreviewUpdateGameServerCluster diff --git a/google/cloud/gaming_v1/services/game_server_clusters_service/pagers.py b/google/cloud/gaming_v1/services/game_server_clusters_service/pagers.py index b2487187..a8b06121 100644 --- a/google/cloud/gaming_v1/services/game_server_clusters_service/pagers.py +++ b/google/cloud/gaming_v1/services/game_server_clusters_service/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.gaming_v1.types import game_server_clusters @@ -24,7 +33,7 @@ class ListGameServerClustersPager: """A pager for iterating through ``list_game_server_clusters`` requests. This class thinly wraps an initial - :class:`~.game_server_clusters.ListGameServerClustersResponse` object, and + :class:`google.cloud.gaming_v1.types.ListGameServerClustersResponse` object, and provides an ``__iter__`` method to iterate through its ``game_server_clusters`` field. @@ -33,7 +42,7 @@ class ListGameServerClustersPager: through the ``game_server_clusters`` field on the corresponding responses. - All the usual :class:`~.game_server_clusters.ListGameServerClustersResponse` + All the usual :class:`google.cloud.gaming_v1.types.ListGameServerClustersResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +60,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_clusters.ListGameServerClustersRequest`): + request (google.cloud.gaming_v1.types.ListGameServerClustersRequest): The initial request object. - response (:class:`~.game_server_clusters.ListGameServerClustersResponse`): + response (google.cloud.gaming_v1.types.ListGameServerClustersResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +95,7 @@ class ListGameServerClustersAsyncPager: """A pager for iterating through ``list_game_server_clusters`` requests. This class thinly wraps an initial - :class:`~.game_server_clusters.ListGameServerClustersResponse` object, and + :class:`google.cloud.gaming_v1.types.ListGameServerClustersResponse` object, and provides an ``__aiter__`` method to iterate through its ``game_server_clusters`` field. @@ -95,7 +104,7 @@ class ListGameServerClustersAsyncPager: through the ``game_server_clusters`` field on the corresponding responses. - All the usual :class:`~.game_server_clusters.ListGameServerClustersResponse` + All the usual :class:`google.cloud.gaming_v1.types.ListGameServerClustersResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +124,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_clusters.ListGameServerClustersRequest`): + request (google.cloud.gaming_v1.types.ListGameServerClustersRequest): The initial request object. - response (:class:`~.game_server_clusters.ListGameServerClustersResponse`): + response (google.cloud.gaming_v1.types.ListGameServerClustersResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/gaming_v1/services/game_server_clusters_service/transports/base.py b/google/cloud/gaming_v1/services/game_server_clusters_service/transports/base.py index ea91f479..d0ee22d1 100644 --- a/google/cloud/gaming_v1/services/game_server_clusters_service/transports/base.py +++ b/google/cloud/gaming_v1/services/game_server_clusters_service/transports/base.py @@ -71,10 +71,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -82,6 +82,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -91,20 +94,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -115,6 +115,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -126,6 +127,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -142,6 +144,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -158,6 +161,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -174,6 +178,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, diff --git a/google/cloud/gaming_v1/services/game_server_clusters_service/transports/grpc.py b/google/cloud/gaming_v1/services/game_server_clusters_service/transports/grpc.py index 4d5ed3c9..f6e1cb03 100644 --- a/google/cloud/gaming_v1/services/game_server_clusters_service/transports/grpc.py +++ b/google/cloud/gaming_v1/services/game_server_clusters_service/transports/grpc.py @@ -60,6 +60,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -90,6 +91,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -104,72 +109,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -177,18 +171,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -202,7 +186,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/gaming_v1/services/game_server_clusters_service/transports/grpc_asyncio.py b/google/cloud/gaming_v1/services/game_server_clusters_service/transports/grpc_asyncio.py index 31c71904..7784bbd6 100644 --- a/google/cloud/gaming_v1/services/game_server_clusters_service/transports/grpc_asyncio.py +++ b/google/cloud/gaming_v1/services/game_server_clusters_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -104,6 +104,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -135,12 +136,16 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -149,72 +154,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -222,18 +216,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/gaming_v1/services/game_server_configs_service/async_client.py b/google/cloud/gaming_v1/services/game_server_configs_service/async_client.py index 57b7d0c1..c9e2a2c6 100644 --- a/google/cloud/gaming_v1/services/game_server_configs_service/async_client.py +++ b/google/cloud/gaming_v1/services/game_server_configs_service/async_client.py @@ -91,7 +91,36 @@ class GameServerConfigsServiceAsyncClient: GameServerConfigsServiceClient.parse_common_location_path ) - from_service_account_file = GameServerConfigsServiceClient.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerConfigsServiceAsyncClient: The constructed client. + """ + return GameServerConfigsServiceClient.from_service_account_info.__func__(GameServerConfigsServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerConfigsServiceAsyncClient: The constructed client. + """ + return GameServerConfigsServiceClient.from_service_account_file.__func__(GameServerConfigsServiceAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -169,13 +198,14 @@ async def list_game_server_configs( location, and game server deployment. Args: - request (:class:`~.game_server_configs.ListGameServerConfigsRequest`): + request (:class:`google.cloud.gaming_v1.types.ListGameServerConfigsRequest`): The request object. Request message for GameServerConfigsService.ListGameServerConfigs. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/*``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -187,7 +217,7 @@ async def list_game_server_configs( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerConfigsAsyncPager: + google.cloud.gaming_v1.services.game_server_configs_service.pagers.ListGameServerConfigsAsyncPager: Response message for GameServerConfigsService.ListGameServerConfigs. Iterating over this object will yield @@ -222,6 +252,7 @@ async def list_game_server_configs( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -257,7 +288,7 @@ async def get_game_server_config( r"""Gets details of a single game server config. Args: - request (:class:`~.game_server_configs.GetGameServerConfigRequest`): + request (:class:`google.cloud.gaming_v1.types.GetGameServerConfigRequest`): The request object. Request message for GameServerConfigsService.GetGameServerConfig. name (:class:`str`): @@ -265,6 +296,7 @@ async def get_game_server_config( retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/{config}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -276,7 +308,7 @@ async def get_game_server_config( sent along with the request as metadata. Returns: - ~.game_server_configs.GameServerConfig: + google.cloud.gaming_v1.types.GameServerConfig: A game server config resource. """ # Create or coerce a protobuf request object. @@ -306,6 +338,7 @@ async def get_game_server_config( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -340,19 +373,21 @@ async def create_game_server_config( resource. Args: - request (:class:`~.game_server_configs.CreateGameServerConfigRequest`): + request (:class:`google.cloud.gaming_v1.types.CreateGameServerConfigRequest`): The request object. Request message for GameServerConfigsService.CreateGameServerConfig. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_config (:class:`~.game_server_configs.GameServerConfig`): + game_server_config (:class:`google.cloud.gaming_v1.types.GameServerConfig`): Required. The game server config resource to be created. + This corresponds to the ``game_server_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -364,11 +399,11 @@ async def create_game_server_config( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_configs.GameServerConfig``: A + :class:`google.cloud.gaming_v1.types.GameServerConfig` A game server config resource. """ @@ -434,7 +469,7 @@ async def delete_game_server_config( game server deployment rollout. Args: - request (:class:`~.game_server_configs.DeleteGameServerConfigRequest`): + request (:class:`google.cloud.gaming_v1.types.DeleteGameServerConfigRequest`): The request object. Request message for GameServerConfigsService.DeleteGameServerConfig. name (:class:`str`): @@ -442,6 +477,7 @@ async def delete_game_server_config( Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/{config}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -453,24 +489,22 @@ async def delete_game_server_config( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/gaming_v1/services/game_server_configs_service/client.py b/google/cloud/gaming_v1/services/game_server_configs_service/client.py index fcb5a880..0056a258 100644 --- a/google/cloud/gaming_v1/services/game_server_configs_service/client.py +++ b/google/cloud/gaming_v1/services/game_server_configs_service/client.py @@ -119,6 +119,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerConfigsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -131,7 +147,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + GameServerConfigsServiceClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -241,10 +257,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.GameServerConfigsServiceTransport]): The + transport (Union[str, GameServerConfigsServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -280,21 +296,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -337,7 +349,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -355,13 +367,14 @@ def list_game_server_configs( location, and game server deployment. Args: - request (:class:`~.game_server_configs.ListGameServerConfigsRequest`): + request (google.cloud.gaming_v1.types.ListGameServerConfigsRequest): The request object. Request message for GameServerConfigsService.ListGameServerConfigs. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/*``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -373,7 +386,7 @@ def list_game_server_configs( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerConfigsPager: + google.cloud.gaming_v1.services.game_server_configs_service.pagers.ListGameServerConfigsPager: Response message for GameServerConfigsService.ListGameServerConfigs. Iterating over this object will yield @@ -438,14 +451,15 @@ def get_game_server_config( r"""Gets details of a single game server config. Args: - request (:class:`~.game_server_configs.GetGameServerConfigRequest`): + request (google.cloud.gaming_v1.types.GetGameServerConfigRequest): The request object. Request message for GameServerConfigsService.GetGameServerConfig. - name (:class:`str`): + name (str): Required. The name of the game server config to retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/{config}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -457,7 +471,7 @@ def get_game_server_config( sent along with the request as metadata. Returns: - ~.game_server_configs.GameServerConfig: + google.cloud.gaming_v1.types.GameServerConfig: A game server config resource. """ # Create or coerce a protobuf request object. @@ -516,19 +530,21 @@ def create_game_server_config( resource. Args: - request (:class:`~.game_server_configs.CreateGameServerConfigRequest`): + request (google.cloud.gaming_v1.types.CreateGameServerConfigRequest): The request object. Request message for GameServerConfigsService.CreateGameServerConfig. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_config (:class:`~.game_server_configs.GameServerConfig`): + game_server_config (google.cloud.gaming_v1.types.GameServerConfig): Required. The game server config resource to be created. + This corresponds to the ``game_server_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -540,11 +556,11 @@ def create_game_server_config( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_configs.GameServerConfig``: A + :class:`google.cloud.gaming_v1.types.GameServerConfig` A game server config resource. """ @@ -613,14 +629,15 @@ def delete_game_server_config( game server deployment rollout. Args: - request (:class:`~.game_server_configs.DeleteGameServerConfigRequest`): + request (google.cloud.gaming_v1.types.DeleteGameServerConfigRequest): The request object. Request message for GameServerConfigsService.DeleteGameServerConfig. - name (:class:`str`): + name (str): Required. The name of the game server config to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/{config}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -632,24 +649,22 @@ def delete_game_server_config( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/gaming_v1/services/game_server_configs_service/pagers.py b/google/cloud/gaming_v1/services/game_server_configs_service/pagers.py index 538eef8f..b016710c 100644 --- a/google/cloud/gaming_v1/services/game_server_configs_service/pagers.py +++ b/google/cloud/gaming_v1/services/game_server_configs_service/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.gaming_v1.types import game_server_configs @@ -24,7 +33,7 @@ class ListGameServerConfigsPager: """A pager for iterating through ``list_game_server_configs`` requests. This class thinly wraps an initial - :class:`~.game_server_configs.ListGameServerConfigsResponse` object, and + :class:`google.cloud.gaming_v1.types.ListGameServerConfigsResponse` object, and provides an ``__iter__`` method to iterate through its ``game_server_configs`` field. @@ -33,7 +42,7 @@ class ListGameServerConfigsPager: through the ``game_server_configs`` field on the corresponding responses. - All the usual :class:`~.game_server_configs.ListGameServerConfigsResponse` + All the usual :class:`google.cloud.gaming_v1.types.ListGameServerConfigsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +60,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_configs.ListGameServerConfigsRequest`): + request (google.cloud.gaming_v1.types.ListGameServerConfigsRequest): The initial request object. - response (:class:`~.game_server_configs.ListGameServerConfigsResponse`): + response (google.cloud.gaming_v1.types.ListGameServerConfigsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +95,7 @@ class ListGameServerConfigsAsyncPager: """A pager for iterating through ``list_game_server_configs`` requests. This class thinly wraps an initial - :class:`~.game_server_configs.ListGameServerConfigsResponse` object, and + :class:`google.cloud.gaming_v1.types.ListGameServerConfigsResponse` object, and provides an ``__aiter__`` method to iterate through its ``game_server_configs`` field. @@ -95,7 +104,7 @@ class ListGameServerConfigsAsyncPager: through the ``game_server_configs`` field on the corresponding responses. - All the usual :class:`~.game_server_configs.ListGameServerConfigsResponse` + All the usual :class:`google.cloud.gaming_v1.types.ListGameServerConfigsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +124,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_configs.ListGameServerConfigsRequest`): + request (google.cloud.gaming_v1.types.ListGameServerConfigsRequest): The initial request object. - response (:class:`~.game_server_configs.ListGameServerConfigsResponse`): + response (google.cloud.gaming_v1.types.ListGameServerConfigsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/gaming_v1/services/game_server_configs_service/transports/base.py b/google/cloud/gaming_v1/services/game_server_configs_service/transports/base.py index f814a1a3..06cfab48 100644 --- a/google/cloud/gaming_v1/services/game_server_configs_service/transports/base.py +++ b/google/cloud/gaming_v1/services/game_server_configs_service/transports/base.py @@ -71,10 +71,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -82,6 +82,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -91,20 +94,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -115,6 +115,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -126,6 +127,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, diff --git a/google/cloud/gaming_v1/services/game_server_configs_service/transports/grpc.py b/google/cloud/gaming_v1/services/game_server_configs_service/transports/grpc.py index 3535d0ea..da8ae1ff 100644 --- a/google/cloud/gaming_v1/services/game_server_configs_service/transports/grpc.py +++ b/google/cloud/gaming_v1/services/game_server_configs_service/transports/grpc.py @@ -60,6 +60,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -90,6 +91,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -104,72 +109,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -177,18 +171,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -202,7 +186,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/gaming_v1/services/game_server_configs_service/transports/grpc_asyncio.py b/google/cloud/gaming_v1/services/game_server_configs_service/transports/grpc_asyncio.py index 02b033c9..bba13ad8 100644 --- a/google/cloud/gaming_v1/services/game_server_configs_service/transports/grpc_asyncio.py +++ b/google/cloud/gaming_v1/services/game_server_configs_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -104,6 +104,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -135,12 +136,16 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -149,72 +154,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -222,18 +216,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/gaming_v1/services/game_server_deployments_service/async_client.py b/google/cloud/gaming_v1/services/game_server_deployments_service/async_client.py index fb8217c8..0aa3fc47 100644 --- a/google/cloud/gaming_v1/services/game_server_deployments_service/async_client.py +++ b/google/cloud/gaming_v1/services/game_server_deployments_service/async_client.py @@ -100,9 +100,36 @@ class GameServerDeploymentsServiceAsyncClient: GameServerDeploymentsServiceClient.parse_common_location_path ) - from_service_account_file = ( - GameServerDeploymentsServiceClient.from_service_account_file - ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerDeploymentsServiceAsyncClient: The constructed client. + """ + return GameServerDeploymentsServiceClient.from_service_account_info.__func__(GameServerDeploymentsServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerDeploymentsServiceAsyncClient: The constructed client. + """ + return GameServerDeploymentsServiceClient.from_service_account_file.__func__(GameServerDeploymentsServiceAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -180,12 +207,13 @@ async def list_game_server_deployments( location. Args: - request (:class:`~.game_server_deployments.ListGameServerDeploymentsRequest`): + request (:class:`google.cloud.gaming_v1.types.ListGameServerDeploymentsRequest`): The request object. Request message for GameServerDeploymentsService.ListGameServerDeployments. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -197,7 +225,7 @@ async def list_game_server_deployments( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerDeploymentsAsyncPager: + google.cloud.gaming_v1.services.game_server_deployments_service.pagers.ListGameServerDeploymentsAsyncPager: Response message for GameServerDeploymentsService.ListGameServerDeployments. Iterating over this object will yield @@ -232,6 +260,7 @@ async def list_game_server_deployments( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -267,7 +296,7 @@ async def get_game_server_deployment( r"""Gets details of a single game server deployment. Args: - request (:class:`~.game_server_deployments.GetGameServerDeploymentRequest`): + request (:class:`google.cloud.gaming_v1.types.GetGameServerDeploymentRequest`): The request object. Request message for GameServerDeploymentsService.GetGameServerDeployment. name (:class:`str`): @@ -275,6 +304,7 @@ async def get_game_server_deployment( retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -286,7 +316,7 @@ async def get_game_server_deployment( sent along with the request as metadata. Returns: - ~.game_server_deployments.GameServerDeployment: + google.cloud.gaming_v1.types.GameServerDeployment: A game server deployment resource. """ # Create or coerce a protobuf request object. @@ -316,6 +346,7 @@ async def get_game_server_deployment( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -347,18 +378,20 @@ async def create_game_server_deployment( project and location. Args: - request (:class:`~.game_server_deployments.CreateGameServerDeploymentRequest`): + request (:class:`google.cloud.gaming_v1.types.CreateGameServerDeploymentRequest`): The request object. Request message for GameServerDeploymentsService.CreateGameServerDeployment. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_deployment (:class:`~.game_server_deployments.GameServerDeployment`): + game_server_deployment (:class:`google.cloud.gaming_v1.types.GameServerDeployment`): Required. The game server delpoyment resource to be created. + This corresponds to the ``game_server_deployment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -370,11 +403,11 @@ async def create_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1.types.GameServerDeployment` A game server deployment resource. """ @@ -438,7 +471,7 @@ async def delete_game_server_deployment( r"""Deletes a single game server deployment. Args: - request (:class:`~.game_server_deployments.DeleteGameServerDeploymentRequest`): + request (:class:`google.cloud.gaming_v1.types.DeleteGameServerDeploymentRequest`): The request object. Request message for GameServerDeploymentsService.DeleteGameServerDeployment. name (:class:`str`): @@ -446,6 +479,7 @@ async def delete_game_server_deployment( delete. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -457,24 +491,22 @@ async def delete_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -536,23 +568,25 @@ async def update_game_server_deployment( r"""Patches a game server deployment. Args: - request (:class:`~.game_server_deployments.UpdateGameServerDeploymentRequest`): + request (:class:`google.cloud.gaming_v1.types.UpdateGameServerDeploymentRequest`): The request object. Request message for GameServerDeploymentsService.UpdateGameServerDeployment. Only allows updates for labels. - game_server_deployment (:class:`~.game_server_deployments.GameServerDeployment`): + game_server_deployment (:class:`google.cloud.gaming_v1.types.GameServerDeployment`): Required. The game server delpoyment to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``game_server_deployment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -564,11 +598,11 @@ async def update_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1.types.GameServerDeployment` A game server deployment resource. """ @@ -634,7 +668,7 @@ async def get_game_server_deployment_rollout( r"""Gets details a single game server deployment rollout. Args: - request (:class:`~.game_server_deployments.GetGameServerDeploymentRolloutRequest`): + request (:class:`google.cloud.gaming_v1.types.GetGameServerDeploymentRolloutRequest`): The request object. Request message for GameServerDeploymentsService.GetGameServerDeploymentRollout. name (:class:`str`): @@ -642,6 +676,7 @@ async def get_game_server_deployment_rollout( retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -653,7 +688,7 @@ async def get_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.game_server_deployments.GameServerDeploymentRollout: + google.cloud.gaming_v1.types.GameServerDeploymentRollout: The game server deployment rollout which represents the desired rollout state. @@ -686,6 +721,7 @@ async def get_game_server_deployment_rollout( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -722,23 +758,25 @@ async def update_game_server_deployment_rollout( an error. Args: - request (:class:`~.game_server_deployments.UpdateGameServerDeploymentRolloutRequest`): + request (:class:`google.cloud.gaming_v1.types.UpdateGameServerDeploymentRolloutRequest`): The request object. Request message for GameServerDeploymentsService.UpdateGameServerRolloutDeployment. - rollout (:class:`~.game_server_deployments.GameServerDeploymentRollout`): + rollout (:class:`google.cloud.gaming_v1.types.GameServerDeploymentRollout`): Required. The game server delpoyment rollout to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``rollout`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -750,11 +788,11 @@ async def update_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1.types.GameServerDeployment` A game server deployment resource. """ @@ -822,7 +860,7 @@ async def preview_game_server_deployment_rollout( does not mutate the rollout resource. Args: - request (:class:`~.game_server_deployments.PreviewGameServerDeploymentRolloutRequest`): + request (:class:`google.cloud.gaming_v1.types.PreviewGameServerDeploymentRolloutRequest`): The request object. Request message for PreviewGameServerDeploymentRollout. @@ -833,7 +871,7 @@ async def preview_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.game_server_deployments.PreviewGameServerDeploymentRolloutResponse: + google.cloud.gaming_v1.types.PreviewGameServerDeploymentRolloutResponse: Response message for PreviewGameServerDeploymentRollout. This has details about the Agones fleet and @@ -855,6 +893,7 @@ async def preview_game_server_deployment_rollout( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -888,7 +927,7 @@ async def fetch_deployment_state( older version of the game server deployment. Args: - request (:class:`~.game_server_deployments.FetchDeploymentStateRequest`): + request (:class:`google.cloud.gaming_v1.types.FetchDeploymentStateRequest`): The request object. Request message for GameServerDeploymentsService.FetchDeploymentState. @@ -899,7 +938,7 @@ async def fetch_deployment_state( sent along with the request as metadata. Returns: - ~.game_server_deployments.FetchDeploymentStateResponse: + google.cloud.gaming_v1.types.FetchDeploymentStateResponse: Response message for GameServerDeploymentsService.FetchDeploymentState. @@ -917,6 +956,7 @@ async def fetch_deployment_state( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=120.0, ), default_timeout=120.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/google/cloud/gaming_v1/services/game_server_deployments_service/client.py b/google/cloud/gaming_v1/services/game_server_deployments_service/client.py index efc3bff5..a173df5c 100644 --- a/google/cloud/gaming_v1/services/game_server_deployments_service/client.py +++ b/google/cloud/gaming_v1/services/game_server_deployments_service/client.py @@ -124,6 +124,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerDeploymentsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -136,7 +152,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + GameServerDeploymentsServiceClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -264,10 +280,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.GameServerDeploymentsServiceTransport]): The + transport (Union[str, GameServerDeploymentsServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -303,21 +319,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -360,7 +372,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -378,12 +390,13 @@ def list_game_server_deployments( location. Args: - request (:class:`~.game_server_deployments.ListGameServerDeploymentsRequest`): + request (google.cloud.gaming_v1.types.ListGameServerDeploymentsRequest): The request object. Request message for GameServerDeploymentsService.ListGameServerDeployments. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -395,7 +408,7 @@ def list_game_server_deployments( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerDeploymentsPager: + google.cloud.gaming_v1.services.game_server_deployments_service.pagers.ListGameServerDeploymentsPager: Response message for GameServerDeploymentsService.ListGameServerDeployments. Iterating over this object will yield @@ -464,14 +477,15 @@ def get_game_server_deployment( r"""Gets details of a single game server deployment. Args: - request (:class:`~.game_server_deployments.GetGameServerDeploymentRequest`): + request (google.cloud.gaming_v1.types.GetGameServerDeploymentRequest): The request object. Request message for GameServerDeploymentsService.GetGameServerDeployment. - name (:class:`str`): + name (str): Required. The name of the game server delpoyment to retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -483,7 +497,7 @@ def get_game_server_deployment( sent along with the request as metadata. Returns: - ~.game_server_deployments.GameServerDeployment: + google.cloud.gaming_v1.types.GameServerDeployment: A game server deployment resource. """ # Create or coerce a protobuf request object. @@ -543,18 +557,20 @@ def create_game_server_deployment( project and location. Args: - request (:class:`~.game_server_deployments.CreateGameServerDeploymentRequest`): + request (google.cloud.gaming_v1.types.CreateGameServerDeploymentRequest): The request object. Request message for GameServerDeploymentsService.CreateGameServerDeployment. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_deployment (:class:`~.game_server_deployments.GameServerDeployment`): + game_server_deployment (google.cloud.gaming_v1.types.GameServerDeployment): Required. The game server delpoyment resource to be created. + This corresponds to the ``game_server_deployment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -566,11 +582,11 @@ def create_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1.types.GameServerDeployment` A game server deployment resource. """ @@ -639,14 +655,15 @@ def delete_game_server_deployment( r"""Deletes a single game server deployment. Args: - request (:class:`~.game_server_deployments.DeleteGameServerDeploymentRequest`): + request (google.cloud.gaming_v1.types.DeleteGameServerDeploymentRequest): The request object. Request message for GameServerDeploymentsService.DeleteGameServerDeployment. - name (:class:`str`): + name (str): Required. The name of the game server delpoyment to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -658,24 +675,22 @@ def delete_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -742,23 +757,25 @@ def update_game_server_deployment( r"""Patches a game server deployment. Args: - request (:class:`~.game_server_deployments.UpdateGameServerDeploymentRequest`): + request (google.cloud.gaming_v1.types.UpdateGameServerDeploymentRequest): The request object. Request message for GameServerDeploymentsService.UpdateGameServerDeployment. Only allows updates for labels. - game_server_deployment (:class:`~.game_server_deployments.GameServerDeployment`): + game_server_deployment (google.cloud.gaming_v1.types.GameServerDeployment): Required. The game server delpoyment to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``game_server_deployment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -770,11 +787,11 @@ def update_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1.types.GameServerDeployment` A game server deployment resource. """ @@ -845,14 +862,15 @@ def get_game_server_deployment_rollout( r"""Gets details a single game server deployment rollout. Args: - request (:class:`~.game_server_deployments.GetGameServerDeploymentRolloutRequest`): + request (google.cloud.gaming_v1.types.GetGameServerDeploymentRolloutRequest): The request object. Request message for GameServerDeploymentsService.GetGameServerDeploymentRollout. - name (:class:`str`): + name (str): Required. The name of the game server delpoyment to retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -864,7 +882,7 @@ def get_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.game_server_deployments.GameServerDeploymentRollout: + google.cloud.gaming_v1.types.GameServerDeploymentRollout: The game server deployment rollout which represents the desired rollout state. @@ -934,23 +952,25 @@ def update_game_server_deployment_rollout( an error. Args: - request (:class:`~.game_server_deployments.UpdateGameServerDeploymentRolloutRequest`): + request (google.cloud.gaming_v1.types.UpdateGameServerDeploymentRolloutRequest): The request object. Request message for GameServerDeploymentsService.UpdateGameServerRolloutDeployment. - rollout (:class:`~.game_server_deployments.GameServerDeploymentRollout`): + rollout (google.cloud.gaming_v1.types.GameServerDeploymentRollout): Required. The game server delpoyment rollout to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``rollout`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -962,11 +982,11 @@ def update_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1.types.GameServerDeployment` A game server deployment resource. """ @@ -1039,7 +1059,7 @@ def preview_game_server_deployment_rollout( does not mutate the rollout resource. Args: - request (:class:`~.game_server_deployments.PreviewGameServerDeploymentRolloutRequest`): + request (google.cloud.gaming_v1.types.PreviewGameServerDeploymentRolloutRequest): The request object. Request message for PreviewGameServerDeploymentRollout. @@ -1050,7 +1070,7 @@ def preview_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.game_server_deployments.PreviewGameServerDeploymentRolloutResponse: + google.cloud.gaming_v1.types.PreviewGameServerDeploymentRolloutResponse: Response message for PreviewGameServerDeploymentRollout. This has details about the Agones fleet and @@ -1104,7 +1124,7 @@ def fetch_deployment_state( older version of the game server deployment. Args: - request (:class:`~.game_server_deployments.FetchDeploymentStateRequest`): + request (google.cloud.gaming_v1.types.FetchDeploymentStateRequest): The request object. Request message for GameServerDeploymentsService.FetchDeploymentState. @@ -1115,7 +1135,7 @@ def fetch_deployment_state( sent along with the request as metadata. Returns: - ~.game_server_deployments.FetchDeploymentStateResponse: + google.cloud.gaming_v1.types.FetchDeploymentStateResponse: Response message for GameServerDeploymentsService.FetchDeploymentState. diff --git a/google/cloud/gaming_v1/services/game_server_deployments_service/pagers.py b/google/cloud/gaming_v1/services/game_server_deployments_service/pagers.py index 5fed613e..ae778492 100644 --- a/google/cloud/gaming_v1/services/game_server_deployments_service/pagers.py +++ b/google/cloud/gaming_v1/services/game_server_deployments_service/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.gaming_v1.types import game_server_deployments @@ -24,7 +33,7 @@ class ListGameServerDeploymentsPager: """A pager for iterating through ``list_game_server_deployments`` requests. This class thinly wraps an initial - :class:`~.game_server_deployments.ListGameServerDeploymentsResponse` object, and + :class:`google.cloud.gaming_v1.types.ListGameServerDeploymentsResponse` object, and provides an ``__iter__`` method to iterate through its ``game_server_deployments`` field. @@ -33,7 +42,7 @@ class ListGameServerDeploymentsPager: through the ``game_server_deployments`` field on the corresponding responses. - All the usual :class:`~.game_server_deployments.ListGameServerDeploymentsResponse` + All the usual :class:`google.cloud.gaming_v1.types.ListGameServerDeploymentsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -53,9 +62,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_deployments.ListGameServerDeploymentsRequest`): + request (google.cloud.gaming_v1.types.ListGameServerDeploymentsRequest): The initial request object. - response (:class:`~.game_server_deployments.ListGameServerDeploymentsResponse`): + response (google.cloud.gaming_v1.types.ListGameServerDeploymentsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -92,7 +101,7 @@ class ListGameServerDeploymentsAsyncPager: """A pager for iterating through ``list_game_server_deployments`` requests. This class thinly wraps an initial - :class:`~.game_server_deployments.ListGameServerDeploymentsResponse` object, and + :class:`google.cloud.gaming_v1.types.ListGameServerDeploymentsResponse` object, and provides an ``__aiter__`` method to iterate through its ``game_server_deployments`` field. @@ -101,7 +110,7 @@ class ListGameServerDeploymentsAsyncPager: through the ``game_server_deployments`` field on the corresponding responses. - All the usual :class:`~.game_server_deployments.ListGameServerDeploymentsResponse` + All the usual :class:`google.cloud.gaming_v1.types.ListGameServerDeploymentsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -121,9 +130,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_deployments.ListGameServerDeploymentsRequest`): + request (google.cloud.gaming_v1.types.ListGameServerDeploymentsRequest): The initial request object. - response (:class:`~.game_server_deployments.ListGameServerDeploymentsResponse`): + response (google.cloud.gaming_v1.types.ListGameServerDeploymentsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/gaming_v1/services/game_server_deployments_service/transports/base.py b/google/cloud/gaming_v1/services/game_server_deployments_service/transports/base.py index 6596afea..ac543b18 100644 --- a/google/cloud/gaming_v1/services/game_server_deployments_service/transports/base.py +++ b/google/cloud/gaming_v1/services/game_server_deployments_service/transports/base.py @@ -71,10 +71,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -82,6 +82,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -91,20 +94,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -115,6 +115,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -126,6 +127,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -152,6 +154,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -168,6 +171,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -179,6 +183,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=120.0, ), default_timeout=120.0, client_info=client_info, diff --git a/google/cloud/gaming_v1/services/game_server_deployments_service/transports/grpc.py b/google/cloud/gaming_v1/services/game_server_deployments_service/transports/grpc.py index 39d40288..fe196d4a 100644 --- a/google/cloud/gaming_v1/services/game_server_deployments_service/transports/grpc.py +++ b/google/cloud/gaming_v1/services/game_server_deployments_service/transports/grpc.py @@ -60,6 +60,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -90,6 +91,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -104,72 +109,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -177,18 +171,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -202,7 +186,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/gaming_v1/services/game_server_deployments_service/transports/grpc_asyncio.py b/google/cloud/gaming_v1/services/game_server_deployments_service/transports/grpc_asyncio.py index 67f3eafd..24d13d35 100644 --- a/google/cloud/gaming_v1/services/game_server_deployments_service/transports/grpc_asyncio.py +++ b/google/cloud/gaming_v1/services/game_server_deployments_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -106,6 +106,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -137,12 +138,16 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -151,72 +156,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -224,18 +218,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/gaming_v1/services/realms_service/async_client.py b/google/cloud/gaming_v1/services/realms_service/async_client.py index 63abe9f5..22b545aa 100644 --- a/google/cloud/gaming_v1/services/realms_service/async_client.py +++ b/google/cloud/gaming_v1/services/realms_service/async_client.py @@ -84,7 +84,36 @@ class RealmsServiceAsyncClient: RealmsServiceClient.parse_common_location_path ) - from_service_account_file = RealmsServiceClient.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + RealmsServiceAsyncClient: The constructed client. + """ + return RealmsServiceClient.from_service_account_info.__func__(RealmsServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + RealmsServiceAsyncClient: The constructed client. + """ + return RealmsServiceClient.from_service_account_file.__func__(RealmsServiceAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -160,12 +189,13 @@ async def list_realms( r"""Lists realms in a given project and location. Args: - request (:class:`~.realms.ListRealmsRequest`): + request (:class:`google.cloud.gaming_v1.types.ListRealmsRequest`): The request object. Request message for RealmsService.ListRealms. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -177,7 +207,7 @@ async def list_realms( sent along with the request as metadata. Returns: - ~.pagers.ListRealmsAsyncPager: + google.cloud.gaming_v1.services.realms_service.pagers.ListRealmsAsyncPager: Response message for RealmsService.ListRealms. Iterating over this object will yield @@ -212,6 +242,7 @@ async def list_realms( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -247,13 +278,14 @@ async def get_realm( r"""Gets details of a single realm. Args: - request (:class:`~.realms.GetRealmRequest`): + request (:class:`google.cloud.gaming_v1.types.GetRealmRequest`): The request object. Request message for RealmsService.GetRealm. name (:class:`str`): Required. The name of the realm to retrieve. Uses the form: ``projects/{project}/locations/{location}/realms/{realm}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -265,7 +297,7 @@ async def get_realm( sent along with the request as metadata. Returns: - ~.realms.Realm: + google.cloud.gaming_v1.types.Realm: A realm resource. """ # Create or coerce a protobuf request object. @@ -295,6 +327,7 @@ async def get_realm( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -326,24 +359,27 @@ async def create_realm( r"""Creates a new realm in a given project and location. Args: - request (:class:`~.realms.CreateRealmRequest`): + request (:class:`google.cloud.gaming_v1.types.CreateRealmRequest`): The request object. Request message for RealmsService.CreateRealm. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - realm (:class:`~.realms.Realm`): + realm (:class:`google.cloud.gaming_v1.types.Realm`): Required. The realm resource to be created. + This corresponds to the ``realm`` field on the ``request`` instance; if ``request`` is provided, this should not be set. realm_id (:class:`str`): Required. The ID of the realm resource to be created. + This corresponds to the ``realm_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -355,11 +391,12 @@ async def create_realm( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.realms.Realm``: A realm resource. + :class:`google.cloud.gaming_v1.types.Realm` A realm + resource. """ # Create or coerce a protobuf request object. @@ -424,13 +461,14 @@ async def delete_realm( r"""Deletes a single realm. Args: - request (:class:`~.realms.DeleteRealmRequest`): + request (:class:`google.cloud.gaming_v1.types.DeleteRealmRequest`): The request object. Request message for RealmsService.DeleteRealm. name (:class:`str`): Required. The name of the realm to delete. Uses the form: ``projects/{project}/locations/{location}/realms/{realm}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -442,24 +480,22 @@ async def delete_realm( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -521,21 +557,23 @@ async def update_realm( r"""Patches a single realm. Args: - request (:class:`~.realms.UpdateRealmRequest`): + request (:class:`google.cloud.gaming_v1.types.UpdateRealmRequest`): The request object. Request message for RealmsService.UpdateRealm. - realm (:class:`~.realms.Realm`): + realm (:class:`google.cloud.gaming_v1.types.Realm`): Required. The realm to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``realm`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -547,11 +585,12 @@ async def update_realm( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.realms.Realm``: A realm resource. + :class:`google.cloud.gaming_v1.types.Realm` A realm + resource. """ # Create or coerce a protobuf request object. @@ -615,7 +654,7 @@ async def preview_realm_update( r"""Previews patches to a single realm. Args: - request (:class:`~.realms.PreviewRealmUpdateRequest`): + request (:class:`google.cloud.gaming_v1.types.PreviewRealmUpdateRequest`): The request object. Request message for RealmsService.PreviewRealmUpdate. @@ -626,7 +665,7 @@ async def preview_realm_update( sent along with the request as metadata. Returns: - ~.realms.PreviewRealmUpdateResponse: + google.cloud.gaming_v1.types.PreviewRealmUpdateResponse: Response message for RealmsService.PreviewRealmUpdate. @@ -644,6 +683,7 @@ async def preview_realm_update( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/google/cloud/gaming_v1/services/realms_service/client.py b/google/cloud/gaming_v1/services/realms_service/client.py index dc55bf61..a1752123 100644 --- a/google/cloud/gaming_v1/services/realms_service/client.py +++ b/google/cloud/gaming_v1/services/realms_service/client.py @@ -116,6 +116,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + RealmsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -128,7 +144,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + RealmsServiceClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -236,10 +252,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.RealmsServiceTransport]): The + transport (Union[str, RealmsServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -275,21 +291,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -332,7 +344,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -349,12 +361,13 @@ def list_realms( r"""Lists realms in a given project and location. Args: - request (:class:`~.realms.ListRealmsRequest`): + request (google.cloud.gaming_v1.types.ListRealmsRequest): The request object. Request message for RealmsService.ListRealms. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -366,7 +379,7 @@ def list_realms( sent along with the request as metadata. Returns: - ~.pagers.ListRealmsPager: + google.cloud.gaming_v1.services.realms_service.pagers.ListRealmsPager: Response message for RealmsService.ListRealms. Iterating over this object will yield @@ -431,13 +444,14 @@ def get_realm( r"""Gets details of a single realm. Args: - request (:class:`~.realms.GetRealmRequest`): + request (google.cloud.gaming_v1.types.GetRealmRequest): The request object. Request message for RealmsService.GetRealm. - name (:class:`str`): + name (str): Required. The name of the realm to retrieve. Uses the form: ``projects/{project}/locations/{location}/realms/{realm}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -449,7 +463,7 @@ def get_realm( sent along with the request as metadata. Returns: - ~.realms.Realm: + google.cloud.gaming_v1.types.Realm: A realm resource. """ # Create or coerce a protobuf request object. @@ -505,24 +519,27 @@ def create_realm( r"""Creates a new realm in a given project and location. Args: - request (:class:`~.realms.CreateRealmRequest`): + request (google.cloud.gaming_v1.types.CreateRealmRequest): The request object. Request message for RealmsService.CreateRealm. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - realm (:class:`~.realms.Realm`): + realm (google.cloud.gaming_v1.types.Realm): Required. The realm resource to be created. + This corresponds to the ``realm`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - realm_id (:class:`str`): + realm_id (str): Required. The ID of the realm resource to be created. + This corresponds to the ``realm_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -534,11 +551,12 @@ def create_realm( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.realms.Realm``: A realm resource. + :class:`google.cloud.gaming_v1.types.Realm` A realm + resource. """ # Create or coerce a protobuf request object. @@ -604,13 +622,14 @@ def delete_realm( r"""Deletes a single realm. Args: - request (:class:`~.realms.DeleteRealmRequest`): + request (google.cloud.gaming_v1.types.DeleteRealmRequest): The request object. Request message for RealmsService.DeleteRealm. - name (:class:`str`): + name (str): Required. The name of the realm to delete. Uses the form: ``projects/{project}/locations/{location}/realms/{realm}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -622,24 +641,22 @@ def delete_realm( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -702,21 +719,23 @@ def update_realm( r"""Patches a single realm. Args: - request (:class:`~.realms.UpdateRealmRequest`): + request (google.cloud.gaming_v1.types.UpdateRealmRequest): The request object. Request message for RealmsService.UpdateRealm. - realm (:class:`~.realms.Realm`): + realm (google.cloud.gaming_v1.types.Realm): Required. The realm to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``realm`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -728,11 +747,12 @@ def update_realm( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.realms.Realm``: A realm resource. + :class:`google.cloud.gaming_v1.types.Realm` A realm + resource. """ # Create or coerce a protobuf request object. @@ -797,7 +817,7 @@ def preview_realm_update( r"""Previews patches to a single realm. Args: - request (:class:`~.realms.PreviewRealmUpdateRequest`): + request (google.cloud.gaming_v1.types.PreviewRealmUpdateRequest): The request object. Request message for RealmsService.PreviewRealmUpdate. @@ -808,7 +828,7 @@ def preview_realm_update( sent along with the request as metadata. Returns: - ~.realms.PreviewRealmUpdateResponse: + google.cloud.gaming_v1.types.PreviewRealmUpdateResponse: Response message for RealmsService.PreviewRealmUpdate. diff --git a/google/cloud/gaming_v1/services/realms_service/pagers.py b/google/cloud/gaming_v1/services/realms_service/pagers.py index 2d93adc0..45ffbaed 100644 --- a/google/cloud/gaming_v1/services/realms_service/pagers.py +++ b/google/cloud/gaming_v1/services/realms_service/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.gaming_v1.types import realms @@ -24,7 +33,7 @@ class ListRealmsPager: """A pager for iterating through ``list_realms`` requests. This class thinly wraps an initial - :class:`~.realms.ListRealmsResponse` object, and + :class:`google.cloud.gaming_v1.types.ListRealmsResponse` object, and provides an ``__iter__`` method to iterate through its ``realms`` field. @@ -33,7 +42,7 @@ class ListRealmsPager: through the ``realms`` field on the corresponding responses. - All the usual :class:`~.realms.ListRealmsResponse` + All the usual :class:`google.cloud.gaming_v1.types.ListRealmsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +60,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.realms.ListRealmsRequest`): + request (google.cloud.gaming_v1.types.ListRealmsRequest): The initial request object. - response (:class:`~.realms.ListRealmsResponse`): + response (google.cloud.gaming_v1.types.ListRealmsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +95,7 @@ class ListRealmsAsyncPager: """A pager for iterating through ``list_realms`` requests. This class thinly wraps an initial - :class:`~.realms.ListRealmsResponse` object, and + :class:`google.cloud.gaming_v1.types.ListRealmsResponse` object, and provides an ``__aiter__`` method to iterate through its ``realms`` field. @@ -95,7 +104,7 @@ class ListRealmsAsyncPager: through the ``realms`` field on the corresponding responses. - All the usual :class:`~.realms.ListRealmsResponse` + All the usual :class:`google.cloud.gaming_v1.types.ListRealmsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -113,9 +122,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.realms.ListRealmsRequest`): + request (google.cloud.gaming_v1.types.ListRealmsRequest): The initial request object. - response (:class:`~.realms.ListRealmsResponse`): + response (google.cloud.gaming_v1.types.ListRealmsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/gaming_v1/services/realms_service/transports/base.py b/google/cloud/gaming_v1/services/realms_service/transports/base.py index 7bea019d..05855613 100644 --- a/google/cloud/gaming_v1/services/realms_service/transports/base.py +++ b/google/cloud/gaming_v1/services/realms_service/transports/base.py @@ -71,10 +71,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -82,6 +82,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -91,20 +94,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -115,6 +115,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -126,6 +127,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -146,6 +148,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, diff --git a/google/cloud/gaming_v1/services/realms_service/transports/grpc.py b/google/cloud/gaming_v1/services/realms_service/transports/grpc.py index 2a58fadf..5be1295a 100644 --- a/google/cloud/gaming_v1/services/realms_service/transports/grpc.py +++ b/google/cloud/gaming_v1/services/realms_service/transports/grpc.py @@ -60,6 +60,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -90,6 +91,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -104,72 +109,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -177,18 +171,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -202,7 +186,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/gaming_v1/services/realms_service/transports/grpc_asyncio.py b/google/cloud/gaming_v1/services/realms_service/transports/grpc_asyncio.py index c4960a75..f6d9a4da 100644 --- a/google/cloud/gaming_v1/services/realms_service/transports/grpc_asyncio.py +++ b/google/cloud/gaming_v1/services/realms_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -104,6 +104,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -135,12 +136,16 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -149,72 +154,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -222,18 +216,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/gaming_v1/types/__init__.py b/google/cloud/gaming_v1/types/__init__.py index ebfd8342..0f6f0c03 100644 --- a/google/cloud/gaming_v1/types/__init__.py +++ b/google/cloud/gaming_v1/types/__init__.py @@ -16,127 +16,127 @@ # from .common import ( + DeployedFleetDetails, + LabelSelector, OperationMetadata, OperationStatus, - LabelSelector, RealmSelector, Schedule, SpecSource, TargetDetails, TargetState, - DeployedFleetDetails, ) from .game_server_clusters import ( + CreateGameServerClusterRequest, + DeleteGameServerClusterRequest, + GameServerCluster, + GameServerClusterConnectionInfo, + GetGameServerClusterRequest, + GkeClusterReference, ListGameServerClustersRequest, ListGameServerClustersResponse, - GetGameServerClusterRequest, - CreateGameServerClusterRequest, PreviewCreateGameServerClusterRequest, PreviewCreateGameServerClusterResponse, - DeleteGameServerClusterRequest, PreviewDeleteGameServerClusterRequest, PreviewDeleteGameServerClusterResponse, - UpdateGameServerClusterRequest, PreviewUpdateGameServerClusterRequest, PreviewUpdateGameServerClusterResponse, - GameServerClusterConnectionInfo, - GkeClusterReference, - GameServerCluster, + UpdateGameServerClusterRequest, ) from .game_server_configs import ( - ListGameServerConfigsRequest, - ListGameServerConfigsResponse, - GetGameServerConfigRequest, CreateGameServerConfigRequest, DeleteGameServerConfigRequest, - ScalingConfig, FleetConfig, GameServerConfig, + GetGameServerConfigRequest, + ListGameServerConfigsRequest, + ListGameServerConfigsResponse, + ScalingConfig, ) from .game_server_deployments import ( - ListGameServerDeploymentsRequest, - ListGameServerDeploymentsResponse, - GetGameServerDeploymentRequest, - GetGameServerDeploymentRolloutRequest, CreateGameServerDeploymentRequest, DeleteGameServerDeploymentRequest, - UpdateGameServerDeploymentRequest, - UpdateGameServerDeploymentRolloutRequest, FetchDeploymentStateRequest, FetchDeploymentStateResponse, - GameServerDeployment, GameServerConfigOverride, + GameServerDeployment, GameServerDeploymentRollout, + GetGameServerDeploymentRequest, + GetGameServerDeploymentRolloutRequest, + ListGameServerDeploymentsRequest, + ListGameServerDeploymentsResponse, PreviewGameServerDeploymentRolloutRequest, PreviewGameServerDeploymentRolloutResponse, + UpdateGameServerDeploymentRequest, + UpdateGameServerDeploymentRolloutRequest, ) from .realms import ( - ListRealmsRequest, - ListRealmsResponse, - GetRealmRequest, CreateRealmRequest, DeleteRealmRequest, - UpdateRealmRequest, + GetRealmRequest, + ListRealmsRequest, + ListRealmsResponse, PreviewRealmUpdateRequest, PreviewRealmUpdateResponse, Realm, + UpdateRealmRequest, ) __all__ = ( + "DeployedFleetDetails", + "LabelSelector", "OperationMetadata", "OperationStatus", - "LabelSelector", "RealmSelector", "Schedule", "SpecSource", "TargetDetails", "TargetState", - "DeployedFleetDetails", + "CreateGameServerClusterRequest", + "DeleteGameServerClusterRequest", + "GameServerCluster", + "GameServerClusterConnectionInfo", + "GetGameServerClusterRequest", + "GkeClusterReference", "ListGameServerClustersRequest", "ListGameServerClustersResponse", - "GetGameServerClusterRequest", - "CreateGameServerClusterRequest", "PreviewCreateGameServerClusterRequest", "PreviewCreateGameServerClusterResponse", - "DeleteGameServerClusterRequest", "PreviewDeleteGameServerClusterRequest", "PreviewDeleteGameServerClusterResponse", - "UpdateGameServerClusterRequest", "PreviewUpdateGameServerClusterRequest", "PreviewUpdateGameServerClusterResponse", - "GameServerClusterConnectionInfo", - "GkeClusterReference", - "GameServerCluster", - "ListGameServerConfigsRequest", - "ListGameServerConfigsResponse", - "GetGameServerConfigRequest", + "UpdateGameServerClusterRequest", "CreateGameServerConfigRequest", "DeleteGameServerConfigRequest", - "ScalingConfig", "FleetConfig", "GameServerConfig", - "ListGameServerDeploymentsRequest", - "ListGameServerDeploymentsResponse", - "GetGameServerDeploymentRequest", - "GetGameServerDeploymentRolloutRequest", + "GetGameServerConfigRequest", + "ListGameServerConfigsRequest", + "ListGameServerConfigsResponse", + "ScalingConfig", "CreateGameServerDeploymentRequest", "DeleteGameServerDeploymentRequest", - "UpdateGameServerDeploymentRequest", - "UpdateGameServerDeploymentRolloutRequest", "FetchDeploymentStateRequest", "FetchDeploymentStateResponse", - "GameServerDeployment", "GameServerConfigOverride", + "GameServerDeployment", "GameServerDeploymentRollout", + "GetGameServerDeploymentRequest", + "GetGameServerDeploymentRolloutRequest", + "ListGameServerDeploymentsRequest", + "ListGameServerDeploymentsResponse", "PreviewGameServerDeploymentRolloutRequest", "PreviewGameServerDeploymentRolloutResponse", - "ListRealmsRequest", - "ListRealmsResponse", - "GetRealmRequest", + "UpdateGameServerDeploymentRequest", + "UpdateGameServerDeploymentRolloutRequest", "CreateRealmRequest", "DeleteRealmRequest", - "UpdateRealmRequest", + "GetRealmRequest", + "ListRealmsRequest", + "ListRealmsResponse", "PreviewRealmUpdateRequest", "PreviewRealmUpdateResponse", "Realm", + "UpdateRealmRequest", ) diff --git a/google/cloud/gaming_v1/types/common.py b/google/cloud/gaming_v1/types/common.py index 43422427..daa4f7a1 100644 --- a/google/cloud/gaming_v1/types/common.py +++ b/google/cloud/gaming_v1/types/common.py @@ -42,10 +42,10 @@ class OperationMetadata(proto.Message): r"""Represents the metadata of the long-running operation. Attributes: - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time the operation was created. - end_time (~.timestamp.Timestamp): + end_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time the operation finished running. target (str): @@ -69,7 +69,7 @@ class OperationMetadata(proto.Message): unreachable (Sequence[str]): Output only. List of Locations that could not be reached. - operation_status (Sequence[~.common.OperationMetadata.OperationStatusEntry]): + operation_status (Sequence[google.cloud.gaming_v1.types.OperationMetadata.OperationStatusEntry]): Output only. Operation status for Game Services API operations. Operation status is in the form of key-value pairs where keys are @@ -106,7 +106,7 @@ class OperationStatus(proto.Message): done (bool): Output only. Whether the operation is done or still in progress. - error_code (~.common.OperationStatus.ErrorCode): + error_code (google.cloud.gaming_v1.types.OperationStatus.ErrorCode): The error code in case of failures. error_message (str): The human-readable error message. @@ -130,7 +130,7 @@ class LabelSelector(proto.Message): r"""The label selector, used to group labels on the resources. Attributes: - labels (Sequence[~.common.LabelSelector.LabelsEntry]): + labels (Sequence[google.cloud.gaming_v1.types.LabelSelector.LabelsEntry]): Resource labels for this selector. """ @@ -163,11 +163,11 @@ class Schedule(proto.Message): Attributes: - start_time (~.timestamp.Timestamp): + start_time (google.protobuf.timestamp_pb2.Timestamp): The start time of the event. - end_time (~.timestamp.Timestamp): + end_time (google.protobuf.timestamp_pb2.Timestamp): The end time of the event. - cron_job_duration (~.duration.Duration): + cron_job_duration (google.protobuf.duration_pb2.Duration): The duration for the cron job event. The duration of the event is effective after the cron job's start time. @@ -219,7 +219,7 @@ class TargetDetails(proto.Message): The game server deployment name. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment_id}``. - fleet_details (Sequence[~.common.TargetDetails.TargetFleetDetails]): + fleet_details (Sequence[google.cloud.gaming_v1.types.TargetDetails.TargetFleetDetails]): Agones fleet details for game server clusters and game server deployments. """ @@ -228,9 +228,9 @@ class TargetFleetDetails(proto.Message): r"""Details of the target Agones fleet. Attributes: - fleet (~.common.TargetDetails.TargetFleetDetails.TargetFleet): + fleet (google.cloud.gaming_v1.types.TargetDetails.TargetFleetDetails.TargetFleet): Reference to target Agones fleet. - autoscaler (~.common.TargetDetails.TargetFleetDetails.TargetFleetAutoscaler): + autoscaler (google.cloud.gaming_v1.types.TargetDetails.TargetFleetDetails.TargetFleetAutoscaler): Reference to target Agones fleet autoscaling policy. """ @@ -241,7 +241,7 @@ class TargetFleet(proto.Message): Attributes: name (str): The name of the Agones fleet. - spec_source (~.common.SpecSource): + spec_source (google.cloud.gaming_v1.types.SpecSource): Encapsulates the source of the Agones fleet spec. The Agones fleet spec source. """ @@ -256,7 +256,7 @@ class TargetFleetAutoscaler(proto.Message): Attributes: name (str): The name of the Agones autoscaler. - spec_source (~.common.SpecSource): + spec_source (google.cloud.gaming_v1.types.SpecSource): Encapsulates the source of the Agones fleet spec. Details about the Agones autoscaler spec. """ @@ -290,7 +290,7 @@ class TargetState(proto.Message): r"""Encapsulates the Target state. Attributes: - details (Sequence[~.common.TargetDetails]): + details (Sequence[google.cloud.gaming_v1.types.TargetDetails]): Details about Agones fleets. """ @@ -301,9 +301,9 @@ class DeployedFleetDetails(proto.Message): r"""Details of the deployed Agones fleet. Attributes: - deployed_fleet (~.common.DeployedFleetDetails.DeployedFleet): + deployed_fleet (google.cloud.gaming_v1.types.DeployedFleetDetails.DeployedFleet): Information about the Agones fleet. - deployed_autoscaler (~.common.DeployedFleetDetails.DeployedFleetAutoscaler): + deployed_autoscaler (google.cloud.gaming_v1.types.DeployedFleetDetails.DeployedFleetAutoscaler): Information about the Agones autoscaler for that fleet. """ @@ -317,11 +317,11 @@ class DeployedFleet(proto.Message): fleet_spec (str): The fleet spec retrieved from the Agones fleet. - spec_source (~.common.SpecSource): + spec_source (google.cloud.gaming_v1.types.SpecSource): The source spec that is used to create the Agones fleet. The GameServerConfig resource may no longer exist in the system. - status (~.common.DeployedFleetDetails.DeployedFleet.DeployedFleetStatus): + status (google.cloud.gaming_v1.types.DeployedFleetDetails.DeployedFleet.DeployedFleetStatus): The current status of the Agones fleet. Includes count of game servers in various states. @@ -374,7 +374,7 @@ class DeployedFleetAutoscaler(proto.Message): Attributes: autoscaler (str): The name of the Agones autoscaler. - spec_source (~.common.SpecSource): + spec_source (google.cloud.gaming_v1.types.SpecSource): The source spec that is used to create the autoscaler. The GameServerConfig resource may no longer exist in the system. diff --git a/google/cloud/gaming_v1/types/game_server_clusters.py b/google/cloud/gaming_v1/types/game_server_clusters.py index 27e4b963..567524ac 100644 --- a/google/cloud/gaming_v1/types/game_server_clusters.py +++ b/google/cloud/gaming_v1/types/game_server_clusters.py @@ -90,7 +90,7 @@ class ListGameServerClustersResponse(proto.Message): GameServerClustersService.ListGameServerClusters. Attributes: - game_server_clusters (Sequence[~.gcg_game_server_clusters.GameServerCluster]): + game_server_clusters (Sequence[google.cloud.gaming_v1.types.GameServerCluster]): The list of game server clusters. next_page_token (str): Token to retrieve the next page of results, @@ -139,7 +139,7 @@ class CreateGameServerClusterRequest(proto.Message): game_server_cluster_id (str): Required. The ID of the game server cluster resource to be created. - game_server_cluster (~.gcg_game_server_clusters.GameServerCluster): + game_server_cluster (google.cloud.gaming_v1.types.GameServerCluster): Required. The game server cluster resource to be created. """ @@ -164,10 +164,10 @@ class PreviewCreateGameServerClusterRequest(proto.Message): game_server_cluster_id (str): Required. The ID of the game server cluster resource to be created. - game_server_cluster (~.gcg_game_server_clusters.GameServerCluster): + game_server_cluster (google.cloud.gaming_v1.types.GameServerCluster): Required. The game server cluster resource to be created. - preview_time (~.timestamp.Timestamp): + preview_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The target timestamp to compute the preview. """ @@ -190,7 +190,7 @@ class PreviewCreateGameServerClusterResponse(proto.Message): Attributes: etag (str): The ETag of the game server cluster. - target_state (~.common.TargetState): + target_state (google.cloud.gaming_v1.types.TargetState): The target state. """ @@ -222,7 +222,7 @@ class PreviewDeleteGameServerClusterRequest(proto.Message): Required. The name of the game server cluster to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerClusters/{cluster}``. - preview_time (~.timestamp.Timestamp): + preview_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The target timestamp to compute the preview. """ @@ -239,7 +239,7 @@ class PreviewDeleteGameServerClusterResponse(proto.Message): Attributes: etag (str): The ETag of the game server cluster. - target_state (~.common.TargetState): + target_state (google.cloud.gaming_v1.types.TargetState): The target state. """ @@ -253,10 +253,10 @@ class UpdateGameServerClusterRequest(proto.Message): GameServerClustersService.UpdateGameServerCluster. Attributes: - game_server_cluster (~.gcg_game_server_clusters.GameServerCluster): + game_server_cluster (google.cloud.gaming_v1.types.GameServerCluster): Required. The game server cluster to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see @@ -277,17 +277,17 @@ class PreviewUpdateGameServerClusterRequest(proto.Message): GameServerClustersService.UpdateGameServerCluster. Attributes: - game_server_cluster (~.gcg_game_server_clusters.GameServerCluster): + game_server_cluster (google.cloud.gaming_v1.types.GameServerCluster): Required. The game server cluster to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask - preview_time (~.timestamp.Timestamp): + preview_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The target timestamp to compute the preview. """ @@ -308,7 +308,7 @@ class PreviewUpdateGameServerClusterResponse(proto.Message): Attributes: etag (str): The ETag of the game server cluster. - target_state (~.common.TargetState): + target_state (google.cloud.gaming_v1.types.TargetState): The target state. """ @@ -321,7 +321,7 @@ class GameServerClusterConnectionInfo(proto.Message): r"""The game server cluster connection information. Attributes: - gke_cluster_reference (~.gcg_game_server_clusters.GkeClusterReference): + gke_cluster_reference (google.cloud.gaming_v1.types.GkeClusterReference): Reference to the GKE cluster where the game servers are installed. namespace (str): @@ -372,14 +372,14 @@ class GameServerCluster(proto.Message): For example, ``projects/my-project/locations/{location}/realms/zanzibar/gameServerClusters/my-onprem-cluster``. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation time. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last-modified time. - labels (Sequence[~.gcg_game_server_clusters.GameServerCluster.LabelsEntry]): + labels (Sequence[google.cloud.gaming_v1.types.GameServerCluster.LabelsEntry]): The labels associated with this game server cluster. Each label is a key-value pair. - connection_info (~.gcg_game_server_clusters.GameServerClusterConnectionInfo): + connection_info (google.cloud.gaming_v1.types.GameServerClusterConnectionInfo): The game server cluster connection information. This information is used to manage game server clusters. diff --git a/google/cloud/gaming_v1/types/game_server_configs.py b/google/cloud/gaming_v1/types/game_server_configs.py index 226bff5b..59f1edf1 100644 --- a/google/cloud/gaming_v1/types/game_server_configs.py +++ b/google/cloud/gaming_v1/types/game_server_configs.py @@ -82,7 +82,7 @@ class ListGameServerConfigsResponse(proto.Message): GameServerConfigsService.ListGameServerConfigs. Attributes: - game_server_configs (Sequence[~.gcg_game_server_configs.GameServerConfig]): + game_server_configs (Sequence[google.cloud.gaming_v1.types.GameServerConfig]): The list of game server configs. next_page_token (str): Token to retrieve the next page of results, @@ -132,7 +132,7 @@ class CreateGameServerConfigRequest(proto.Message): config_id (str): Required. The ID of the game server config resource to be created. - game_server_config (~.gcg_game_server_configs.GameServerConfig): + game_server_config (google.cloud.gaming_v1.types.GameServerConfig): Required. The game server config resource to be created. """ @@ -171,13 +171,13 @@ class ScalingConfig(proto.Message): Required. Agones fleet autoscaler spec. Example spec: https://agones.dev/site/docs/reference/fleetautoscaler/ - selectors (Sequence[~.common.LabelSelector]): + selectors (Sequence[google.cloud.gaming_v1.types.LabelSelector]): Labels used to identify the game server clusters to which this Agones scaling config applies. A game server cluster is subject to this Agones scaling config if its labels match any of the selector entries. - schedules (Sequence[~.common.Schedule]): + schedules (Sequence[google.cloud.gaming_v1.types.Schedule]): The schedules to which this Scaling Config applies. """ @@ -220,17 +220,17 @@ class GameServerConfig(proto.Message): For example, ``projects/my-project/locations/global/gameServerDeployments/my-game/configs/my-config``. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation time. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last-modified time. - labels (Sequence[~.gcg_game_server_configs.GameServerConfig.LabelsEntry]): + labels (Sequence[google.cloud.gaming_v1.types.GameServerConfig.LabelsEntry]): The labels associated with this game server config. Each label is a key-value pair. - fleet_configs (Sequence[~.gcg_game_server_configs.FleetConfig]): + fleet_configs (Sequence[google.cloud.gaming_v1.types.FleetConfig]): FleetConfig contains a list of Agones fleet specs. Only one FleetConfig is allowed. - scaling_configs (Sequence[~.gcg_game_server_configs.ScalingConfig]): + scaling_configs (Sequence[google.cloud.gaming_v1.types.ScalingConfig]): The autoscaling settings. description (str): The description of the game server config. diff --git a/google/cloud/gaming_v1/types/game_server_deployments.py b/google/cloud/gaming_v1/types/game_server_deployments.py index 31174596..11edd91b 100644 --- a/google/cloud/gaming_v1/types/game_server_deployments.py +++ b/google/cloud/gaming_v1/types/game_server_deployments.py @@ -89,7 +89,7 @@ class ListGameServerDeploymentsResponse(proto.Message): GameServerDeploymentsService.ListGameServerDeployments. Attributes: - game_server_deployments (Sequence[~.gcg_game_server_deployments.GameServerDeployment]): + game_server_deployments (Sequence[google.cloud.gaming_v1.types.GameServerDeployment]): The list of game server deployments. next_page_token (str): Token to retrieve the next page of results, @@ -153,7 +153,7 @@ class CreateGameServerDeploymentRequest(proto.Message): deployment_id (str): Required. The ID of the game server delpoyment resource to be created. - game_server_deployment (~.gcg_game_server_deployments.GameServerDeployment): + game_server_deployment (google.cloud.gaming_v1.types.GameServerDeployment): Required. The game server delpoyment resource to be created. """ @@ -188,10 +188,10 @@ class UpdateGameServerDeploymentRequest(proto.Message): allows updates for labels. Attributes: - game_server_deployment (~.gcg_game_server_deployments.GameServerDeployment): + game_server_deployment (google.cloud.gaming_v1.types.GameServerDeployment): Required. The game server delpoyment to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see @@ -212,10 +212,10 @@ class UpdateGameServerDeploymentRolloutRequest(proto.Message): GameServerDeploymentsService.UpdateGameServerRolloutDeployment. Attributes: - rollout (~.gcg_game_server_deployments.GameServerDeploymentRollout): + rollout (google.cloud.gaming_v1.types.GameServerDeploymentRollout): Required. The game server delpoyment rollout to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see @@ -251,7 +251,7 @@ class FetchDeploymentStateResponse(proto.Message): GameServerDeploymentsService.FetchDeploymentState. Attributes: - cluster_state (Sequence[~.gcg_game_server_deployments.FetchDeploymentStateResponse.DeployedClusterState]): + cluster_state (Sequence[google.cloud.gaming_v1.types.FetchDeploymentStateResponse.DeployedClusterState]): The state of the game server deployment in each game server cluster. unavailable (Sequence[str]): @@ -265,7 +265,7 @@ class DeployedClusterState(proto.Message): Attributes: cluster (str): The name of the cluster. - fleet_details (Sequence[~.common.DeployedFleetDetails]): + fleet_details (Sequence[google.cloud.gaming_v1.types.DeployedFleetDetails]): The details about the Agones fleets and autoscalers created in the game server cluster. """ @@ -294,11 +294,11 @@ class GameServerDeployment(proto.Message): ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}``. For example, ``projects/my-project/locations/global/gameServerDeployments/my-deployment``. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation time. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last-modified time. - labels (Sequence[~.gcg_game_server_deployments.GameServerDeployment.LabelsEntry]): + labels (Sequence[google.cloud.gaming_v1.types.GameServerDeployment.LabelsEntry]): The labels associated with this game server deployment. Each label is a key-value pair. etag (str): @@ -325,7 +325,7 @@ class GameServerConfigOverride(proto.Message): r"""A game server config override. Attributes: - realms_selector (~.common.RealmSelector): + realms_selector (google.cloud.gaming_v1.types.RealmSelector): Selector for choosing applicable realms. config_version (str): The game server config for this override. @@ -351,16 +351,16 @@ class GameServerDeploymentRollout(proto.Message): For example, ``projects/my-project/locations/global/gameServerDeployments/my-deployment/rollout``. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation time. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last-modified time. default_game_server_config (str): The default game server config is applied to all realms unless overridden in the rollout. For example, ``projects/my-project/locations/global/gameServerDeployments/my-game/configs/my-config``. - game_server_config_overrides (Sequence[~.gcg_game_server_deployments.GameServerConfigOverride]): + game_server_config_overrides (Sequence[google.cloud.gaming_v1.types.GameServerConfigOverride]): Contains the game server config rollout overrides. Overrides are processed in the order they are listed. Once a match is found for a @@ -388,17 +388,17 @@ class PreviewGameServerDeploymentRolloutRequest(proto.Message): r"""Request message for PreviewGameServerDeploymentRollout. Attributes: - rollout (~.gcg_game_server_deployments.GameServerDeploymentRollout): + rollout (google.cloud.gaming_v1.types.GameServerDeploymentRollout): Required. The game server deployment rollout to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Optional. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask - preview_time (~.timestamp.Timestamp): + preview_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The target timestamp to compute the preview. Defaults to the immediately after the proposed rollout completes. @@ -424,7 +424,7 @@ class PreviewGameServerDeploymentRolloutResponse(proto.Message): request. etag (str): ETag of the game server deployment. - target_state (~.common.TargetState): + target_state (google.cloud.gaming_v1.types.TargetState): The target state. """ diff --git a/google/cloud/gaming_v1/types/realms.py b/google/cloud/gaming_v1/types/realms.py index 9133dcd9..53f69f78 100644 --- a/google/cloud/gaming_v1/types/realms.py +++ b/google/cloud/gaming_v1/types/realms.py @@ -80,7 +80,7 @@ class ListRealmsResponse(proto.Message): r"""Response message for RealmsService.ListRealms. Attributes: - realms (Sequence[~.gcg_realms.Realm]): + realms (Sequence[google.cloud.gaming_v1.types.Realm]): The list of realms. next_page_token (str): Token to retrieve the next page of results, @@ -123,7 +123,7 @@ class CreateRealmRequest(proto.Message): realm_id (str): Required. The ID of the realm resource to be created. - realm (~.gcg_realms.Realm): + realm (google.cloud.gaming_v1.types.Realm): Required. The realm resource to be created. """ @@ -150,10 +150,10 @@ class UpdateRealmRequest(proto.Message): r"""Request message for RealmsService.UpdateRealm. Attributes: - realm (~.gcg_realms.Realm): + realm (google.cloud.gaming_v1.types.Realm): Required. The realm to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see @@ -170,16 +170,16 @@ class PreviewRealmUpdateRequest(proto.Message): r"""Request message for RealmsService.PreviewRealmUpdate. Attributes: - realm (~.gcg_realms.Realm): + realm (google.cloud.gaming_v1.types.Realm): Required. The realm to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask - preview_time (~.timestamp.Timestamp): + preview_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The target timestamp to compute the preview. """ @@ -197,7 +197,7 @@ class PreviewRealmUpdateResponse(proto.Message): Attributes: etag (str): ETag of the realm. - target_state (~.common.TargetState): + target_state (google.cloud.gaming_v1.types.TargetState): The target state. """ @@ -215,11 +215,11 @@ class Realm(proto.Message): ``projects/{project}/locations/{location}/realms/{realm}``. For example, ``projects/my-project/locations/{location}/realms/my-realm``. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation time. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last-modified time. - labels (Sequence[~.gcg_realms.Realm.LabelsEntry]): + labels (Sequence[google.cloud.gaming_v1.types.Realm.LabelsEntry]): The labels associated with this realm. Each label is a key-value pair. time_zone (str): diff --git a/google/cloud/gaming_v1beta/__init__.py b/google/cloud/gaming_v1beta/__init__.py index d565585b..cddeaeec 100644 --- a/google/cloud/gaming_v1beta/__init__.py +++ b/google/cloud/gaming_v1beta/__init__.py @@ -92,6 +92,7 @@ "FleetConfig", "GameServerCluster", "GameServerClusterConnectionInfo", + "GameServerClustersServiceClient", "GameServerConfig", "GameServerConfigOverride", "GameServerConfigsServiceClient", @@ -127,7 +128,6 @@ "PreviewUpdateGameServerClusterResponse", "Realm", "RealmSelector", - "RealmsServiceClient", "ScalingConfig", "Schedule", "SpecSource", @@ -137,5 +137,5 @@ "UpdateGameServerDeploymentRequest", "UpdateGameServerDeploymentRolloutRequest", "UpdateRealmRequest", - "GameServerClustersServiceClient", + "RealmsServiceClient", ) diff --git a/google/cloud/gaming_v1beta/services/game_server_clusters_service/async_client.py b/google/cloud/gaming_v1beta/services/game_server_clusters_service/async_client.py index 9a48f628..409fcd19 100644 --- a/google/cloud/gaming_v1beta/services/game_server_clusters_service/async_client.py +++ b/google/cloud/gaming_v1beta/services/game_server_clusters_service/async_client.py @@ -94,9 +94,36 @@ class GameServerClustersServiceAsyncClient: GameServerClustersServiceClient.parse_common_location_path ) - from_service_account_file = ( - GameServerClustersServiceClient.from_service_account_file - ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerClustersServiceAsyncClient: The constructed client. + """ + return GameServerClustersServiceClient.from_service_account_info.__func__(GameServerClustersServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerClustersServiceAsyncClient: The constructed client. + """ + return GameServerClustersServiceClient.from_service_account_file.__func__(GameServerClustersServiceAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -174,13 +201,14 @@ async def list_game_server_clusters( location. Args: - request (:class:`~.game_server_clusters.ListGameServerClustersRequest`): + request (:class:`google.cloud.gaming_v1beta.types.ListGameServerClustersRequest`): The request object. Request message for GameServerClustersService.ListGameServerClusters. parent (:class:`str`): Required. The parent resource name. Uses the form: "projects/{project}/locations/{location}/realms/{realm}". + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -192,7 +220,7 @@ async def list_game_server_clusters( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerClustersAsyncPager: + google.cloud.gaming_v1beta.services.game_server_clusters_service.pagers.ListGameServerClustersAsyncPager: Response message for GameServerClustersService.ListGameServerClusters. Iterating over this object will yield @@ -227,6 +255,7 @@ async def list_game_server_clusters( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -262,7 +291,7 @@ async def get_game_server_cluster( r"""Gets details of a single game server cluster. Args: - request (:class:`~.game_server_clusters.GetGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1beta.types.GetGameServerClusterRequest`): The request object. Request message for GameServerClustersService.GetGameServerCluster. name (:class:`str`): @@ -270,6 +299,7 @@ async def get_game_server_cluster( retrieve. Uses the form: ``projects/{project}/locations/{location}/realms/{realm-id}/gameServerClusters/{cluster}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -281,7 +311,7 @@ async def get_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.GameServerCluster: + google.cloud.gaming_v1beta.types.GameServerCluster: A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -311,6 +341,7 @@ async def get_game_server_cluster( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -343,24 +374,27 @@ async def create_game_server_cluster( and location. Args: - request (:class:`~.game_server_clusters.CreateGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1beta.types.CreateGameServerClusterRequest`): The request object. Request message for GameServerClustersService.CreateGameServerCluster. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/realms/{realm-id}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_cluster (:class:`~.game_server_clusters.GameServerCluster`): + game_server_cluster (:class:`google.cloud.gaming_v1beta.types.GameServerCluster`): Required. The game server cluster resource to be created. + This corresponds to the ``game_server_cluster`` field on the ``request`` instance; if ``request`` is provided, this should not be set. game_server_cluster_id (:class:`str`): Required. The ID of the game server cluster resource to be created. + This corresponds to the ``game_server_cluster_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -372,12 +406,12 @@ async def create_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_clusters.GameServerCluster``: A - game server cluster resource. + :class:`google.cloud.gaming_v1beta.types.GameServerCluster` + A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -444,7 +478,7 @@ async def preview_create_game_server_cluster( given project and location. Args: - request (:class:`~.game_server_clusters.PreviewCreateGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1beta.types.PreviewCreateGameServerClusterRequest`): The request object. Request message for GameServerClustersService.PreviewCreateGameServerCluster. @@ -455,7 +489,7 @@ async def preview_create_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewCreateGameServerClusterResponse: + google.cloud.gaming_v1beta.types.PreviewCreateGameServerClusterResponse: Response message for GameServerClustersService.PreviewCreateGameServerCluster. @@ -473,6 +507,7 @@ async def preview_create_game_server_cluster( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -502,13 +537,14 @@ async def delete_game_server_cluster( r"""Deletes a single game server cluster. Args: - request (:class:`~.game_server_clusters.DeleteGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1beta.types.DeleteGameServerClusterRequest`): The request object. Request message for GameServerClustersService.DeleteGameServerCluster. name (:class:`str`): Required. The name of the game server cluster to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerClusters/{cluster}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -520,24 +556,22 @@ async def delete_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -597,7 +631,7 @@ async def preview_delete_game_server_cluster( r"""Previews deletion of a single game server cluster. Args: - request (:class:`~.game_server_clusters.PreviewDeleteGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1beta.types.PreviewDeleteGameServerClusterRequest`): The request object. Request message for GameServerClustersService.PreviewDeleteGameServerCluster. @@ -608,7 +642,7 @@ async def preview_delete_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewDeleteGameServerClusterResponse: + google.cloud.gaming_v1beta.types.PreviewDeleteGameServerClusterResponse: Response message for GameServerClustersService.PreviewDeleteGameServerCluster. @@ -626,6 +660,7 @@ async def preview_delete_game_server_cluster( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -656,22 +691,24 @@ async def update_game_server_cluster( r"""Patches a single game server cluster. Args: - request (:class:`~.game_server_clusters.UpdateGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1beta.types.UpdateGameServerClusterRequest`): The request object. Request message for GameServerClustersService.UpdateGameServerCluster. - game_server_cluster (:class:`~.game_server_clusters.GameServerCluster`): + game_server_cluster (:class:`google.cloud.gaming_v1beta.types.GameServerCluster`): Required. The game server cluster to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``game_server_cluster`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -683,12 +720,12 @@ async def update_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_clusters.GameServerCluster``: A - game server cluster resource. + :class:`google.cloud.gaming_v1beta.types.GameServerCluster` + A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -752,7 +789,7 @@ async def preview_update_game_server_cluster( r"""Previews updating a GameServerCluster. Args: - request (:class:`~.game_server_clusters.PreviewUpdateGameServerClusterRequest`): + request (:class:`google.cloud.gaming_v1beta.types.PreviewUpdateGameServerClusterRequest`): The request object. Request message for GameServerClustersService.UpdateGameServerCluster. @@ -763,7 +800,7 @@ async def preview_update_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewUpdateGameServerClusterResponse: + google.cloud.gaming_v1beta.types.PreviewUpdateGameServerClusterResponse: Response message for GameServerClustersService.PreviewUpdateGameServerCluster @@ -781,6 +818,7 @@ async def preview_update_game_server_cluster( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/google/cloud/gaming_v1beta/services/game_server_clusters_service/client.py b/google/cloud/gaming_v1beta/services/game_server_clusters_service/client.py index 44ed94af..14d8d55b 100644 --- a/google/cloud/gaming_v1beta/services/game_server_clusters_service/client.py +++ b/google/cloud/gaming_v1beta/services/game_server_clusters_service/client.py @@ -120,6 +120,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerClustersServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -132,7 +148,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + GameServerClustersServiceClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -242,10 +258,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.GameServerClustersServiceTransport]): The + transport (Union[str, GameServerClustersServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -281,21 +297,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -338,7 +350,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -356,13 +368,14 @@ def list_game_server_clusters( location. Args: - request (:class:`~.game_server_clusters.ListGameServerClustersRequest`): + request (google.cloud.gaming_v1beta.types.ListGameServerClustersRequest): The request object. Request message for GameServerClustersService.ListGameServerClusters. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: "projects/{project}/locations/{location}/realms/{realm}". + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -374,7 +387,7 @@ def list_game_server_clusters( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerClustersPager: + google.cloud.gaming_v1beta.services.game_server_clusters_service.pagers.ListGameServerClustersPager: Response message for GameServerClustersService.ListGameServerClusters. Iterating over this object will yield @@ -441,14 +454,15 @@ def get_game_server_cluster( r"""Gets details of a single game server cluster. Args: - request (:class:`~.game_server_clusters.GetGameServerClusterRequest`): + request (google.cloud.gaming_v1beta.types.GetGameServerClusterRequest): The request object. Request message for GameServerClustersService.GetGameServerCluster. - name (:class:`str`): + name (str): Required. The name of the game server cluster to retrieve. Uses the form: ``projects/{project}/locations/{location}/realms/{realm-id}/gameServerClusters/{cluster}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -460,7 +474,7 @@ def get_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.GameServerCluster: + google.cloud.gaming_v1beta.types.GameServerCluster: A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -517,24 +531,27 @@ def create_game_server_cluster( and location. Args: - request (:class:`~.game_server_clusters.CreateGameServerClusterRequest`): + request (google.cloud.gaming_v1beta.types.CreateGameServerClusterRequest): The request object. Request message for GameServerClustersService.CreateGameServerCluster. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/realms/{realm-id}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_cluster (:class:`~.game_server_clusters.GameServerCluster`): + game_server_cluster (google.cloud.gaming_v1beta.types.GameServerCluster): Required. The game server cluster resource to be created. + This corresponds to the ``game_server_cluster`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_cluster_id (:class:`str`): + game_server_cluster_id (str): Required. The ID of the game server cluster resource to be created. + This corresponds to the ``game_server_cluster_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -546,12 +563,12 @@ def create_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_clusters.GameServerCluster``: A - game server cluster resource. + :class:`google.cloud.gaming_v1beta.types.GameServerCluster` + A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -621,7 +638,7 @@ def preview_create_game_server_cluster( given project and location. Args: - request (:class:`~.game_server_clusters.PreviewCreateGameServerClusterRequest`): + request (google.cloud.gaming_v1beta.types.PreviewCreateGameServerClusterRequest): The request object. Request message for GameServerClustersService.PreviewCreateGameServerCluster. @@ -632,7 +649,7 @@ def preview_create_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewCreateGameServerClusterResponse: + google.cloud.gaming_v1beta.types.PreviewCreateGameServerClusterResponse: Response message for GameServerClustersService.PreviewCreateGameServerCluster. @@ -680,13 +697,14 @@ def delete_game_server_cluster( r"""Deletes a single game server cluster. Args: - request (:class:`~.game_server_clusters.DeleteGameServerClusterRequest`): + request (google.cloud.gaming_v1beta.types.DeleteGameServerClusterRequest): The request object. Request message for GameServerClustersService.DeleteGameServerCluster. - name (:class:`str`): + name (str): Required. The name of the game server cluster to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerClusters/{cluster}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -698,24 +716,22 @@ def delete_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -778,7 +794,7 @@ def preview_delete_game_server_cluster( r"""Previews deletion of a single game server cluster. Args: - request (:class:`~.game_server_clusters.PreviewDeleteGameServerClusterRequest`): + request (google.cloud.gaming_v1beta.types.PreviewDeleteGameServerClusterRequest): The request object. Request message for GameServerClustersService.PreviewDeleteGameServerCluster. @@ -789,7 +805,7 @@ def preview_delete_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewDeleteGameServerClusterResponse: + google.cloud.gaming_v1beta.types.PreviewDeleteGameServerClusterResponse: Response message for GameServerClustersService.PreviewDeleteGameServerCluster. @@ -838,22 +854,24 @@ def update_game_server_cluster( r"""Patches a single game server cluster. Args: - request (:class:`~.game_server_clusters.UpdateGameServerClusterRequest`): + request (google.cloud.gaming_v1beta.types.UpdateGameServerClusterRequest): The request object. Request message for GameServerClustersService.UpdateGameServerCluster. - game_server_cluster (:class:`~.game_server_clusters.GameServerCluster`): + game_server_cluster (google.cloud.gaming_v1beta.types.GameServerCluster): Required. The game server cluster to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``game_server_cluster`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -865,12 +883,12 @@ def update_game_server_cluster( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_clusters.GameServerCluster``: A - game server cluster resource. + :class:`google.cloud.gaming_v1beta.types.GameServerCluster` + A game server cluster resource. """ # Create or coerce a protobuf request object. @@ -937,7 +955,7 @@ def preview_update_game_server_cluster( r"""Previews updating a GameServerCluster. Args: - request (:class:`~.game_server_clusters.PreviewUpdateGameServerClusterRequest`): + request (google.cloud.gaming_v1beta.types.PreviewUpdateGameServerClusterRequest): The request object. Request message for GameServerClustersService.UpdateGameServerCluster. @@ -948,7 +966,7 @@ def preview_update_game_server_cluster( sent along with the request as metadata. Returns: - ~.game_server_clusters.PreviewUpdateGameServerClusterResponse: + google.cloud.gaming_v1beta.types.PreviewUpdateGameServerClusterResponse: Response message for GameServerClustersService.PreviewUpdateGameServerCluster diff --git a/google/cloud/gaming_v1beta/services/game_server_clusters_service/pagers.py b/google/cloud/gaming_v1beta/services/game_server_clusters_service/pagers.py index 9dbc6c32..5e6e832b 100644 --- a/google/cloud/gaming_v1beta/services/game_server_clusters_service/pagers.py +++ b/google/cloud/gaming_v1beta/services/game_server_clusters_service/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.gaming_v1beta.types import game_server_clusters @@ -24,7 +33,7 @@ class ListGameServerClustersPager: """A pager for iterating through ``list_game_server_clusters`` requests. This class thinly wraps an initial - :class:`~.game_server_clusters.ListGameServerClustersResponse` object, and + :class:`google.cloud.gaming_v1beta.types.ListGameServerClustersResponse` object, and provides an ``__iter__`` method to iterate through its ``game_server_clusters`` field. @@ -33,7 +42,7 @@ class ListGameServerClustersPager: through the ``game_server_clusters`` field on the corresponding responses. - All the usual :class:`~.game_server_clusters.ListGameServerClustersResponse` + All the usual :class:`google.cloud.gaming_v1beta.types.ListGameServerClustersResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +60,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_clusters.ListGameServerClustersRequest`): + request (google.cloud.gaming_v1beta.types.ListGameServerClustersRequest): The initial request object. - response (:class:`~.game_server_clusters.ListGameServerClustersResponse`): + response (google.cloud.gaming_v1beta.types.ListGameServerClustersResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +95,7 @@ class ListGameServerClustersAsyncPager: """A pager for iterating through ``list_game_server_clusters`` requests. This class thinly wraps an initial - :class:`~.game_server_clusters.ListGameServerClustersResponse` object, and + :class:`google.cloud.gaming_v1beta.types.ListGameServerClustersResponse` object, and provides an ``__aiter__`` method to iterate through its ``game_server_clusters`` field. @@ -95,7 +104,7 @@ class ListGameServerClustersAsyncPager: through the ``game_server_clusters`` field on the corresponding responses. - All the usual :class:`~.game_server_clusters.ListGameServerClustersResponse` + All the usual :class:`google.cloud.gaming_v1beta.types.ListGameServerClustersResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +124,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_clusters.ListGameServerClustersRequest`): + request (google.cloud.gaming_v1beta.types.ListGameServerClustersRequest): The initial request object. - response (:class:`~.game_server_clusters.ListGameServerClustersResponse`): + response (google.cloud.gaming_v1beta.types.ListGameServerClustersResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/base.py b/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/base.py index 41a3a591..706791e9 100644 --- a/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/base.py +++ b/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/base.py @@ -71,10 +71,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -82,6 +82,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -91,20 +94,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -115,6 +115,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -126,6 +127,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -142,6 +144,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -158,6 +161,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -174,6 +178,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, diff --git a/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/grpc.py b/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/grpc.py index e8fe40ee..e7e73636 100644 --- a/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/grpc.py +++ b/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/grpc.py @@ -60,6 +60,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -90,6 +91,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -104,72 +109,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -177,18 +171,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -202,7 +186,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/grpc_asyncio.py b/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/grpc_asyncio.py index 336396b3..f49e9b71 100644 --- a/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/grpc_asyncio.py +++ b/google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -104,6 +104,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -135,12 +136,16 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -149,72 +154,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -222,18 +216,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/gaming_v1beta/services/game_server_configs_service/async_client.py b/google/cloud/gaming_v1beta/services/game_server_configs_service/async_client.py index 3da8992e..f692d319 100644 --- a/google/cloud/gaming_v1beta/services/game_server_configs_service/async_client.py +++ b/google/cloud/gaming_v1beta/services/game_server_configs_service/async_client.py @@ -91,7 +91,36 @@ class GameServerConfigsServiceAsyncClient: GameServerConfigsServiceClient.parse_common_location_path ) - from_service_account_file = GameServerConfigsServiceClient.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerConfigsServiceAsyncClient: The constructed client. + """ + return GameServerConfigsServiceClient.from_service_account_info.__func__(GameServerConfigsServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerConfigsServiceAsyncClient: The constructed client. + """ + return GameServerConfigsServiceClient.from_service_account_file.__func__(GameServerConfigsServiceAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -169,13 +198,14 @@ async def list_game_server_configs( location, and game server deployment. Args: - request (:class:`~.game_server_configs.ListGameServerConfigsRequest`): + request (:class:`google.cloud.gaming_v1beta.types.ListGameServerConfigsRequest`): The request object. Request message for GameServerConfigsService.ListGameServerConfigs. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/*``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -187,7 +217,7 @@ async def list_game_server_configs( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerConfigsAsyncPager: + google.cloud.gaming_v1beta.services.game_server_configs_service.pagers.ListGameServerConfigsAsyncPager: Response message for GameServerConfigsService.ListGameServerConfigs. Iterating over this object will yield @@ -222,6 +252,7 @@ async def list_game_server_configs( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -257,7 +288,7 @@ async def get_game_server_config( r"""Gets details of a single game server config. Args: - request (:class:`~.game_server_configs.GetGameServerConfigRequest`): + request (:class:`google.cloud.gaming_v1beta.types.GetGameServerConfigRequest`): The request object. Request message for GameServerConfigsService.GetGameServerConfig. name (:class:`str`): @@ -265,6 +296,7 @@ async def get_game_server_config( retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/{config}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -276,7 +308,7 @@ async def get_game_server_config( sent along with the request as metadata. Returns: - ~.game_server_configs.GameServerConfig: + google.cloud.gaming_v1beta.types.GameServerConfig: A game server config resource. """ # Create or coerce a protobuf request object. @@ -306,6 +338,7 @@ async def get_game_server_config( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -340,19 +373,21 @@ async def create_game_server_config( resource. Args: - request (:class:`~.game_server_configs.CreateGameServerConfigRequest`): + request (:class:`google.cloud.gaming_v1beta.types.CreateGameServerConfigRequest`): The request object. Request message for GameServerConfigsService.CreateGameServerConfig. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_config (:class:`~.game_server_configs.GameServerConfig`): + game_server_config (:class:`google.cloud.gaming_v1beta.types.GameServerConfig`): Required. The game server config resource to be created. + This corresponds to the ``game_server_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -364,12 +399,12 @@ async def create_game_server_config( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_configs.GameServerConfig``: A - game server config resource. + :class:`google.cloud.gaming_v1beta.types.GameServerConfig` + A game server config resource. """ # Create or coerce a protobuf request object. @@ -434,7 +469,7 @@ async def delete_game_server_config( game server deployment rollout. Args: - request (:class:`~.game_server_configs.DeleteGameServerConfigRequest`): + request (:class:`google.cloud.gaming_v1beta.types.DeleteGameServerConfigRequest`): The request object. Request message for GameServerConfigsService.DeleteGameServerConfig. name (:class:`str`): @@ -442,6 +477,7 @@ async def delete_game_server_config( Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/{config}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -453,24 +489,22 @@ async def delete_game_server_config( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/gaming_v1beta/services/game_server_configs_service/client.py b/google/cloud/gaming_v1beta/services/game_server_configs_service/client.py index aab3bfac..5d60783a 100644 --- a/google/cloud/gaming_v1beta/services/game_server_configs_service/client.py +++ b/google/cloud/gaming_v1beta/services/game_server_configs_service/client.py @@ -119,6 +119,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerConfigsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -131,7 +147,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + GameServerConfigsServiceClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -241,10 +257,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.GameServerConfigsServiceTransport]): The + transport (Union[str, GameServerConfigsServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -280,21 +296,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -337,7 +349,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -355,13 +367,14 @@ def list_game_server_configs( location, and game server deployment. Args: - request (:class:`~.game_server_configs.ListGameServerConfigsRequest`): + request (google.cloud.gaming_v1beta.types.ListGameServerConfigsRequest): The request object. Request message for GameServerConfigsService.ListGameServerConfigs. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/*``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -373,7 +386,7 @@ def list_game_server_configs( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerConfigsPager: + google.cloud.gaming_v1beta.services.game_server_configs_service.pagers.ListGameServerConfigsPager: Response message for GameServerConfigsService.ListGameServerConfigs. Iterating over this object will yield @@ -438,14 +451,15 @@ def get_game_server_config( r"""Gets details of a single game server config. Args: - request (:class:`~.game_server_configs.GetGameServerConfigRequest`): + request (google.cloud.gaming_v1beta.types.GetGameServerConfigRequest): The request object. Request message for GameServerConfigsService.GetGameServerConfig. - name (:class:`str`): + name (str): Required. The name of the game server config to retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/{config}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -457,7 +471,7 @@ def get_game_server_config( sent along with the request as metadata. Returns: - ~.game_server_configs.GameServerConfig: + google.cloud.gaming_v1beta.types.GameServerConfig: A game server config resource. """ # Create or coerce a protobuf request object. @@ -516,19 +530,21 @@ def create_game_server_config( resource. Args: - request (:class:`~.game_server_configs.CreateGameServerConfigRequest`): + request (google.cloud.gaming_v1beta.types.CreateGameServerConfigRequest): The request object. Request message for GameServerConfigsService.CreateGameServerConfig. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_config (:class:`~.game_server_configs.GameServerConfig`): + game_server_config (google.cloud.gaming_v1beta.types.GameServerConfig): Required. The game server config resource to be created. + This corresponds to the ``game_server_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -540,12 +556,12 @@ def create_game_server_config( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_configs.GameServerConfig``: A - game server config resource. + :class:`google.cloud.gaming_v1beta.types.GameServerConfig` + A game server config resource. """ # Create or coerce a protobuf request object. @@ -613,14 +629,15 @@ def delete_game_server_config( game server deployment rollout. Args: - request (:class:`~.game_server_configs.DeleteGameServerConfigRequest`): + request (google.cloud.gaming_v1beta.types.DeleteGameServerConfigRequest): The request object. Request message for GameServerConfigsService.DeleteGameServerConfig. - name (:class:`str`): + name (str): Required. The name of the game server config to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/configs/{config}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -632,24 +649,22 @@ def delete_game_server_config( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/gaming_v1beta/services/game_server_configs_service/pagers.py b/google/cloud/gaming_v1beta/services/game_server_configs_service/pagers.py index 60fb386c..adcc2aff 100644 --- a/google/cloud/gaming_v1beta/services/game_server_configs_service/pagers.py +++ b/google/cloud/gaming_v1beta/services/game_server_configs_service/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.gaming_v1beta.types import game_server_configs @@ -24,7 +33,7 @@ class ListGameServerConfigsPager: """A pager for iterating through ``list_game_server_configs`` requests. This class thinly wraps an initial - :class:`~.game_server_configs.ListGameServerConfigsResponse` object, and + :class:`google.cloud.gaming_v1beta.types.ListGameServerConfigsResponse` object, and provides an ``__iter__`` method to iterate through its ``game_server_configs`` field. @@ -33,7 +42,7 @@ class ListGameServerConfigsPager: through the ``game_server_configs`` field on the corresponding responses. - All the usual :class:`~.game_server_configs.ListGameServerConfigsResponse` + All the usual :class:`google.cloud.gaming_v1beta.types.ListGameServerConfigsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +60,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_configs.ListGameServerConfigsRequest`): + request (google.cloud.gaming_v1beta.types.ListGameServerConfigsRequest): The initial request object. - response (:class:`~.game_server_configs.ListGameServerConfigsResponse`): + response (google.cloud.gaming_v1beta.types.ListGameServerConfigsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +95,7 @@ class ListGameServerConfigsAsyncPager: """A pager for iterating through ``list_game_server_configs`` requests. This class thinly wraps an initial - :class:`~.game_server_configs.ListGameServerConfigsResponse` object, and + :class:`google.cloud.gaming_v1beta.types.ListGameServerConfigsResponse` object, and provides an ``__aiter__`` method to iterate through its ``game_server_configs`` field. @@ -95,7 +104,7 @@ class ListGameServerConfigsAsyncPager: through the ``game_server_configs`` field on the corresponding responses. - All the usual :class:`~.game_server_configs.ListGameServerConfigsResponse` + All the usual :class:`google.cloud.gaming_v1beta.types.ListGameServerConfigsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +124,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_configs.ListGameServerConfigsRequest`): + request (google.cloud.gaming_v1beta.types.ListGameServerConfigsRequest): The initial request object. - response (:class:`~.game_server_configs.ListGameServerConfigsResponse`): + response (google.cloud.gaming_v1beta.types.ListGameServerConfigsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/base.py b/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/base.py index 1d658506..9b15e30c 100644 --- a/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/base.py +++ b/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/base.py @@ -71,10 +71,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -82,6 +82,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -91,20 +94,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -115,6 +115,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -126,6 +127,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, diff --git a/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/grpc.py b/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/grpc.py index e0284bbd..2f45ab3b 100644 --- a/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/grpc.py +++ b/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/grpc.py @@ -60,6 +60,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -90,6 +91,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -104,72 +109,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -177,18 +171,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -202,7 +186,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/grpc_asyncio.py b/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/grpc_asyncio.py index 7975e17d..66c12adc 100644 --- a/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/grpc_asyncio.py +++ b/google/cloud/gaming_v1beta/services/game_server_configs_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -104,6 +104,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -135,12 +136,16 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -149,72 +154,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -222,18 +216,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/gaming_v1beta/services/game_server_deployments_service/async_client.py b/google/cloud/gaming_v1beta/services/game_server_deployments_service/async_client.py index 7ebafb02..ec27755a 100644 --- a/google/cloud/gaming_v1beta/services/game_server_deployments_service/async_client.py +++ b/google/cloud/gaming_v1beta/services/game_server_deployments_service/async_client.py @@ -100,9 +100,36 @@ class GameServerDeploymentsServiceAsyncClient: GameServerDeploymentsServiceClient.parse_common_location_path ) - from_service_account_file = ( - GameServerDeploymentsServiceClient.from_service_account_file - ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerDeploymentsServiceAsyncClient: The constructed client. + """ + return GameServerDeploymentsServiceClient.from_service_account_info.__func__(GameServerDeploymentsServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerDeploymentsServiceAsyncClient: The constructed client. + """ + return GameServerDeploymentsServiceClient.from_service_account_file.__func__(GameServerDeploymentsServiceAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -180,12 +207,13 @@ async def list_game_server_deployments( location. Args: - request (:class:`~.game_server_deployments.ListGameServerDeploymentsRequest`): + request (:class:`google.cloud.gaming_v1beta.types.ListGameServerDeploymentsRequest`): The request object. Request message for GameServerDeploymentsService.ListGameServerDeployments. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -197,7 +225,7 @@ async def list_game_server_deployments( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerDeploymentsAsyncPager: + google.cloud.gaming_v1beta.services.game_server_deployments_service.pagers.ListGameServerDeploymentsAsyncPager: Response message for GameServerDeploymentsService.ListGameServerDeployments. Iterating over this object will yield @@ -232,6 +260,7 @@ async def list_game_server_deployments( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -267,7 +296,7 @@ async def get_game_server_deployment( r"""Gets details of a single game server deployment. Args: - request (:class:`~.game_server_deployments.GetGameServerDeploymentRequest`): + request (:class:`google.cloud.gaming_v1beta.types.GetGameServerDeploymentRequest`): The request object. Request message for GameServerDeploymentsService.GetGameServerDeployment. name (:class:`str`): @@ -275,6 +304,7 @@ async def get_game_server_deployment( retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -286,7 +316,7 @@ async def get_game_server_deployment( sent along with the request as metadata. Returns: - ~.game_server_deployments.GameServerDeployment: + google.cloud.gaming_v1beta.types.GameServerDeployment: A game server deployment resource. """ # Create or coerce a protobuf request object. @@ -316,6 +346,7 @@ async def get_game_server_deployment( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -347,18 +378,20 @@ async def create_game_server_deployment( project and location. Args: - request (:class:`~.game_server_deployments.CreateGameServerDeploymentRequest`): + request (:class:`google.cloud.gaming_v1beta.types.CreateGameServerDeploymentRequest`): The request object. Request message for GameServerDeploymentsService.CreateGameServerDeployment. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_deployment (:class:`~.game_server_deployments.GameServerDeployment`): + game_server_deployment (:class:`google.cloud.gaming_v1beta.types.GameServerDeployment`): Required. The game server delpoyment resource to be created. + This corresponds to the ``game_server_deployment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -370,11 +403,11 @@ async def create_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1beta.types.GameServerDeployment` A game server deployment resource. """ @@ -438,7 +471,7 @@ async def delete_game_server_deployment( r"""Deletes a single game server deployment. Args: - request (:class:`~.game_server_deployments.DeleteGameServerDeploymentRequest`): + request (:class:`google.cloud.gaming_v1beta.types.DeleteGameServerDeploymentRequest`): The request object. Request message for GameServerDeploymentsService.DeleteGameServerDeployment. name (:class:`str`): @@ -446,6 +479,7 @@ async def delete_game_server_deployment( delete. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -457,24 +491,22 @@ async def delete_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -536,23 +568,25 @@ async def update_game_server_deployment( r"""Patches a game server deployment. Args: - request (:class:`~.game_server_deployments.UpdateGameServerDeploymentRequest`): + request (:class:`google.cloud.gaming_v1beta.types.UpdateGameServerDeploymentRequest`): The request object. Request message for GameServerDeploymentsService.UpdateGameServerDeployment. Only allows updates for labels. - game_server_deployment (:class:`~.game_server_deployments.GameServerDeployment`): + game_server_deployment (:class:`google.cloud.gaming_v1beta.types.GameServerDeployment`): Required. The game server delpoyment to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``game_server_deployment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -564,11 +598,11 @@ async def update_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1beta.types.GameServerDeployment` A game server deployment resource. """ @@ -634,7 +668,7 @@ async def get_game_server_deployment_rollout( r"""Gets details a single game server deployment rollout. Args: - request (:class:`~.game_server_deployments.GetGameServerDeploymentRolloutRequest`): + request (:class:`google.cloud.gaming_v1beta.types.GetGameServerDeploymentRolloutRequest`): The request object. Request message for GameServerDeploymentsService.GetGameServerDeploymentRollout. name (:class:`str`): @@ -642,6 +676,7 @@ async def get_game_server_deployment_rollout( retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -653,7 +688,7 @@ async def get_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.game_server_deployments.GameServerDeploymentRollout: + google.cloud.gaming_v1beta.types.GameServerDeploymentRollout: The game server deployment rollout which represents the desired rollout state. @@ -686,6 +721,7 @@ async def get_game_server_deployment_rollout( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -722,23 +758,25 @@ async def update_game_server_deployment_rollout( an error. Args: - request (:class:`~.game_server_deployments.UpdateGameServerDeploymentRolloutRequest`): + request (:class:`google.cloud.gaming_v1beta.types.UpdateGameServerDeploymentRolloutRequest`): The request object. Request message for GameServerDeploymentsService.UpdateGameServerRolloutDeployment. - rollout (:class:`~.game_server_deployments.GameServerDeploymentRollout`): + rollout (:class:`google.cloud.gaming_v1beta.types.GameServerDeploymentRollout`): Required. The game server delpoyment rollout to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``rollout`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -750,11 +788,11 @@ async def update_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1beta.types.GameServerDeployment` A game server deployment resource. """ @@ -822,7 +860,7 @@ async def preview_game_server_deployment_rollout( does not mutate the rollout resource. Args: - request (:class:`~.game_server_deployments.PreviewGameServerDeploymentRolloutRequest`): + request (:class:`google.cloud.gaming_v1beta.types.PreviewGameServerDeploymentRolloutRequest`): The request object. Request message for PreviewGameServerDeploymentRollout. @@ -833,7 +871,7 @@ async def preview_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.game_server_deployments.PreviewGameServerDeploymentRolloutResponse: + google.cloud.gaming_v1beta.types.PreviewGameServerDeploymentRolloutResponse: Response message for PreviewGameServerDeploymentRollout. This has details about the Agones fleet and @@ -855,6 +893,7 @@ async def preview_game_server_deployment_rollout( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -888,7 +927,7 @@ async def fetch_deployment_state( older version of the game server deployment. Args: - request (:class:`~.game_server_deployments.FetchDeploymentStateRequest`): + request (:class:`google.cloud.gaming_v1beta.types.FetchDeploymentStateRequest`): The request object. Request message for GameServerDeploymentsService.FetchDeploymentState. @@ -899,7 +938,7 @@ async def fetch_deployment_state( sent along with the request as metadata. Returns: - ~.game_server_deployments.FetchDeploymentStateResponse: + google.cloud.gaming_v1beta.types.FetchDeploymentStateResponse: Response message for GameServerDeploymentsService.FetchDeploymentState. @@ -917,6 +956,7 @@ async def fetch_deployment_state( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/google/cloud/gaming_v1beta/services/game_server_deployments_service/client.py b/google/cloud/gaming_v1beta/services/game_server_deployments_service/client.py index 358055a4..0cb11b93 100644 --- a/google/cloud/gaming_v1beta/services/game_server_deployments_service/client.py +++ b/google/cloud/gaming_v1beta/services/game_server_deployments_service/client.py @@ -124,6 +124,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + GameServerDeploymentsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -136,7 +152,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + GameServerDeploymentsServiceClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -264,10 +280,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.GameServerDeploymentsServiceTransport]): The + transport (Union[str, GameServerDeploymentsServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -303,21 +319,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -360,7 +372,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -378,12 +390,13 @@ def list_game_server_deployments( location. Args: - request (:class:`~.game_server_deployments.ListGameServerDeploymentsRequest`): + request (google.cloud.gaming_v1beta.types.ListGameServerDeploymentsRequest): The request object. Request message for GameServerDeploymentsService.ListGameServerDeployments. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -395,7 +408,7 @@ def list_game_server_deployments( sent along with the request as metadata. Returns: - ~.pagers.ListGameServerDeploymentsPager: + google.cloud.gaming_v1beta.services.game_server_deployments_service.pagers.ListGameServerDeploymentsPager: Response message for GameServerDeploymentsService.ListGameServerDeployments. Iterating over this object will yield @@ -464,14 +477,15 @@ def get_game_server_deployment( r"""Gets details of a single game server deployment. Args: - request (:class:`~.game_server_deployments.GetGameServerDeploymentRequest`): + request (google.cloud.gaming_v1beta.types.GetGameServerDeploymentRequest): The request object. Request message for GameServerDeploymentsService.GetGameServerDeployment. - name (:class:`str`): + name (str): Required. The name of the game server delpoyment to retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -483,7 +497,7 @@ def get_game_server_deployment( sent along with the request as metadata. Returns: - ~.game_server_deployments.GameServerDeployment: + google.cloud.gaming_v1beta.types.GameServerDeployment: A game server deployment resource. """ # Create or coerce a protobuf request object. @@ -543,18 +557,20 @@ def create_game_server_deployment( project and location. Args: - request (:class:`~.game_server_deployments.CreateGameServerDeploymentRequest`): + request (google.cloud.gaming_v1beta.types.CreateGameServerDeploymentRequest): The request object. Request message for GameServerDeploymentsService.CreateGameServerDeployment. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - game_server_deployment (:class:`~.game_server_deployments.GameServerDeployment`): + game_server_deployment (google.cloud.gaming_v1beta.types.GameServerDeployment): Required. The game server delpoyment resource to be created. + This corresponds to the ``game_server_deployment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -566,11 +582,11 @@ def create_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1beta.types.GameServerDeployment` A game server deployment resource. """ @@ -639,14 +655,15 @@ def delete_game_server_deployment( r"""Deletes a single game server deployment. Args: - request (:class:`~.game_server_deployments.DeleteGameServerDeploymentRequest`): + request (google.cloud.gaming_v1beta.types.DeleteGameServerDeploymentRequest): The request object. Request message for GameServerDeploymentsService.DeleteGameServerDeployment. - name (:class:`str`): + name (str): Required. The name of the game server delpoyment to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -658,24 +675,22 @@ def delete_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -742,23 +757,25 @@ def update_game_server_deployment( r"""Patches a game server deployment. Args: - request (:class:`~.game_server_deployments.UpdateGameServerDeploymentRequest`): + request (google.cloud.gaming_v1beta.types.UpdateGameServerDeploymentRequest): The request object. Request message for GameServerDeploymentsService.UpdateGameServerDeployment. Only allows updates for labels. - game_server_deployment (:class:`~.game_server_deployments.GameServerDeployment`): + game_server_deployment (google.cloud.gaming_v1beta.types.GameServerDeployment): Required. The game server delpoyment to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``game_server_deployment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -770,11 +787,11 @@ def update_game_server_deployment( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1beta.types.GameServerDeployment` A game server deployment resource. """ @@ -845,14 +862,15 @@ def get_game_server_deployment_rollout( r"""Gets details a single game server deployment rollout. Args: - request (:class:`~.game_server_deployments.GetGameServerDeploymentRolloutRequest`): + request (google.cloud.gaming_v1beta.types.GetGameServerDeploymentRolloutRequest): The request object. Request message for GameServerDeploymentsService.GetGameServerDeploymentRollout. - name (:class:`str`): + name (str): Required. The name of the game server delpoyment to retrieve. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment}/rollout``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -864,7 +882,7 @@ def get_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.game_server_deployments.GameServerDeploymentRollout: + google.cloud.gaming_v1beta.types.GameServerDeploymentRollout: The game server deployment rollout which represents the desired rollout state. @@ -934,23 +952,25 @@ def update_game_server_deployment_rollout( an error. Args: - request (:class:`~.game_server_deployments.UpdateGameServerDeploymentRolloutRequest`): + request (google.cloud.gaming_v1beta.types.UpdateGameServerDeploymentRolloutRequest): The request object. Request message for GameServerDeploymentsService.UpdateGameServerRolloutDeployment. - rollout (:class:`~.game_server_deployments.GameServerDeploymentRollout`): + rollout (google.cloud.gaming_v1beta.types.GameServerDeploymentRollout): Required. The game server delpoyment rollout to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``rollout`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -962,11 +982,11 @@ def update_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.game_server_deployments.GameServerDeployment``: + :class:`google.cloud.gaming_v1beta.types.GameServerDeployment` A game server deployment resource. """ @@ -1039,7 +1059,7 @@ def preview_game_server_deployment_rollout( does not mutate the rollout resource. Args: - request (:class:`~.game_server_deployments.PreviewGameServerDeploymentRolloutRequest`): + request (google.cloud.gaming_v1beta.types.PreviewGameServerDeploymentRolloutRequest): The request object. Request message for PreviewGameServerDeploymentRollout. @@ -1050,7 +1070,7 @@ def preview_game_server_deployment_rollout( sent along with the request as metadata. Returns: - ~.game_server_deployments.PreviewGameServerDeploymentRolloutResponse: + google.cloud.gaming_v1beta.types.PreviewGameServerDeploymentRolloutResponse: Response message for PreviewGameServerDeploymentRollout. This has details about the Agones fleet and @@ -1104,7 +1124,7 @@ def fetch_deployment_state( older version of the game server deployment. Args: - request (:class:`~.game_server_deployments.FetchDeploymentStateRequest`): + request (google.cloud.gaming_v1beta.types.FetchDeploymentStateRequest): The request object. Request message for GameServerDeploymentsService.FetchDeploymentState. @@ -1115,7 +1135,7 @@ def fetch_deployment_state( sent along with the request as metadata. Returns: - ~.game_server_deployments.FetchDeploymentStateResponse: + google.cloud.gaming_v1beta.types.FetchDeploymentStateResponse: Response message for GameServerDeploymentsService.FetchDeploymentState. diff --git a/google/cloud/gaming_v1beta/services/game_server_deployments_service/pagers.py b/google/cloud/gaming_v1beta/services/game_server_deployments_service/pagers.py index c3ca0a87..7f168712 100644 --- a/google/cloud/gaming_v1beta/services/game_server_deployments_service/pagers.py +++ b/google/cloud/gaming_v1beta/services/game_server_deployments_service/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.gaming_v1beta.types import game_server_deployments @@ -24,7 +33,7 @@ class ListGameServerDeploymentsPager: """A pager for iterating through ``list_game_server_deployments`` requests. This class thinly wraps an initial - :class:`~.game_server_deployments.ListGameServerDeploymentsResponse` object, and + :class:`google.cloud.gaming_v1beta.types.ListGameServerDeploymentsResponse` object, and provides an ``__iter__`` method to iterate through its ``game_server_deployments`` field. @@ -33,7 +42,7 @@ class ListGameServerDeploymentsPager: through the ``game_server_deployments`` field on the corresponding responses. - All the usual :class:`~.game_server_deployments.ListGameServerDeploymentsResponse` + All the usual :class:`google.cloud.gaming_v1beta.types.ListGameServerDeploymentsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -53,9 +62,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_deployments.ListGameServerDeploymentsRequest`): + request (google.cloud.gaming_v1beta.types.ListGameServerDeploymentsRequest): The initial request object. - response (:class:`~.game_server_deployments.ListGameServerDeploymentsResponse`): + response (google.cloud.gaming_v1beta.types.ListGameServerDeploymentsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -92,7 +101,7 @@ class ListGameServerDeploymentsAsyncPager: """A pager for iterating through ``list_game_server_deployments`` requests. This class thinly wraps an initial - :class:`~.game_server_deployments.ListGameServerDeploymentsResponse` object, and + :class:`google.cloud.gaming_v1beta.types.ListGameServerDeploymentsResponse` object, and provides an ``__aiter__`` method to iterate through its ``game_server_deployments`` field. @@ -101,7 +110,7 @@ class ListGameServerDeploymentsAsyncPager: through the ``game_server_deployments`` field on the corresponding responses. - All the usual :class:`~.game_server_deployments.ListGameServerDeploymentsResponse` + All the usual :class:`google.cloud.gaming_v1beta.types.ListGameServerDeploymentsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -121,9 +130,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.game_server_deployments.ListGameServerDeploymentsRequest`): + request (google.cloud.gaming_v1beta.types.ListGameServerDeploymentsRequest): The initial request object. - response (:class:`~.game_server_deployments.ListGameServerDeploymentsResponse`): + response (google.cloud.gaming_v1beta.types.ListGameServerDeploymentsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/base.py b/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/base.py index 8a510155..4f3db241 100644 --- a/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/base.py +++ b/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/base.py @@ -71,10 +71,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -82,6 +82,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -91,20 +94,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -115,6 +115,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -126,6 +127,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -152,6 +154,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -168,6 +171,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -179,6 +183,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, diff --git a/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/grpc.py b/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/grpc.py index 749f3132..23b4a7f7 100644 --- a/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/grpc.py +++ b/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/grpc.py @@ -60,6 +60,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -90,6 +91,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -104,72 +109,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -177,18 +171,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -202,7 +186,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/grpc_asyncio.py b/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/grpc_asyncio.py index e27273e4..49951d83 100644 --- a/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/grpc_asyncio.py +++ b/google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -106,6 +106,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -137,12 +138,16 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -151,72 +156,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -224,18 +218,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/gaming_v1beta/services/realms_service/async_client.py b/google/cloud/gaming_v1beta/services/realms_service/async_client.py index eb9ff3b0..7273bc10 100644 --- a/google/cloud/gaming_v1beta/services/realms_service/async_client.py +++ b/google/cloud/gaming_v1beta/services/realms_service/async_client.py @@ -84,7 +84,36 @@ class RealmsServiceAsyncClient: RealmsServiceClient.parse_common_location_path ) - from_service_account_file = RealmsServiceClient.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + RealmsServiceAsyncClient: The constructed client. + """ + return RealmsServiceClient.from_service_account_info.__func__(RealmsServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + RealmsServiceAsyncClient: The constructed client. + """ + return RealmsServiceClient.from_service_account_file.__func__(RealmsServiceAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property @@ -160,12 +189,13 @@ async def list_realms( r"""Lists realms in a given project and location. Args: - request (:class:`~.realms.ListRealmsRequest`): + request (:class:`google.cloud.gaming_v1beta.types.ListRealmsRequest`): The request object. Request message for RealmsService.ListRealms. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -177,7 +207,7 @@ async def list_realms( sent along with the request as metadata. Returns: - ~.pagers.ListRealmsAsyncPager: + google.cloud.gaming_v1beta.services.realms_service.pagers.ListRealmsAsyncPager: Response message for RealmsService.ListRealms. Iterating over this object will yield @@ -212,6 +242,7 @@ async def list_realms( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -247,13 +278,14 @@ async def get_realm( r"""Gets details of a single realm. Args: - request (:class:`~.realms.GetRealmRequest`): + request (:class:`google.cloud.gaming_v1beta.types.GetRealmRequest`): The request object. Request message for RealmsService.GetRealm. name (:class:`str`): Required. The name of the realm to retrieve. Uses the form: ``projects/{project}/locations/{location}/realms/{realm}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -265,7 +297,7 @@ async def get_realm( sent along with the request as metadata. Returns: - ~.realms.Realm: + google.cloud.gaming_v1beta.types.Realm: A realm resource. """ # Create or coerce a protobuf request object. @@ -295,6 +327,7 @@ async def get_realm( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, @@ -326,24 +359,27 @@ async def create_realm( r"""Creates a new realm in a given project and location. Args: - request (:class:`~.realms.CreateRealmRequest`): + request (:class:`google.cloud.gaming_v1beta.types.CreateRealmRequest`): The request object. Request message for RealmsService.CreateRealm. parent (:class:`str`): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - realm (:class:`~.realms.Realm`): + realm (:class:`google.cloud.gaming_v1beta.types.Realm`): Required. The realm resource to be created. + This corresponds to the ``realm`` field on the ``request`` instance; if ``request`` is provided, this should not be set. realm_id (:class:`str`): Required. The ID of the realm resource to be created. + This corresponds to the ``realm_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -355,11 +391,12 @@ async def create_realm( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.realms.Realm``: A realm resource. + :class:`google.cloud.gaming_v1beta.types.Realm` A realm + resource. """ # Create or coerce a protobuf request object. @@ -424,13 +461,14 @@ async def delete_realm( r"""Deletes a single realm. Args: - request (:class:`~.realms.DeleteRealmRequest`): + request (:class:`google.cloud.gaming_v1beta.types.DeleteRealmRequest`): The request object. Request message for RealmsService.DeleteRealm. name (:class:`str`): Required. The name of the realm to delete. Uses the form: ``projects/{project}/locations/{location}/realms/{realm}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -442,24 +480,22 @@ async def delete_realm( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -521,21 +557,23 @@ async def update_realm( r"""Patches a single realm. Args: - request (:class:`~.realms.UpdateRealmRequest`): + request (:class:`google.cloud.gaming_v1beta.types.UpdateRealmRequest`): The request object. Request message for RealmsService.UpdateRealm. - realm (:class:`~.realms.Realm`): + realm (:class:`google.cloud.gaming_v1beta.types.Realm`): Required. The realm to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``realm`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -547,11 +585,12 @@ async def update_realm( sent along with the request as metadata. Returns: - ~.operation_async.AsyncOperation: + google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. The result type for the operation will be - :class:``~.realms.Realm``: A realm resource. + :class:`google.cloud.gaming_v1beta.types.Realm` A realm + resource. """ # Create or coerce a protobuf request object. @@ -615,7 +654,7 @@ async def preview_realm_update( r"""Previews patches to a single realm. Args: - request (:class:`~.realms.PreviewRealmUpdateRequest`): + request (:class:`google.cloud.gaming_v1beta.types.PreviewRealmUpdateRequest`): The request object. Request message for RealmsService.PreviewRealmUpdate. @@ -626,7 +665,7 @@ async def preview_realm_update( sent along with the request as metadata. Returns: - ~.realms.PreviewRealmUpdateResponse: + google.cloud.gaming_v1beta.types.PreviewRealmUpdateResponse: Response message for RealmsService.PreviewRealmUpdate. @@ -644,6 +683,7 @@ async def preview_realm_update( maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/google/cloud/gaming_v1beta/services/realms_service/client.py b/google/cloud/gaming_v1beta/services/realms_service/client.py index aa4dc719..102e1141 100644 --- a/google/cloud/gaming_v1beta/services/realms_service/client.py +++ b/google/cloud/gaming_v1beta/services/realms_service/client.py @@ -116,6 +116,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + RealmsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -128,7 +144,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + RealmsServiceClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -236,10 +252,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.RealmsServiceTransport]): The + transport (Union[str, RealmsServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -275,21 +291,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -332,7 +344,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -349,12 +361,13 @@ def list_realms( r"""Lists realms in a given project and location. Args: - request (:class:`~.realms.ListRealmsRequest`): + request (google.cloud.gaming_v1beta.types.ListRealmsRequest): The request object. Request message for RealmsService.ListRealms. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -366,7 +379,7 @@ def list_realms( sent along with the request as metadata. Returns: - ~.pagers.ListRealmsPager: + google.cloud.gaming_v1beta.services.realms_service.pagers.ListRealmsPager: Response message for RealmsService.ListRealms. Iterating over this object will yield @@ -431,13 +444,14 @@ def get_realm( r"""Gets details of a single realm. Args: - request (:class:`~.realms.GetRealmRequest`): + request (google.cloud.gaming_v1beta.types.GetRealmRequest): The request object. Request message for RealmsService.GetRealm. - name (:class:`str`): + name (str): Required. The name of the realm to retrieve. Uses the form: ``projects/{project}/locations/{location}/realms/{realm}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -449,7 +463,7 @@ def get_realm( sent along with the request as metadata. Returns: - ~.realms.Realm: + google.cloud.gaming_v1beta.types.Realm: A realm resource. """ # Create or coerce a protobuf request object. @@ -505,24 +519,27 @@ def create_realm( r"""Creates a new realm in a given project and location. Args: - request (:class:`~.realms.CreateRealmRequest`): + request (google.cloud.gaming_v1beta.types.CreateRealmRequest): The request object. Request message for RealmsService.CreateRealm. - parent (:class:`str`): + parent (str): Required. The parent resource name. Uses the form: ``projects/{project}/locations/{location}``. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - realm (:class:`~.realms.Realm`): + realm (google.cloud.gaming_v1beta.types.Realm): Required. The realm resource to be created. + This corresponds to the ``realm`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - realm_id (:class:`str`): + realm_id (str): Required. The ID of the realm resource to be created. + This corresponds to the ``realm_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -534,11 +551,12 @@ def create_realm( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.realms.Realm``: A realm resource. + :class:`google.cloud.gaming_v1beta.types.Realm` A realm + resource. """ # Create or coerce a protobuf request object. @@ -604,13 +622,14 @@ def delete_realm( r"""Deletes a single realm. Args: - request (:class:`~.realms.DeleteRealmRequest`): + request (google.cloud.gaming_v1beta.types.DeleteRealmRequest): The request object. Request message for RealmsService.DeleteRealm. - name (:class:`str`): + name (str): Required. The name of the realm to delete. Uses the form: ``projects/{project}/locations/{location}/realms/{realm}``. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -622,24 +641,22 @@ def delete_realm( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:``~.empty.Empty``: A generic empty message that - you can re-use to avoid defining duplicated empty - messages in your APIs. A typical example is to use it as - the request or the response type of an API method. For - instance: + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: - :: + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); - service Foo { - rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); - } + } - The JSON representation for ``Empty`` is empty JSON - object ``{}``. + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. @@ -702,21 +719,23 @@ def update_realm( r"""Patches a single realm. Args: - request (:class:`~.realms.UpdateRealmRequest`): + request (google.cloud.gaming_v1beta.types.UpdateRealmRequest): The request object. Request message for RealmsService.UpdateRealm. - realm (:class:`~.realms.Realm`): + realm (google.cloud.gaming_v1beta.types.Realm): Required. The realm to be updated. Only fields specified in update_mask are updated. + This corresponds to the ``realm`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -728,11 +747,12 @@ def update_realm( sent along with the request as metadata. Returns: - ~.operation.Operation: + google.api_core.operation.Operation: An object representing a long-running operation. The result type for the operation will be - :class:``~.realms.Realm``: A realm resource. + :class:`google.cloud.gaming_v1beta.types.Realm` A realm + resource. """ # Create or coerce a protobuf request object. @@ -797,7 +817,7 @@ def preview_realm_update( r"""Previews patches to a single realm. Args: - request (:class:`~.realms.PreviewRealmUpdateRequest`): + request (google.cloud.gaming_v1beta.types.PreviewRealmUpdateRequest): The request object. Request message for RealmsService.PreviewRealmUpdate. @@ -808,7 +828,7 @@ def preview_realm_update( sent along with the request as metadata. Returns: - ~.realms.PreviewRealmUpdateResponse: + google.cloud.gaming_v1beta.types.PreviewRealmUpdateResponse: Response message for RealmsService.PreviewRealmUpdate. diff --git a/google/cloud/gaming_v1beta/services/realms_service/pagers.py b/google/cloud/gaming_v1beta/services/realms_service/pagers.py index e3ab4306..7c013ccb 100644 --- a/google/cloud/gaming_v1beta/services/realms_service/pagers.py +++ b/google/cloud/gaming_v1beta/services/realms_service/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.gaming_v1beta.types import realms @@ -24,7 +33,7 @@ class ListRealmsPager: """A pager for iterating through ``list_realms`` requests. This class thinly wraps an initial - :class:`~.realms.ListRealmsResponse` object, and + :class:`google.cloud.gaming_v1beta.types.ListRealmsResponse` object, and provides an ``__iter__`` method to iterate through its ``realms`` field. @@ -33,7 +42,7 @@ class ListRealmsPager: through the ``realms`` field on the corresponding responses. - All the usual :class:`~.realms.ListRealmsResponse` + All the usual :class:`google.cloud.gaming_v1beta.types.ListRealmsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -51,9 +60,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.realms.ListRealmsRequest`): + request (google.cloud.gaming_v1beta.types.ListRealmsRequest): The initial request object. - response (:class:`~.realms.ListRealmsResponse`): + response (google.cloud.gaming_v1beta.types.ListRealmsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -86,7 +95,7 @@ class ListRealmsAsyncPager: """A pager for iterating through ``list_realms`` requests. This class thinly wraps an initial - :class:`~.realms.ListRealmsResponse` object, and + :class:`google.cloud.gaming_v1beta.types.ListRealmsResponse` object, and provides an ``__aiter__`` method to iterate through its ``realms`` field. @@ -95,7 +104,7 @@ class ListRealmsAsyncPager: through the ``realms`` field on the corresponding responses. - All the usual :class:`~.realms.ListRealmsResponse` + All the usual :class:`google.cloud.gaming_v1beta.types.ListRealmsResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -113,9 +122,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.realms.ListRealmsRequest`): + request (google.cloud.gaming_v1beta.types.ListRealmsRequest): The initial request object. - response (:class:`~.realms.ListRealmsResponse`): + response (google.cloud.gaming_v1beta.types.ListRealmsResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/gaming_v1beta/services/realms_service/transports/base.py b/google/cloud/gaming_v1beta/services/realms_service/transports/base.py index ee7b7b69..f06c0c6b 100644 --- a/google/cloud/gaming_v1beta/services/realms_service/transports/base.py +++ b/google/cloud/gaming_v1beta/services/realms_service/transports/base.py @@ -71,10 +71,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -82,6 +82,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -91,20 +94,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -115,6 +115,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -126,6 +127,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, @@ -146,6 +148,7 @@ def _prep_wrapped_messages(self, client_info): maximum=10.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=60.0, ), default_timeout=60.0, client_info=client_info, diff --git a/google/cloud/gaming_v1beta/services/realms_service/transports/grpc.py b/google/cloud/gaming_v1beta/services/realms_service/transports/grpc.py index 9df29246..961a0a40 100644 --- a/google/cloud/gaming_v1beta/services/realms_service/transports/grpc.py +++ b/google/cloud/gaming_v1beta/services/realms_service/transports/grpc.py @@ -60,6 +60,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -90,6 +91,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -104,72 +109,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -177,18 +171,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -202,7 +186,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/google/cloud/gaming_v1beta/services/realms_service/transports/grpc_asyncio.py b/google/cloud/gaming_v1beta/services/realms_service/transports/grpc_asyncio.py index 9a4c381d..8125ce12 100644 --- a/google/cloud/gaming_v1beta/services/realms_service/transports/grpc_asyncio.py +++ b/google/cloud/gaming_v1beta/services/realms_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -104,6 +104,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -135,12 +136,16 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -149,72 +154,61 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) else: - ssl_credentials = SslCredentials().ssl_credentials + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials - else: - host = host if ":" in host else host + ":443" - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -222,18 +216,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/google/cloud/gaming_v1beta/types/__init__.py b/google/cloud/gaming_v1beta/types/__init__.py index ebfd8342..0f6f0c03 100644 --- a/google/cloud/gaming_v1beta/types/__init__.py +++ b/google/cloud/gaming_v1beta/types/__init__.py @@ -16,127 +16,127 @@ # from .common import ( + DeployedFleetDetails, + LabelSelector, OperationMetadata, OperationStatus, - LabelSelector, RealmSelector, Schedule, SpecSource, TargetDetails, TargetState, - DeployedFleetDetails, ) from .game_server_clusters import ( + CreateGameServerClusterRequest, + DeleteGameServerClusterRequest, + GameServerCluster, + GameServerClusterConnectionInfo, + GetGameServerClusterRequest, + GkeClusterReference, ListGameServerClustersRequest, ListGameServerClustersResponse, - GetGameServerClusterRequest, - CreateGameServerClusterRequest, PreviewCreateGameServerClusterRequest, PreviewCreateGameServerClusterResponse, - DeleteGameServerClusterRequest, PreviewDeleteGameServerClusterRequest, PreviewDeleteGameServerClusterResponse, - UpdateGameServerClusterRequest, PreviewUpdateGameServerClusterRequest, PreviewUpdateGameServerClusterResponse, - GameServerClusterConnectionInfo, - GkeClusterReference, - GameServerCluster, + UpdateGameServerClusterRequest, ) from .game_server_configs import ( - ListGameServerConfigsRequest, - ListGameServerConfigsResponse, - GetGameServerConfigRequest, CreateGameServerConfigRequest, DeleteGameServerConfigRequest, - ScalingConfig, FleetConfig, GameServerConfig, + GetGameServerConfigRequest, + ListGameServerConfigsRequest, + ListGameServerConfigsResponse, + ScalingConfig, ) from .game_server_deployments import ( - ListGameServerDeploymentsRequest, - ListGameServerDeploymentsResponse, - GetGameServerDeploymentRequest, - GetGameServerDeploymentRolloutRequest, CreateGameServerDeploymentRequest, DeleteGameServerDeploymentRequest, - UpdateGameServerDeploymentRequest, - UpdateGameServerDeploymentRolloutRequest, FetchDeploymentStateRequest, FetchDeploymentStateResponse, - GameServerDeployment, GameServerConfigOverride, + GameServerDeployment, GameServerDeploymentRollout, + GetGameServerDeploymentRequest, + GetGameServerDeploymentRolloutRequest, + ListGameServerDeploymentsRequest, + ListGameServerDeploymentsResponse, PreviewGameServerDeploymentRolloutRequest, PreviewGameServerDeploymentRolloutResponse, + UpdateGameServerDeploymentRequest, + UpdateGameServerDeploymentRolloutRequest, ) from .realms import ( - ListRealmsRequest, - ListRealmsResponse, - GetRealmRequest, CreateRealmRequest, DeleteRealmRequest, - UpdateRealmRequest, + GetRealmRequest, + ListRealmsRequest, + ListRealmsResponse, PreviewRealmUpdateRequest, PreviewRealmUpdateResponse, Realm, + UpdateRealmRequest, ) __all__ = ( + "DeployedFleetDetails", + "LabelSelector", "OperationMetadata", "OperationStatus", - "LabelSelector", "RealmSelector", "Schedule", "SpecSource", "TargetDetails", "TargetState", - "DeployedFleetDetails", + "CreateGameServerClusterRequest", + "DeleteGameServerClusterRequest", + "GameServerCluster", + "GameServerClusterConnectionInfo", + "GetGameServerClusterRequest", + "GkeClusterReference", "ListGameServerClustersRequest", "ListGameServerClustersResponse", - "GetGameServerClusterRequest", - "CreateGameServerClusterRequest", "PreviewCreateGameServerClusterRequest", "PreviewCreateGameServerClusterResponse", - "DeleteGameServerClusterRequest", "PreviewDeleteGameServerClusterRequest", "PreviewDeleteGameServerClusterResponse", - "UpdateGameServerClusterRequest", "PreviewUpdateGameServerClusterRequest", "PreviewUpdateGameServerClusterResponse", - "GameServerClusterConnectionInfo", - "GkeClusterReference", - "GameServerCluster", - "ListGameServerConfigsRequest", - "ListGameServerConfigsResponse", - "GetGameServerConfigRequest", + "UpdateGameServerClusterRequest", "CreateGameServerConfigRequest", "DeleteGameServerConfigRequest", - "ScalingConfig", "FleetConfig", "GameServerConfig", - "ListGameServerDeploymentsRequest", - "ListGameServerDeploymentsResponse", - "GetGameServerDeploymentRequest", - "GetGameServerDeploymentRolloutRequest", + "GetGameServerConfigRequest", + "ListGameServerConfigsRequest", + "ListGameServerConfigsResponse", + "ScalingConfig", "CreateGameServerDeploymentRequest", "DeleteGameServerDeploymentRequest", - "UpdateGameServerDeploymentRequest", - "UpdateGameServerDeploymentRolloutRequest", "FetchDeploymentStateRequest", "FetchDeploymentStateResponse", - "GameServerDeployment", "GameServerConfigOverride", + "GameServerDeployment", "GameServerDeploymentRollout", + "GetGameServerDeploymentRequest", + "GetGameServerDeploymentRolloutRequest", + "ListGameServerDeploymentsRequest", + "ListGameServerDeploymentsResponse", "PreviewGameServerDeploymentRolloutRequest", "PreviewGameServerDeploymentRolloutResponse", - "ListRealmsRequest", - "ListRealmsResponse", - "GetRealmRequest", + "UpdateGameServerDeploymentRequest", + "UpdateGameServerDeploymentRolloutRequest", "CreateRealmRequest", "DeleteRealmRequest", - "UpdateRealmRequest", + "GetRealmRequest", + "ListRealmsRequest", + "ListRealmsResponse", "PreviewRealmUpdateRequest", "PreviewRealmUpdateResponse", "Realm", + "UpdateRealmRequest", ) diff --git a/google/cloud/gaming_v1beta/types/common.py b/google/cloud/gaming_v1beta/types/common.py index 3efaba32..5048c996 100644 --- a/google/cloud/gaming_v1beta/types/common.py +++ b/google/cloud/gaming_v1beta/types/common.py @@ -42,10 +42,10 @@ class OperationMetadata(proto.Message): r"""Represents the metadata of the long-running operation. Attributes: - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time the operation was created. - end_time (~.timestamp.Timestamp): + end_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time the operation finished running. target (str): @@ -69,7 +69,7 @@ class OperationMetadata(proto.Message): unreachable (Sequence[str]): Output only. List of Locations that could not be reached. - operation_status (Sequence[~.common.OperationMetadata.OperationStatusEntry]): + operation_status (Sequence[google.cloud.gaming_v1beta.types.OperationMetadata.OperationStatusEntry]): Output only. Operation status for Game Services API operations. Operation status is in the form of key-value pairs where keys are @@ -106,7 +106,7 @@ class OperationStatus(proto.Message): done (bool): Output only. Whether the operation is done or still in progress. - error_code (~.common.OperationStatus.ErrorCode): + error_code (google.cloud.gaming_v1beta.types.OperationStatus.ErrorCode): The error code in case of failures. error_message (str): The human-readable error message. @@ -130,7 +130,7 @@ class LabelSelector(proto.Message): r"""The label selector, used to group labels on the resources. Attributes: - labels (Sequence[~.common.LabelSelector.LabelsEntry]): + labels (Sequence[google.cloud.gaming_v1beta.types.LabelSelector.LabelsEntry]): Resource labels for this selector. """ @@ -163,11 +163,11 @@ class Schedule(proto.Message): Attributes: - start_time (~.timestamp.Timestamp): + start_time (google.protobuf.timestamp_pb2.Timestamp): The start time of the event. - end_time (~.timestamp.Timestamp): + end_time (google.protobuf.timestamp_pb2.Timestamp): The end time of the event. - cron_job_duration (~.duration.Duration): + cron_job_duration (google.protobuf.duration_pb2.Duration): The duration for the cron job event. The duration of the event is effective after the cron job's start time. @@ -219,7 +219,7 @@ class TargetDetails(proto.Message): The game server deployment name. Uses the form: ``projects/{project}/locations/{location}/gameServerDeployments/{deployment_id}``. - fleet_details (Sequence[~.common.TargetDetails.TargetFleetDetails]): + fleet_details (Sequence[google.cloud.gaming_v1beta.types.TargetDetails.TargetFleetDetails]): Agones fleet details for game server clusters and game server deployments. """ @@ -228,9 +228,9 @@ class TargetFleetDetails(proto.Message): r"""Details of the target Agones fleet. Attributes: - fleet (~.common.TargetDetails.TargetFleetDetails.TargetFleet): + fleet (google.cloud.gaming_v1beta.types.TargetDetails.TargetFleetDetails.TargetFleet): Reference to target Agones fleet. - autoscaler (~.common.TargetDetails.TargetFleetDetails.TargetFleetAutoscaler): + autoscaler (google.cloud.gaming_v1beta.types.TargetDetails.TargetFleetDetails.TargetFleetAutoscaler): Reference to target Agones fleet autoscaling policy. """ @@ -241,7 +241,7 @@ class TargetFleet(proto.Message): Attributes: name (str): The name of the Agones fleet. - spec_source (~.common.SpecSource): + spec_source (google.cloud.gaming_v1beta.types.SpecSource): Encapsulates the source of the Agones fleet spec. The Agones fleet spec source. """ @@ -256,7 +256,7 @@ class TargetFleetAutoscaler(proto.Message): Attributes: name (str): The name of the Agones autoscaler. - spec_source (~.common.SpecSource): + spec_source (google.cloud.gaming_v1beta.types.SpecSource): Encapsulates the source of the Agones fleet spec. Details about the Agones autoscaler spec. """ @@ -290,7 +290,7 @@ class TargetState(proto.Message): r"""Encapsulates the Target state. Attributes: - details (Sequence[~.common.TargetDetails]): + details (Sequence[google.cloud.gaming_v1beta.types.TargetDetails]): Details about Agones fleets. """ @@ -301,9 +301,9 @@ class DeployedFleetDetails(proto.Message): r"""Details of the deployed Agones fleet. Attributes: - deployed_fleet (~.common.DeployedFleetDetails.DeployedFleet): + deployed_fleet (google.cloud.gaming_v1beta.types.DeployedFleetDetails.DeployedFleet): Information about the Agones fleet. - deployed_autoscaler (~.common.DeployedFleetDetails.DeployedFleetAutoscaler): + deployed_autoscaler (google.cloud.gaming_v1beta.types.DeployedFleetDetails.DeployedFleetAutoscaler): Information about the Agones autoscaler for that fleet. """ @@ -317,11 +317,11 @@ class DeployedFleet(proto.Message): fleet_spec (str): The fleet spec retrieved from the Agones fleet. - spec_source (~.common.SpecSource): + spec_source (google.cloud.gaming_v1beta.types.SpecSource): The source spec that is used to create the Agones fleet. The GameServerConfig resource may no longer exist in the system. - status (~.common.DeployedFleetDetails.DeployedFleet.DeployedFleetStatus): + status (google.cloud.gaming_v1beta.types.DeployedFleetDetails.DeployedFleet.DeployedFleetStatus): The current status of the Agones fleet. Includes count of game servers in various states. @@ -374,7 +374,7 @@ class DeployedFleetAutoscaler(proto.Message): Attributes: autoscaler (str): The name of the Agones autoscaler. - spec_source (~.common.SpecSource): + spec_source (google.cloud.gaming_v1beta.types.SpecSource): The source spec that is used to create the autoscaler. The GameServerConfig resource may no longer exist in the system. diff --git a/google/cloud/gaming_v1beta/types/game_server_clusters.py b/google/cloud/gaming_v1beta/types/game_server_clusters.py index 5214f202..d7469000 100644 --- a/google/cloud/gaming_v1beta/types/game_server_clusters.py +++ b/google/cloud/gaming_v1beta/types/game_server_clusters.py @@ -90,7 +90,7 @@ class ListGameServerClustersResponse(proto.Message): GameServerClustersService.ListGameServerClusters. Attributes: - game_server_clusters (Sequence[~.gcg_game_server_clusters.GameServerCluster]): + game_server_clusters (Sequence[google.cloud.gaming_v1beta.types.GameServerCluster]): The list of game server clusters. next_page_token (str): Token to retrieve the next page of results, @@ -139,7 +139,7 @@ class CreateGameServerClusterRequest(proto.Message): game_server_cluster_id (str): Required. The ID of the game server cluster resource to be created. - game_server_cluster (~.gcg_game_server_clusters.GameServerCluster): + game_server_cluster (google.cloud.gaming_v1beta.types.GameServerCluster): Required. The game server cluster resource to be created. """ @@ -164,10 +164,10 @@ class PreviewCreateGameServerClusterRequest(proto.Message): game_server_cluster_id (str): Required. The ID of the game server cluster resource to be created. - game_server_cluster (~.gcg_game_server_clusters.GameServerCluster): + game_server_cluster (google.cloud.gaming_v1beta.types.GameServerCluster): Required. The game server cluster resource to be created. - preview_time (~.timestamp.Timestamp): + preview_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The target timestamp to compute the preview. """ @@ -190,7 +190,7 @@ class PreviewCreateGameServerClusterResponse(proto.Message): Attributes: etag (str): The ETag of the game server cluster. - target_state (~.common.TargetState): + target_state (google.cloud.gaming_v1beta.types.TargetState): The target state. """ @@ -222,7 +222,7 @@ class PreviewDeleteGameServerClusterRequest(proto.Message): Required. The name of the game server cluster to delete. Uses the form: ``projects/{project}/locations/{location}/gameServerClusters/{cluster}``. - preview_time (~.timestamp.Timestamp): + preview_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The target timestamp to compute the preview. """ @@ -239,7 +239,7 @@ class PreviewDeleteGameServerClusterResponse(proto.Message): Attributes: etag (str): The ETag of the game server cluster. - target_state (~.common.TargetState): + target_state (google.cloud.gaming_v1beta.types.TargetState): The target state. """ @@ -253,10 +253,10 @@ class UpdateGameServerClusterRequest(proto.Message): GameServerClustersService.UpdateGameServerCluster. Attributes: - game_server_cluster (~.gcg_game_server_clusters.GameServerCluster): + game_server_cluster (google.cloud.gaming_v1beta.types.GameServerCluster): Required. The game server cluster to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see @@ -277,17 +277,17 @@ class PreviewUpdateGameServerClusterRequest(proto.Message): GameServerClustersService.UpdateGameServerCluster. Attributes: - game_server_cluster (~.gcg_game_server_clusters.GameServerCluster): + game_server_cluster (google.cloud.gaming_v1beta.types.GameServerCluster): Required. The game server cluster to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask - preview_time (~.timestamp.Timestamp): + preview_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The target timestamp to compute the preview. """ @@ -308,7 +308,7 @@ class PreviewUpdateGameServerClusterResponse(proto.Message): Attributes: etag (str): The ETag of the game server cluster. - target_state (~.common.TargetState): + target_state (google.cloud.gaming_v1beta.types.TargetState): The target state. """ @@ -321,7 +321,7 @@ class GameServerClusterConnectionInfo(proto.Message): r"""The game server cluster connection information. Attributes: - gke_cluster_reference (~.gcg_game_server_clusters.GkeClusterReference): + gke_cluster_reference (google.cloud.gaming_v1beta.types.GkeClusterReference): Reference to the GKE cluster where the game servers are installed. namespace (str): @@ -372,14 +372,14 @@ class GameServerCluster(proto.Message): For example, ``projects/my-project/locations/{location}/realms/zanzibar/gameServerClusters/my-onprem-cluster``. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation time. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last-modified time. - labels (Sequence[~.gcg_game_server_clusters.GameServerCluster.LabelsEntry]): + labels (Sequence[google.cloud.gaming_v1beta.types.GameServerCluster.LabelsEntry]): The labels associated with this game server cluster. Each label is a key-value pair. - connection_info (~.gcg_game_server_clusters.GameServerClusterConnectionInfo): + connection_info (google.cloud.gaming_v1beta.types.GameServerClusterConnectionInfo): The game server cluster connection information. This information is used to manage game server clusters. diff --git a/google/cloud/gaming_v1beta/types/game_server_configs.py b/google/cloud/gaming_v1beta/types/game_server_configs.py index dabb462d..5745f2df 100644 --- a/google/cloud/gaming_v1beta/types/game_server_configs.py +++ b/google/cloud/gaming_v1beta/types/game_server_configs.py @@ -82,7 +82,7 @@ class ListGameServerConfigsResponse(proto.Message): GameServerConfigsService.ListGameServerConfigs. Attributes: - game_server_configs (Sequence[~.gcg_game_server_configs.GameServerConfig]): + game_server_configs (Sequence[google.cloud.gaming_v1beta.types.GameServerConfig]): The list of game server configs. next_page_token (str): Token to retrieve the next page of results, @@ -132,7 +132,7 @@ class CreateGameServerConfigRequest(proto.Message): config_id (str): Required. The ID of the game server config resource to be created. - game_server_config (~.gcg_game_server_configs.GameServerConfig): + game_server_config (google.cloud.gaming_v1beta.types.GameServerConfig): Required. The game server config resource to be created. """ @@ -171,13 +171,13 @@ class ScalingConfig(proto.Message): Required. Agones fleet autoscaler spec. Example spec: https://agones.dev/site/docs/reference/fleetautoscaler/ - selectors (Sequence[~.common.LabelSelector]): + selectors (Sequence[google.cloud.gaming_v1beta.types.LabelSelector]): Labels used to identify the game server clusters to which this Agones scaling config applies. A game server cluster is subject to this Agones scaling config if its labels match any of the selector entries. - schedules (Sequence[~.common.Schedule]): + schedules (Sequence[google.cloud.gaming_v1beta.types.Schedule]): The schedules to which this Scaling Config applies. """ @@ -220,17 +220,17 @@ class GameServerConfig(proto.Message): For example, ``projects/my-project/locations/global/gameServerDeployments/my-game/configs/my-config``. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation time. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last-modified time. - labels (Sequence[~.gcg_game_server_configs.GameServerConfig.LabelsEntry]): + labels (Sequence[google.cloud.gaming_v1beta.types.GameServerConfig.LabelsEntry]): The labels associated with this game server config. Each label is a key-value pair. - fleet_configs (Sequence[~.gcg_game_server_configs.FleetConfig]): + fleet_configs (Sequence[google.cloud.gaming_v1beta.types.FleetConfig]): FleetConfig contains a list of Agones fleet specs. Only one FleetConfig is allowed. - scaling_configs (Sequence[~.gcg_game_server_configs.ScalingConfig]): + scaling_configs (Sequence[google.cloud.gaming_v1beta.types.ScalingConfig]): The autoscaling settings. description (str): The description of the game server config. diff --git a/google/cloud/gaming_v1beta/types/game_server_deployments.py b/google/cloud/gaming_v1beta/types/game_server_deployments.py index dfae4b88..344da5f5 100644 --- a/google/cloud/gaming_v1beta/types/game_server_deployments.py +++ b/google/cloud/gaming_v1beta/types/game_server_deployments.py @@ -89,7 +89,7 @@ class ListGameServerDeploymentsResponse(proto.Message): GameServerDeploymentsService.ListGameServerDeployments. Attributes: - game_server_deployments (Sequence[~.gcg_game_server_deployments.GameServerDeployment]): + game_server_deployments (Sequence[google.cloud.gaming_v1beta.types.GameServerDeployment]): The list of game server deployments. next_page_token (str): Token to retrieve the next page of results, @@ -153,7 +153,7 @@ class CreateGameServerDeploymentRequest(proto.Message): deployment_id (str): Required. The ID of the game server delpoyment resource to be created. - game_server_deployment (~.gcg_game_server_deployments.GameServerDeployment): + game_server_deployment (google.cloud.gaming_v1beta.types.GameServerDeployment): Required. The game server delpoyment resource to be created. """ @@ -188,10 +188,10 @@ class UpdateGameServerDeploymentRequest(proto.Message): allows updates for labels. Attributes: - game_server_deployment (~.gcg_game_server_deployments.GameServerDeployment): + game_server_deployment (google.cloud.gaming_v1beta.types.GameServerDeployment): Required. The game server delpoyment to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see @@ -212,10 +212,10 @@ class UpdateGameServerDeploymentRolloutRequest(proto.Message): GameServerDeploymentsService.UpdateGameServerRolloutDeployment. Attributes: - rollout (~.gcg_game_server_deployments.GameServerDeploymentRollout): + rollout (google.cloud.gaming_v1beta.types.GameServerDeploymentRollout): Required. The game server delpoyment rollout to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see @@ -251,7 +251,7 @@ class FetchDeploymentStateResponse(proto.Message): GameServerDeploymentsService.FetchDeploymentState. Attributes: - cluster_state (Sequence[~.gcg_game_server_deployments.FetchDeploymentStateResponse.DeployedClusterState]): + cluster_state (Sequence[google.cloud.gaming_v1beta.types.FetchDeploymentStateResponse.DeployedClusterState]): The state of the game server deployment in each game server cluster. unavailable (Sequence[str]): @@ -265,7 +265,7 @@ class DeployedClusterState(proto.Message): Attributes: cluster (str): The name of the cluster. - fleet_details (Sequence[~.common.DeployedFleetDetails]): + fleet_details (Sequence[google.cloud.gaming_v1beta.types.DeployedFleetDetails]): The details about the Agones fleets and autoscalers created in the game server cluster. """ @@ -295,11 +295,11 @@ class GameServerDeployment(proto.Message): For example, ``projects/my-project/locations/{location}/gameServerDeployments/my-deployment``. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation time. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last-modified time. - labels (Sequence[~.gcg_game_server_deployments.GameServerDeployment.LabelsEntry]): + labels (Sequence[google.cloud.gaming_v1beta.types.GameServerDeployment.LabelsEntry]): The labels associated with this game server deployment. Each label is a key-value pair. etag (str): @@ -326,7 +326,7 @@ class GameServerConfigOverride(proto.Message): r"""A game server config override. Attributes: - realms_selector (~.common.RealmSelector): + realms_selector (google.cloud.gaming_v1beta.types.RealmSelector): Selector for choosing applicable realms. config_version (str): The game server config for this override. @@ -352,16 +352,16 @@ class GameServerDeploymentRollout(proto.Message): For example, ``projects/my-project/locations/{location}/gameServerDeployments/my-deployment/rollout``. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation time. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last-modified time. default_game_server_config (str): The default game server config is applied to all realms unless overridden in the rollout. For example, ``projects/my-project/locations/global/gameServerDeployments/my-game/configs/my-config``. - game_server_config_overrides (Sequence[~.gcg_game_server_deployments.GameServerConfigOverride]): + game_server_config_overrides (Sequence[google.cloud.gaming_v1beta.types.GameServerConfigOverride]): Contains the game server config rollout overrides. Overrides are processed in the order they are listed. Once a match is found for a @@ -389,17 +389,17 @@ class PreviewGameServerDeploymentRolloutRequest(proto.Message): r"""Request message for PreviewGameServerDeploymentRollout. Attributes: - rollout (~.gcg_game_server_deployments.GameServerDeploymentRollout): + rollout (google.cloud.gaming_v1beta.types.GameServerDeploymentRollout): Required. The game server deployment rollout to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Optional. Mask of fields to update. At least one path must be supplied in this field. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask - preview_time (~.timestamp.Timestamp): + preview_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The target timestamp to compute the preview. Defaults to the immediately after the proposed rollout completes. @@ -425,7 +425,7 @@ class PreviewGameServerDeploymentRolloutResponse(proto.Message): request. etag (str): ETag of the game server deployment. - target_state (~.common.TargetState): + target_state (google.cloud.gaming_v1beta.types.TargetState): The target state. """ diff --git a/google/cloud/gaming_v1beta/types/realms.py b/google/cloud/gaming_v1beta/types/realms.py index 56884286..57f32069 100644 --- a/google/cloud/gaming_v1beta/types/realms.py +++ b/google/cloud/gaming_v1beta/types/realms.py @@ -80,7 +80,7 @@ class ListRealmsResponse(proto.Message): r"""Response message for RealmsService.ListRealms. Attributes: - realms (Sequence[~.gcg_realms.Realm]): + realms (Sequence[google.cloud.gaming_v1beta.types.Realm]): The list of realms. next_page_token (str): Token to retrieve the next page of results, @@ -123,7 +123,7 @@ class CreateRealmRequest(proto.Message): realm_id (str): Required. The ID of the realm resource to be created. - realm (~.gcg_realms.Realm): + realm (google.cloud.gaming_v1beta.types.Realm): Required. The realm resource to be created. """ @@ -150,10 +150,10 @@ class UpdateRealmRequest(proto.Message): r"""Request message for RealmsService.UpdateRealm. Attributes: - realm (~.gcg_realms.Realm): + realm (google.cloud.gaming_v1beta.types.Realm): Required. The realm to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see @@ -170,16 +170,16 @@ class PreviewRealmUpdateRequest(proto.Message): r"""Request message for RealmsService.PreviewRealmUpdate. Attributes: - realm (~.gcg_realms.Realm): + realm (google.cloud.gaming_v1beta.types.Realm): Required. The realm to be updated. Only fields specified in update_mask are updated. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see https: //developers.google.com/protocol-buffers // /docs/reference/google.protobuf#fieldmask - preview_time (~.timestamp.Timestamp): + preview_time (google.protobuf.timestamp_pb2.Timestamp): Optional. The target timestamp to compute the preview. """ @@ -197,7 +197,7 @@ class PreviewRealmUpdateResponse(proto.Message): Attributes: etag (str): ETag of the realm. - target_state (~.common.TargetState): + target_state (google.cloud.gaming_v1beta.types.TargetState): The target state. """ @@ -215,11 +215,11 @@ class Realm(proto.Message): ``projects/{project}/locations/{location}/realms/{realm}``. For example, ``projects/my-project/locations/{location}/realms/my-realm``. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The creation time. - update_time (~.timestamp.Timestamp): + update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last-modified time. - labels (Sequence[~.gcg_realms.Realm.LabelsEntry]): + labels (Sequence[google.cloud.gaming_v1beta.types.Realm.LabelsEntry]): The labels associated with this realm. Each label is a key-value pair. time_zone (str): diff --git a/noxfile.py b/noxfile.py index a57e24be..af50a606 100644 --- a/noxfile.py +++ b/noxfile.py @@ -18,6 +18,7 @@ from __future__ import absolute_import import os +import pathlib import shutil import nox @@ -30,6 +31,22 @@ SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + +# 'docfx' is excluded since it only needs to run in 'docs-presubmit' +nox.options.sessions = [ + "unit", + "system", + "cover", + "lint", + "lint_setup_py", + "blacken", + "docs", +] + +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + @nox.session(python=DEFAULT_PYTHON_VERSION) def lint(session): @@ -70,17 +87,21 @@ def lint_setup_py(session): def default(session): # Install all test dependencies, then install this package in-place. - session.install("asyncmock", "pytest-asyncio") - session.install( - "mock", "pytest", "pytest-cov", + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) - session.install("-e", ".") + session.install("asyncmock", "pytest-asyncio", "-c", constraints_path) + + session.install("mock", "pytest", "pytest-cov", "-c", constraints_path) + + session.install("-e", ".", "-c", constraints_path) # Run py.test against the unit tests. session.run( "py.test", "--quiet", + f"--junitxml=unit_{session.python}_sponge_log.xml", "--cov=google/cloud", "--cov=tests/unit", "--cov-append", @@ -101,6 +122,9 @@ def unit(session): @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def system(session): """Run the system test suite.""" + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) system_test_path = os.path.join("tests", "system.py") system_test_folder_path = os.path.join("tests", "system") @@ -110,6 +134,9 @@ def system(session): # Sanity check: Only run tests if the environment variable is set. if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""): session.skip("Credentials must be set via environment variable") + # Install pyopenssl for mTLS testing. + if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": + session.install("pyopenssl") system_test_exists = os.path.exists(system_test_path) system_test_folder_exists = os.path.exists(system_test_folder_path) @@ -122,16 +149,26 @@ def system(session): # Install all test dependencies, then install this package into the # virtualenv's dist-packages. - session.install( - "mock", "pytest", "google-cloud-testutils", - ) - session.install("-e", ".") + session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path) + session.install("-e", ".", "-c", constraints_path) # Run py.test against the system tests. if system_test_exists: - session.run("py.test", "--quiet", system_test_path, *session.posargs) + session.run( + "py.test", + "--quiet", + f"--junitxml=system_{session.python}_sponge_log.xml", + system_test_path, + *session.posargs, + ) if system_test_folder_exists: - session.run("py.test", "--quiet", system_test_folder_path, *session.posargs) + session.run( + "py.test", + "--quiet", + f"--junitxml=system_{session.python}_sponge_log.xml", + system_test_folder_path, + *session.posargs, + ) @nox.session(python=DEFAULT_PYTHON_VERSION) @@ -174,9 +211,7 @@ def docfx(session): """Build the docfx yaml files for this library.""" session.install("-e", ".") - # sphinx-docfx-yaml supports up to sphinx version 1.5.5. - # https://github.com/docascode/sphinx-docfx-yaml/issues/97 - session.install("sphinx==1.5.5", "alabaster", "recommonmark", "sphinx-docfx-yaml") + session.install("sphinx", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml") shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( diff --git a/renovate.json b/renovate.json index 4fa94931..f08bc22c 100644 --- a/renovate.json +++ b/renovate.json @@ -1,5 +1,6 @@ { "extends": [ "config:base", ":preserveSemverRanges" - ] + ], + "ignorePaths": [".pre-commit-config.yaml"] } diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index bca0522e..97bf7da8 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -85,7 +85,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] diff --git a/setup.py b/setup.py index 7a6f0f1b..fb48a162 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,6 @@ include_package_data=True, install_requires=( "google-api-core[grpc] >= 1.22.2, < 2.0.0dev", - "googleapis-common-protos >= 1.5.8", "proto-plus >= 1.4.0", ), python_requires=">=3.6", diff --git a/synth.metadata b/synth.metadata index 574f488b..320fbf2e 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,30 +3,30 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-game-servers.git", - "sha": "a2f4992addb34bed9b9f7b366e8d8a90b86259a8" + "remote": "git@github.com:googleapis/python-game-servers", + "sha": "dee0992f989cc356cc4a741aeec0e7c2373e471f" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "69697504d9eba1d064820c3085b4750767be6d08", - "internalRef": "348952930" + "sha": "915925089600094e72e4bfa8cf586c170e6b7109", + "internalRef": "366152684" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "41a4e56982620d3edcf110d76f4fcdfdec471ac8" + "sha": "6d76df2138f8f841e5a5b9ac427f81def520c15f" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "41a4e56982620d3edcf110d76f4fcdfdec471ac8" + "sha": "6d76df2138f8f841e5a5b9ac427f81def520c15f" } } ], @@ -49,181 +49,5 @@ "generator": "bazel" } } - ], - "generatedFiles": [ - ".flake8", - ".github/CONTRIBUTING.md", - ".github/ISSUE_TEMPLATE/bug_report.md", - ".github/ISSUE_TEMPLATE/feature_request.md", - ".github/ISSUE_TEMPLATE/support_request.md", - ".github/PULL_REQUEST_TEMPLATE.md", - ".github/release-please.yml", - ".github/snippet-bot.yml", - ".gitignore", - ".kokoro/build.sh", - ".kokoro/continuous/common.cfg", - ".kokoro/continuous/continuous.cfg", - ".kokoro/docker/docs/Dockerfile", - ".kokoro/docker/docs/fetch_gpg_keys.sh", - ".kokoro/docs/common.cfg", - ".kokoro/docs/docs-presubmit.cfg", - ".kokoro/docs/docs.cfg", - ".kokoro/populate-secrets.sh", - ".kokoro/presubmit/common.cfg", - ".kokoro/presubmit/presubmit.cfg", - ".kokoro/publish-docs.sh", - ".kokoro/release.sh", - ".kokoro/release/common.cfg", - ".kokoro/release/release.cfg", - ".kokoro/samples/lint/common.cfg", - ".kokoro/samples/lint/continuous.cfg", - ".kokoro/samples/lint/periodic.cfg", - ".kokoro/samples/lint/presubmit.cfg", - ".kokoro/samples/python3.6/common.cfg", - ".kokoro/samples/python3.6/continuous.cfg", - ".kokoro/samples/python3.6/periodic.cfg", - ".kokoro/samples/python3.6/presubmit.cfg", - ".kokoro/samples/python3.7/common.cfg", - ".kokoro/samples/python3.7/continuous.cfg", - ".kokoro/samples/python3.7/periodic.cfg", - ".kokoro/samples/python3.7/presubmit.cfg", - ".kokoro/samples/python3.8/common.cfg", - ".kokoro/samples/python3.8/continuous.cfg", - ".kokoro/samples/python3.8/periodic.cfg", - ".kokoro/samples/python3.8/presubmit.cfg", - ".kokoro/test-samples.sh", - ".kokoro/trampoline.sh", - ".kokoro/trampoline_v2.sh", - ".pre-commit-config.yaml", - ".trampolinerc", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.rst", - "LICENSE", - "MANIFEST.in", - "docs/_static/custom.css", - "docs/_templates/layout.html", - "docs/conf.py", - "docs/gaming_v1/services.rst", - "docs/gaming_v1/types.rst", - "docs/gaming_v1beta/services.rst", - "docs/gaming_v1beta/types.rst", - "docs/multiprocessing.rst", - "google/cloud/gaming/__init__.py", - "google/cloud/gaming/py.typed", - "google/cloud/gaming_v1/__init__.py", - "google/cloud/gaming_v1/py.typed", - "google/cloud/gaming_v1/services/__init__.py", - "google/cloud/gaming_v1/services/game_server_clusters_service/__init__.py", - "google/cloud/gaming_v1/services/game_server_clusters_service/async_client.py", - "google/cloud/gaming_v1/services/game_server_clusters_service/client.py", - "google/cloud/gaming_v1/services/game_server_clusters_service/pagers.py", - "google/cloud/gaming_v1/services/game_server_clusters_service/transports/__init__.py", - "google/cloud/gaming_v1/services/game_server_clusters_service/transports/base.py", - "google/cloud/gaming_v1/services/game_server_clusters_service/transports/grpc.py", - "google/cloud/gaming_v1/services/game_server_clusters_service/transports/grpc_asyncio.py", - "google/cloud/gaming_v1/services/game_server_configs_service/__init__.py", - "google/cloud/gaming_v1/services/game_server_configs_service/async_client.py", - "google/cloud/gaming_v1/services/game_server_configs_service/client.py", - "google/cloud/gaming_v1/services/game_server_configs_service/pagers.py", - "google/cloud/gaming_v1/services/game_server_configs_service/transports/__init__.py", - "google/cloud/gaming_v1/services/game_server_configs_service/transports/base.py", - "google/cloud/gaming_v1/services/game_server_configs_service/transports/grpc.py", - "google/cloud/gaming_v1/services/game_server_configs_service/transports/grpc_asyncio.py", - "google/cloud/gaming_v1/services/game_server_deployments_service/__init__.py", - "google/cloud/gaming_v1/services/game_server_deployments_service/async_client.py", - "google/cloud/gaming_v1/services/game_server_deployments_service/client.py", - "google/cloud/gaming_v1/services/game_server_deployments_service/pagers.py", - "google/cloud/gaming_v1/services/game_server_deployments_service/transports/__init__.py", - "google/cloud/gaming_v1/services/game_server_deployments_service/transports/base.py", - "google/cloud/gaming_v1/services/game_server_deployments_service/transports/grpc.py", - "google/cloud/gaming_v1/services/game_server_deployments_service/transports/grpc_asyncio.py", - "google/cloud/gaming_v1/services/realms_service/__init__.py", - "google/cloud/gaming_v1/services/realms_service/async_client.py", - "google/cloud/gaming_v1/services/realms_service/client.py", - "google/cloud/gaming_v1/services/realms_service/pagers.py", - "google/cloud/gaming_v1/services/realms_service/transports/__init__.py", - "google/cloud/gaming_v1/services/realms_service/transports/base.py", - "google/cloud/gaming_v1/services/realms_service/transports/grpc.py", - "google/cloud/gaming_v1/services/realms_service/transports/grpc_asyncio.py", - "google/cloud/gaming_v1/types/__init__.py", - "google/cloud/gaming_v1/types/common.py", - "google/cloud/gaming_v1/types/game_server_clusters.py", - "google/cloud/gaming_v1/types/game_server_clusters_service.py", - "google/cloud/gaming_v1/types/game_server_configs.py", - "google/cloud/gaming_v1/types/game_server_configs_service.py", - "google/cloud/gaming_v1/types/game_server_deployments.py", - "google/cloud/gaming_v1/types/game_server_deployments_service.py", - "google/cloud/gaming_v1/types/realms.py", - "google/cloud/gaming_v1/types/realms_service.py", - "google/cloud/gaming_v1beta/__init__.py", - "google/cloud/gaming_v1beta/py.typed", - "google/cloud/gaming_v1beta/services/__init__.py", - "google/cloud/gaming_v1beta/services/game_server_clusters_service/__init__.py", - "google/cloud/gaming_v1beta/services/game_server_clusters_service/async_client.py", - "google/cloud/gaming_v1beta/services/game_server_clusters_service/client.py", - "google/cloud/gaming_v1beta/services/game_server_clusters_service/pagers.py", - "google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/__init__.py", - "google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/base.py", - "google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/grpc.py", - "google/cloud/gaming_v1beta/services/game_server_clusters_service/transports/grpc_asyncio.py", - "google/cloud/gaming_v1beta/services/game_server_configs_service/__init__.py", - "google/cloud/gaming_v1beta/services/game_server_configs_service/async_client.py", - "google/cloud/gaming_v1beta/services/game_server_configs_service/client.py", - "google/cloud/gaming_v1beta/services/game_server_configs_service/pagers.py", - "google/cloud/gaming_v1beta/services/game_server_configs_service/transports/__init__.py", - "google/cloud/gaming_v1beta/services/game_server_configs_service/transports/base.py", - "google/cloud/gaming_v1beta/services/game_server_configs_service/transports/grpc.py", - "google/cloud/gaming_v1beta/services/game_server_configs_service/transports/grpc_asyncio.py", - "google/cloud/gaming_v1beta/services/game_server_deployments_service/__init__.py", - "google/cloud/gaming_v1beta/services/game_server_deployments_service/async_client.py", - "google/cloud/gaming_v1beta/services/game_server_deployments_service/client.py", - "google/cloud/gaming_v1beta/services/game_server_deployments_service/pagers.py", - "google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/__init__.py", - "google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/base.py", - "google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/grpc.py", - "google/cloud/gaming_v1beta/services/game_server_deployments_service/transports/grpc_asyncio.py", - "google/cloud/gaming_v1beta/services/realms_service/__init__.py", - "google/cloud/gaming_v1beta/services/realms_service/async_client.py", - "google/cloud/gaming_v1beta/services/realms_service/client.py", - "google/cloud/gaming_v1beta/services/realms_service/pagers.py", - "google/cloud/gaming_v1beta/services/realms_service/transports/__init__.py", - "google/cloud/gaming_v1beta/services/realms_service/transports/base.py", - "google/cloud/gaming_v1beta/services/realms_service/transports/grpc.py", - "google/cloud/gaming_v1beta/services/realms_service/transports/grpc_asyncio.py", - "google/cloud/gaming_v1beta/types/__init__.py", - "google/cloud/gaming_v1beta/types/common.py", - "google/cloud/gaming_v1beta/types/game_server_clusters.py", - "google/cloud/gaming_v1beta/types/game_server_clusters_service.py", - "google/cloud/gaming_v1beta/types/game_server_configs.py", - "google/cloud/gaming_v1beta/types/game_server_configs_service.py", - "google/cloud/gaming_v1beta/types/game_server_deployments.py", - "google/cloud/gaming_v1beta/types/game_server_deployments_service.py", - "google/cloud/gaming_v1beta/types/realms.py", - "google/cloud/gaming_v1beta/types/realms_service.py", - "mypy.ini", - "noxfile.py", - "renovate.json", - "samples/snippets/noxfile.py", - "scripts/decrypt-secrets.sh", - "scripts/fixup_gaming_v1_keywords.py", - "scripts/fixup_gaming_v1beta_keywords.py", - "scripts/readme-gen/readme_gen.py", - "scripts/readme-gen/templates/README.tmpl.rst", - "scripts/readme-gen/templates/auth.tmpl.rst", - "scripts/readme-gen/templates/auth_api_key.tmpl.rst", - "scripts/readme-gen/templates/install_deps.tmpl.rst", - "scripts/readme-gen/templates/install_portaudio.tmpl.rst", - "setup.cfg", - "testing/.gitignore", - "tests/unit/gapic/gaming_v1/__init__.py", - "tests/unit/gapic/gaming_v1/test_game_server_clusters_service.py", - "tests/unit/gapic/gaming_v1/test_game_server_configs_service.py", - "tests/unit/gapic/gaming_v1/test_game_server_deployments_service.py", - "tests/unit/gapic/gaming_v1/test_realms_service.py", - "tests/unit/gapic/gaming_v1beta/__init__.py", - "tests/unit/gapic/gaming_v1beta/test_game_server_clusters_service.py", - "tests/unit/gapic/gaming_v1beta/test_game_server_configs_service.py", - "tests/unit/gapic/gaming_v1beta/test_game_server_deployments_service.py", - "tests/unit/gapic/gaming_v1beta/test_realms_service.py" ] } \ No newline at end of file diff --git a/synth.py b/synth.py index cf0bcd26..d55f0d28 100644 --- a/synth.py +++ b/synth.py @@ -32,7 +32,7 @@ "gameservices", version, bazel_target=f"//google/cloud/gaming/{version}:gaming-{version}-py" ) - s.move(library, excludes=["nox.py", "setup.py", "README.rst", "docs/index.rst"]) + s.move(library, excludes=["nox.py", "setup.py", "README.rst", "docs/index.rst", "*.tar.gz"]) # rename library to google-cloud-game-servers @@ -48,7 +48,7 @@ "google/**/common.py", """ start_time\|-------\[cron job\]-------\[cron job\]-------\[cron job\]---\|end_time cron job: cron spec start time \+ duration""", - """ :: + """ :: start_time|-------[cron job]-------[cron job]-------[cron job]---|end_time cron job: cron spec start time + duration diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index dd356c90..a37a34af 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -6,5 +6,4 @@ # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 google-api-core==1.22.2 -googleapis-common-protos==1.5.8 -proto-plus==1.4.0 \ No newline at end of file +proto-plus==1.4.0 diff --git a/tests/unit/gapic/gaming_v1/__init__.py b/tests/unit/gapic/gaming_v1/__init__.py index 8b137891..42ffdf2b 100644 --- a/tests/unit/gapic/gaming_v1/__init__.py +++ b/tests/unit/gapic/gaming_v1/__init__.py @@ -1 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/gaming_v1/test_game_server_clusters_service.py b/tests/unit/gapic/gaming_v1/test_game_server_clusters_service.py index 7f0d325e..8a4c8fcd 100644 --- a/tests/unit/gapic/gaming_v1/test_game_server_clusters_service.py +++ b/tests/unit/gapic/gaming_v1/test_game_server_clusters_service.py @@ -100,7 +100,25 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( "client_class", - [GameServerClustersServiceClient, GameServerClustersServiceAsyncClient], + [GameServerClustersServiceClient, GameServerClustersServiceAsyncClient,], +) +def test_game_server_clusters_service_client_from_service_account_info(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "gameservices.googleapis.com:443" + + +@pytest.mark.parametrize( + "client_class", + [GameServerClustersServiceClient, GameServerClustersServiceAsyncClient,], ) def test_game_server_clusters_service_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -110,16 +128,21 @@ def test_game_server_clusters_service_client_from_service_account_file(client_cl factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "gameservices.googleapis.com:443" def test_game_server_clusters_service_client_get_transport_class(): transport = GameServerClustersServiceClient.get_transport_class() - assert transport == transports.GameServerClustersServiceGrpcTransport + available_transports = [ + transports.GameServerClustersServiceGrpcTransport, + ] + assert transport in available_transports transport = GameServerClustersServiceClient.get_transport_class("grpc") assert transport == transports.GameServerClustersServiceGrpcTransport @@ -178,7 +201,7 @@ def test_game_server_clusters_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -194,7 +217,7 @@ def test_game_server_clusters_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -210,7 +233,7 @@ def test_game_server_clusters_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -238,7 +261,7 @@ def test_game_server_clusters_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -299,29 +322,25 @@ def test_game_server_clusters_service_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -330,66 +349,53 @@ def test_game_server_clusters_service_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -419,7 +425,7 @@ def test_game_server_clusters_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -453,7 +459,7 @@ def test_game_server_clusters_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -472,7 +478,7 @@ def test_game_server_clusters_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -520,6 +526,24 @@ def test_list_game_server_clusters_from_dict(): test_list_game_server_clusters(request_type=dict) +def test_list_game_server_clusters_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_game_server_clusters), "__call__" + ) as call: + client.list_game_server_clusters() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.ListGameServerClustersRequest() + + @pytest.mark.asyncio async def test_list_game_server_clusters_async( transport: str = "grpc_asyncio", @@ -930,6 +954,24 @@ def test_get_game_server_cluster_from_dict(): test_get_game_server_cluster(request_type=dict) +def test_get_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_game_server_cluster), "__call__" + ) as call: + client.get_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.GetGameServerClusterRequest() + + @pytest.mark.asyncio async def test_get_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -1150,6 +1192,24 @@ def test_create_game_server_cluster_from_dict(): test_create_game_server_cluster(request_type=dict) +def test_create_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_game_server_cluster), "__call__" + ) as call: + client.create_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.CreateGameServerClusterRequest() + + @pytest.mark.asyncio async def test_create_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -1403,6 +1463,24 @@ def test_preview_create_game_server_cluster_from_dict(): test_preview_create_game_server_cluster(request_type=dict) +def test_preview_create_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.preview_create_game_server_cluster), "__call__" + ) as call: + client.preview_create_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.PreviewCreateGameServerClusterRequest() + + @pytest.mark.asyncio async def test_preview_create_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -1544,6 +1622,24 @@ def test_delete_game_server_cluster_from_dict(): test_delete_game_server_cluster(request_type=dict) +def test_delete_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_game_server_cluster), "__call__" + ) as call: + client.delete_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.DeleteGameServerClusterRequest() + + @pytest.mark.asyncio async def test_delete_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -1763,6 +1859,24 @@ def test_preview_delete_game_server_cluster_from_dict(): test_preview_delete_game_server_cluster(request_type=dict) +def test_preview_delete_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.preview_delete_game_server_cluster), "__call__" + ) as call: + client.preview_delete_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.PreviewDeleteGameServerClusterRequest() + + @pytest.mark.asyncio async def test_preview_delete_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -1904,6 +2018,24 @@ def test_update_game_server_cluster_from_dict(): test_update_game_server_cluster(request_type=dict) +def test_update_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_game_server_cluster), "__call__" + ) as call: + client.update_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.UpdateGameServerClusterRequest() + + @pytest.mark.asyncio async def test_update_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -2155,6 +2287,24 @@ def test_preview_update_game_server_cluster_from_dict(): test_preview_update_game_server_cluster(request_type=dict) +def test_preview_update_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.preview_update_game_server_cluster), "__call__" + ) as call: + client.preview_update_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.PreviewUpdateGameServerClusterRequest() + + @pytest.mark.asyncio async def test_preview_update_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -2442,6 +2592,53 @@ def test_game_server_clusters_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.GameServerClustersServiceGrpcTransport, + transports.GameServerClustersServiceGrpcAsyncIOTransport, + ], +) +def test_game_server_clusters_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_game_server_clusters_service_host_no_port(): client = GameServerClustersServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2463,7 +2660,7 @@ def test_game_server_clusters_service_host_with_port(): def test_game_server_clusters_service_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerClustersServiceGrpcTransport( @@ -2475,7 +2672,7 @@ def test_game_server_clusters_service_grpc_transport_channel(): def test_game_server_clusters_service_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerClustersServiceGrpcAsyncIOTransport( @@ -2486,6 +2683,8 @@ def test_game_server_clusters_service_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -2500,7 +2699,7 @@ def test_game_server_clusters_service_transport_channel_mtls_with_client_cert_so "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -2538,6 +2737,8 @@ def test_game_server_clusters_service_transport_channel_mtls_with_client_cert_so assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -2553,7 +2754,7 @@ def test_game_server_clusters_service_transport_channel_mtls_with_adc(transport_ ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/gaming_v1/test_game_server_configs_service.py b/tests/unit/gapic/gaming_v1/test_game_server_configs_service.py index 440eb4da..143889fa 100644 --- a/tests/unit/gapic/gaming_v1/test_game_server_configs_service.py +++ b/tests/unit/gapic/gaming_v1/test_game_server_configs_service.py @@ -98,7 +98,25 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( "client_class", - [GameServerConfigsServiceClient, GameServerConfigsServiceAsyncClient], + [GameServerConfigsServiceClient, GameServerConfigsServiceAsyncClient,], +) +def test_game_server_configs_service_client_from_service_account_info(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "gameservices.googleapis.com:443" + + +@pytest.mark.parametrize( + "client_class", + [GameServerConfigsServiceClient, GameServerConfigsServiceAsyncClient,], ) def test_game_server_configs_service_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -108,16 +126,21 @@ def test_game_server_configs_service_client_from_service_account_file(client_cla factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "gameservices.googleapis.com:443" def test_game_server_configs_service_client_get_transport_class(): transport = GameServerConfigsServiceClient.get_transport_class() - assert transport == transports.GameServerConfigsServiceGrpcTransport + available_transports = [ + transports.GameServerConfigsServiceGrpcTransport, + ] + assert transport in available_transports transport = GameServerConfigsServiceClient.get_transport_class("grpc") assert transport == transports.GameServerConfigsServiceGrpcTransport @@ -176,7 +199,7 @@ def test_game_server_configs_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -192,7 +215,7 @@ def test_game_server_configs_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -208,7 +231,7 @@ def test_game_server_configs_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -236,7 +259,7 @@ def test_game_server_configs_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -297,29 +320,25 @@ def test_game_server_configs_service_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -328,66 +347,53 @@ def test_game_server_configs_service_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -417,7 +423,7 @@ def test_game_server_configs_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -451,7 +457,7 @@ def test_game_server_configs_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -470,7 +476,7 @@ def test_game_server_configs_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -518,6 +524,24 @@ def test_list_game_server_configs_from_dict(): test_list_game_server_configs(request_type=dict) +def test_list_game_server_configs_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerConfigsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_game_server_configs), "__call__" + ) as call: + client.list_game_server_configs() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_configs.ListGameServerConfigsRequest() + + @pytest.mark.asyncio async def test_list_game_server_configs_async( transport: str = "grpc_asyncio", @@ -923,6 +947,24 @@ def test_get_game_server_config_from_dict(): test_get_game_server_config(request_type=dict) +def test_get_game_server_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerConfigsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_game_server_config), "__call__" + ) as call: + client.get_game_server_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_configs.GetGameServerConfigRequest() + + @pytest.mark.asyncio async def test_get_game_server_config_async( transport: str = "grpc_asyncio", @@ -1141,6 +1183,24 @@ def test_create_game_server_config_from_dict(): test_create_game_server_config(request_type=dict) +def test_create_game_server_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerConfigsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_game_server_config), "__call__" + ) as call: + client.create_game_server_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_configs.CreateGameServerConfigRequest() + + @pytest.mark.asyncio async def test_create_game_server_config_async( transport: str = "grpc_asyncio", @@ -1371,6 +1431,24 @@ def test_delete_game_server_config_from_dict(): test_delete_game_server_config(request_type=dict) +def test_delete_game_server_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerConfigsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_game_server_config), "__call__" + ) as call: + client.delete_game_server_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_configs.DeleteGameServerConfigRequest() + + @pytest.mark.asyncio async def test_delete_game_server_config_async( transport: str = "grpc_asyncio", @@ -1719,6 +1797,53 @@ def test_game_server_configs_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.GameServerConfigsServiceGrpcTransport, + transports.GameServerConfigsServiceGrpcAsyncIOTransport, + ], +) +def test_game_server_configs_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_game_server_configs_service_host_no_port(): client = GameServerConfigsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1740,7 +1865,7 @@ def test_game_server_configs_service_host_with_port(): def test_game_server_configs_service_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerConfigsServiceGrpcTransport( @@ -1752,7 +1877,7 @@ def test_game_server_configs_service_grpc_transport_channel(): def test_game_server_configs_service_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerConfigsServiceGrpcAsyncIOTransport( @@ -1763,6 +1888,8 @@ def test_game_server_configs_service_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1777,7 +1904,7 @@ def test_game_server_configs_service_transport_channel_mtls_with_client_cert_sou "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -1815,6 +1942,8 @@ def test_game_server_configs_service_transport_channel_mtls_with_client_cert_sou assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1830,7 +1959,7 @@ def test_game_server_configs_service_transport_channel_mtls_with_adc(transport_c ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/gaming_v1/test_game_server_deployments_service.py b/tests/unit/gapic/gaming_v1/test_game_server_deployments_service.py index fc46942a..76b80af8 100644 --- a/tests/unit/gapic/gaming_v1/test_game_server_deployments_service.py +++ b/tests/unit/gapic/gaming_v1/test_game_server_deployments_service.py @@ -100,7 +100,25 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( "client_class", - [GameServerDeploymentsServiceClient, GameServerDeploymentsServiceAsyncClient], + [GameServerDeploymentsServiceClient, GameServerDeploymentsServiceAsyncClient,], +) +def test_game_server_deployments_service_client_from_service_account_info(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "gameservices.googleapis.com:443" + + +@pytest.mark.parametrize( + "client_class", + [GameServerDeploymentsServiceClient, GameServerDeploymentsServiceAsyncClient,], ) def test_game_server_deployments_service_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -110,16 +128,21 @@ def test_game_server_deployments_service_client_from_service_account_file(client factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "gameservices.googleapis.com:443" def test_game_server_deployments_service_client_get_transport_class(): transport = GameServerDeploymentsServiceClient.get_transport_class() - assert transport == transports.GameServerDeploymentsServiceGrpcTransport + available_transports = [ + transports.GameServerDeploymentsServiceGrpcTransport, + ] + assert transport in available_transports transport = GameServerDeploymentsServiceClient.get_transport_class("grpc") assert transport == transports.GameServerDeploymentsServiceGrpcTransport @@ -178,7 +201,7 @@ def test_game_server_deployments_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -194,7 +217,7 @@ def test_game_server_deployments_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -210,7 +233,7 @@ def test_game_server_deployments_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -238,7 +261,7 @@ def test_game_server_deployments_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -299,29 +322,25 @@ def test_game_server_deployments_service_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -330,66 +349,53 @@ def test_game_server_deployments_service_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -419,7 +425,7 @@ def test_game_server_deployments_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -453,7 +459,7 @@ def test_game_server_deployments_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -472,7 +478,7 @@ def test_game_server_deployments_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -520,6 +526,24 @@ def test_list_game_server_deployments_from_dict(): test_list_game_server_deployments(request_type=dict) +def test_list_game_server_deployments_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_game_server_deployments), "__call__" + ) as call: + client.list_game_server_deployments() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.ListGameServerDeploymentsRequest() + + @pytest.mark.asyncio async def test_list_game_server_deployments_async( transport: str = "grpc_asyncio", @@ -943,6 +967,24 @@ def test_get_game_server_deployment_from_dict(): test_get_game_server_deployment(request_type=dict) +def test_get_game_server_deployment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_game_server_deployment), "__call__" + ) as call: + client.get_game_server_deployment() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.GetGameServerDeploymentRequest() + + @pytest.mark.asyncio async def test_get_game_server_deployment_async( transport: str = "grpc_asyncio", @@ -1163,6 +1205,24 @@ def test_create_game_server_deployment_from_dict(): test_create_game_server_deployment(request_type=dict) +def test_create_game_server_deployment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_game_server_deployment), "__call__" + ) as call: + client.create_game_server_deployment() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.CreateGameServerDeploymentRequest() + + @pytest.mark.asyncio async def test_create_game_server_deployment_async( transport: str = "grpc_asyncio", @@ -1405,6 +1465,24 @@ def test_delete_game_server_deployment_from_dict(): test_delete_game_server_deployment(request_type=dict) +def test_delete_game_server_deployment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_game_server_deployment), "__call__" + ) as call: + client.delete_game_server_deployment() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.DeleteGameServerDeploymentRequest() + + @pytest.mark.asyncio async def test_delete_game_server_deployment_async( transport: str = "grpc_asyncio", @@ -1619,6 +1697,24 @@ def test_update_game_server_deployment_from_dict(): test_update_game_server_deployment(request_type=dict) +def test_update_game_server_deployment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_game_server_deployment), "__call__" + ) as call: + client.update_game_server_deployment() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.UpdateGameServerDeploymentRequest() + + @pytest.mark.asyncio async def test_update_game_server_deployment_async( transport: str = "grpc_asyncio", @@ -1880,6 +1976,26 @@ def test_get_game_server_deployment_rollout_from_dict(): test_get_game_server_deployment_rollout(request_type=dict) +def test_get_game_server_deployment_rollout_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_game_server_deployment_rollout), "__call__" + ) as call: + client.get_game_server_deployment_rollout() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert ( + args[0] == game_server_deployments.GetGameServerDeploymentRolloutRequest() + ) + + @pytest.mark.asyncio async def test_get_game_server_deployment_rollout_async( transport: str = "grpc_asyncio", @@ -2109,6 +2225,27 @@ def test_update_game_server_deployment_rollout_from_dict(): test_update_game_server_deployment_rollout(request_type=dict) +def test_update_game_server_deployment_rollout_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_game_server_deployment_rollout), "__call__" + ) as call: + client.update_game_server_deployment_rollout() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert ( + args[0] + == game_server_deployments.UpdateGameServerDeploymentRolloutRequest() + ) + + @pytest.mark.asyncio async def test_update_game_server_deployment_rollout_async( transport: str = "grpc_asyncio", @@ -2366,6 +2503,27 @@ def test_preview_game_server_deployment_rollout_from_dict(): test_preview_game_server_deployment_rollout(request_type=dict) +def test_preview_game_server_deployment_rollout_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.preview_game_server_deployment_rollout), "__call__" + ) as call: + client.preview_game_server_deployment_rollout() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert ( + args[0] + == game_server_deployments.PreviewGameServerDeploymentRolloutRequest() + ) + + @pytest.mark.asyncio async def test_preview_game_server_deployment_rollout_async( transport: str = "grpc_asyncio", @@ -2521,6 +2679,24 @@ def test_fetch_deployment_state_from_dict(): test_fetch_deployment_state(request_type=dict) +def test_fetch_deployment_state_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_deployment_state), "__call__" + ) as call: + client.fetch_deployment_state() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.FetchDeploymentStateRequest() + + @pytest.mark.asyncio async def test_fetch_deployment_state_async( transport: str = "grpc_asyncio", @@ -2799,6 +2975,53 @@ def test_game_server_deployments_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.GameServerDeploymentsServiceGrpcTransport, + transports.GameServerDeploymentsServiceGrpcAsyncIOTransport, + ], +) +def test_game_server_deployments_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_game_server_deployments_service_host_no_port(): client = GameServerDeploymentsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2820,7 +3043,7 @@ def test_game_server_deployments_service_host_with_port(): def test_game_server_deployments_service_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerDeploymentsServiceGrpcTransport( @@ -2832,7 +3055,7 @@ def test_game_server_deployments_service_grpc_transport_channel(): def test_game_server_deployments_service_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerDeploymentsServiceGrpcAsyncIOTransport( @@ -2843,6 +3066,8 @@ def test_game_server_deployments_service_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -2857,7 +3082,7 @@ def test_game_server_deployments_service_transport_channel_mtls_with_client_cert "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -2895,6 +3120,8 @@ def test_game_server_deployments_service_transport_channel_mtls_with_client_cert assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -2912,7 +3139,7 @@ def test_game_server_deployments_service_transport_channel_mtls_with_adc( ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/gaming_v1/test_realms_service.py b/tests/unit/gapic/gaming_v1/test_realms_service.py index 08a180f5..7d4308ca 100644 --- a/tests/unit/gapic/gaming_v1/test_realms_service.py +++ b/tests/unit/gapic/gaming_v1/test_realms_service.py @@ -92,7 +92,24 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [RealmsServiceClient, RealmsServiceAsyncClient] + "client_class", [RealmsServiceClient, RealmsServiceAsyncClient,] +) +def test_realms_service_client_from_service_account_info(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "gameservices.googleapis.com:443" + + +@pytest.mark.parametrize( + "client_class", [RealmsServiceClient, RealmsServiceAsyncClient,] ) def test_realms_service_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -102,16 +119,21 @@ def test_realms_service_client_from_service_account_file(client_class): factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "gameservices.googleapis.com:443" def test_realms_service_client_get_transport_class(): transport = RealmsServiceClient.get_transport_class() - assert transport == transports.RealmsServiceGrpcTransport + available_transports = [ + transports.RealmsServiceGrpcTransport, + ] + assert transport in available_transports transport = RealmsServiceClient.get_transport_class("grpc") assert transport == transports.RealmsServiceGrpcTransport @@ -162,7 +184,7 @@ def test_realms_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -178,7 +200,7 @@ def test_realms_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -194,7 +216,7 @@ def test_realms_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -222,7 +244,7 @@ def test_realms_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -273,29 +295,25 @@ def test_realms_service_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -304,66 +322,53 @@ def test_realms_service_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -389,7 +394,7 @@ def test_realms_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -419,7 +424,7 @@ def test_realms_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -438,7 +443,7 @@ def test_realms_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -481,6 +486,22 @@ def test_list_realms_from_dict(): test_list_realms(request_type=dict) +def test_list_realms_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_realms), "__call__") as call: + client.list_realms() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.ListRealmsRequest() + + @pytest.mark.asyncio async def test_list_realms_async( transport: str = "grpc_asyncio", request_type=realms.ListRealmsRequest @@ -792,6 +813,22 @@ def test_get_realm_from_dict(): test_get_realm(request_type=dict) +def test_get_realm_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_realm), "__call__") as call: + client.get_realm() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.GetRealmRequest() + + @pytest.mark.asyncio async def test_get_realm_async( transport: str = "grpc_asyncio", request_type=realms.GetRealmRequest @@ -985,6 +1022,22 @@ def test_create_realm_from_dict(): test_create_realm(request_type=dict) +def test_create_realm_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_realm), "__call__") as call: + client.create_realm() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.CreateRealmRequest() + + @pytest.mark.asyncio async def test_create_realm_async( transport: str = "grpc_asyncio", request_type=realms.CreateRealmRequest @@ -1191,6 +1244,22 @@ def test_delete_realm_from_dict(): test_delete_realm(request_type=dict) +def test_delete_realm_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_realm), "__call__") as call: + client.delete_realm() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.DeleteRealmRequest() + + @pytest.mark.asyncio async def test_delete_realm_async( transport: str = "grpc_asyncio", request_type=realms.DeleteRealmRequest @@ -1375,6 +1444,22 @@ def test_update_realm_from_dict(): test_update_realm(request_type=dict) +def test_update_realm_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_realm), "__call__") as call: + client.update_realm() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.UpdateRealmRequest() + + @pytest.mark.asyncio async def test_update_realm_async( transport: str = "grpc_asyncio", request_type=realms.UpdateRealmRequest @@ -1580,6 +1665,24 @@ def test_preview_realm_update_from_dict(): test_preview_realm_update(request_type=dict) +def test_preview_realm_update_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.preview_realm_update), "__call__" + ) as call: + client.preview_realm_update() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.PreviewRealmUpdateRequest() + + @pytest.mark.asyncio async def test_preview_realm_update_async( transport: str = "grpc_asyncio", request_type=realms.PreviewRealmUpdateRequest @@ -1844,6 +1947,51 @@ def test_realms_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.RealmsServiceGrpcTransport, + transports.RealmsServiceGrpcAsyncIOTransport, + ], +) +def test_realms_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_realms_service_host_no_port(): client = RealmsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1865,7 +2013,7 @@ def test_realms_service_host_with_port(): def test_realms_service_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.RealmsServiceGrpcTransport( @@ -1877,7 +2025,7 @@ def test_realms_service_grpc_transport_channel(): def test_realms_service_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.RealmsServiceGrpcAsyncIOTransport( @@ -1888,6 +2036,8 @@ def test_realms_service_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1900,7 +2050,7 @@ def test_realms_service_transport_channel_mtls_with_client_cert_source(transport "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -1938,6 +2088,8 @@ def test_realms_service_transport_channel_mtls_with_client_cert_source(transport assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1953,7 +2105,7 @@ def test_realms_service_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/gaming_v1beta/__init__.py b/tests/unit/gapic/gaming_v1beta/__init__.py index 8b137891..42ffdf2b 100644 --- a/tests/unit/gapic/gaming_v1beta/__init__.py +++ b/tests/unit/gapic/gaming_v1beta/__init__.py @@ -1 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/gaming_v1beta/test_game_server_clusters_service.py b/tests/unit/gapic/gaming_v1beta/test_game_server_clusters_service.py index fc9dab62..0414658f 100644 --- a/tests/unit/gapic/gaming_v1beta/test_game_server_clusters_service.py +++ b/tests/unit/gapic/gaming_v1beta/test_game_server_clusters_service.py @@ -100,7 +100,25 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( "client_class", - [GameServerClustersServiceClient, GameServerClustersServiceAsyncClient], + [GameServerClustersServiceClient, GameServerClustersServiceAsyncClient,], +) +def test_game_server_clusters_service_client_from_service_account_info(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "gameservices.googleapis.com:443" + + +@pytest.mark.parametrize( + "client_class", + [GameServerClustersServiceClient, GameServerClustersServiceAsyncClient,], ) def test_game_server_clusters_service_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -110,16 +128,21 @@ def test_game_server_clusters_service_client_from_service_account_file(client_cl factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "gameservices.googleapis.com:443" def test_game_server_clusters_service_client_get_transport_class(): transport = GameServerClustersServiceClient.get_transport_class() - assert transport == transports.GameServerClustersServiceGrpcTransport + available_transports = [ + transports.GameServerClustersServiceGrpcTransport, + ] + assert transport in available_transports transport = GameServerClustersServiceClient.get_transport_class("grpc") assert transport == transports.GameServerClustersServiceGrpcTransport @@ -178,7 +201,7 @@ def test_game_server_clusters_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -194,7 +217,7 @@ def test_game_server_clusters_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -210,7 +233,7 @@ def test_game_server_clusters_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -238,7 +261,7 @@ def test_game_server_clusters_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -299,29 +322,25 @@ def test_game_server_clusters_service_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -330,66 +349,53 @@ def test_game_server_clusters_service_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -419,7 +425,7 @@ def test_game_server_clusters_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -453,7 +459,7 @@ def test_game_server_clusters_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -472,7 +478,7 @@ def test_game_server_clusters_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -520,6 +526,24 @@ def test_list_game_server_clusters_from_dict(): test_list_game_server_clusters(request_type=dict) +def test_list_game_server_clusters_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_game_server_clusters), "__call__" + ) as call: + client.list_game_server_clusters() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.ListGameServerClustersRequest() + + @pytest.mark.asyncio async def test_list_game_server_clusters_async( transport: str = "grpc_asyncio", @@ -930,6 +954,24 @@ def test_get_game_server_cluster_from_dict(): test_get_game_server_cluster(request_type=dict) +def test_get_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_game_server_cluster), "__call__" + ) as call: + client.get_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.GetGameServerClusterRequest() + + @pytest.mark.asyncio async def test_get_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -1150,6 +1192,24 @@ def test_create_game_server_cluster_from_dict(): test_create_game_server_cluster(request_type=dict) +def test_create_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_game_server_cluster), "__call__" + ) as call: + client.create_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.CreateGameServerClusterRequest() + + @pytest.mark.asyncio async def test_create_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -1403,6 +1463,24 @@ def test_preview_create_game_server_cluster_from_dict(): test_preview_create_game_server_cluster(request_type=dict) +def test_preview_create_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.preview_create_game_server_cluster), "__call__" + ) as call: + client.preview_create_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.PreviewCreateGameServerClusterRequest() + + @pytest.mark.asyncio async def test_preview_create_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -1544,6 +1622,24 @@ def test_delete_game_server_cluster_from_dict(): test_delete_game_server_cluster(request_type=dict) +def test_delete_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_game_server_cluster), "__call__" + ) as call: + client.delete_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.DeleteGameServerClusterRequest() + + @pytest.mark.asyncio async def test_delete_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -1763,6 +1859,24 @@ def test_preview_delete_game_server_cluster_from_dict(): test_preview_delete_game_server_cluster(request_type=dict) +def test_preview_delete_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.preview_delete_game_server_cluster), "__call__" + ) as call: + client.preview_delete_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.PreviewDeleteGameServerClusterRequest() + + @pytest.mark.asyncio async def test_preview_delete_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -1904,6 +2018,24 @@ def test_update_game_server_cluster_from_dict(): test_update_game_server_cluster(request_type=dict) +def test_update_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_game_server_cluster), "__call__" + ) as call: + client.update_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.UpdateGameServerClusterRequest() + + @pytest.mark.asyncio async def test_update_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -2155,6 +2287,24 @@ def test_preview_update_game_server_cluster_from_dict(): test_preview_update_game_server_cluster(request_type=dict) +def test_preview_update_game_server_cluster_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerClustersServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.preview_update_game_server_cluster), "__call__" + ) as call: + client.preview_update_game_server_cluster() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_clusters.PreviewUpdateGameServerClusterRequest() + + @pytest.mark.asyncio async def test_preview_update_game_server_cluster_async( transport: str = "grpc_asyncio", @@ -2442,6 +2592,53 @@ def test_game_server_clusters_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.GameServerClustersServiceGrpcTransport, + transports.GameServerClustersServiceGrpcAsyncIOTransport, + ], +) +def test_game_server_clusters_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_game_server_clusters_service_host_no_port(): client = GameServerClustersServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2463,7 +2660,7 @@ def test_game_server_clusters_service_host_with_port(): def test_game_server_clusters_service_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerClustersServiceGrpcTransport( @@ -2475,7 +2672,7 @@ def test_game_server_clusters_service_grpc_transport_channel(): def test_game_server_clusters_service_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerClustersServiceGrpcAsyncIOTransport( @@ -2486,6 +2683,8 @@ def test_game_server_clusters_service_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -2500,7 +2699,7 @@ def test_game_server_clusters_service_transport_channel_mtls_with_client_cert_so "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -2538,6 +2737,8 @@ def test_game_server_clusters_service_transport_channel_mtls_with_client_cert_so assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -2553,7 +2754,7 @@ def test_game_server_clusters_service_transport_channel_mtls_with_adc(transport_ ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/gaming_v1beta/test_game_server_configs_service.py b/tests/unit/gapic/gaming_v1beta/test_game_server_configs_service.py index fcb89945..49f1b1ff 100644 --- a/tests/unit/gapic/gaming_v1beta/test_game_server_configs_service.py +++ b/tests/unit/gapic/gaming_v1beta/test_game_server_configs_service.py @@ -98,7 +98,25 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( "client_class", - [GameServerConfigsServiceClient, GameServerConfigsServiceAsyncClient], + [GameServerConfigsServiceClient, GameServerConfigsServiceAsyncClient,], +) +def test_game_server_configs_service_client_from_service_account_info(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "gameservices.googleapis.com:443" + + +@pytest.mark.parametrize( + "client_class", + [GameServerConfigsServiceClient, GameServerConfigsServiceAsyncClient,], ) def test_game_server_configs_service_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -108,16 +126,21 @@ def test_game_server_configs_service_client_from_service_account_file(client_cla factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "gameservices.googleapis.com:443" def test_game_server_configs_service_client_get_transport_class(): transport = GameServerConfigsServiceClient.get_transport_class() - assert transport == transports.GameServerConfigsServiceGrpcTransport + available_transports = [ + transports.GameServerConfigsServiceGrpcTransport, + ] + assert transport in available_transports transport = GameServerConfigsServiceClient.get_transport_class("grpc") assert transport == transports.GameServerConfigsServiceGrpcTransport @@ -176,7 +199,7 @@ def test_game_server_configs_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -192,7 +215,7 @@ def test_game_server_configs_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -208,7 +231,7 @@ def test_game_server_configs_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -236,7 +259,7 @@ def test_game_server_configs_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -297,29 +320,25 @@ def test_game_server_configs_service_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -328,66 +347,53 @@ def test_game_server_configs_service_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -417,7 +423,7 @@ def test_game_server_configs_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -451,7 +457,7 @@ def test_game_server_configs_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -470,7 +476,7 @@ def test_game_server_configs_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -518,6 +524,24 @@ def test_list_game_server_configs_from_dict(): test_list_game_server_configs(request_type=dict) +def test_list_game_server_configs_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerConfigsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_game_server_configs), "__call__" + ) as call: + client.list_game_server_configs() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_configs.ListGameServerConfigsRequest() + + @pytest.mark.asyncio async def test_list_game_server_configs_async( transport: str = "grpc_asyncio", @@ -923,6 +947,24 @@ def test_get_game_server_config_from_dict(): test_get_game_server_config(request_type=dict) +def test_get_game_server_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerConfigsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_game_server_config), "__call__" + ) as call: + client.get_game_server_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_configs.GetGameServerConfigRequest() + + @pytest.mark.asyncio async def test_get_game_server_config_async( transport: str = "grpc_asyncio", @@ -1141,6 +1183,24 @@ def test_create_game_server_config_from_dict(): test_create_game_server_config(request_type=dict) +def test_create_game_server_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerConfigsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_game_server_config), "__call__" + ) as call: + client.create_game_server_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_configs.CreateGameServerConfigRequest() + + @pytest.mark.asyncio async def test_create_game_server_config_async( transport: str = "grpc_asyncio", @@ -1371,6 +1431,24 @@ def test_delete_game_server_config_from_dict(): test_delete_game_server_config(request_type=dict) +def test_delete_game_server_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerConfigsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_game_server_config), "__call__" + ) as call: + client.delete_game_server_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_configs.DeleteGameServerConfigRequest() + + @pytest.mark.asyncio async def test_delete_game_server_config_async( transport: str = "grpc_asyncio", @@ -1719,6 +1797,53 @@ def test_game_server_configs_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.GameServerConfigsServiceGrpcTransport, + transports.GameServerConfigsServiceGrpcAsyncIOTransport, + ], +) +def test_game_server_configs_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_game_server_configs_service_host_no_port(): client = GameServerConfigsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1740,7 +1865,7 @@ def test_game_server_configs_service_host_with_port(): def test_game_server_configs_service_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerConfigsServiceGrpcTransport( @@ -1752,7 +1877,7 @@ def test_game_server_configs_service_grpc_transport_channel(): def test_game_server_configs_service_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerConfigsServiceGrpcAsyncIOTransport( @@ -1763,6 +1888,8 @@ def test_game_server_configs_service_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1777,7 +1904,7 @@ def test_game_server_configs_service_transport_channel_mtls_with_client_cert_sou "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -1815,6 +1942,8 @@ def test_game_server_configs_service_transport_channel_mtls_with_client_cert_sou assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1830,7 +1959,7 @@ def test_game_server_configs_service_transport_channel_mtls_with_adc(transport_c ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/gaming_v1beta/test_game_server_deployments_service.py b/tests/unit/gapic/gaming_v1beta/test_game_server_deployments_service.py index 0fe7376f..b1705f6c 100644 --- a/tests/unit/gapic/gaming_v1beta/test_game_server_deployments_service.py +++ b/tests/unit/gapic/gaming_v1beta/test_game_server_deployments_service.py @@ -102,7 +102,25 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( "client_class", - [GameServerDeploymentsServiceClient, GameServerDeploymentsServiceAsyncClient], + [GameServerDeploymentsServiceClient, GameServerDeploymentsServiceAsyncClient,], +) +def test_game_server_deployments_service_client_from_service_account_info(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "gameservices.googleapis.com:443" + + +@pytest.mark.parametrize( + "client_class", + [GameServerDeploymentsServiceClient, GameServerDeploymentsServiceAsyncClient,], ) def test_game_server_deployments_service_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -112,16 +130,21 @@ def test_game_server_deployments_service_client_from_service_account_file(client factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "gameservices.googleapis.com:443" def test_game_server_deployments_service_client_get_transport_class(): transport = GameServerDeploymentsServiceClient.get_transport_class() - assert transport == transports.GameServerDeploymentsServiceGrpcTransport + available_transports = [ + transports.GameServerDeploymentsServiceGrpcTransport, + ] + assert transport in available_transports transport = GameServerDeploymentsServiceClient.get_transport_class("grpc") assert transport == transports.GameServerDeploymentsServiceGrpcTransport @@ -180,7 +203,7 @@ def test_game_server_deployments_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -196,7 +219,7 @@ def test_game_server_deployments_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -212,7 +235,7 @@ def test_game_server_deployments_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -240,7 +263,7 @@ def test_game_server_deployments_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -301,29 +324,25 @@ def test_game_server_deployments_service_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -332,66 +351,53 @@ def test_game_server_deployments_service_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -421,7 +427,7 @@ def test_game_server_deployments_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -455,7 +461,7 @@ def test_game_server_deployments_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -474,7 +480,7 @@ def test_game_server_deployments_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -522,6 +528,24 @@ def test_list_game_server_deployments_from_dict(): test_list_game_server_deployments(request_type=dict) +def test_list_game_server_deployments_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_game_server_deployments), "__call__" + ) as call: + client.list_game_server_deployments() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.ListGameServerDeploymentsRequest() + + @pytest.mark.asyncio async def test_list_game_server_deployments_async( transport: str = "grpc_asyncio", @@ -945,6 +969,24 @@ def test_get_game_server_deployment_from_dict(): test_get_game_server_deployment(request_type=dict) +def test_get_game_server_deployment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_game_server_deployment), "__call__" + ) as call: + client.get_game_server_deployment() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.GetGameServerDeploymentRequest() + + @pytest.mark.asyncio async def test_get_game_server_deployment_async( transport: str = "grpc_asyncio", @@ -1165,6 +1207,24 @@ def test_create_game_server_deployment_from_dict(): test_create_game_server_deployment(request_type=dict) +def test_create_game_server_deployment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_game_server_deployment), "__call__" + ) as call: + client.create_game_server_deployment() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.CreateGameServerDeploymentRequest() + + @pytest.mark.asyncio async def test_create_game_server_deployment_async( transport: str = "grpc_asyncio", @@ -1407,6 +1467,24 @@ def test_delete_game_server_deployment_from_dict(): test_delete_game_server_deployment(request_type=dict) +def test_delete_game_server_deployment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_game_server_deployment), "__call__" + ) as call: + client.delete_game_server_deployment() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.DeleteGameServerDeploymentRequest() + + @pytest.mark.asyncio async def test_delete_game_server_deployment_async( transport: str = "grpc_asyncio", @@ -1621,6 +1699,24 @@ def test_update_game_server_deployment_from_dict(): test_update_game_server_deployment(request_type=dict) +def test_update_game_server_deployment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_game_server_deployment), "__call__" + ) as call: + client.update_game_server_deployment() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.UpdateGameServerDeploymentRequest() + + @pytest.mark.asyncio async def test_update_game_server_deployment_async( transport: str = "grpc_asyncio", @@ -1882,6 +1978,26 @@ def test_get_game_server_deployment_rollout_from_dict(): test_get_game_server_deployment_rollout(request_type=dict) +def test_get_game_server_deployment_rollout_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_game_server_deployment_rollout), "__call__" + ) as call: + client.get_game_server_deployment_rollout() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert ( + args[0] == game_server_deployments.GetGameServerDeploymentRolloutRequest() + ) + + @pytest.mark.asyncio async def test_get_game_server_deployment_rollout_async( transport: str = "grpc_asyncio", @@ -2111,6 +2227,27 @@ def test_update_game_server_deployment_rollout_from_dict(): test_update_game_server_deployment_rollout(request_type=dict) +def test_update_game_server_deployment_rollout_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_game_server_deployment_rollout), "__call__" + ) as call: + client.update_game_server_deployment_rollout() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert ( + args[0] + == game_server_deployments.UpdateGameServerDeploymentRolloutRequest() + ) + + @pytest.mark.asyncio async def test_update_game_server_deployment_rollout_async( transport: str = "grpc_asyncio", @@ -2368,6 +2505,27 @@ def test_preview_game_server_deployment_rollout_from_dict(): test_preview_game_server_deployment_rollout(request_type=dict) +def test_preview_game_server_deployment_rollout_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.preview_game_server_deployment_rollout), "__call__" + ) as call: + client.preview_game_server_deployment_rollout() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert ( + args[0] + == game_server_deployments.PreviewGameServerDeploymentRolloutRequest() + ) + + @pytest.mark.asyncio async def test_preview_game_server_deployment_rollout_async( transport: str = "grpc_asyncio", @@ -2523,6 +2681,24 @@ def test_fetch_deployment_state_from_dict(): test_fetch_deployment_state(request_type=dict) +def test_fetch_deployment_state_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = GameServerDeploymentsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_deployment_state), "__call__" + ) as call: + client.fetch_deployment_state() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == game_server_deployments.FetchDeploymentStateRequest() + + @pytest.mark.asyncio async def test_fetch_deployment_state_async( transport: str = "grpc_asyncio", @@ -2801,6 +2977,53 @@ def test_game_server_deployments_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.GameServerDeploymentsServiceGrpcTransport, + transports.GameServerDeploymentsServiceGrpcAsyncIOTransport, + ], +) +def test_game_server_deployments_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_game_server_deployments_service_host_no_port(): client = GameServerDeploymentsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2822,7 +3045,7 @@ def test_game_server_deployments_service_host_with_port(): def test_game_server_deployments_service_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerDeploymentsServiceGrpcTransport( @@ -2834,7 +3057,7 @@ def test_game_server_deployments_service_grpc_transport_channel(): def test_game_server_deployments_service_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.GameServerDeploymentsServiceGrpcAsyncIOTransport( @@ -2845,6 +3068,8 @@ def test_game_server_deployments_service_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -2859,7 +3084,7 @@ def test_game_server_deployments_service_transport_channel_mtls_with_client_cert "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -2897,6 +3122,8 @@ def test_game_server_deployments_service_transport_channel_mtls_with_client_cert assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -2914,7 +3141,7 @@ def test_game_server_deployments_service_transport_channel_mtls_with_adc( ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/gaming_v1beta/test_realms_service.py b/tests/unit/gapic/gaming_v1beta/test_realms_service.py index c4277570..4f43d272 100644 --- a/tests/unit/gapic/gaming_v1beta/test_realms_service.py +++ b/tests/unit/gapic/gaming_v1beta/test_realms_service.py @@ -92,7 +92,24 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [RealmsServiceClient, RealmsServiceAsyncClient] + "client_class", [RealmsServiceClient, RealmsServiceAsyncClient,] +) +def test_realms_service_client_from_service_account_info(client_class): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "gameservices.googleapis.com:443" + + +@pytest.mark.parametrize( + "client_class", [RealmsServiceClient, RealmsServiceAsyncClient,] ) def test_realms_service_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() @@ -102,16 +119,21 @@ def test_realms_service_client_from_service_account_file(client_class): factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "gameservices.googleapis.com:443" def test_realms_service_client_get_transport_class(): transport = RealmsServiceClient.get_transport_class() - assert transport == transports.RealmsServiceGrpcTransport + available_transports = [ + transports.RealmsServiceGrpcTransport, + ] + assert transport in available_transports transport = RealmsServiceClient.get_transport_class("grpc") assert transport == transports.RealmsServiceGrpcTransport @@ -162,7 +184,7 @@ def test_realms_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -178,7 +200,7 @@ def test_realms_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -194,7 +216,7 @@ def test_realms_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -222,7 +244,7 @@ def test_realms_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -273,29 +295,25 @@ def test_realms_service_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -304,66 +322,53 @@ def test_realms_service_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -389,7 +394,7 @@ def test_realms_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -419,7 +424,7 @@ def test_realms_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -438,7 +443,7 @@ def test_realms_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -481,6 +486,22 @@ def test_list_realms_from_dict(): test_list_realms(request_type=dict) +def test_list_realms_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_realms), "__call__") as call: + client.list_realms() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.ListRealmsRequest() + + @pytest.mark.asyncio async def test_list_realms_async( transport: str = "grpc_asyncio", request_type=realms.ListRealmsRequest @@ -792,6 +813,22 @@ def test_get_realm_from_dict(): test_get_realm(request_type=dict) +def test_get_realm_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_realm), "__call__") as call: + client.get_realm() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.GetRealmRequest() + + @pytest.mark.asyncio async def test_get_realm_async( transport: str = "grpc_asyncio", request_type=realms.GetRealmRequest @@ -985,6 +1022,22 @@ def test_create_realm_from_dict(): test_create_realm(request_type=dict) +def test_create_realm_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_realm), "__call__") as call: + client.create_realm() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.CreateRealmRequest() + + @pytest.mark.asyncio async def test_create_realm_async( transport: str = "grpc_asyncio", request_type=realms.CreateRealmRequest @@ -1191,6 +1244,22 @@ def test_delete_realm_from_dict(): test_delete_realm(request_type=dict) +def test_delete_realm_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_realm), "__call__") as call: + client.delete_realm() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.DeleteRealmRequest() + + @pytest.mark.asyncio async def test_delete_realm_async( transport: str = "grpc_asyncio", request_type=realms.DeleteRealmRequest @@ -1375,6 +1444,22 @@ def test_update_realm_from_dict(): test_update_realm(request_type=dict) +def test_update_realm_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_realm), "__call__") as call: + client.update_realm() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.UpdateRealmRequest() + + @pytest.mark.asyncio async def test_update_realm_async( transport: str = "grpc_asyncio", request_type=realms.UpdateRealmRequest @@ -1580,6 +1665,24 @@ def test_preview_realm_update_from_dict(): test_preview_realm_update(request_type=dict) +def test_preview_realm_update_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = RealmsServiceClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.preview_realm_update), "__call__" + ) as call: + client.preview_realm_update() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == realms.PreviewRealmUpdateRequest() + + @pytest.mark.asyncio async def test_preview_realm_update_async( transport: str = "grpc_asyncio", request_type=realms.PreviewRealmUpdateRequest @@ -1844,6 +1947,51 @@ def test_realms_service_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.RealmsServiceGrpcTransport, + transports.RealmsServiceGrpcAsyncIOTransport, + ], +) +def test_realms_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_realms_service_host_no_port(): client = RealmsServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1865,7 +2013,7 @@ def test_realms_service_host_with_port(): def test_realms_service_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.RealmsServiceGrpcTransport( @@ -1877,7 +2025,7 @@ def test_realms_service_grpc_transport_channel(): def test_realms_service_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.RealmsServiceGrpcAsyncIOTransport( @@ -1888,6 +2036,8 @@ def test_realms_service_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1900,7 +2050,7 @@ def test_realms_service_transport_channel_mtls_with_client_cert_source(transport "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -1938,6 +2088,8 @@ def test_realms_service_transport_channel_mtls_with_client_cert_source(transport assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1953,7 +2105,7 @@ def test_realms_service_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel