diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 108063d..39ad3ce 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,16 @@ +# Copyright 2022 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. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:4ee57a76a176ede9087c14330c625a71553cf9c72828b2c0ca12f5338171ba60 + digest: sha256:d22cd2ddce65fdac6986f115563faf2fc81482b09dfbea83ac2808c92ecfdff0 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index be888a9..e446644 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,9 +3,10 @@ # # For syntax help see: # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax +# Note: This file is autogenerated. To make changes to the codeowner team, please update .repo-metadata.json. -# The @googleapis/yoshi-python is the default owner for changes in this repo -* @googleapis/yoshi-python +# @googleapis/yoshi-python is the default owner for changes in this repo +* @googleapis/yoshi-python - -/samples/ @googleapis/python-samples-owners +# @googleapis/python-samples-reviewers is the default owner for samples changes +/samples/ @googleapis/python-samples-reviewers diff --git a/.github/release-please.yml b/.github/release-please.yml index 4507ad0..466597e 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1 +1,2 @@ releaseType: python +handleGHRelease: true diff --git a/.github/release-trigger.yml b/.github/release-trigger.yml new file mode 100644 index 0000000..d4ca941 --- /dev/null +++ b/.github/release-trigger.yml @@ -0,0 +1 @@ +enabled: true diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..f7b8344 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,38 @@ +on: + pull_request: + branches: + - main +name: docs +jobs: + docs: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run docs + run: | + nox -s docs + docfx: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run docfx + run: | + nox -s docfx diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..1e8b05c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +on: + pull_request: + branches: + - main +name: lint +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run lint + run: | + nox -s lint + - name: Run lint_setup_py + run: | + nox -s lint_setup_py diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 0000000..074ee25 --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,57 @@ +on: + pull_request: + branches: + - main +name: unittest +jobs: + unit: + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.6', '3.7', '3.8', '3.9', '3.10'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run unit tests + env: + COVERAGE_FILE: .coverage-${{ matrix.python }} + run: | + nox -s unit-${{ matrix.python }} + - name: Upload coverage results + uses: actions/upload-artifact@v2 + with: + name: coverage-artifacts + path: .coverage-${{ matrix.python }} + + cover: + runs-on: ubuntu-latest + needs: + - unit + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install coverage + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install coverage + - name: Download coverage results + uses: actions/download-artifact@v2 + with: + name: coverage-artifacts + path: .coverage-results/ + - name: Report coverage results + run: | + coverage combine .coverage-results/.coverage* + coverage report --show-missing --fail-under=100 diff --git a/.kokoro/release.sh b/.kokoro/release.sh index 0427607..2f57a75 100755 --- a/.kokoro/release.sh +++ b/.kokoro/release.sh @@ -26,7 +26,7 @@ python3 -m pip install --upgrade twine wheel setuptools export PYTHONUNBUFFERED=1 # Move into the package, build the distribution and upload. -TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token") +TWINE_PASSWORD=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google-cloud-pypi-token-keystore-1") cd github/python-debugger-client python3 setup.py sdist bdist_wheel twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/* diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index 1532d91..2395e95 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,8 +23,18 @@ env_vars: { value: "github/python-debugger-client/.kokoro/release.sh" } +# Fetch PyPI password +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "google-cloud-pypi-token-keystore-1" + } + } +} + # Tokens needed to report release status back to GitHub env_vars: { key: "SECRET_MANAGER_KEYS" - value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,google-cloud-pypi-token" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" } diff --git a/.repo-metadata.json b/.repo-metadata.json index ce179e8..06a845d 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -2,14 +2,15 @@ "name": "clouddebugger", "name_pretty": "Cloud Debugger", "product_documentation": "cloud.google.com/debugger", - "client_documentation": "https://googleapis.dev/python/clouddebugger/latest", + "client_documentation": "https://cloud.google.com/python/docs/reference/clouddebugger/latest", "issue_tracker": "", - "release_level": "ga", + "release_level": "stable", "language": "python", "library_type": "GAPIC_AUTO", "repo": "googleapis/python-debugger-client", "distribution_name": "google-cloud-debugger-client", "api_id": "clouddebugger.googleapis.com", "default_version": "v2", - "codeowner_team": "" + "codeowner_team": "", + "api_shortname": "clouddebugger" } diff --git a/CHANGELOG.md b/CHANGELOG.md index a2c664f..f5458cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [1.3.0](https://github.com/googleapis/python-debugger-client/compare/v1.2.1...v1.3.0) (2022-02-26) + + +### Features + +* add api key support ([#61](https://github.com/googleapis/python-debugger-client/issues/61)) ([57c2e93](https://github.com/googleapis/python-debugger-client/commit/57c2e9396b2b56e7bed4fe49d68f2cb0a9495a22)) + + +### Bug Fixes + +* resolve DuplicateCredentialArgs error when using credentials_file ([a4fe64d](https://github.com/googleapis/python-debugger-client/commit/a4fe64ddb07ff580ec7ba64fe02629678117a1bf)) + ### [1.2.1](https://www.github.com/googleapis/python-debugger-client/compare/v1.2.0...v1.2.1) (2021-11-01) diff --git a/README.rst b/README.rst index 7d813c5..ac17213 100644 --- a/README.rst +++ b/README.rst @@ -17,7 +17,7 @@ view the application state without adding logging statements. .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-debugger-client.svg :target: https://pypi.org/project/google-cloud-debugger-client/ .. _Cloud Debugger: https://cloud.google.com/debugger/docs -.. _Client Library Documentation: https://googleapis.dev/python/clouddebugger/latest +.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/clouddebugger/latest .. _Product Documentation: https://cloud.google.com/debugger/docs Quick Start diff --git a/google/cloud/debugger/__init__.py b/google/cloud/debugger/__init__.py index 172f407..13f3316 100644 --- a/google/cloud/debugger/__init__.py +++ b/google/cloud/debugger/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/debugger_v2/__init__.py b/google/cloud/debugger_v2/__init__.py index 044a833..78f5d3e 100644 --- a/google/cloud/debugger_v2/__init__.py +++ b/google/cloud/debugger_v2/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/debugger_v2/services/__init__.py b/google/cloud/debugger_v2/services/__init__.py index 4de6597..e8e1c38 100644 --- a/google/cloud/debugger_v2/services/__init__.py +++ b/google/cloud/debugger_v2/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/debugger_v2/services/controller2/__init__.py b/google/cloud/debugger_v2/services/controller2/__init__.py index 6560481..c6ec2f0 100644 --- a/google/cloud/debugger_v2/services/controller2/__init__.py +++ b/google/cloud/debugger_v2/services/controller2/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/debugger_v2/services/controller2/async_client.py b/google/cloud/debugger_v2/services/controller2/async_client.py index e53901f..c08f317 100644 --- a/google/cloud/debugger_v2/services/controller2/async_client.py +++ b/google/cloud/debugger_v2/services/controller2/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.debugger_v2.types import controller from google.cloud.debugger_v2.types import data @@ -119,6 +122,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return Controller2Client.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> Controller2Transport: """Returns the transport used by the client instance. @@ -201,6 +240,25 @@ async def register_debuggee( format. Agents must handle ``debuggee_id`` value changing upon re-registration. + + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_register_debuggee(): + # Create a client + client = debugger_v2.Controller2Client() + + # Initialize request argument(s) + request = debugger_v2.RegisterDebuggeeRequest( + ) + + # Make the request + response = client.register_debuggee(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.RegisterDebuggeeRequest, dict]): The request object. Request to register a debuggee. @@ -223,7 +281,7 @@ async def register_debuggee( Response for registering a debuggee. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee]) if request is not None and has_flattened_params: @@ -277,6 +335,26 @@ async def list_active_breakpoints( breakpoints that are completed until the controller removes them from the active list to avoid setting those breakpoints again. + + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_list_active_breakpoints(): + # Create a client + client = debugger_v2.Controller2Client() + + # Initialize request argument(s) + request = debugger_v2.ListActiveBreakpointsRequest( + debuggee_id="debuggee_id_value", + ) + + # Make the request + response = client.list_active_breakpoints(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.ListActiveBreakpointsRequest, dict]): The request object. Request to list active breakpoints. @@ -298,7 +376,7 @@ async def list_active_breakpoints( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id]) if request is not None and has_flattened_params: @@ -358,6 +436,26 @@ async def update_active_breakpoint( changes such as canonicalizing a value or snapping the location to the correct line of code. + + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_update_active_breakpoint(): + # Create a client + client = debugger_v2.Controller2Client() + + # Initialize request argument(s) + request = debugger_v2.UpdateActiveBreakpointRequest( + debuggee_id="debuggee_id_value", + ) + + # Make the request + response = client.update_active_breakpoint(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.UpdateActiveBreakpointRequest, dict]): The request object. Request to update an active @@ -391,7 +489,7 @@ async def update_active_breakpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id, breakpoint_]) if request is not None and has_flattened_params: diff --git a/google/cloud/debugger_v2/services/controller2/client.py b/google/cloud/debugger_v2/services/controller2/client.py index dee8747..f3914f5 100644 --- a/google/cloud/debugger_v2/services/controller2/client.py +++ b/google/cloud/debugger_v2/services/controller2/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.debugger_v2.types import controller from google.cloud.debugger_v2.types import data @@ -236,6 +238,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -286,50 +355,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, Controller2Transport): # transport is a Controller2Transport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -341,6 +382,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -375,6 +425,25 @@ def register_debuggee( format. Agents must handle ``debuggee_id`` value changing upon re-registration. + + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_register_debuggee(): + # Create a client + client = debugger_v2.Controller2Client() + + # Initialize request argument(s) + request = debugger_v2.RegisterDebuggeeRequest( + ) + + # Make the request + response = client.register_debuggee(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.RegisterDebuggeeRequest, dict]): The request object. Request to register a debuggee. @@ -397,7 +466,7 @@ def register_debuggee( Response for registering a debuggee. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee]) if request is not None and has_flattened_params: @@ -451,6 +520,26 @@ def list_active_breakpoints( breakpoints that are completed until the controller removes them from the active list to avoid setting those breakpoints again. + + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_list_active_breakpoints(): + # Create a client + client = debugger_v2.Controller2Client() + + # Initialize request argument(s) + request = debugger_v2.ListActiveBreakpointsRequest( + debuggee_id="debuggee_id_value", + ) + + # Make the request + response = client.list_active_breakpoints(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.ListActiveBreakpointsRequest, dict]): The request object. Request to list active breakpoints. @@ -472,7 +561,7 @@ def list_active_breakpoints( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id]) if request is not None and has_flattened_params: @@ -522,6 +611,26 @@ def update_active_breakpoint( changes such as canonicalizing a value or snapping the location to the correct line of code. + + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_update_active_breakpoint(): + # Create a client + client = debugger_v2.Controller2Client() + + # Initialize request argument(s) + request = debugger_v2.UpdateActiveBreakpointRequest( + debuggee_id="debuggee_id_value", + ) + + # Make the request + response = client.update_active_breakpoint(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.UpdateActiveBreakpointRequest, dict]): The request object. Request to update an active @@ -555,7 +664,7 @@ def update_active_breakpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id, breakpoint_]) if request is not None and has_flattened_params: diff --git a/google/cloud/debugger_v2/services/controller2/transports/__init__.py b/google/cloud/debugger_v2/services/controller2/transports/__init__.py index fcf3caf..ccbb3cc 100644 --- a/google/cloud/debugger_v2/services/controller2/transports/__init__.py +++ b/google/cloud/debugger_v2/services/controller2/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/debugger_v2/services/controller2/transports/base.py b/google/cloud/debugger_v2/services/controller2/transports/base.py index 5d80888..9d06849 100644 --- a/google/cloud/debugger_v2/services/controller2/transports/base.py +++ b/google/cloud/debugger_v2/services/controller2/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -104,7 +104,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/debugger_v2/services/controller2/transports/grpc.py b/google/cloud/debugger_v2/services/controller2/transports/grpc.py index eb82c5f..e3756bc 100644 --- a/google/cloud/debugger_v2/services/controller2/transports/grpc.py +++ b/google/cloud/debugger_v2/services/controller2/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -179,8 +179,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/debugger_v2/services/controller2/transports/grpc_asyncio.py b/google/cloud/debugger_v2/services/controller2/transports/grpc_asyncio.py index 172c6b0..3fa3c06 100644 --- a/google/cloud/debugger_v2/services/controller2/transports/grpc_asyncio.py +++ b/google/cloud/debugger_v2/services/controller2/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -224,8 +224,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/debugger_v2/services/debugger2/__init__.py b/google/cloud/debugger_v2/services/debugger2/__init__.py index 8eee46a..269f5aa 100644 --- a/google/cloud/debugger_v2/services/debugger2/__init__.py +++ b/google/cloud/debugger_v2/services/debugger2/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/debugger_v2/services/debugger2/async_client.py b/google/cloud/debugger_v2/services/debugger2/async_client.py index c8db347..5e15048 100644 --- a/google/cloud/debugger_v2/services/debugger2/async_client.py +++ b/google/cloud/debugger_v2/services/debugger2/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.debugger_v2.types import data from google.cloud.debugger_v2.types import debugger @@ -108,6 +111,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return Debugger2Client.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> Debugger2Transport: """Returns the transport used by the client instance. @@ -181,6 +220,26 @@ async def set_breakpoint( ) -> debugger.SetBreakpointResponse: r"""Sets the breakpoint to the debuggee. + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_set_breakpoint(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.SetBreakpointRequest( + debuggee_id="debuggee_id_value", + client_version="client_version_value", + ) + + # Make the request + response = client.set_breakpoint(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.SetBreakpointRequest, dict]): The request object. Request to set a breakpoint @@ -217,7 +276,7 @@ async def set_breakpoint( Response for setting a breakpoint. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id, breakpoint_, client_version]) if request is not None and has_flattened_params: @@ -264,6 +323,27 @@ async def get_breakpoint( ) -> debugger.GetBreakpointResponse: r"""Gets breakpoint information. + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_get_breakpoint(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.GetBreakpointRequest( + debuggee_id="debuggee_id_value", + breakpoint_id="breakpoint_id_value", + client_version="client_version_value", + ) + + # Make the request + response = client.get_breakpoint(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.GetBreakpointRequest, dict]): The request object. Request to get breakpoint @@ -303,7 +383,7 @@ async def get_breakpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id, breakpoint_id, client_version]) if request is not None and has_flattened_params: @@ -360,6 +440,24 @@ async def delete_breakpoint( ) -> None: r"""Deletes the breakpoint from the debuggee. + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_delete_breakpoint(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.DeleteBreakpointRequest( + debuggee_id="debuggee_id_value", + breakpoint_id="breakpoint_id_value", + client_version="client_version_value", + ) + + # Make the request + client.delete_breakpoint(request=request) + Args: request (Union[google.cloud.debugger_v2.types.DeleteBreakpointRequest, dict]): The request object. Request to delete a breakpoint. @@ -392,7 +490,7 @@ async def delete_breakpoint( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id, breakpoint_id, client_version]) if request is not None and has_flattened_params: @@ -447,6 +545,26 @@ async def list_breakpoints( ) -> debugger.ListBreakpointsResponse: r"""Lists all breakpoints for the debuggee. + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_list_breakpoints(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.ListBreakpointsRequest( + debuggee_id="debuggee_id_value", + client_version="client_version_value", + ) + + # Make the request + response = client.list_breakpoints(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.ListBreakpointsRequest, dict]): The request object. Request to list breakpoints. @@ -476,7 +594,7 @@ async def list_breakpoints( Response for listing breakpoints. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id, client_version]) if request is not None and has_flattened_params: @@ -530,6 +648,26 @@ async def list_debuggees( ) -> debugger.ListDebuggeesResponse: r"""Lists all the debuggees that the user has access to. + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_list_debuggees(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.ListDebuggeesRequest( + project="project_value", + client_version="client_version_value", + ) + + # Make the request + response = client.list_debuggees(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.ListDebuggeesRequest, dict]): The request object. Request to list debuggees. @@ -559,7 +697,7 @@ async def list_debuggees( Response for listing debuggees. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([project, client_version]) if request is not None and has_flattened_params: diff --git a/google/cloud/debugger_v2/services/debugger2/client.py b/google/cloud/debugger_v2/services/debugger2/client.py index a2fbe87..2a73d87 100644 --- a/google/cloud/debugger_v2/services/debugger2/client.py +++ b/google/cloud/debugger_v2/services/debugger2/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.debugger_v2.types import data from google.cloud.debugger_v2.types import debugger @@ -227,6 +229,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -277,50 +346,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, Debugger2Transport): # transport is a Debugger2Transport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -332,6 +373,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -357,6 +407,26 @@ def set_breakpoint( ) -> debugger.SetBreakpointResponse: r"""Sets the breakpoint to the debuggee. + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_set_breakpoint(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.SetBreakpointRequest( + debuggee_id="debuggee_id_value", + client_version="client_version_value", + ) + + # Make the request + response = client.set_breakpoint(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.SetBreakpointRequest, dict]): The request object. Request to set a breakpoint @@ -393,7 +463,7 @@ def set_breakpoint( Response for setting a breakpoint. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id, breakpoint_, client_version]) if request is not None and has_flattened_params: @@ -440,6 +510,27 @@ def get_breakpoint( ) -> debugger.GetBreakpointResponse: r"""Gets breakpoint information. + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_get_breakpoint(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.GetBreakpointRequest( + debuggee_id="debuggee_id_value", + breakpoint_id="breakpoint_id_value", + client_version="client_version_value", + ) + + # Make the request + response = client.get_breakpoint(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.GetBreakpointRequest, dict]): The request object. Request to get breakpoint @@ -479,7 +570,7 @@ def get_breakpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id, breakpoint_id, client_version]) if request is not None and has_flattened_params: @@ -526,6 +617,24 @@ def delete_breakpoint( ) -> None: r"""Deletes the breakpoint from the debuggee. + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_delete_breakpoint(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.DeleteBreakpointRequest( + debuggee_id="debuggee_id_value", + breakpoint_id="breakpoint_id_value", + client_version="client_version_value", + ) + + # Make the request + client.delete_breakpoint(request=request) + Args: request (Union[google.cloud.debugger_v2.types.DeleteBreakpointRequest, dict]): The request object. Request to delete a breakpoint. @@ -558,7 +667,7 @@ def delete_breakpoint( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id, breakpoint_id, client_version]) if request is not None and has_flattened_params: @@ -603,6 +712,26 @@ def list_breakpoints( ) -> debugger.ListBreakpointsResponse: r"""Lists all breakpoints for the debuggee. + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_list_breakpoints(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.ListBreakpointsRequest( + debuggee_id="debuggee_id_value", + client_version="client_version_value", + ) + + # Make the request + response = client.list_breakpoints(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.ListBreakpointsRequest, dict]): The request object. Request to list breakpoints. @@ -632,7 +761,7 @@ def list_breakpoints( Response for listing breakpoints. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([debuggee_id, client_version]) if request is not None and has_flattened_params: @@ -676,6 +805,26 @@ def list_debuggees( ) -> debugger.ListDebuggeesResponse: r"""Lists all the debuggees that the user has access to. + .. code-block:: python + + from google.cloud import debugger_v2 + + def sample_list_debuggees(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.ListDebuggeesRequest( + project="project_value", + client_version="client_version_value", + ) + + # Make the request + response = client.list_debuggees(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.debugger_v2.types.ListDebuggeesRequest, dict]): The request object. Request to list debuggees. @@ -705,7 +854,7 @@ def list_debuggees( Response for listing debuggees. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([project, client_version]) if request is not None and has_flattened_params: diff --git a/google/cloud/debugger_v2/services/debugger2/transports/__init__.py b/google/cloud/debugger_v2/services/debugger2/transports/__init__.py index 6ab6f37..681104d 100644 --- a/google/cloud/debugger_v2/services/debugger2/transports/__init__.py +++ b/google/cloud/debugger_v2/services/debugger2/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/debugger_v2/services/debugger2/transports/base.py b/google/cloud/debugger_v2/services/debugger2/transports/base.py index 7afaabd..c9ce324 100644 --- a/google/cloud/debugger_v2/services/debugger2/transports/base.py +++ b/google/cloud/debugger_v2/services/debugger2/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -105,7 +105,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/debugger_v2/services/debugger2/transports/grpc.py b/google/cloud/debugger_v2/services/debugger2/transports/grpc.py index 3015b8f..9df8b3d 100644 --- a/google/cloud/debugger_v2/services/debugger2/transports/grpc.py +++ b/google/cloud/debugger_v2/services/debugger2/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -171,8 +171,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/debugger_v2/services/debugger2/transports/grpc_asyncio.py b/google/cloud/debugger_v2/services/debugger2/transports/grpc_asyncio.py index da08e70..9c4c23b 100644 --- a/google/cloud/debugger_v2/services/debugger2/transports/grpc_asyncio.py +++ b/google/cloud/debugger_v2/services/debugger2/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -216,8 +216,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/debugger_v2/types/__init__.py b/google/cloud/debugger_v2/types/__init__.py index fdc607b..9c5f482 100644 --- a/google/cloud/debugger_v2/types/__init__.py +++ b/google/cloud/debugger_v2/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/debugger_v2/types/controller.py b/google/cloud/debugger_v2/types/controller.py index 0e10db8..51df565 100644 --- a/google/cloud/debugger_v2/types/controller.py +++ b/google/cloud/debugger_v2/types/controller.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/debugger_v2/types/data.py b/google/cloud/debugger_v2/types/data.py index 2e3b2bf..adf429b 100644 --- a/google/cloud/debugger_v2/types/data.py +++ b/google/cloud/debugger_v2/types/data.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/debugger_v2/types/debugger.py b/google/cloud/debugger_v2/types/debugger.py index 281d2a7..0c34f2b 100644 --- a/google/cloud/debugger_v2/types/debugger.py +++ b/google/cloud/debugger_v2/types/debugger.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/noxfile.py b/noxfile.py index de41c6b..2a2001c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -175,7 +175,7 @@ def cover(session): test runs (not system test runs), and then erases coverage data. """ session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=99") + session.run("coverage", "report", "--show-missing", "--fail-under=100") session.run("coverage", "erase") diff --git a/owlbot.py b/owlbot.py index 1eb84cd..0f3e541 100644 --- a/owlbot.py +++ b/owlbot.py @@ -59,62 +59,9 @@ # Add templated files # ---------------------------------------------------------------------------- -templated_files = gcp.CommonTemplates().py_library(cov_level=99, microgenerator=True) +templated_files = gcp.CommonTemplates().py_library(cov_level=100, microgenerator=True) python.py_samples(skip_readmes=True) s.move(templated_files, excludes=[".coveragerc"]) # the microgenerator has a good coveragerc file -# Remove the replacements below once https://github.com/googleapis/synthtool/pull/1188 is merged - -# Update googleapis/repo-automation-bots repo to main in .kokoro/*.sh files -s.replace(".kokoro/*.sh", "repo-automation-bots/tree/master", "repo-automation-bots/tree/main") - -# Customize CONTRIBUTING.rst to replace master with main -s.replace( - "CONTRIBUTING.rst", - "fetch and merge changes from upstream into master", - "fetch and merge changes from upstream into main", -) - -s.replace( - "CONTRIBUTING.rst", - "git merge upstream/master", - "git merge upstream/main", -) - -s.replace( - "CONTRIBUTING.rst", - """export GOOGLE_CLOUD_TESTING_BRANCH=\"master\"""", - """export GOOGLE_CLOUD_TESTING_BRANCH=\"main\"""", -) - -s.replace( - "CONTRIBUTING.rst", - "remote \(``master``\)", - "remote (``main``)", -) - -s.replace( - "CONTRIBUTING.rst", - "blob/master/CONTRIBUTING.rst", - "blob/main/CONTRIBUTING.rst", -) - -s.replace( - "CONTRIBUTING.rst", - "blob/master/noxfile.py", - "blob/main/noxfile.py", -) - -s.replace( - "docs/conf.py", - "master_doc", - "root_doc", -) - -s.replace( - "docs/conf.py", - "# The master toctree document.", - "# The root toctree document.", -) # ---------------------------------------------------------------------------- # Run blacken session diff --git a/samples/generated_samples/clouddebugger_v2_generated_controller2_list_active_breakpoints_async.py b/samples/generated_samples/clouddebugger_v2_generated_controller2_list_active_breakpoints_async.py new file mode 100644 index 0000000..535fdc1 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_controller2_list_active_breakpoints_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListActiveBreakpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Controller2_ListActiveBreakpoints_async] +from google.cloud import debugger_v2 + + +async def sample_list_active_breakpoints(): + # Create a client + client = debugger_v2.Controller2AsyncClient() + + # Initialize request argument(s) + request = debugger_v2.ListActiveBreakpointsRequest( + debuggee_id="debuggee_id_value", + ) + + # Make the request + response = await client.list_active_breakpoints(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Controller2_ListActiveBreakpoints_async] diff --git a/samples/generated_samples/clouddebugger_v2_generated_controller2_list_active_breakpoints_sync.py b/samples/generated_samples/clouddebugger_v2_generated_controller2_list_active_breakpoints_sync.py new file mode 100644 index 0000000..a385e95 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_controller2_list_active_breakpoints_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListActiveBreakpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Controller2_ListActiveBreakpoints_sync] +from google.cloud import debugger_v2 + + +def sample_list_active_breakpoints(): + # Create a client + client = debugger_v2.Controller2Client() + + # Initialize request argument(s) + request = debugger_v2.ListActiveBreakpointsRequest( + debuggee_id="debuggee_id_value", + ) + + # Make the request + response = client.list_active_breakpoints(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Controller2_ListActiveBreakpoints_sync] diff --git a/samples/generated_samples/clouddebugger_v2_generated_controller2_register_debuggee_async.py b/samples/generated_samples/clouddebugger_v2_generated_controller2_register_debuggee_async.py new file mode 100644 index 0000000..c8d695c --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_controller2_register_debuggee_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RegisterDebuggee +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Controller2_RegisterDebuggee_async] +from google.cloud import debugger_v2 + + +async def sample_register_debuggee(): + # Create a client + client = debugger_v2.Controller2AsyncClient() + + # Initialize request argument(s) + request = debugger_v2.RegisterDebuggeeRequest( + ) + + # Make the request + response = await client.register_debuggee(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Controller2_RegisterDebuggee_async] diff --git a/samples/generated_samples/clouddebugger_v2_generated_controller2_register_debuggee_sync.py b/samples/generated_samples/clouddebugger_v2_generated_controller2_register_debuggee_sync.py new file mode 100644 index 0000000..bb031e6 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_controller2_register_debuggee_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RegisterDebuggee +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Controller2_RegisterDebuggee_sync] +from google.cloud import debugger_v2 + + +def sample_register_debuggee(): + # Create a client + client = debugger_v2.Controller2Client() + + # Initialize request argument(s) + request = debugger_v2.RegisterDebuggeeRequest( + ) + + # Make the request + response = client.register_debuggee(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Controller2_RegisterDebuggee_sync] diff --git a/samples/generated_samples/clouddebugger_v2_generated_controller2_update_active_breakpoint_async.py b/samples/generated_samples/clouddebugger_v2_generated_controller2_update_active_breakpoint_async.py new file mode 100644 index 0000000..7db54d8 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_controller2_update_active_breakpoint_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateActiveBreakpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Controller2_UpdateActiveBreakpoint_async] +from google.cloud import debugger_v2 + + +async def sample_update_active_breakpoint(): + # Create a client + client = debugger_v2.Controller2AsyncClient() + + # Initialize request argument(s) + request = debugger_v2.UpdateActiveBreakpointRequest( + debuggee_id="debuggee_id_value", + ) + + # Make the request + response = await client.update_active_breakpoint(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Controller2_UpdateActiveBreakpoint_async] diff --git a/samples/generated_samples/clouddebugger_v2_generated_controller2_update_active_breakpoint_sync.py b/samples/generated_samples/clouddebugger_v2_generated_controller2_update_active_breakpoint_sync.py new file mode 100644 index 0000000..a868ae9 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_controller2_update_active_breakpoint_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateActiveBreakpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Controller2_UpdateActiveBreakpoint_sync] +from google.cloud import debugger_v2 + + +def sample_update_active_breakpoint(): + # Create a client + client = debugger_v2.Controller2Client() + + # Initialize request argument(s) + request = debugger_v2.UpdateActiveBreakpointRequest( + debuggee_id="debuggee_id_value", + ) + + # Make the request + response = client.update_active_breakpoint(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Controller2_UpdateActiveBreakpoint_sync] diff --git a/samples/generated_samples/clouddebugger_v2_generated_debugger2_delete_breakpoint_async.py b/samples/generated_samples/clouddebugger_v2_generated_debugger2_delete_breakpoint_async.py new file mode 100644 index 0000000..c331029 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_debugger2_delete_breakpoint_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBreakpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Debugger2_DeleteBreakpoint_async] +from google.cloud import debugger_v2 + + +async def sample_delete_breakpoint(): + # Create a client + client = debugger_v2.Debugger2AsyncClient() + + # Initialize request argument(s) + request = debugger_v2.DeleteBreakpointRequest( + debuggee_id="debuggee_id_value", + breakpoint_id="breakpoint_id_value", + client_version="client_version_value", + ) + + # Make the request + await client.delete_breakpoint(request=request) + + +# [END clouddebugger_v2_generated_Debugger2_DeleteBreakpoint_async] diff --git a/samples/generated_samples/clouddebugger_v2_generated_debugger2_delete_breakpoint_sync.py b/samples/generated_samples/clouddebugger_v2_generated_debugger2_delete_breakpoint_sync.py new file mode 100644 index 0000000..7a2bbb7 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_debugger2_delete_breakpoint_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBreakpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Debugger2_DeleteBreakpoint_sync] +from google.cloud import debugger_v2 + + +def sample_delete_breakpoint(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.DeleteBreakpointRequest( + debuggee_id="debuggee_id_value", + breakpoint_id="breakpoint_id_value", + client_version="client_version_value", + ) + + # Make the request + client.delete_breakpoint(request=request) + + +# [END clouddebugger_v2_generated_Debugger2_DeleteBreakpoint_sync] diff --git a/samples/generated_samples/clouddebugger_v2_generated_debugger2_get_breakpoint_async.py b/samples/generated_samples/clouddebugger_v2_generated_debugger2_get_breakpoint_async.py new file mode 100644 index 0000000..afba7ed --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_debugger2_get_breakpoint_async.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBreakpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Debugger2_GetBreakpoint_async] +from google.cloud import debugger_v2 + + +async def sample_get_breakpoint(): + # Create a client + client = debugger_v2.Debugger2AsyncClient() + + # Initialize request argument(s) + request = debugger_v2.GetBreakpointRequest( + debuggee_id="debuggee_id_value", + breakpoint_id="breakpoint_id_value", + client_version="client_version_value", + ) + + # Make the request + response = await client.get_breakpoint(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Debugger2_GetBreakpoint_async] diff --git a/samples/generated_samples/clouddebugger_v2_generated_debugger2_get_breakpoint_sync.py b/samples/generated_samples/clouddebugger_v2_generated_debugger2_get_breakpoint_sync.py new file mode 100644 index 0000000..69245b5 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_debugger2_get_breakpoint_sync.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBreakpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Debugger2_GetBreakpoint_sync] +from google.cloud import debugger_v2 + + +def sample_get_breakpoint(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.GetBreakpointRequest( + debuggee_id="debuggee_id_value", + breakpoint_id="breakpoint_id_value", + client_version="client_version_value", + ) + + # Make the request + response = client.get_breakpoint(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Debugger2_GetBreakpoint_sync] diff --git a/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_breakpoints_async.py b/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_breakpoints_async.py new file mode 100644 index 0000000..ae51efc --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_breakpoints_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBreakpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Debugger2_ListBreakpoints_async] +from google.cloud import debugger_v2 + + +async def sample_list_breakpoints(): + # Create a client + client = debugger_v2.Debugger2AsyncClient() + + # Initialize request argument(s) + request = debugger_v2.ListBreakpointsRequest( + debuggee_id="debuggee_id_value", + client_version="client_version_value", + ) + + # Make the request + response = await client.list_breakpoints(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Debugger2_ListBreakpoints_async] diff --git a/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_breakpoints_sync.py b/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_breakpoints_sync.py new file mode 100644 index 0000000..d3bb098 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_breakpoints_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBreakpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Debugger2_ListBreakpoints_sync] +from google.cloud import debugger_v2 + + +def sample_list_breakpoints(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.ListBreakpointsRequest( + debuggee_id="debuggee_id_value", + client_version="client_version_value", + ) + + # Make the request + response = client.list_breakpoints(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Debugger2_ListBreakpoints_sync] diff --git a/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_debuggees_async.py b/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_debuggees_async.py new file mode 100644 index 0000000..93967fc --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_debuggees_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDebuggees +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Debugger2_ListDebuggees_async] +from google.cloud import debugger_v2 + + +async def sample_list_debuggees(): + # Create a client + client = debugger_v2.Debugger2AsyncClient() + + # Initialize request argument(s) + request = debugger_v2.ListDebuggeesRequest( + project="project_value", + client_version="client_version_value", + ) + + # Make the request + response = await client.list_debuggees(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Debugger2_ListDebuggees_async] diff --git a/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_debuggees_sync.py b/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_debuggees_sync.py new file mode 100644 index 0000000..cbfa227 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_debugger2_list_debuggees_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDebuggees +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Debugger2_ListDebuggees_sync] +from google.cloud import debugger_v2 + + +def sample_list_debuggees(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.ListDebuggeesRequest( + project="project_value", + client_version="client_version_value", + ) + + # Make the request + response = client.list_debuggees(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Debugger2_ListDebuggees_sync] diff --git a/samples/generated_samples/clouddebugger_v2_generated_debugger2_set_breakpoint_async.py b/samples/generated_samples/clouddebugger_v2_generated_debugger2_set_breakpoint_async.py new file mode 100644 index 0000000..1d9f7ba --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_debugger2_set_breakpoint_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SetBreakpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Debugger2_SetBreakpoint_async] +from google.cloud import debugger_v2 + + +async def sample_set_breakpoint(): + # Create a client + client = debugger_v2.Debugger2AsyncClient() + + # Initialize request argument(s) + request = debugger_v2.SetBreakpointRequest( + debuggee_id="debuggee_id_value", + client_version="client_version_value", + ) + + # Make the request + response = await client.set_breakpoint(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Debugger2_SetBreakpoint_async] diff --git a/samples/generated_samples/clouddebugger_v2_generated_debugger2_set_breakpoint_sync.py b/samples/generated_samples/clouddebugger_v2_generated_debugger2_set_breakpoint_sync.py new file mode 100644 index 0000000..14244f4 --- /dev/null +++ b/samples/generated_samples/clouddebugger_v2_generated_debugger2_set_breakpoint_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SetBreakpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-debugger-client + + +# [START clouddebugger_v2_generated_Debugger2_SetBreakpoint_sync] +from google.cloud import debugger_v2 + + +def sample_set_breakpoint(): + # Create a client + client = debugger_v2.Debugger2Client() + + # Initialize request argument(s) + request = debugger_v2.SetBreakpointRequest( + debuggee_id="debuggee_id_value", + client_version="client_version_value", + ) + + # Make the request + response = client.set_breakpoint(request=request) + + # Handle the response + print(response) + +# [END clouddebugger_v2_generated_Debugger2_SetBreakpoint_sync] diff --git a/samples/generated_samples/snippet_metadata_debugger_v2.json b/samples/generated_samples/snippet_metadata_debugger_v2.json new file mode 100644 index 0000000..eafbe07 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_debugger_v2.json @@ -0,0 +1,712 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Controller2" + }, + "shortName": "ListActiveBreakpoints" + } + }, + "file": "clouddebugger_v2_generated_controller2_list_active_breakpoints_async.py", + "regionTag": "clouddebugger_v2_generated_Controller2_ListActiveBreakpoints_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Controller2" + }, + "shortName": "ListActiveBreakpoints" + } + }, + "file": "clouddebugger_v2_generated_controller2_list_active_breakpoints_sync.py", + "regionTag": "clouddebugger_v2_generated_Controller2_ListActiveBreakpoints_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Controller2" + }, + "shortName": "RegisterDebuggee" + } + }, + "file": "clouddebugger_v2_generated_controller2_register_debuggee_async.py", + "regionTag": "clouddebugger_v2_generated_Controller2_RegisterDebuggee_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Controller2" + }, + "shortName": "RegisterDebuggee" + } + }, + "file": "clouddebugger_v2_generated_controller2_register_debuggee_sync.py", + "regionTag": "clouddebugger_v2_generated_Controller2_RegisterDebuggee_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Controller2" + }, + "shortName": "UpdateActiveBreakpoint" + } + }, + "file": "clouddebugger_v2_generated_controller2_update_active_breakpoint_async.py", + "regionTag": "clouddebugger_v2_generated_Controller2_UpdateActiveBreakpoint_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Controller2" + }, + "shortName": "UpdateActiveBreakpoint" + } + }, + "file": "clouddebugger_v2_generated_controller2_update_active_breakpoint_sync.py", + "regionTag": "clouddebugger_v2_generated_Controller2_UpdateActiveBreakpoint_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Debugger2" + }, + "shortName": "DeleteBreakpoint" + } + }, + "file": "clouddebugger_v2_generated_debugger2_delete_breakpoint_async.py", + "regionTag": "clouddebugger_v2_generated_Debugger2_DeleteBreakpoint_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Debugger2" + }, + "shortName": "DeleteBreakpoint" + } + }, + "file": "clouddebugger_v2_generated_debugger2_delete_breakpoint_sync.py", + "regionTag": "clouddebugger_v2_generated_Debugger2_DeleteBreakpoint_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Debugger2" + }, + "shortName": "GetBreakpoint" + } + }, + "file": "clouddebugger_v2_generated_debugger2_get_breakpoint_async.py", + "regionTag": "clouddebugger_v2_generated_Debugger2_GetBreakpoint_async", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 43, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Debugger2" + }, + "shortName": "GetBreakpoint" + } + }, + "file": "clouddebugger_v2_generated_debugger2_get_breakpoint_sync.py", + "regionTag": "clouddebugger_v2_generated_Debugger2_GetBreakpoint_sync", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 43, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Debugger2" + }, + "shortName": "ListBreakpoints" + } + }, + "file": "clouddebugger_v2_generated_debugger2_list_breakpoints_async.py", + "regionTag": "clouddebugger_v2_generated_Debugger2_ListBreakpoints_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Debugger2" + }, + "shortName": "ListBreakpoints" + } + }, + "file": "clouddebugger_v2_generated_debugger2_list_breakpoints_sync.py", + "regionTag": "clouddebugger_v2_generated_Debugger2_ListBreakpoints_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Debugger2" + }, + "shortName": "ListDebuggees" + } + }, + "file": "clouddebugger_v2_generated_debugger2_list_debuggees_async.py", + "regionTag": "clouddebugger_v2_generated_Debugger2_ListDebuggees_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Debugger2" + }, + "shortName": "ListDebuggees" + } + }, + "file": "clouddebugger_v2_generated_debugger2_list_debuggees_sync.py", + "regionTag": "clouddebugger_v2_generated_Debugger2_ListDebuggees_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Debugger2" + }, + "shortName": "SetBreakpoint" + } + }, + "file": "clouddebugger_v2_generated_debugger2_set_breakpoint_async.py", + "regionTag": "clouddebugger_v2_generated_Debugger2_SetBreakpoint_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Debugger2" + }, + "shortName": "SetBreakpoint" + } + }, + "file": "clouddebugger_v2_generated_debugger2_set_breakpoint_sync.py", + "regionTag": "clouddebugger_v2_generated_Debugger2_SetBreakpoint_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/scripts/fixup_debugger_v2_keywords.py b/scripts/fixup_debugger_v2_keywords.py index 0f21424..9802c14 100644 --- a/scripts/fixup_debugger_v2_keywords.py +++ b/scripts/fixup_debugger_v2_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/setup.py b/setup.py index 3036a1c..fc84e76 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ name = "google-cloud-debugger-client" description = "Cloud Debugger API client library" -version = "1.2.1" +version = "1.3.0" release_status = "Development Status :: 5 - Production/Stable" url = "https://github.com/googleapis/python-debugger-client" dependencies = [ diff --git a/tests/__init__.py b/tests/__init__.py index 4de6597..e8e1c38 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 4de6597..e8e1c38 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py index 4de6597..e8e1c38 100644 --- a/tests/unit/gapic/__init__.py +++ b/tests/unit/gapic/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/debugger_v2/__init__.py b/tests/unit/gapic/debugger_v2/__init__.py index 4de6597..e8e1c38 100644 --- a/tests/unit/gapic/debugger_v2/__init__.py +++ b/tests/unit/gapic/debugger_v2/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/debugger_v2/test_controller2.py b/tests/unit/gapic/debugger_v2/test_controller2.py index 04f2e24..e589508 100644 --- a/tests/unit/gapic/debugger_v2/test_controller2.py +++ b/tests/unit/gapic/debugger_v2/test_controller2.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -240,20 +240,20 @@ def test_controller2_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -310,7 +310,7 @@ def test_controller2_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -387,6 +387,83 @@ def test_controller2_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [Controller2Client, Controller2AsyncClient]) +@mock.patch.object( + Controller2Client, "DEFAULT_ENDPOINT", modify_default_endpoint(Controller2Client) +) +@mock.patch.object( + Controller2AsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(Controller2AsyncClient), +) +def test_controller2_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -405,7 +482,7 @@ def test_controller2_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -419,24 +496,26 @@ def test_controller2_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (Controller2Client, transports.Controller2GrpcTransport, "grpc"), + (Controller2Client, transports.Controller2GrpcTransport, "grpc", grpc_helpers), ( Controller2AsyncClient, transports.Controller2GrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_controller2_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -467,9 +546,72 @@ def test_controller2_client_client_options_from_dict(): ) -def test_register_debuggee( - transport: str = "grpc", request_type=controller.RegisterDebuggeeRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (Controller2Client, transports.Controller2GrpcTransport, "grpc", grpc_helpers), + ( + Controller2AsyncClient, + transports.Controller2GrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_controller2_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "clouddebugger.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud_debugger", + ), + scopes=None, + default_host="clouddebugger.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [controller.RegisterDebuggeeRequest, dict,]) +def test_register_debuggee(request_type, transport: str = "grpc"): client = Controller2Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -495,10 +637,6 @@ def test_register_debuggee( assert isinstance(response, controller.RegisterDebuggeeResponse) -def test_register_debuggee_from_dict(): - test_register_debuggee(request_type=dict) - - def test_register_debuggee_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. @@ -569,7 +707,9 @@ def test_register_debuggee_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].debuggee == data.Debuggee(id="id_value") + arg = args[0].debuggee + mock_val = data.Debuggee(id="id_value") + assert arg == mock_val def test_register_debuggee_flattened_error(): @@ -607,7 +747,9 @@ async def test_register_debuggee_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].debuggee == data.Debuggee(id="id_value") + arg = args[0].debuggee + mock_val = data.Debuggee(id="id_value") + assert arg == mock_val @pytest.mark.asyncio @@ -622,9 +764,10 @@ async def test_register_debuggee_flattened_error_async(): ) -def test_list_active_breakpoints( - transport: str = "grpc", request_type=controller.ListActiveBreakpointsRequest -): +@pytest.mark.parametrize( + "request_type", [controller.ListActiveBreakpointsRequest, dict,] +) +def test_list_active_breakpoints(request_type, transport: str = "grpc"): client = Controller2Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -654,10 +797,6 @@ def test_list_active_breakpoints( assert response.wait_expired is True -def test_list_active_breakpoints_from_dict(): - test_list_active_breakpoints(request_type=dict) - - def test_list_active_breakpoints_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. @@ -733,7 +872,9 @@ def test_list_active_breakpoints_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val def test_list_active_breakpoints_flattened_error(): @@ -771,7 +912,9 @@ async def test_list_active_breakpoints_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -786,9 +929,10 @@ async def test_list_active_breakpoints_flattened_error_async(): ) -def test_update_active_breakpoint( - transport: str = "grpc", request_type=controller.UpdateActiveBreakpointRequest -): +@pytest.mark.parametrize( + "request_type", [controller.UpdateActiveBreakpointRequest, dict,] +) +def test_update_active_breakpoint(request_type, transport: str = "grpc"): client = Controller2Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -814,10 +958,6 @@ def test_update_active_breakpoint( assert isinstance(response, controller.UpdateActiveBreakpointResponse) -def test_update_active_breakpoint_from_dict(): - test_update_active_breakpoint(request_type=dict) - - def test_update_active_breakpoint_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. @@ -891,8 +1031,12 @@ def test_update_active_breakpoint_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" - assert args[0].breakpoint_ == data.Breakpoint(id="id_value") + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val + arg = args[0].breakpoint_ + mock_val = data.Breakpoint(id="id_value") + assert arg == mock_val def test_update_active_breakpoint_flattened_error(): @@ -932,8 +1076,12 @@ async def test_update_active_breakpoint_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" - assert args[0].breakpoint_ == data.Breakpoint(id="id_value") + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val + arg = args[0].breakpoint_ + mock_val = data.Breakpoint(id="id_value") + assert arg == mock_val @pytest.mark.asyncio @@ -970,6 +1118,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.Controller2GrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = Controller2Client(client_options=options, transport=transport,) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = Controller2Client( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.Controller2GrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1437,7 +1602,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( @@ -1502,3 +1667,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (Controller2Client, transports.Controller2GrpcTransport), + (Controller2AsyncClient, transports.Controller2GrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + 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, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/debugger_v2/test_debugger2.py b/tests/unit/gapic/debugger_v2/test_debugger2.py index 10cb9ef..3f4810c 100644 --- a/tests/unit/gapic/debugger_v2/test_debugger2.py +++ b/tests/unit/gapic/debugger_v2/test_debugger2.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -235,20 +235,20 @@ def test_debugger2_client_client_options(client_class, transport_class, transpor # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -305,7 +305,7 @@ def test_debugger2_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -382,6 +382,83 @@ def test_debugger2_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [Debugger2Client, Debugger2AsyncClient]) +@mock.patch.object( + Debugger2Client, "DEFAULT_ENDPOINT", modify_default_endpoint(Debugger2Client) +) +@mock.patch.object( + Debugger2AsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(Debugger2AsyncClient), +) +def test_debugger2_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -400,7 +477,7 @@ def test_debugger2_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -414,24 +491,26 @@ def test_debugger2_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (Debugger2Client, transports.Debugger2GrpcTransport, "grpc"), + (Debugger2Client, transports.Debugger2GrpcTransport, "grpc", grpc_helpers), ( Debugger2AsyncClient, transports.Debugger2GrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_debugger2_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -462,9 +541,72 @@ def test_debugger2_client_client_options_from_dict(): ) -def test_set_breakpoint( - transport: str = "grpc", request_type=debugger.SetBreakpointRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (Debugger2Client, transports.Debugger2GrpcTransport, "grpc", grpc_helpers), + ( + Debugger2AsyncClient, + transports.Debugger2GrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_debugger2_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "clouddebugger.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud_debugger", + ), + scopes=None, + default_host="clouddebugger.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [debugger.SetBreakpointRequest, dict,]) +def test_set_breakpoint(request_type, transport: str = "grpc"): client = Debugger2Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -488,10 +630,6 @@ def test_set_breakpoint( assert isinstance(response, debugger.SetBreakpointResponse) -def test_set_breakpoint_from_dict(): - test_set_breakpoint(request_type=dict) - - def test_set_breakpoint_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. @@ -560,9 +698,15 @@ def test_set_breakpoint_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" - assert args[0].breakpoint_ == data.Breakpoint(id="id_value") - assert args[0].client_version == "client_version_value" + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val + arg = args[0].breakpoint_ + mock_val = data.Breakpoint(id="id_value") + assert arg == mock_val + arg = args[0].client_version + mock_val = "client_version_value" + assert arg == mock_val def test_set_breakpoint_flattened_error(): @@ -603,9 +747,15 @@ async def test_set_breakpoint_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" - assert args[0].breakpoint_ == data.Breakpoint(id="id_value") - assert args[0].client_version == "client_version_value" + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val + arg = args[0].breakpoint_ + mock_val = data.Breakpoint(id="id_value") + assert arg == mock_val + arg = args[0].client_version + mock_val = "client_version_value" + assert arg == mock_val @pytest.mark.asyncio @@ -623,9 +773,8 @@ async def test_set_breakpoint_flattened_error_async(): ) -def test_get_breakpoint( - transport: str = "grpc", request_type=debugger.GetBreakpointRequest -): +@pytest.mark.parametrize("request_type", [debugger.GetBreakpointRequest, dict,]) +def test_get_breakpoint(request_type, transport: str = "grpc"): client = Debugger2Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -649,10 +798,6 @@ def test_get_breakpoint( assert isinstance(response, debugger.GetBreakpointResponse) -def test_get_breakpoint_from_dict(): - test_get_breakpoint(request_type=dict) - - def test_get_breakpoint_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. @@ -721,9 +866,15 @@ def test_get_breakpoint_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" - assert args[0].breakpoint_id == "breakpoint_id_value" - assert args[0].client_version == "client_version_value" + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val + arg = args[0].breakpoint_id + mock_val = "breakpoint_id_value" + assert arg == mock_val + arg = args[0].client_version + mock_val = "client_version_value" + assert arg == mock_val def test_get_breakpoint_flattened_error(): @@ -764,9 +915,15 @@ async def test_get_breakpoint_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" - assert args[0].breakpoint_id == "breakpoint_id_value" - assert args[0].client_version == "client_version_value" + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val + arg = args[0].breakpoint_id + mock_val = "breakpoint_id_value" + assert arg == mock_val + arg = args[0].client_version + mock_val = "client_version_value" + assert arg == mock_val @pytest.mark.asyncio @@ -784,9 +941,8 @@ async def test_get_breakpoint_flattened_error_async(): ) -def test_delete_breakpoint( - transport: str = "grpc", request_type=debugger.DeleteBreakpointRequest -): +@pytest.mark.parametrize("request_type", [debugger.DeleteBreakpointRequest, dict,]) +def test_delete_breakpoint(request_type, transport: str = "grpc"): client = Debugger2Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -812,10 +968,6 @@ def test_delete_breakpoint( assert response is None -def test_delete_breakpoint_from_dict(): - test_delete_breakpoint(request_type=dict) - - def test_delete_breakpoint_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. @@ -888,9 +1040,15 @@ def test_delete_breakpoint_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" - assert args[0].breakpoint_id == "breakpoint_id_value" - assert args[0].client_version == "client_version_value" + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val + arg = args[0].breakpoint_id + mock_val = "breakpoint_id_value" + assert arg == mock_val + arg = args[0].client_version + mock_val = "client_version_value" + assert arg == mock_val def test_delete_breakpoint_flattened_error(): @@ -931,9 +1089,15 @@ async def test_delete_breakpoint_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" - assert args[0].breakpoint_id == "breakpoint_id_value" - assert args[0].client_version == "client_version_value" + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val + arg = args[0].breakpoint_id + mock_val = "breakpoint_id_value" + assert arg == mock_val + arg = args[0].client_version + mock_val = "client_version_value" + assert arg == mock_val @pytest.mark.asyncio @@ -951,9 +1115,8 @@ async def test_delete_breakpoint_flattened_error_async(): ) -def test_list_breakpoints( - transport: str = "grpc", request_type=debugger.ListBreakpointsRequest -): +@pytest.mark.parametrize("request_type", [debugger.ListBreakpointsRequest, dict,]) +def test_list_breakpoints(request_type, transport: str = "grpc"): client = Debugger2Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -980,10 +1143,6 @@ def test_list_breakpoints( assert response.next_wait_token == "next_wait_token_value" -def test_list_breakpoints_from_dict(): - test_list_breakpoints(request_type=dict) - - def test_list_breakpoints_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. @@ -1051,8 +1210,12 @@ def test_list_breakpoints_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" - assert args[0].client_version == "client_version_value" + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val + arg = args[0].client_version + mock_val = "client_version_value" + assert arg == mock_val def test_list_breakpoints_flattened_error(): @@ -1090,8 +1253,12 @@ async def test_list_breakpoints_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].debuggee_id == "debuggee_id_value" - assert args[0].client_version == "client_version_value" + arg = args[0].debuggee_id + mock_val = "debuggee_id_value" + assert arg == mock_val + arg = args[0].client_version + mock_val = "client_version_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1108,9 +1275,8 @@ async def test_list_breakpoints_flattened_error_async(): ) -def test_list_debuggees( - transport: str = "grpc", request_type=debugger.ListDebuggeesRequest -): +@pytest.mark.parametrize("request_type", [debugger.ListDebuggeesRequest, dict,]) +def test_list_debuggees(request_type, transport: str = "grpc"): client = Debugger2Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1134,10 +1300,6 @@ def test_list_debuggees( assert isinstance(response, debugger.ListDebuggeesResponse) -def test_list_debuggees_from_dict(): - test_list_debuggees(request_type=dict) - - def test_list_debuggees_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. @@ -1204,8 +1366,12 @@ def test_list_debuggees_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].project == "project_value" - assert args[0].client_version == "client_version_value" + arg = args[0].project + mock_val = "project_value" + assert arg == mock_val + arg = args[0].client_version + mock_val = "client_version_value" + assert arg == mock_val def test_list_debuggees_flattened_error(): @@ -1243,8 +1409,12 @@ async def test_list_debuggees_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].project == "project_value" - assert args[0].client_version == "client_version_value" + arg = args[0].project + mock_val = "project_value" + assert arg == mock_val + arg = args[0].client_version + mock_val = "client_version_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1281,6 +1451,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.Debugger2GrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = Debugger2Client(client_options=options, transport=transport,) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = Debugger2Client( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.Debugger2GrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1750,7 +1937,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( @@ -1815,3 +2002,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (Debugger2Client, transports.Debugger2GrpcTransport), + (Debugger2AsyncClient, transports.Debugger2GrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + 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, + always_use_jwt_access=True, + )