diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 0b3c8cd9..b668c04d 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,17 @@ +# 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:2f90537dd7df70f6b663cd654b1fa5dee483cf6a4edcfd46072b2775be8a23ec + digest: sha256:ed1f9983d5a935a89fe8085e8bb97d94e41015252c5b6c9771257cf8624367e6 + diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b26afefd..62aced93 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -8,5 +8,5 @@ # @googleapis/yoshi-python @googleapis/cdpe-cloudai are the default owners for changes in this repo * @googleapis/yoshi-python @googleapis/cdpe-cloudai -# @googleapis/python-samples-owners @googleapis/cdpe-cloudai are the default owners for samples changes -/samples/ @googleapis/python-samples-owners @googleapis/cdpe-cloudai +# @googleapis/python-samples-reviewers @googleapis/cdpe-cloudai are the default owners for samples changes +/samples/ @googleapis/python-samples-reviewers @googleapis/cdpe-cloudai diff --git a/.github/release-please.yml b/.github/release-please.yml index 4507ad05..466597e5 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1 +1,2 @@ releaseType: python +handleGHRelease: true diff --git a/.github/release-trigger.yml b/.github/release-trigger.yml new file mode 100644 index 00000000..d4ca9418 --- /dev/null +++ b/.github/release-trigger.yml @@ -0,0 +1 @@ +enabled: true diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 3e98ae70..37438d33 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -10,6 +10,5 @@ branchProtectionRules: - 'Kokoro' - 'cla/google' - 'Samples - Lint' - - 'Samples - Python 3.6' - 'Samples - Python 3.7' - 'Samples - Python 3.8' diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 00000000..f7b8344c --- /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 00000000..1e8b05c3 --- /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 00000000..e84424b8 --- /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=99 diff --git a/.kokoro/release.sh b/.kokoro/release.sh index 15990123..fd81d068 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-vision 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 de8ffad4..4e14286f 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,8 +23,18 @@ env_vars: { value: "github/python-vision/.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 d944e21a..18b2e4de 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -4,7 +4,7 @@ "product_documentation": "https://cloud.google.com/vision/docs/", "client_documentation": "https://cloud.google.com/python/docs/reference/vision/latest", "issue_tracker": "https://issuetracker.google.com/issues?q=status:open%20componentid:187174", - "release_level": "ga", + "release_level": "stable", "language": "python", "library_type": "GAPIC_COMBO", "repo": "googleapis/python-vision", @@ -12,5 +12,6 @@ "api_id": "vision.googleapis.com", "requires_billing": false, "default_version": "v1", - "codeowner_team": "@googleapis/cdpe-cloudai" + "codeowner_team": "@googleapis/cdpe-cloudai", + "api_shortname": "vision" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e3d59c3..9126a6ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ [1]: https://pypi.org/project/google-cloud-vision/#history +## [2.7.0](https://github.com/googleapis/python-vision/compare/v2.6.3...v2.7.0) (2022-02-28) + + +### Features + +* add api key support ([#300](https://github.com/googleapis/python-vision/issues/300)) ([25fc254](https://github.com/googleapis/python-vision/commit/25fc254a117f025bd0c7bddbc7b246b3c5a2b760)) + + +### Bug Fixes + +* resolve DuplicateCredentialArgs error when using credentials_file ([#304](https://github.com/googleapis/python-vision/issues/304)) ([6cca548](https://github.com/googleapis/python-vision/commit/6cca5487296127d7690734fdc610672b983607f2)) + + +### Documentation + +* add auto-generated samples ([#309](https://github.com/googleapis/python-vision/issues/309)) ([efc022d](https://github.com/googleapis/python-vision/commit/efc022d6b850dffbb621c066aa8fd1ff69cb0519)) + ### [2.6.3](https://www.github.com/googleapis/python-vision/compare/v2.6.2...v2.6.3) (2021-12-12) diff --git a/google/cloud/vision_v1/__init__.py b/google/cloud/vision_v1/__init__.py index 001f641a..bfe927d2 100644 --- a/google/cloud/vision_v1/__init__.py +++ b/google/cloud/vision_v1/__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/vision_v1/services/__init__.py b/google/cloud/vision_v1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/vision_v1/services/__init__.py +++ b/google/cloud/vision_v1/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/vision_v1/services/image_annotator/__init__.py b/google/cloud/vision_v1/services/image_annotator/__init__.py index 422732ba..b2fb517b 100644 --- a/google/cloud/vision_v1/services/image_annotator/__init__.py +++ b/google/cloud/vision_v1/services/image_annotator/__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/vision_v1/services/image_annotator/async_client.py b/google/cloud/vision_v1/services/image_annotator/async_client.py index 42d7fa6d..f8f2191a 100644 --- a/google/cloud/vision_v1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1/services/image_annotator/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,7 +16,7 @@ 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 @@ -113,6 +113,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 ImageAnnotatorClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ImageAnnotatorTransport: """Returns the transport used by the client instance. @@ -185,6 +221,25 @@ async def batch_annotate_images( r"""Run image detection and annotation for a batch of images. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_batch_annotate_images(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests @@ -209,7 +264,7 @@ async def batch_annotate_images( """ # 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([requests]) if request is not None and has_flattened_params: @@ -267,6 +322,25 @@ async def batch_annotate_files( perform detection and annotation for each image extracted. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_batch_annotate_files(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.BatchAnnotateFilesRequest( + ) + + # Make the request + response = client.batch_annotate_files(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.BatchAnnotateFilesRequest, dict]): The request object. A list of requests to annotate files @@ -291,7 +365,7 @@ async def batch_annotate_files( A list of file annotation responses. """ # 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([requests]) if request is not None and has_flattened_params: @@ -354,6 +428,29 @@ async def async_batch_annotate_images( in customer GCS bucket, each json file containing BatchAnnotateImagesResponse proto. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_async_batch_annotate_images(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.AsyncBatchAnnotateImagesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_images(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.AsyncBatchAnnotateImagesRequest, dict]): The request object. Request for async image annotation @@ -388,7 +485,7 @@ async def async_batch_annotate_images( """ # 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([requests, output_config]) if request is not None and has_flattened_params: @@ -455,6 +552,29 @@ async def async_batch_annotate_files( (metadata). ``Operation.response`` contains ``AsyncBatchAnnotateFilesResponse`` (results). + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation @@ -482,7 +602,7 @@ async def async_batch_annotate_files( """ # 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([requests]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1/services/image_annotator/client.py b/google/cloud/vision_v1/services/image_annotator/client.py index 220497d8..4a90a27d 100644 --- a/google/cloud/vision_v1/services/image_annotator/client.py +++ b/google/cloud/vision_v1/services/image_annotator/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. @@ -255,6 +255,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, *, @@ -305,57 +372,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + 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, ImageAnnotatorTransport): # transport is a ImageAnnotatorTransport 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." @@ -367,6 +399,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, @@ -391,6 +432,25 @@ def batch_annotate_images( r"""Run image detection and annotation for a batch of images. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_batch_annotate_images(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests @@ -415,7 +475,7 @@ def batch_annotate_images( """ # 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([requests]) if request is not None and has_flattened_params: @@ -466,6 +526,25 @@ def batch_annotate_files( perform detection and annotation for each image extracted. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_batch_annotate_files(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.BatchAnnotateFilesRequest( + ) + + # Make the request + response = client.batch_annotate_files(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.BatchAnnotateFilesRequest, dict]): The request object. A list of requests to annotate files @@ -490,7 +569,7 @@ def batch_annotate_files( A list of file annotation responses. """ # 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([requests]) if request is not None and has_flattened_params: @@ -546,6 +625,29 @@ def async_batch_annotate_images( in customer GCS bucket, each json file containing BatchAnnotateImagesResponse proto. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_async_batch_annotate_images(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.AsyncBatchAnnotateImagesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_images(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.AsyncBatchAnnotateImagesRequest, dict]): The request object. Request for async image annotation @@ -580,7 +682,7 @@ def async_batch_annotate_images( """ # 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([requests, output_config]) if request is not None and has_flattened_params: @@ -642,6 +744,29 @@ def async_batch_annotate_files( (metadata). ``Operation.response`` contains ``AsyncBatchAnnotateFilesResponse`` (results). + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation @@ -669,7 +794,7 @@ def async_batch_annotate_files( """ # 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([requests]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1/services/image_annotator/transports/__init__.py b/google/cloud/vision_v1/services/image_annotator/transports/__init__.py index 419b4293..bb856540 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/__init__.py +++ b/google/cloud/vision_v1/services/image_annotator/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/vision_v1/services/image_annotator/transports/base.py b/google/cloud/vision_v1/services/image_annotator/transports/base.py index b3cebed0..73affdfd 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1/services/image_annotator/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. @@ -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/vision_v1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1/services/image_annotator/transports/grpc.py index 7feec28f..fcf02b74 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1/services/image_annotator/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. @@ -164,8 +164,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, @@ -238,7 +241,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py index f4486945..97d2f74c 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1/services/image_annotator/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. @@ -209,8 +209,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, @@ -240,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/vision_v1/services/product_search/__init__.py b/google/cloud/vision_v1/services/product_search/__init__.py index f357996e..3b50e361 100644 --- a/google/cloud/vision_v1/services/product_search/__init__.py +++ b/google/cloud/vision_v1/services/product_search/__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/vision_v1/services/product_search/async_client.py b/google/cloud/vision_v1/services/product_search/async_client.py index f3ca08a3..91e79755 100644 --- a/google/cloud/vision_v1/services/product_search/async_client.py +++ b/google/cloud/vision_v1/services/product_search/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,7 +16,7 @@ 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 @@ -137,6 +137,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 ProductSearchClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ProductSearchTransport: """Returns the transport used by the client instance. @@ -215,6 +251,26 @@ async def create_product_set( - Returns INVALID_ARGUMENT if display_name is missing, or is longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_create_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.CreateProductSetRequest, dict]): The request object. Request message for the @@ -259,7 +315,7 @@ async def create_product_set( """ # 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([parent, product_set, product_set_id]) if request is not None and has_flattened_params: @@ -322,6 +378,27 @@ async def list_product_sets( - Returns INVALID_ARGUMENT if page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_list_product_sets(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1.types.ListProductSetsRequest, dict]): The request object. Request message for the @@ -350,7 +427,7 @@ async def list_product_sets( """ # 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([parent]) if request is not None and has_flattened_params: @@ -417,6 +494,26 @@ async def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_get_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = client.get_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.GetProductSetRequest, dict]): The request object. Request message for the @@ -446,7 +543,7 @@ async def get_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -512,6 +609,25 @@ async def update_product_set( update_mask but missing from the request or longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_update_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.UpdateProductSetRequest( + ) + + # Make the request + response = client.update_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.UpdateProductSetRequest, dict]): The request object. Request message for the @@ -548,7 +664,7 @@ async def update_product_set( """ # 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([product_set, update_mask]) if request is not None and has_flattened_params: @@ -612,6 +728,23 @@ async def delete_product_set( The actual image files are not deleted from Google Cloud Storage. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_delete_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + client.delete_product_set(request=request) + Args: request (Union[google.cloud.vision_v1.types.DeleteProductSetRequest, dict]): The request object. Request message for the @@ -632,7 +765,7 @@ async def delete_product_set( 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([name]) if request is not None and has_flattened_params: @@ -699,6 +832,26 @@ async def create_product( - Returns INVALID_ARGUMENT if product_category is missing or invalid. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_create_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.CreateProductRequest, dict]): The request object. Request message for the @@ -738,7 +891,7 @@ async def create_product( A Product contains ReferenceImages. """ # 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([parent, product, product_id]) if request is not None and has_flattened_params: @@ -801,6 +954,27 @@ async def list_products( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_list_products(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1.types.ListProductsRequest, dict]): The request object. Request message for the @@ -829,7 +1003,7 @@ async def list_products( """ # 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([parent]) if request is not None and has_flattened_params: @@ -896,6 +1070,26 @@ async def get_product( - Returns NOT_FOUND if the Product does not exist. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_get_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.GetProductRequest, dict]): The request object. Request message for the `GetProduct` @@ -920,7 +1114,7 @@ async def get_product( A Product contains ReferenceImages. """ # 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([name]) if request is not None and has_flattened_params: @@ -993,6 +1187,25 @@ async def update_product( - Returns INVALID_ARGUMENT if product_category is present in update_mask. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_update_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.UpdateProductRequest( + ) + + # Make the request + response = client.update_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.UpdateProductRequest, dict]): The request object. Request message for the @@ -1026,7 +1239,7 @@ async def update_product( A Product contains ReferenceImages. """ # 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([product, update_mask]) if request is not None and has_flattened_params: @@ -1092,6 +1305,23 @@ async def delete_product( ProductSets containing the product may still work until all related caches are refreshed. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_delete_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + client.delete_product(request=request) + Args: request (Union[google.cloud.vision_v1.types.DeleteProductRequest, dict]): The request object. Request message for the @@ -1112,7 +1342,7 @@ async def delete_product( 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([name]) if request is not None and has_flattened_params: @@ -1191,6 +1421,30 @@ async def create_reference_image( - Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_create_reference_image(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + reference_image = vision_v1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = client.create_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.CreateReferenceImageRequest, dict]): The request object. Request message for the @@ -1236,7 +1490,7 @@ async def create_reference_image( """ # 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([parent, reference_image, reference_image_id]) if request is not None and has_flattened_params: @@ -1300,6 +1554,23 @@ async def delete_reference_image( The actual image files are not deleted from Google Cloud Storage. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_delete_reference_image(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + client.delete_reference_image(request=request) + Args: request (Union[google.cloud.vision_v1.types.DeleteReferenceImageRequest, dict]): The request object. Request message for the @@ -1321,7 +1592,7 @@ async def delete_reference_image( 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([name]) if request is not None and has_flattened_params: @@ -1383,6 +1654,27 @@ async def list_reference_images( - Returns INVALID_ARGUMENT if the page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_list_reference_images(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1.types.ListReferenceImagesRequest, dict]): The request object. Request message for the @@ -1412,7 +1704,7 @@ async def list_reference_images( """ # 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([parent]) if request is not None and has_flattened_params: @@ -1479,6 +1771,26 @@ async def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_get_reference_image(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = client.get_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.GetReferenceImageRequest, dict]): The request object. Request message for the @@ -1506,7 +1818,7 @@ async def get_reference_image( """ # 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([name]) if request is not None and has_flattened_params: @@ -1574,6 +1886,24 @@ async def add_product_to_product_set( - Returns NOT_FOUND if the Product or the ProductSet doesn't exist. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_add_product_to_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.add_product_to_product_set(request=request) + Args: request (Union[google.cloud.vision_v1.types.AddProductToProductSetRequest, dict]): The request object. Request message for the @@ -1605,7 +1935,7 @@ async def add_product_to_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1666,6 +1996,23 @@ async def remove_product_from_product_set( ) -> None: r"""Removes a Product from the specified ProductSet. + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.remove_product_from_product_set(request=request) + Args: request (Union[google.cloud.vision_v1.types.RemoveProductFromProductSetRequest, dict]): The request object. Request message for the @@ -1697,7 +2044,7 @@ async def remove_product_from_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1764,6 +2111,27 @@ async def list_products_in_product_set( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_list_products_in_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1.types.ListProductsInProductSetRequest, dict]): The request object. Request message for the @@ -1794,7 +2162,7 @@ async def list_products_in_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -1869,6 +2237,30 @@ async def import_product_sets( Storage. For the format of the csv file please see [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_import_product_sets(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.ImportProductSetsRequest, dict]): The request object. Request message for the @@ -1911,7 +2303,7 @@ async def import_product_sets( """ # 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([parent, input_config]) if request is not None and has_flattened_params: @@ -2001,6 +2393,30 @@ async def purge_products( request. ``Operation.metadata`` contains ``BatchOperationMetadata``. (progress) + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_purge_products(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.PurgeProductsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.purge_products(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.PurgeProductsRequest, dict]): The request object. Request message for the @@ -2040,7 +2456,7 @@ async def purge_products( """ # 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([parent]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1/services/product_search/client.py b/google/cloud/vision_v1/services/product_search/client.py index 9d64ec1e..7e1d0966 100644 --- a/google/cloud/vision_v1/services/product_search/client.py +++ b/google/cloud/vision_v1/services/product_search/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. @@ -294,6 +294,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, *, @@ -344,57 +411,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + 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, ProductSearchTransport): # transport is a ProductSearchTransport 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." @@ -406,6 +438,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, @@ -436,6 +477,26 @@ def create_product_set( - Returns INVALID_ARGUMENT if display_name is missing, or is longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_create_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.CreateProductSetRequest, dict]): The request object. Request message for the @@ -480,7 +541,7 @@ def create_product_set( """ # 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([parent, product_set, product_set_id]) if request is not None and has_flattened_params: @@ -536,6 +597,27 @@ def list_product_sets( - Returns INVALID_ARGUMENT if page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_list_product_sets(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1.types.ListProductSetsRequest, dict]): The request object. Request message for the @@ -564,7 +646,7 @@ def list_product_sets( """ # 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([parent]) if request is not None and has_flattened_params: @@ -621,6 +703,26 @@ def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_get_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = client.get_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.GetProductSetRequest, dict]): The request object. Request message for the @@ -650,7 +752,7 @@ def get_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -706,6 +808,25 @@ def update_product_set( update_mask but missing from the request or longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_update_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.UpdateProductSetRequest( + ) + + # Make the request + response = client.update_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.UpdateProductSetRequest, dict]): The request object. Request message for the @@ -742,7 +863,7 @@ def update_product_set( """ # 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([product_set, update_mask]) if request is not None and has_flattened_params: @@ -796,6 +917,23 @@ def delete_product_set( The actual image files are not deleted from Google Cloud Storage. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_delete_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + client.delete_product_set(request=request) + Args: request (Union[google.cloud.vision_v1.types.DeleteProductSetRequest, dict]): The request object. Request message for the @@ -816,7 +954,7 @@ def delete_product_set( 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([name]) if request is not None and has_flattened_params: @@ -873,6 +1011,26 @@ def create_product( - Returns INVALID_ARGUMENT if product_category is missing or invalid. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_create_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.CreateProductRequest, dict]): The request object. Request message for the @@ -912,7 +1070,7 @@ def create_product( A Product contains ReferenceImages. """ # 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([parent, product, product_id]) if request is not None and has_flattened_params: @@ -968,6 +1126,27 @@ def list_products( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_list_products(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1.types.ListProductsRequest, dict]): The request object. Request message for the @@ -996,7 +1175,7 @@ def list_products( """ # 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([parent]) if request is not None and has_flattened_params: @@ -1053,6 +1232,26 @@ def get_product( - Returns NOT_FOUND if the Product does not exist. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_get_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.GetProductRequest, dict]): The request object. Request message for the `GetProduct` @@ -1077,7 +1276,7 @@ def get_product( A Product contains ReferenceImages. """ # 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([name]) if request is not None and has_flattened_params: @@ -1140,6 +1339,25 @@ def update_product( - Returns INVALID_ARGUMENT if product_category is present in update_mask. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_update_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.UpdateProductRequest( + ) + + # Make the request + response = client.update_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.UpdateProductRequest, dict]): The request object. Request message for the @@ -1173,7 +1391,7 @@ def update_product( A Product contains ReferenceImages. """ # 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([product, update_mask]) if request is not None and has_flattened_params: @@ -1229,6 +1447,23 @@ def delete_product( ProductSets containing the product may still work until all related caches are refreshed. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_delete_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + client.delete_product(request=request) + Args: request (Union[google.cloud.vision_v1.types.DeleteProductRequest, dict]): The request object. Request message for the @@ -1249,7 +1484,7 @@ def delete_product( 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([name]) if request is not None and has_flattened_params: @@ -1318,6 +1553,30 @@ def create_reference_image( - Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_create_reference_image(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + reference_image = vision_v1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = client.create_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.CreateReferenceImageRequest, dict]): The request object. Request message for the @@ -1363,7 +1622,7 @@ def create_reference_image( """ # 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([parent, reference_image, reference_image_id]) if request is not None and has_flattened_params: @@ -1420,6 +1679,23 @@ def delete_reference_image( The actual image files are not deleted from Google Cloud Storage. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_delete_reference_image(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + client.delete_reference_image(request=request) + Args: request (Union[google.cloud.vision_v1.types.DeleteReferenceImageRequest, dict]): The request object. Request message for the @@ -1441,7 +1717,7 @@ def delete_reference_image( 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([name]) if request is not None and has_flattened_params: @@ -1493,6 +1769,27 @@ def list_reference_images( - Returns INVALID_ARGUMENT if the page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_list_reference_images(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1.types.ListReferenceImagesRequest, dict]): The request object. Request message for the @@ -1522,7 +1819,7 @@ def list_reference_images( """ # 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([parent]) if request is not None and has_flattened_params: @@ -1579,6 +1876,26 @@ def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_get_reference_image(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = client.get_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.GetReferenceImageRequest, dict]): The request object. Request message for the @@ -1606,7 +1923,7 @@ def get_reference_image( """ # 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([name]) if request is not None and has_flattened_params: @@ -1664,6 +1981,24 @@ def add_product_to_product_set( - Returns NOT_FOUND if the Product or the ProductSet doesn't exist. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_add_product_to_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.add_product_to_product_set(request=request) + Args: request (Union[google.cloud.vision_v1.types.AddProductToProductSetRequest, dict]): The request object. Request message for the @@ -1695,7 +2030,7 @@ def add_product_to_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1750,6 +2085,23 @@ def remove_product_from_product_set( ) -> None: r"""Removes a Product from the specified ProductSet. + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.remove_product_from_product_set(request=request) + Args: request (Union[google.cloud.vision_v1.types.RemoveProductFromProductSetRequest, dict]): The request object. Request message for the @@ -1781,7 +2133,7 @@ def remove_product_from_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1842,6 +2194,27 @@ def list_products_in_product_set( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_list_products_in_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1.types.ListProductsInProductSetRequest, dict]): The request object. Request message for the @@ -1872,7 +2245,7 @@ def list_products_in_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -1941,6 +2314,30 @@ def import_product_sets( Storage. For the format of the csv file please see [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_import_product_sets(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.ImportProductSetsRequest, dict]): The request object. Request message for the @@ -1983,7 +2380,7 @@ def import_product_sets( """ # 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([parent, input_config]) if request is not None and has_flattened_params: @@ -2066,6 +2463,30 @@ def purge_products( request. ``Operation.metadata`` contains ``BatchOperationMetadata``. (progress) + + .. code-block:: python + + from google.cloud import vision_v1 + + def sample_purge_products(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.PurgeProductsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.purge_products(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1.types.PurgeProductsRequest, dict]): The request object. Request message for the @@ -2105,7 +2526,7 @@ def purge_products( """ # 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([parent]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1/services/product_search/pagers.py b/google/cloud/vision_v1/services/product_search/pagers.py index ccb1ca01..971a9523 100644 --- a/google/cloud/vision_v1/services/product_search/pagers.py +++ b/google/cloud/vision_v1/services/product_search/pagers.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/vision_v1/services/product_search/transports/__init__.py b/google/cloud/vision_v1/services/product_search/transports/__init__.py index f38d3aef..40a758f5 100644 --- a/google/cloud/vision_v1/services/product_search/transports/__init__.py +++ b/google/cloud/vision_v1/services/product_search/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/vision_v1/services/product_search/transports/base.py b/google/cloud/vision_v1/services/product_search/transports/base.py index a24f4523..128571c9 100644 --- a/google/cloud/vision_v1/services/product_search/transports/base.py +++ b/google/cloud/vision_v1/services/product_search/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. @@ -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/vision_v1/services/product_search/transports/grpc.py b/google/cloud/vision_v1/services/product_search/transports/grpc.py index 4c7f6741..9df85193 100644 --- a/google/cloud/vision_v1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1/services/product_search/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. @@ -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, @@ -253,7 +256,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py index 6952b9e1..12e1ce82 100644 --- a/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1/services/product_search/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. @@ -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, @@ -255,7 +258,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/vision_v1/types/__init__.py b/google/cloud/vision_v1/types/__init__.py index 497df9a2..123c02e5 100644 --- a/google/cloud/vision_v1/types/__init__.py +++ b/google/cloud/vision_v1/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/vision_v1/types/geometry.py b/google/cloud/vision_v1/types/geometry.py index 47731f18..7fa5fbef 100644 --- a/google/cloud/vision_v1/types/geometry.py +++ b/google/cloud/vision_v1/types/geometry.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/vision_v1/types/image_annotator.py b/google/cloud/vision_v1/types/image_annotator.py index 2570e8ca..bd5f9230 100644 --- a/google/cloud/vision_v1/types/image_annotator.py +++ b/google/cloud/vision_v1/types/image_annotator.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/vision_v1/types/product_search.py b/google/cloud/vision_v1/types/product_search.py index 7d09aecd..64c0b02e 100644 --- a/google/cloud/vision_v1/types/product_search.py +++ b/google/cloud/vision_v1/types/product_search.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/vision_v1/types/product_search_service.py b/google/cloud/vision_v1/types/product_search_service.py index 05be5f57..c458b590 100644 --- a/google/cloud/vision_v1/types/product_search_service.py +++ b/google/cloud/vision_v1/types/product_search_service.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. @@ -190,8 +190,8 @@ class ReferenceImage(proto.Message): field is empty, the system will try to detect regions of interest. At most 10 bounding polygons will be used. - The provided shape is converted into a non- - rotated rectangle. Once converted, the small + The provided shape is converted into a + non-rotated rectangle. Once converted, the small edge of the rectangle must be greater than or equal to 300 pixels. The aspect ratio must be 1:4 or less (i.e. 1:3 is ok; 1:5 is not). diff --git a/google/cloud/vision_v1/types/text_annotation.py b/google/cloud/vision_v1/types/text_annotation.py index 94643170..c3e80790 100644 --- a/google/cloud/vision_v1/types/text_annotation.py +++ b/google/cloud/vision_v1/types/text_annotation.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/vision_v1/types/web_detection.py b/google/cloud/vision_v1/types/web_detection.py index 78bab322..de03fe7a 100644 --- a/google/cloud/vision_v1/types/web_detection.py +++ b/google/cloud/vision_v1/types/web_detection.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/vision_v1p1beta1/__init__.py b/google/cloud/vision_v1p1beta1/__init__.py index 84c64ab0..757507fe 100644 --- a/google/cloud/vision_v1p1beta1/__init__.py +++ b/google/cloud/vision_v1p1beta1/__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/vision_v1p1beta1/services/__init__.py b/google/cloud/vision_v1p1beta1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/vision_v1p1beta1/services/__init__.py +++ b/google/cloud/vision_v1p1beta1/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/vision_v1p1beta1/services/image_annotator/__init__.py b/google/cloud/vision_v1p1beta1/services/image_annotator/__init__.py index 422732ba..b2fb517b 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/__init__.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/__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/vision_v1p1beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py index 2b8f8785..8f7ec1b6 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/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,7 +16,7 @@ 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 @@ -107,6 +107,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 ImageAnnotatorClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ImageAnnotatorTransport: """Returns the transport used by the client instance. @@ -179,6 +215,25 @@ async def batch_annotate_images( r"""Run image detection and annotation for a batch of images. + + .. code-block:: python + + from google.cloud import vision_v1p1beta1 + + def sample_batch_annotate_images(): + # Create a client + client = vision_v1p1beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p1beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests @@ -203,7 +258,7 @@ async def batch_annotate_images( """ # 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([requests]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/client.py b/google/cloud/vision_v1p1beta1/services/image_annotator/client.py index 3494d849..d71ae614 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/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. @@ -221,6 +221,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, *, @@ -271,57 +338,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + 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, ImageAnnotatorTransport): # transport is a ImageAnnotatorTransport 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." @@ -333,6 +365,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 +398,25 @@ def batch_annotate_images( r"""Run image detection and annotation for a batch of images. + + .. code-block:: python + + from google.cloud import vision_v1p1beta1 + + def sample_batch_annotate_images(): + # Create a client + client = vision_v1p1beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p1beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests @@ -381,7 +441,7 @@ def batch_annotate_images( """ # 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([requests]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/__init__.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/__init__.py index 419b4293..bb856540 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/__init__.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/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/vision_v1p1beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py index c04b41ba..f4ab113b 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/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. @@ -102,7 +102,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/vision_v1p1beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py index 80bfa44d..d6f61ca4 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/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. @@ -161,8 +161,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/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py index d054014e..855fdd40 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/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. @@ -206,8 +206,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/vision_v1p1beta1/types/__init__.py b/google/cloud/vision_v1p1beta1/types/__init__.py index 1333bab5..1e5dc745 100644 --- a/google/cloud/vision_v1p1beta1/types/__init__.py +++ b/google/cloud/vision_v1p1beta1/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/vision_v1p1beta1/types/geometry.py b/google/cloud/vision_v1p1beta1/types/geometry.py index 29d617a7..ac313433 100644 --- a/google/cloud/vision_v1p1beta1/types/geometry.py +++ b/google/cloud/vision_v1p1beta1/types/geometry.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/vision_v1p1beta1/types/image_annotator.py b/google/cloud/vision_v1p1beta1/types/image_annotator.py index a099dbae..a929119a 100644 --- a/google/cloud/vision_v1p1beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p1beta1/types/image_annotator.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/vision_v1p1beta1/types/text_annotation.py b/google/cloud/vision_v1p1beta1/types/text_annotation.py index f7d7c049..330ee749 100644 --- a/google/cloud/vision_v1p1beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p1beta1/types/text_annotation.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/vision_v1p1beta1/types/web_detection.py b/google/cloud/vision_v1p1beta1/types/web_detection.py index d23f94b6..80353b81 100644 --- a/google/cloud/vision_v1p1beta1/types/web_detection.py +++ b/google/cloud/vision_v1p1beta1/types/web_detection.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/vision_v1p2beta1/__init__.py b/google/cloud/vision_v1p2beta1/__init__.py index 9d65b538..2410b40f 100644 --- a/google/cloud/vision_v1p2beta1/__init__.py +++ b/google/cloud/vision_v1p2beta1/__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/vision_v1p2beta1/services/__init__.py b/google/cloud/vision_v1p2beta1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/vision_v1p2beta1/services/__init__.py +++ b/google/cloud/vision_v1p2beta1/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/vision_v1p2beta1/services/image_annotator/__init__.py b/google/cloud/vision_v1p2beta1/services/image_annotator/__init__.py index 422732ba..b2fb517b 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/__init__.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/__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/vision_v1p2beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py index 633eec1c..2f4bfba5 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/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,7 +16,7 @@ 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 @@ -109,6 +109,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 ImageAnnotatorClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ImageAnnotatorTransport: """Returns the transport used by the client instance. @@ -181,6 +217,25 @@ async def batch_annotate_images( r"""Run image detection and annotation for a batch of images. + + .. code-block:: python + + from google.cloud import vision_v1p2beta1 + + def sample_batch_annotate_images(): + # Create a client + client = vision_v1p2beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p2beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests @@ -205,7 +260,7 @@ async def batch_annotate_images( """ # 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([requests]) if request is not None and has_flattened_params: @@ -262,6 +317,29 @@ async def async_batch_annotate_files( (metadata). ``Operation.response`` contains ``AsyncBatchAnnotateFilesResponse`` (results). + + .. code-block:: python + + from google.cloud import vision_v1p2beta1 + + def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p2beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p2beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation @@ -289,7 +367,7 @@ async def async_batch_annotate_files( """ # 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([requests]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/client.py b/google/cloud/vision_v1p2beta1/services/image_annotator/client.py index 6836bf41..aab08015 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/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. @@ -223,6 +223,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, *, @@ -273,57 +340,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + 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, ImageAnnotatorTransport): # transport is a ImageAnnotatorTransport 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." @@ -335,6 +367,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, @@ -359,6 +400,25 @@ def batch_annotate_images( r"""Run image detection and annotation for a batch of images. + + .. code-block:: python + + from google.cloud import vision_v1p2beta1 + + def sample_batch_annotate_images(): + # Create a client + client = vision_v1p2beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p2beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests @@ -383,7 +443,7 @@ def batch_annotate_images( """ # 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([requests]) if request is not None and has_flattened_params: @@ -433,6 +493,29 @@ def async_batch_annotate_files( (metadata). ``Operation.response`` contains ``AsyncBatchAnnotateFilesResponse`` (results). + + .. code-block:: python + + from google.cloud import vision_v1p2beta1 + + def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p2beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p2beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation @@ -460,7 +543,7 @@ def async_batch_annotate_files( """ # 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([requests]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/__init__.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/__init__.py index 419b4293..bb856540 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/__init__.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/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/vision_v1p2beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py index dceb4db3..ea0aaf20 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/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. @@ -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/vision_v1p2beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py index 2eab8766..5d439352 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/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. @@ -164,8 +164,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, @@ -238,7 +241,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py index 4fc73541..68f8c44e 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/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. @@ -209,8 +209,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, @@ -240,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/vision_v1p2beta1/types/__init__.py b/google/cloud/vision_v1p2beta1/types/__init__.py index e95c0f53..a250a877 100644 --- a/google/cloud/vision_v1p2beta1/types/__init__.py +++ b/google/cloud/vision_v1p2beta1/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/vision_v1p2beta1/types/geometry.py b/google/cloud/vision_v1p2beta1/types/geometry.py index c441eca2..229dd576 100644 --- a/google/cloud/vision_v1p2beta1/types/geometry.py +++ b/google/cloud/vision_v1p2beta1/types/geometry.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/vision_v1p2beta1/types/image_annotator.py b/google/cloud/vision_v1p2beta1/types/image_annotator.py index 9761a2e7..3e366baf 100644 --- a/google/cloud/vision_v1p2beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p2beta1/types/image_annotator.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/vision_v1p2beta1/types/text_annotation.py b/google/cloud/vision_v1p2beta1/types/text_annotation.py index 2bd6a914..7ca0670d 100644 --- a/google/cloud/vision_v1p2beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p2beta1/types/text_annotation.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/vision_v1p2beta1/types/web_detection.py b/google/cloud/vision_v1p2beta1/types/web_detection.py index 4ae5075b..1decb343 100644 --- a/google/cloud/vision_v1p2beta1/types/web_detection.py +++ b/google/cloud/vision_v1p2beta1/types/web_detection.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/vision_v1p3beta1/__init__.py b/google/cloud/vision_v1p3beta1/__init__.py index df1779cb..e79b8a02 100644 --- a/google/cloud/vision_v1p3beta1/__init__.py +++ b/google/cloud/vision_v1p3beta1/__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/vision_v1p3beta1/services/__init__.py b/google/cloud/vision_v1p3beta1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/vision_v1p3beta1/services/__init__.py +++ b/google/cloud/vision_v1p3beta1/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/vision_v1p3beta1/services/image_annotator/__init__.py b/google/cloud/vision_v1p3beta1/services/image_annotator/__init__.py index 422732ba..b2fb517b 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/__init__.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/__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/vision_v1p3beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py index 5adce9e0..cebc83e0 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/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,7 +16,7 @@ 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 @@ -113,6 +113,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 ImageAnnotatorClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ImageAnnotatorTransport: """Returns the transport used by the client instance. @@ -185,6 +221,25 @@ async def batch_annotate_images( r"""Run image detection and annotation for a batch of images. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_batch_annotate_images(): + # Create a client + client = vision_v1p3beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests @@ -209,7 +264,7 @@ async def batch_annotate_images( """ # 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([requests]) if request is not None and has_flattened_params: @@ -266,6 +321,29 @@ async def async_batch_annotate_files( (metadata). ``Operation.response`` contains ``AsyncBatchAnnotateFilesResponse`` (results). + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p3beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation @@ -293,7 +371,7 @@ async def async_batch_annotate_files( """ # 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([requests]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/client.py b/google/cloud/vision_v1p3beta1/services/image_annotator/client.py index a6640c35..634f2f5d 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/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. @@ -255,6 +255,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, *, @@ -305,57 +372,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + 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, ImageAnnotatorTransport): # transport is a ImageAnnotatorTransport 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." @@ -367,6 +399,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, @@ -391,6 +432,25 @@ def batch_annotate_images( r"""Run image detection and annotation for a batch of images. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_batch_annotate_images(): + # Create a client + client = vision_v1p3beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests @@ -415,7 +475,7 @@ def batch_annotate_images( """ # 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([requests]) if request is not None and has_flattened_params: @@ -465,6 +525,29 @@ def async_batch_annotate_files( (metadata). ``Operation.response`` contains ``AsyncBatchAnnotateFilesResponse`` (results). + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p3beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation @@ -492,7 +575,7 @@ def async_batch_annotate_files( """ # 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([requests]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/__init__.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/__init__.py index 419b4293..bb856540 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/__init__.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/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/vision_v1p3beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py index eaf5f784..968ae564 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/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. @@ -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/vision_v1p3beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py index 1a961671..af8ce36f 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/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. @@ -164,8 +164,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, @@ -238,7 +241,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py index 1d4725df..99361681 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/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. @@ -209,8 +209,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, @@ -240,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/vision_v1p3beta1/services/product_search/__init__.py b/google/cloud/vision_v1p3beta1/services/product_search/__init__.py index f357996e..3b50e361 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/__init__.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/__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/vision_v1p3beta1/services/product_search/async_client.py b/google/cloud/vision_v1p3beta1/services/product_search/async_client.py index 09368e2b..6dfc93e3 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/async_client.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/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,7 +16,7 @@ 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 @@ -138,6 +138,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 ProductSearchClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ProductSearchTransport: """Returns the transport used by the client instance. @@ -216,6 +252,26 @@ async def create_product_set( - Returns INVALID_ARGUMENT if display_name is missing, or is longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_create_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.CreateProductSetRequest, dict]): The request object. Request message for the @@ -260,7 +316,7 @@ async def create_product_set( """ # 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([parent, product_set, product_set_id]) if request is not None and has_flattened_params: @@ -323,6 +379,27 @@ async def list_product_sets( - Returns INVALID_ARGUMENT if page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_list_product_sets(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.ListProductSetsRequest, dict]): The request object. Request message for the @@ -351,7 +428,7 @@ async def list_product_sets( """ # 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([parent]) if request is not None and has_flattened_params: @@ -418,6 +495,26 @@ async def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_get_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = client.get_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.GetProductSetRequest, dict]): The request object. Request message for the @@ -447,7 +544,7 @@ async def get_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -513,6 +610,25 @@ async def update_product_set( update_mask but missing from the request or longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_update_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.UpdateProductSetRequest( + ) + + # Make the request + response = client.update_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest, dict]): The request object. Request message for the @@ -549,7 +665,7 @@ async def update_product_set( """ # 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([product_set, update_mask]) if request is not None and has_flattened_params: @@ -615,6 +731,23 @@ async def delete_product_set( - Returns NOT_FOUND if the ProductSet does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_delete_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + client.delete_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest, dict]): The request object. Request message for the @@ -635,7 +768,7 @@ async def delete_product_set( 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([name]) if request is not None and has_flattened_params: @@ -702,6 +835,26 @@ async def create_product( - Returns INVALID_ARGUMENT if product_category is missing or invalid. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_create_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.CreateProductRequest, dict]): The request object. Request message for the @@ -741,7 +894,7 @@ async def create_product( A Product contains ReferenceImages. """ # 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([parent, product, product_id]) if request is not None and has_flattened_params: @@ -804,6 +957,27 @@ async def list_products( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_list_products(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.ListProductsRequest, dict]): The request object. Request message for the @@ -832,7 +1006,7 @@ async def list_products( """ # 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([parent]) if request is not None and has_flattened_params: @@ -899,6 +1073,26 @@ async def get_product( - Returns NOT_FOUND if the Product does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_get_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.GetProductRequest, dict]): The request object. Request message for the `GetProduct` @@ -923,7 +1117,7 @@ async def get_product( A Product contains ReferenceImages. """ # 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([name]) if request is not None and has_flattened_params: @@ -996,6 +1190,25 @@ async def update_product( - Returns INVALID_ARGUMENT if product_category is present in update_mask. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_update_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.UpdateProductRequest( + ) + + # Make the request + response = client.update_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductRequest, dict]): The request object. Request message for the @@ -1029,7 +1242,7 @@ async def update_product( A Product contains ReferenceImages. """ # 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([product, update_mask]) if request is not None and has_flattened_params: @@ -1095,6 +1308,23 @@ async def delete_product( - Returns NOT_FOUND if the product does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_delete_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + client.delete_product(request=request) + Args: request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductRequest, dict]): The request object. Request message for the @@ -1115,7 +1345,7 @@ async def delete_product( 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([name]) if request is not None and has_flattened_params: @@ -1194,6 +1424,30 @@ async def create_reference_image( - Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_create_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + reference_image = vision_v1p3beta1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1p3beta1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = client.create_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest, dict]): The request object. Request message for the @@ -1239,7 +1493,7 @@ async def create_reference_image( """ # 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([parent, reference_image, reference_image_id]) if request is not None and has_flattened_params: @@ -1308,6 +1562,23 @@ async def delete_reference_image( - Returns NOT_FOUND if the reference image does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_delete_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + client.delete_reference_image(request=request) + Args: request (Union[google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest, dict]): The request object. Request message for the @@ -1330,7 +1601,7 @@ async def delete_reference_image( 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([name]) if request is not None and has_flattened_params: @@ -1392,6 +1663,27 @@ async def list_reference_images( - Returns INVALID_ARGUMENT if the page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_list_reference_images(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest, dict]): The request object. Request message for the @@ -1421,7 +1713,7 @@ async def list_reference_images( """ # 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([parent]) if request is not None and has_flattened_params: @@ -1488,6 +1780,26 @@ async def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_get_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = client.get_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest, dict]): The request object. Request message for the @@ -1516,7 +1828,7 @@ async def get_reference_image( """ # 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([name]) if request is not None and has_flattened_params: @@ -1584,6 +1896,24 @@ async def add_product_to_product_set( - Returns NOT_FOUND if the Product or the ProductSet doesn't exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_add_product_to_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.add_product_to_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest, dict]): The request object. Request message for the @@ -1615,7 +1945,7 @@ async def add_product_to_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1678,6 +2008,24 @@ async def remove_product_from_product_set( - Returns NOT_FOUND If the Product is not found under the ProductSet. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.remove_product_from_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest, dict]): The request object. Request message for the @@ -1709,7 +2057,7 @@ async def remove_product_from_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1773,6 +2121,27 @@ async def list_products_in_product_set( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_list_products_in_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest, dict]): The request object. Request message for the @@ -1803,7 +2172,7 @@ async def list_products_in_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -1878,6 +2247,30 @@ async def import_product_sets( Storage. For the format of the csv file please see [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_import_product_sets(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest, dict]): The request object. Request message for the @@ -1920,7 +2313,7 @@ async def import_product_sets( """ # 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([parent, input_config]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p3beta1/services/product_search/client.py b/google/cloud/vision_v1p3beta1/services/product_search/client.py index a7810c46..1b33b034 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/client.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/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. @@ -295,6 +295,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, *, @@ -345,57 +412,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + 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, ProductSearchTransport): # transport is a ProductSearchTransport 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." @@ -407,6 +439,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, @@ -437,6 +478,26 @@ def create_product_set( - Returns INVALID_ARGUMENT if display_name is missing, or is longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_create_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.CreateProductSetRequest, dict]): The request object. Request message for the @@ -481,7 +542,7 @@ def create_product_set( """ # 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([parent, product_set, product_set_id]) if request is not None and has_flattened_params: @@ -537,6 +598,27 @@ def list_product_sets( - Returns INVALID_ARGUMENT if page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_list_product_sets(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.ListProductSetsRequest, dict]): The request object. Request message for the @@ -565,7 +647,7 @@ def list_product_sets( """ # 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([parent]) if request is not None and has_flattened_params: @@ -622,6 +704,26 @@ def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_get_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = client.get_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.GetProductSetRequest, dict]): The request object. Request message for the @@ -651,7 +753,7 @@ def get_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -707,6 +809,25 @@ def update_product_set( update_mask but missing from the request or longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_update_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.UpdateProductSetRequest( + ) + + # Make the request + response = client.update_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest, dict]): The request object. Request message for the @@ -743,7 +864,7 @@ def update_product_set( """ # 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([product_set, update_mask]) if request is not None and has_flattened_params: @@ -802,6 +923,23 @@ def delete_product_set( - Returns NOT_FOUND if the ProductSet does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_delete_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + client.delete_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest, dict]): The request object. Request message for the @@ -822,7 +960,7 @@ def delete_product_set( 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([name]) if request is not None and has_flattened_params: @@ -879,6 +1017,26 @@ def create_product( - Returns INVALID_ARGUMENT if product_category is missing or invalid. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_create_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.CreateProductRequest, dict]): The request object. Request message for the @@ -918,7 +1076,7 @@ def create_product( A Product contains ReferenceImages. """ # 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([parent, product, product_id]) if request is not None and has_flattened_params: @@ -974,6 +1132,27 @@ def list_products( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_list_products(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.ListProductsRequest, dict]): The request object. Request message for the @@ -1002,7 +1181,7 @@ def list_products( """ # 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([parent]) if request is not None and has_flattened_params: @@ -1059,6 +1238,26 @@ def get_product( - Returns NOT_FOUND if the Product does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_get_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.GetProductRequest, dict]): The request object. Request message for the `GetProduct` @@ -1083,7 +1282,7 @@ def get_product( A Product contains ReferenceImages. """ # 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([name]) if request is not None and has_flattened_params: @@ -1146,6 +1345,25 @@ def update_product( - Returns INVALID_ARGUMENT if product_category is present in update_mask. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_update_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.UpdateProductRequest( + ) + + # Make the request + response = client.update_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductRequest, dict]): The request object. Request message for the @@ -1179,7 +1397,7 @@ def update_product( A Product contains ReferenceImages. """ # 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([product, update_mask]) if request is not None and has_flattened_params: @@ -1238,6 +1456,23 @@ def delete_product( - Returns NOT_FOUND if the product does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_delete_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + client.delete_product(request=request) + Args: request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductRequest, dict]): The request object. Request message for the @@ -1258,7 +1493,7 @@ def delete_product( 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([name]) if request is not None and has_flattened_params: @@ -1327,6 +1562,30 @@ def create_reference_image( - Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_create_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + reference_image = vision_v1p3beta1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1p3beta1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = client.create_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest, dict]): The request object. Request message for the @@ -1372,7 +1631,7 @@ def create_reference_image( """ # 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([parent, reference_image, reference_image_id]) if request is not None and has_flattened_params: @@ -1434,6 +1693,23 @@ def delete_reference_image( - Returns NOT_FOUND if the reference image does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_delete_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + client.delete_reference_image(request=request) + Args: request (Union[google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest, dict]): The request object. Request message for the @@ -1456,7 +1732,7 @@ def delete_reference_image( 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([name]) if request is not None and has_flattened_params: @@ -1508,6 +1784,27 @@ def list_reference_images( - Returns INVALID_ARGUMENT if the page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_list_reference_images(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest, dict]): The request object. Request message for the @@ -1537,7 +1834,7 @@ def list_reference_images( """ # 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([parent]) if request is not None and has_flattened_params: @@ -1594,6 +1891,26 @@ def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_get_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = client.get_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest, dict]): The request object. Request message for the @@ -1622,7 +1939,7 @@ def get_reference_image( """ # 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([name]) if request is not None and has_flattened_params: @@ -1680,6 +1997,24 @@ def add_product_to_product_set( - Returns NOT_FOUND if the Product or the ProductSet doesn't exist. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_add_product_to_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.add_product_to_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest, dict]): The request object. Request message for the @@ -1711,7 +2046,7 @@ def add_product_to_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1771,6 +2106,24 @@ def remove_product_from_product_set( - Returns NOT_FOUND If the Product is not found under the ProductSet. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.remove_product_from_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest, dict]): The request object. Request message for the @@ -1802,7 +2155,7 @@ def remove_product_from_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1863,6 +2216,27 @@ def list_products_in_product_set( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_list_products_in_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest, dict]): The request object. Request message for the @@ -1893,7 +2267,7 @@ def list_products_in_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -1962,6 +2336,30 @@ def import_product_sets( Storage. For the format of the csv file please see [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. + + .. code-block:: python + + from google.cloud import vision_v1p3beta1 + + def sample_import_product_sets(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest, dict]): The request object. Request message for the @@ -2004,7 +2402,7 @@ def import_product_sets( """ # 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([parent, input_config]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p3beta1/services/product_search/pagers.py b/google/cloud/vision_v1p3beta1/services/product_search/pagers.py index 2553a485..4727d826 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/pagers.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/pagers.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/vision_v1p3beta1/services/product_search/transports/__init__.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/__init__.py index f38d3aef..40a758f5 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/__init__.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/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/vision_v1p3beta1/services/product_search/transports/base.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py index 2f9320d9..975f97ec 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/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. @@ -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/vision_v1p3beta1/services/product_search/transports/grpc.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py index cf63871a..0b97f9d2 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/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. @@ -181,8 +181,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, @@ -255,7 +258,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py index f9822553..1659c447 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/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. @@ -226,8 +226,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, @@ -257,7 +260,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/vision_v1p3beta1/types/__init__.py b/google/cloud/vision_v1p3beta1/types/__init__.py index 8db76dfa..f03a4751 100644 --- a/google/cloud/vision_v1p3beta1/types/__init__.py +++ b/google/cloud/vision_v1p3beta1/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/vision_v1p3beta1/types/geometry.py b/google/cloud/vision_v1p3beta1/types/geometry.py index 1c5e12e6..b6db5111 100644 --- a/google/cloud/vision_v1p3beta1/types/geometry.py +++ b/google/cloud/vision_v1p3beta1/types/geometry.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/vision_v1p3beta1/types/image_annotator.py b/google/cloud/vision_v1p3beta1/types/image_annotator.py index aad0e4fe..ec0ee40b 100644 --- a/google/cloud/vision_v1p3beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p3beta1/types/image_annotator.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/vision_v1p3beta1/types/product_search.py b/google/cloud/vision_v1p3beta1/types/product_search.py index 8f565a8c..0b79813f 100644 --- a/google/cloud/vision_v1p3beta1/types/product_search.py +++ b/google/cloud/vision_v1p3beta1/types/product_search.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/vision_v1p3beta1/types/product_search_service.py b/google/cloud/vision_v1p3beta1/types/product_search_service.py index 50e10191..579e53fe 100644 --- a/google/cloud/vision_v1p3beta1/types/product_search_service.py +++ b/google/cloud/vision_v1p3beta1/types/product_search_service.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. @@ -182,8 +182,8 @@ class ReferenceImage(proto.Message): field is empty, the system will try to detect regions of interest. At most 10 bounding polygons will be used. - The provided shape is converted into a non- - rotated rectangle. Once converted, the small + The provided shape is converted into a + non-rotated rectangle. Once converted, the small edge of the rectangle must be greater than or equal to 300 pixels. The aspect ratio must be 1:4 or less (i.e. 1:3 is ok; 1:5 is not). diff --git a/google/cloud/vision_v1p3beta1/types/text_annotation.py b/google/cloud/vision_v1p3beta1/types/text_annotation.py index 89dbaea4..5348ecd7 100644 --- a/google/cloud/vision_v1p3beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p3beta1/types/text_annotation.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/vision_v1p3beta1/types/web_detection.py b/google/cloud/vision_v1p3beta1/types/web_detection.py index 5cd68aa4..5b2b667c 100644 --- a/google/cloud/vision_v1p3beta1/types/web_detection.py +++ b/google/cloud/vision_v1p3beta1/types/web_detection.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/vision_v1p4beta1/__init__.py b/google/cloud/vision_v1p4beta1/__init__.py index 11d87ea8..74f09c5f 100644 --- a/google/cloud/vision_v1p4beta1/__init__.py +++ b/google/cloud/vision_v1p4beta1/__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/vision_v1p4beta1/services/__init__.py b/google/cloud/vision_v1p4beta1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/vision_v1p4beta1/services/__init__.py +++ b/google/cloud/vision_v1p4beta1/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/vision_v1p4beta1/services/image_annotator/__init__.py b/google/cloud/vision_v1p4beta1/services/image_annotator/__init__.py index 422732ba..b2fb517b 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/__init__.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/__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/vision_v1p4beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py index 805c91c2..7805401a 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/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,7 +16,7 @@ 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 @@ -113,6 +113,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 ImageAnnotatorClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ImageAnnotatorTransport: """Returns the transport used by the client instance. @@ -185,6 +221,25 @@ async def batch_annotate_images( r"""Run image detection and annotation for a batch of images. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_batch_annotate_images(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests @@ -209,7 +264,7 @@ async def batch_annotate_images( """ # 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([requests]) if request is not None and has_flattened_params: @@ -264,6 +319,25 @@ async def batch_annotate_files( perform detection and annotation for each image extracted. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_batch_annotate_files(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.BatchAnnotateFilesRequest( + ) + + # Make the request + response = client.batch_annotate_files(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesRequest, dict]): The request object. A list of requests to annotate files @@ -288,7 +362,7 @@ async def batch_annotate_files( A list of file annotation responses. """ # 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([requests]) if request is not None and has_flattened_params: @@ -348,6 +422,29 @@ async def async_batch_annotate_images( in customer GCS bucket, each json file containing BatchAnnotateImagesResponse proto. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_async_batch_annotate_images(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AsyncBatchAnnotateImagesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_images(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesRequest, dict]): The request object. Request for async image annotation @@ -382,7 +479,7 @@ async def async_batch_annotate_images( """ # 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([requests, output_config]) if request is not None and has_flattened_params: @@ -446,6 +543,29 @@ async def async_batch_annotate_files( (metadata). ``Operation.response`` contains ``AsyncBatchAnnotateFilesResponse`` (results). + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation @@ -473,7 +593,7 @@ async def async_batch_annotate_files( """ # 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([requests]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/client.py b/google/cloud/vision_v1p4beta1/services/image_annotator/client.py index 1d942b66..88fa6023 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/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. @@ -255,6 +255,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, *, @@ -305,57 +372,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + 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, ImageAnnotatorTransport): # transport is a ImageAnnotatorTransport 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." @@ -367,6 +399,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, @@ -391,6 +432,25 @@ def batch_annotate_images( r"""Run image detection and annotation for a batch of images. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_batch_annotate_images(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesRequest, dict]): The request object. Multiple image annotation requests @@ -415,7 +475,7 @@ def batch_annotate_images( """ # 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([requests]) if request is not None and has_flattened_params: @@ -466,6 +526,25 @@ def batch_annotate_files( perform detection and annotation for each image extracted. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_batch_annotate_files(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.BatchAnnotateFilesRequest( + ) + + # Make the request + response = client.batch_annotate_files(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesRequest, dict]): The request object. A list of requests to annotate files @@ -490,7 +569,7 @@ def batch_annotate_files( A list of file annotation responses. """ # 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([requests]) if request is not None and has_flattened_params: @@ -546,6 +625,29 @@ def async_batch_annotate_images( in customer GCS bucket, each json file containing BatchAnnotateImagesResponse proto. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_async_batch_annotate_images(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AsyncBatchAnnotateImagesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_images(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesRequest, dict]): The request object. Request for async image annotation @@ -580,7 +682,7 @@ def async_batch_annotate_images( """ # 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([requests, output_config]) if request is not None and has_flattened_params: @@ -642,6 +744,29 @@ def async_batch_annotate_files( (metadata). ``Operation.response`` contains ``AsyncBatchAnnotateFilesResponse`` (results). + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesRequest, dict]): The request object. Multiple async file annotation @@ -669,7 +794,7 @@ def async_batch_annotate_files( """ # 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([requests]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/__init__.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/__init__.py index 419b4293..bb856540 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/__init__.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/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/vision_v1p4beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py index a09b6b22..8d960da1 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/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. @@ -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/vision_v1p4beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py index 8efff3d5..36975ff4 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/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. @@ -164,8 +164,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, @@ -238,7 +241,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py index a5906c75..7e30d5aa 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/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. @@ -209,8 +209,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, @@ -240,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/vision_v1p4beta1/services/product_search/__init__.py b/google/cloud/vision_v1p4beta1/services/product_search/__init__.py index f357996e..3b50e361 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/__init__.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/__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/vision_v1p4beta1/services/product_search/async_client.py b/google/cloud/vision_v1p4beta1/services/product_search/async_client.py index a8b59156..fdf16a8e 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/async_client.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/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,7 +16,7 @@ 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 @@ -139,6 +139,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 ProductSearchClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ProductSearchTransport: """Returns the transport used by the client instance. @@ -217,6 +253,26 @@ async def create_product_set( - Returns INVALID_ARGUMENT if display_name is missing, or is longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_create_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.CreateProductSetRequest, dict]): The request object. Request message for the @@ -261,7 +317,7 @@ async def create_product_set( """ # 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([parent, product_set, product_set_id]) if request is not None and has_flattened_params: @@ -324,6 +380,27 @@ async def list_product_sets( - Returns INVALID_ARGUMENT if page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_list_product_sets(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.ListProductSetsRequest, dict]): The request object. Request message for the @@ -352,7 +429,7 @@ async def list_product_sets( """ # 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([parent]) if request is not None and has_flattened_params: @@ -419,6 +496,26 @@ async def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_get_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = client.get_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.GetProductSetRequest, dict]): The request object. Request message for the @@ -448,7 +545,7 @@ async def get_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -514,6 +611,25 @@ async def update_product_set( update_mask but missing from the request or longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_update_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.UpdateProductSetRequest( + ) + + # Make the request + response = client.update_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.UpdateProductSetRequest, dict]): The request object. Request message for the @@ -550,7 +666,7 @@ async def update_product_set( """ # 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([product_set, update_mask]) if request is not None and has_flattened_params: @@ -611,6 +727,23 @@ async def delete_product_set( The actual image files are not deleted from Google Cloud Storage. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_delete_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + client.delete_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p4beta1.types.DeleteProductSetRequest, dict]): The request object. Request message for the @@ -631,7 +764,7 @@ async def delete_product_set( 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([name]) if request is not None and has_flattened_params: @@ -698,6 +831,26 @@ async def create_product( - Returns INVALID_ARGUMENT if product_category is missing or invalid. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_create_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.CreateProductRequest, dict]): The request object. Request message for the @@ -737,7 +890,7 @@ async def create_product( A Product contains ReferenceImages. """ # 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([parent, product, product_id]) if request is not None and has_flattened_params: @@ -800,6 +953,27 @@ async def list_products( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_list_products(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.ListProductsRequest, dict]): The request object. Request message for the @@ -828,7 +1002,7 @@ async def list_products( """ # 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([parent]) if request is not None and has_flattened_params: @@ -895,6 +1069,26 @@ async def get_product( - Returns NOT_FOUND if the Product does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_get_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.GetProductRequest, dict]): The request object. Request message for the `GetProduct` @@ -919,7 +1113,7 @@ async def get_product( A Product contains ReferenceImages. """ # 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([name]) if request is not None and has_flattened_params: @@ -992,6 +1186,25 @@ async def update_product( - Returns INVALID_ARGUMENT if product_category is present in update_mask. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_update_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.UpdateProductRequest( + ) + + # Make the request + response = client.update_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.UpdateProductRequest, dict]): The request object. Request message for the @@ -1025,7 +1238,7 @@ async def update_product( A Product contains ReferenceImages. """ # 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([product, update_mask]) if request is not None and has_flattened_params: @@ -1088,6 +1301,23 @@ async def delete_product( ProductSets containing the product may still work until all related caches are refreshed. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_delete_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + client.delete_product(request=request) + Args: request (Union[google.cloud.vision_v1p4beta1.types.DeleteProductRequest, dict]): The request object. Request message for the @@ -1108,7 +1338,7 @@ async def delete_product( 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([name]) if request is not None and has_flattened_params: @@ -1187,6 +1417,30 @@ async def create_reference_image( - Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_create_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + reference_image = vision_v1p4beta1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1p4beta1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = client.create_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.CreateReferenceImageRequest, dict]): The request object. Request message for the @@ -1232,7 +1486,7 @@ async def create_reference_image( """ # 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([parent, reference_image, reference_image_id]) if request is not None and has_flattened_params: @@ -1296,6 +1550,23 @@ async def delete_reference_image( The actual image files are not deleted from Google Cloud Storage. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_delete_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + client.delete_reference_image(request=request) + Args: request (Union[google.cloud.vision_v1p4beta1.types.DeleteReferenceImageRequest, dict]): The request object. Request message for the @@ -1318,7 +1589,7 @@ async def delete_reference_image( 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([name]) if request is not None and has_flattened_params: @@ -1380,6 +1651,27 @@ async def list_reference_images( - Returns INVALID_ARGUMENT if the page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_list_reference_images(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest, dict]): The request object. Request message for the @@ -1409,7 +1701,7 @@ async def list_reference_images( """ # 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([parent]) if request is not None and has_flattened_params: @@ -1476,6 +1768,26 @@ async def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_get_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = client.get_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.GetReferenceImageRequest, dict]): The request object. Request message for the @@ -1504,7 +1816,7 @@ async def get_reference_image( """ # 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([name]) if request is not None and has_flattened_params: @@ -1572,6 +1884,24 @@ async def add_product_to_product_set( - Returns NOT_FOUND if the Product or the ProductSet doesn't exist. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_add_product_to_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.add_product_to_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p4beta1.types.AddProductToProductSetRequest, dict]): The request object. Request message for the @@ -1603,7 +1933,7 @@ async def add_product_to_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1661,6 +1991,23 @@ async def remove_product_from_product_set( ) -> None: r"""Removes a Product from the specified ProductSet. + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.remove_product_from_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p4beta1.types.RemoveProductFromProductSetRequest, dict]): The request object. Request message for the @@ -1692,7 +2039,7 @@ async def remove_product_from_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1756,6 +2103,27 @@ async def list_products_in_product_set( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_list_products_in_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest, dict]): The request object. Request message for the @@ -1786,7 +2154,7 @@ async def list_products_in_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -1861,6 +2229,30 @@ async def import_product_sets( Storage. For the format of the csv file please see [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_import_product_sets(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.ImportProductSetsRequest, dict]): The request object. Request message for the @@ -1903,7 +2295,7 @@ async def import_product_sets( """ # 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([parent, input_config]) if request is not None and has_flattened_params: @@ -1993,6 +2385,30 @@ async def purge_products( request. ``Operation.metadata`` contains ``BatchOperationMetadata``. (progress) + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_purge_products(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.PurgeProductsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.purge_products(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.PurgeProductsRequest, dict]): The request object. Request message for the @@ -2032,7 +2448,7 @@ async def purge_products( """ # 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([parent]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p4beta1/services/product_search/client.py b/google/cloud/vision_v1p4beta1/services/product_search/client.py index d935b9e1..134d3dbe 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/client.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/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. @@ -296,6 +296,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, *, @@ -346,57 +413,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + 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, ProductSearchTransport): # transport is a ProductSearchTransport 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." @@ -408,6 +440,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, @@ -438,6 +479,26 @@ def create_product_set( - Returns INVALID_ARGUMENT if display_name is missing, or is longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_create_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.CreateProductSetRequest, dict]): The request object. Request message for the @@ -482,7 +543,7 @@ def create_product_set( """ # 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([parent, product_set, product_set_id]) if request is not None and has_flattened_params: @@ -538,6 +599,27 @@ def list_product_sets( - Returns INVALID_ARGUMENT if page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_list_product_sets(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.ListProductSetsRequest, dict]): The request object. Request message for the @@ -566,7 +648,7 @@ def list_product_sets( """ # 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([parent]) if request is not None and has_flattened_params: @@ -623,6 +705,26 @@ def get_product_set( - Returns NOT_FOUND if the ProductSet does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_get_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = client.get_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.GetProductSetRequest, dict]): The request object. Request message for the @@ -652,7 +754,7 @@ def get_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -708,6 +810,25 @@ def update_product_set( update_mask but missing from the request or longer than 4096 characters. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_update_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.UpdateProductSetRequest( + ) + + # Make the request + response = client.update_product_set(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.UpdateProductSetRequest, dict]): The request object. Request message for the @@ -744,7 +865,7 @@ def update_product_set( """ # 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([product_set, update_mask]) if request is not None and has_flattened_params: @@ -798,6 +919,23 @@ def delete_product_set( The actual image files are not deleted from Google Cloud Storage. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_delete_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + client.delete_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p4beta1.types.DeleteProductSetRequest, dict]): The request object. Request message for the @@ -818,7 +956,7 @@ def delete_product_set( 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([name]) if request is not None and has_flattened_params: @@ -875,6 +1013,26 @@ def create_product( - Returns INVALID_ARGUMENT if product_category is missing or invalid. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_create_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.CreateProductRequest, dict]): The request object. Request message for the @@ -914,7 +1072,7 @@ def create_product( A Product contains ReferenceImages. """ # 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([parent, product, product_id]) if request is not None and has_flattened_params: @@ -970,6 +1128,27 @@ def list_products( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_list_products(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.ListProductsRequest, dict]): The request object. Request message for the @@ -998,7 +1177,7 @@ def list_products( """ # 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([parent]) if request is not None and has_flattened_params: @@ -1055,6 +1234,26 @@ def get_product( - Returns NOT_FOUND if the Product does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_get_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.GetProductRequest, dict]): The request object. Request message for the `GetProduct` @@ -1079,7 +1278,7 @@ def get_product( A Product contains ReferenceImages. """ # 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([name]) if request is not None and has_flattened_params: @@ -1142,6 +1341,25 @@ def update_product( - Returns INVALID_ARGUMENT if product_category is present in update_mask. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_update_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.UpdateProductRequest( + ) + + # Make the request + response = client.update_product(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.UpdateProductRequest, dict]): The request object. Request message for the @@ -1175,7 +1393,7 @@ def update_product( A Product contains ReferenceImages. """ # 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([product, update_mask]) if request is not None and has_flattened_params: @@ -1231,6 +1449,23 @@ def delete_product( ProductSets containing the product may still work until all related caches are refreshed. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_delete_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + client.delete_product(request=request) + Args: request (Union[google.cloud.vision_v1p4beta1.types.DeleteProductRequest, dict]): The request object. Request message for the @@ -1251,7 +1486,7 @@ def delete_product( 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([name]) if request is not None and has_flattened_params: @@ -1320,6 +1555,30 @@ def create_reference_image( - Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_create_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + reference_image = vision_v1p4beta1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1p4beta1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = client.create_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.CreateReferenceImageRequest, dict]): The request object. Request message for the @@ -1365,7 +1624,7 @@ def create_reference_image( """ # 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([parent, reference_image, reference_image_id]) if request is not None and has_flattened_params: @@ -1422,6 +1681,23 @@ def delete_reference_image( The actual image files are not deleted from Google Cloud Storage. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_delete_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + client.delete_reference_image(request=request) + Args: request (Union[google.cloud.vision_v1p4beta1.types.DeleteReferenceImageRequest, dict]): The request object. Request message for the @@ -1444,7 +1720,7 @@ def delete_reference_image( 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([name]) if request is not None and has_flattened_params: @@ -1496,6 +1772,27 @@ def list_reference_images( - Returns INVALID_ARGUMENT if the page_size is greater than 100, or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_list_reference_images(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest, dict]): The request object. Request message for the @@ -1525,7 +1822,7 @@ def list_reference_images( """ # 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([parent]) if request is not None and has_flattened_params: @@ -1582,6 +1879,26 @@ def get_reference_image( - Returns NOT_FOUND if the specified image does not exist. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_get_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = client.get_reference_image(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.GetReferenceImageRequest, dict]): The request object. Request message for the @@ -1610,7 +1927,7 @@ def get_reference_image( """ # 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([name]) if request is not None and has_flattened_params: @@ -1668,6 +1985,24 @@ def add_product_to_product_set( - Returns NOT_FOUND if the Product or the ProductSet doesn't exist. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_add_product_to_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.add_product_to_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p4beta1.types.AddProductToProductSetRequest, dict]): The request object. Request message for the @@ -1699,7 +2034,7 @@ def add_product_to_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1754,6 +2089,23 @@ def remove_product_from_product_set( ) -> None: r"""Removes a Product from the specified ProductSet. + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.remove_product_from_product_set(request=request) + Args: request (Union[google.cloud.vision_v1p4beta1.types.RemoveProductFromProductSetRequest, dict]): The request object. Request message for the @@ -1785,7 +2137,7 @@ def remove_product_from_product_set( 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([name, product]) if request is not None and has_flattened_params: @@ -1846,6 +2198,27 @@ def list_products_in_product_set( - Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_list_products_in_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest, dict]): The request object. Request message for the @@ -1876,7 +2249,7 @@ def list_products_in_product_set( """ # 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([name]) if request is not None and has_flattened_params: @@ -1945,6 +2318,30 @@ def import_product_sets( Storage. For the format of the csv file please see [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_import_product_sets(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.ImportProductSetsRequest, dict]): The request object. Request message for the @@ -1987,7 +2384,7 @@ def import_product_sets( """ # 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([parent, input_config]) if request is not None and has_flattened_params: @@ -2070,6 +2467,30 @@ def purge_products( request. ``Operation.metadata`` contains ``BatchOperationMetadata``. (progress) + + .. code-block:: python + + from google.cloud import vision_v1p4beta1 + + def sample_purge_products(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.PurgeProductsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.purge_products(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.vision_v1p4beta1.types.PurgeProductsRequest, dict]): The request object. Request message for the @@ -2109,7 +2530,7 @@ def purge_products( """ # 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([parent]) if request is not None and has_flattened_params: diff --git a/google/cloud/vision_v1p4beta1/services/product_search/pagers.py b/google/cloud/vision_v1p4beta1/services/product_search/pagers.py index d557b0af..6b9079bc 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/pagers.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/pagers.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/vision_v1p4beta1/services/product_search/transports/__init__.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/__init__.py index f38d3aef..40a758f5 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/__init__.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/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/vision_v1p4beta1/services/product_search/transports/base.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py index 2b2fe864..ff97ab64 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/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. @@ -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/vision_v1p4beta1/services/product_search/transports/grpc.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py index 6f3a4a53..d769e017 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/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. @@ -181,8 +181,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, @@ -255,7 +258,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py index 5f5f28c0..79655bd6 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/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. @@ -226,8 +226,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, @@ -257,7 +260,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/vision_v1p4beta1/types/__init__.py b/google/cloud/vision_v1p4beta1/types/__init__.py index 9e1748dd..1f031b25 100644 --- a/google/cloud/vision_v1p4beta1/types/__init__.py +++ b/google/cloud/vision_v1p4beta1/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/vision_v1p4beta1/types/face.py b/google/cloud/vision_v1p4beta1/types/face.py index 99b113f0..6d7a311c 100644 --- a/google/cloud/vision_v1p4beta1/types/face.py +++ b/google/cloud/vision_v1p4beta1/types/face.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/vision_v1p4beta1/types/geometry.py b/google/cloud/vision_v1p4beta1/types/geometry.py index ecb31d83..cd4cf8f6 100644 --- a/google/cloud/vision_v1p4beta1/types/geometry.py +++ b/google/cloud/vision_v1p4beta1/types/geometry.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/vision_v1p4beta1/types/image_annotator.py b/google/cloud/vision_v1p4beta1/types/image_annotator.py index 10d51a78..aba2ceac 100644 --- a/google/cloud/vision_v1p4beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p4beta1/types/image_annotator.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/vision_v1p4beta1/types/product_search.py b/google/cloud/vision_v1p4beta1/types/product_search.py index 08065000..d2c1a6ce 100644 --- a/google/cloud/vision_v1p4beta1/types/product_search.py +++ b/google/cloud/vision_v1p4beta1/types/product_search.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/vision_v1p4beta1/types/product_search_service.py b/google/cloud/vision_v1p4beta1/types/product_search_service.py index 225acf94..4e93375f 100644 --- a/google/cloud/vision_v1p4beta1/types/product_search_service.py +++ b/google/cloud/vision_v1p4beta1/types/product_search_service.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. @@ -190,8 +190,8 @@ class ReferenceImage(proto.Message): field is empty, the system will try to detect regions of interest. At most 10 bounding polygons will be used. - The provided shape is converted into a non- - rotated rectangle. Once converted, the small + The provided shape is converted into a + non-rotated rectangle. Once converted, the small edge of the rectangle must be greater than or equal to 300 pixels. The aspect ratio must be 1:4 or less (i.e. 1:3 is ok; 1:5 is not). diff --git a/google/cloud/vision_v1p4beta1/types/text_annotation.py b/google/cloud/vision_v1p4beta1/types/text_annotation.py index 699c7111..a83ec169 100644 --- a/google/cloud/vision_v1p4beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p4beta1/types/text_annotation.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/vision_v1p4beta1/types/web_detection.py b/google/cloud/vision_v1p4beta1/types/web_detection.py index a1ecc0b2..588a4d74 100644 --- a/google/cloud/vision_v1p4beta1/types/web_detection.py +++ b/google/cloud/vision_v1p4beta1/types/web_detection.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 81813bc6..1eddd7b5 100644 --- a/noxfile.py +++ b/noxfile.py @@ -182,7 +182,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=98") + session.run("coverage", "report", "--show-missing", "--fail-under=99") session.run("coverage", "erase") diff --git a/owlbot.py b/owlbot.py index ffdada17..4912eeb4 100644 --- a/owlbot.py +++ b/owlbot.py @@ -100,6 +100,7 @@ # Move docs configuration s.move(library / f"docs/conf.py") + s.move(library / "samples") s.remove_staging_dirs() @@ -109,11 +110,14 @@ templated_files = common.py_library( samples=True, microgenerator=True, - cov_level=98, + cov_level=99, system_test_external_dependencies=["google-cloud-storage"] ) s.move(templated_files, excludes=[".coveragerc"]) # microgenerator has a good .coveragerc file +# Work around bug in templates https://github.com/googleapis/synthtool/pull/1335 +s.replace(".github/workflows/unittest.yml", "--fail-under=100", "--fail-under=99") + # ---------------------------------------------------------------------------- # Samples templates # ---------------------------------------------------------------------------- diff --git a/samples/generated_samples/snippet_metadata_vision_v1.json b/samples/generated_samples/snippet_metadata_vision_v1.json new file mode 100644 index 00000000..9470660d --- /dev/null +++ b/samples/generated_samples/snippet_metadata_vision_v1.json @@ -0,0 +1,2031 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateFiles" + } + }, + "file": "vision_v1_generated_image_annotator_async_batch_annotate_files_async.py", + "regionTag": "vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateFiles" + } + }, + "file": "vision_v1_generated_image_annotator_async_batch_annotate_files_sync.py", + "regionTag": "vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateImages" + } + }, + "file": "vision_v1_generated_image_annotator_async_batch_annotate_images_async.py", + "regionTag": "vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateImages_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateImages" + } + }, + "file": "vision_v1_generated_image_annotator_async_batch_annotate_images_sync.py", + "regionTag": "vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateImages_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "BatchAnnotateFiles" + } + }, + "file": "vision_v1_generated_image_annotator_batch_annotate_files_async.py", + "regionTag": "vision_v1_generated_ImageAnnotator_BatchAnnotateFiles_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": "ImageAnnotator" + }, + "shortName": "BatchAnnotateFiles" + } + }, + "file": "vision_v1_generated_image_annotator_batch_annotate_files_sync.py", + "regionTag": "vision_v1_generated_ImageAnnotator_BatchAnnotateFiles_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": "ImageAnnotator" + }, + "shortName": "BatchAnnotateImages" + } + }, + "file": "vision_v1_generated_image_annotator_batch_annotate_images_async.py", + "regionTag": "vision_v1_generated_ImageAnnotator_BatchAnnotateImages_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": "ImageAnnotator" + }, + "shortName": "BatchAnnotateImages" + } + }, + "file": "vision_v1_generated_image_annotator_batch_annotate_images_sync.py", + "regionTag": "vision_v1_generated_ImageAnnotator_BatchAnnotateImages_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": "ProductSearch" + }, + "shortName": "AddProductToProductSet" + } + }, + "file": "vision_v1_generated_product_search_add_product_to_product_set_async.py", + "regionTag": "vision_v1_generated_ProductSearch_AddProductToProductSet_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "AddProductToProductSet" + } + }, + "file": "vision_v1_generated_product_search_add_product_to_product_set_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_AddProductToProductSet_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "CreateProductSet" + } + }, + "file": "vision_v1_generated_product_search_create_product_set_async.py", + "regionTag": "vision_v1_generated_ProductSearch_CreateProductSet_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": "ProductSearch" + }, + "shortName": "CreateProductSet" + } + }, + "file": "vision_v1_generated_product_search_create_product_set_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_CreateProductSet_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": "ProductSearch" + }, + "shortName": "CreateProduct" + } + }, + "file": "vision_v1_generated_product_search_create_product_async.py", + "regionTag": "vision_v1_generated_ProductSearch_CreateProduct_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": "ProductSearch" + }, + "shortName": "CreateProduct" + } + }, + "file": "vision_v1_generated_product_search_create_product_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_CreateProduct_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": "ProductSearch" + }, + "shortName": "CreateReferenceImage" + } + }, + "file": "vision_v1_generated_product_search_create_reference_image_async.py", + "regionTag": "vision_v1_generated_ProductSearch_CreateReferenceImage_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "CreateReferenceImage" + } + }, + "file": "vision_v1_generated_product_search_create_reference_image_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_CreateReferenceImage_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProductSet" + } + }, + "file": "vision_v1_generated_product_search_delete_product_set_async.py", + "regionTag": "vision_v1_generated_ProductSearch_DeleteProductSet_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProductSet" + } + }, + "file": "vision_v1_generated_product_search_delete_product_set_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_DeleteProductSet_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProduct" + } + }, + "file": "vision_v1_generated_product_search_delete_product_async.py", + "regionTag": "vision_v1_generated_ProductSearch_DeleteProduct_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProduct" + } + }, + "file": "vision_v1_generated_product_search_delete_product_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_DeleteProduct_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteReferenceImage" + } + }, + "file": "vision_v1_generated_product_search_delete_reference_image_async.py", + "regionTag": "vision_v1_generated_ProductSearch_DeleteReferenceImage_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteReferenceImage" + } + }, + "file": "vision_v1_generated_product_search_delete_reference_image_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_DeleteReferenceImage_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "GetProductSet" + } + }, + "file": "vision_v1_generated_product_search_get_product_set_async.py", + "regionTag": "vision_v1_generated_ProductSearch_GetProductSet_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": "ProductSearch" + }, + "shortName": "GetProductSet" + } + }, + "file": "vision_v1_generated_product_search_get_product_set_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_GetProductSet_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": "ProductSearch" + }, + "shortName": "GetProduct" + } + }, + "file": "vision_v1_generated_product_search_get_product_async.py", + "regionTag": "vision_v1_generated_ProductSearch_GetProduct_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": "ProductSearch" + }, + "shortName": "GetProduct" + } + }, + "file": "vision_v1_generated_product_search_get_product_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_GetProduct_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": "ProductSearch" + }, + "shortName": "GetReferenceImage" + } + }, + "file": "vision_v1_generated_product_search_get_reference_image_async.py", + "regionTag": "vision_v1_generated_ProductSearch_GetReferenceImage_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": "ProductSearch" + }, + "shortName": "GetReferenceImage" + } + }, + "file": "vision_v1_generated_product_search_get_reference_image_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_GetReferenceImage_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": "ProductSearch" + }, + "shortName": "ImportProductSets" + } + }, + "file": "vision_v1_generated_product_search_import_product_sets_async.py", + "regionTag": "vision_v1_generated_ProductSearch_ImportProductSets_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ImportProductSets" + } + }, + "file": "vision_v1_generated_product_search_import_product_sets_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_ImportProductSets_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductSets" + } + }, + "file": "vision_v1_generated_product_search_list_product_sets_async.py", + "regionTag": "vision_v1_generated_ProductSearch_ListProductSets_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductSets" + } + }, + "file": "vision_v1_generated_product_search_list_product_sets_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_ListProductSets_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductsInProductSet" + } + }, + "file": "vision_v1_generated_product_search_list_products_in_product_set_async.py", + "regionTag": "vision_v1_generated_ProductSearch_ListProductsInProductSet_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductsInProductSet" + } + }, + "file": "vision_v1_generated_product_search_list_products_in_product_set_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_ListProductsInProductSet_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProducts" + } + }, + "file": "vision_v1_generated_product_search_list_products_async.py", + "regionTag": "vision_v1_generated_ProductSearch_ListProducts_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProducts" + } + }, + "file": "vision_v1_generated_product_search_list_products_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_ListProducts_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListReferenceImages" + } + }, + "file": "vision_v1_generated_product_search_list_reference_images_async.py", + "regionTag": "vision_v1_generated_ProductSearch_ListReferenceImages_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListReferenceImages" + } + }, + "file": "vision_v1_generated_product_search_list_reference_images_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_ListReferenceImages_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "PurgeProducts" + } + }, + "file": "vision_v1_generated_product_search_purge_products_async.py", + "regionTag": "vision_v1_generated_ProductSearch_PurgeProducts_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "PurgeProducts" + } + }, + "file": "vision_v1_generated_product_search_purge_products_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_PurgeProducts_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "RemoveProductFromProductSet" + } + }, + "file": "vision_v1_generated_product_search_remove_product_from_product_set_async.py", + "regionTag": "vision_v1_generated_ProductSearch_RemoveProductFromProductSet_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "RemoveProductFromProductSet" + } + }, + "file": "vision_v1_generated_product_search_remove_product_from_product_set_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_RemoveProductFromProductSet_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "UpdateProductSet" + } + }, + "file": "vision_v1_generated_product_search_update_product_set_async.py", + "regionTag": "vision_v1_generated_ProductSearch_UpdateProductSet_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": "ProductSearch" + }, + "shortName": "UpdateProductSet" + } + }, + "file": "vision_v1_generated_product_search_update_product_set_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_UpdateProductSet_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": "ProductSearch" + }, + "shortName": "UpdateProduct" + } + }, + "file": "vision_v1_generated_product_search_update_product_async.py", + "regionTag": "vision_v1_generated_ProductSearch_UpdateProduct_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": "ProductSearch" + }, + "shortName": "UpdateProduct" + } + }, + "file": "vision_v1_generated_product_search_update_product_sync.py", + "regionTag": "vision_v1_generated_ProductSearch_UpdateProduct_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" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_vision_v1p1beta1.json b/samples/generated_samples/snippet_metadata_vision_v1p1beta1.json new file mode 100644 index 00000000..d588d510 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_vision_v1p1beta1.json @@ -0,0 +1,93 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "BatchAnnotateImages" + } + }, + "file": "vision_v1p1beta1_generated_image_annotator_batch_annotate_images_async.py", + "regionTag": "vision_v1p1beta1_generated_ImageAnnotator_BatchAnnotateImages_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": "ImageAnnotator" + }, + "shortName": "BatchAnnotateImages" + } + }, + "file": "vision_v1p1beta1_generated_image_annotator_batch_annotate_images_sync.py", + "regionTag": "vision_v1p1beta1_generated_ImageAnnotator_BatchAnnotateImages_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" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_vision_v1p2beta1.json b/samples/generated_samples/snippet_metadata_vision_v1p2beta1.json new file mode 100644 index 00000000..80d069b0 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_vision_v1p2beta1.json @@ -0,0 +1,182 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateFiles" + } + }, + "file": "vision_v1p2beta1_generated_image_annotator_async_batch_annotate_files_async.py", + "regionTag": "vision_v1p2beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateFiles" + } + }, + "file": "vision_v1p2beta1_generated_image_annotator_async_batch_annotate_files_sync.py", + "regionTag": "vision_v1p2beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "BatchAnnotateImages" + } + }, + "file": "vision_v1p2beta1_generated_image_annotator_batch_annotate_images_async.py", + "regionTag": "vision_v1p2beta1_generated_ImageAnnotator_BatchAnnotateImages_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": "ImageAnnotator" + }, + "shortName": "BatchAnnotateImages" + } + }, + "file": "vision_v1p2beta1_generated_image_annotator_batch_annotate_images_sync.py", + "regionTag": "vision_v1p2beta1_generated_ImageAnnotator_BatchAnnotateImages_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" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_vision_v1p3beta1.json b/samples/generated_samples/snippet_metadata_vision_v1p3beta1.json new file mode 100644 index 00000000..9cdb395b --- /dev/null +++ b/samples/generated_samples/snippet_metadata_vision_v1p3beta1.json @@ -0,0 +1,1764 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateFiles" + } + }, + "file": "vision_v1p3beta1_generated_image_annotator_async_batch_annotate_files_async.py", + "regionTag": "vision_v1p3beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateFiles" + } + }, + "file": "vision_v1p3beta1_generated_image_annotator_async_batch_annotate_files_sync.py", + "regionTag": "vision_v1p3beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "BatchAnnotateImages" + } + }, + "file": "vision_v1p3beta1_generated_image_annotator_batch_annotate_images_async.py", + "regionTag": "vision_v1p3beta1_generated_ImageAnnotator_BatchAnnotateImages_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": "ImageAnnotator" + }, + "shortName": "BatchAnnotateImages" + } + }, + "file": "vision_v1p3beta1_generated_image_annotator_batch_annotate_images_sync.py", + "regionTag": "vision_v1p3beta1_generated_ImageAnnotator_BatchAnnotateImages_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": "ProductSearch" + }, + "shortName": "AddProductToProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_add_product_to_product_set_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_AddProductToProductSet_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "AddProductToProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_add_product_to_product_set_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_AddProductToProductSet_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "CreateProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_create_product_set_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_CreateProductSet_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": "ProductSearch" + }, + "shortName": "CreateProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_create_product_set_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_CreateProductSet_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": "ProductSearch" + }, + "shortName": "CreateProduct" + } + }, + "file": "vision_v1p3beta1_generated_product_search_create_product_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_CreateProduct_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": "ProductSearch" + }, + "shortName": "CreateProduct" + } + }, + "file": "vision_v1p3beta1_generated_product_search_create_product_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_CreateProduct_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": "ProductSearch" + }, + "shortName": "CreateReferenceImage" + } + }, + "file": "vision_v1p3beta1_generated_product_search_create_reference_image_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_CreateReferenceImage_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "CreateReferenceImage" + } + }, + "file": "vision_v1p3beta1_generated_product_search_create_reference_image_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_CreateReferenceImage_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_delete_product_set_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_DeleteProductSet_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_delete_product_set_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_DeleteProductSet_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProduct" + } + }, + "file": "vision_v1p3beta1_generated_product_search_delete_product_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_DeleteProduct_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProduct" + } + }, + "file": "vision_v1p3beta1_generated_product_search_delete_product_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_DeleteProduct_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteReferenceImage" + } + }, + "file": "vision_v1p3beta1_generated_product_search_delete_reference_image_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_DeleteReferenceImage_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteReferenceImage" + } + }, + "file": "vision_v1p3beta1_generated_product_search_delete_reference_image_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_DeleteReferenceImage_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "GetProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_get_product_set_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_GetProductSet_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": "ProductSearch" + }, + "shortName": "GetProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_get_product_set_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_GetProductSet_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": "ProductSearch" + }, + "shortName": "GetProduct" + } + }, + "file": "vision_v1p3beta1_generated_product_search_get_product_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_GetProduct_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": "ProductSearch" + }, + "shortName": "GetProduct" + } + }, + "file": "vision_v1p3beta1_generated_product_search_get_product_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_GetProduct_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": "ProductSearch" + }, + "shortName": "GetReferenceImage" + } + }, + "file": "vision_v1p3beta1_generated_product_search_get_reference_image_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_GetReferenceImage_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": "ProductSearch" + }, + "shortName": "GetReferenceImage" + } + }, + "file": "vision_v1p3beta1_generated_product_search_get_reference_image_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_GetReferenceImage_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": "ProductSearch" + }, + "shortName": "ImportProductSets" + } + }, + "file": "vision_v1p3beta1_generated_product_search_import_product_sets_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_ImportProductSets_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ImportProductSets" + } + }, + "file": "vision_v1p3beta1_generated_product_search_import_product_sets_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_ImportProductSets_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductSets" + } + }, + "file": "vision_v1p3beta1_generated_product_search_list_product_sets_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_ListProductSets_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductSets" + } + }, + "file": "vision_v1p3beta1_generated_product_search_list_product_sets_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_ListProductSets_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductsInProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_list_products_in_product_set_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_ListProductsInProductSet_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductsInProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_list_products_in_product_set_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_ListProductsInProductSet_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProducts" + } + }, + "file": "vision_v1p3beta1_generated_product_search_list_products_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_ListProducts_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProducts" + } + }, + "file": "vision_v1p3beta1_generated_product_search_list_products_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_ListProducts_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListReferenceImages" + } + }, + "file": "vision_v1p3beta1_generated_product_search_list_reference_images_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_ListReferenceImages_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListReferenceImages" + } + }, + "file": "vision_v1p3beta1_generated_product_search_list_reference_images_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_ListReferenceImages_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "RemoveProductFromProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_remove_product_from_product_set_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_RemoveProductFromProductSet_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "RemoveProductFromProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_remove_product_from_product_set_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_RemoveProductFromProductSet_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "UpdateProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_update_product_set_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_UpdateProductSet_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": "ProductSearch" + }, + "shortName": "UpdateProductSet" + } + }, + "file": "vision_v1p3beta1_generated_product_search_update_product_set_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_UpdateProductSet_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": "ProductSearch" + }, + "shortName": "UpdateProduct" + } + }, + "file": "vision_v1p3beta1_generated_product_search_update_product_async.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_UpdateProduct_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": "ProductSearch" + }, + "shortName": "UpdateProduct" + } + }, + "file": "vision_v1p3beta1_generated_product_search_update_product_sync.py", + "regionTag": "vision_v1p3beta1_generated_ProductSearch_UpdateProduct_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" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_vision_v1p4beta1.json b/samples/generated_samples/snippet_metadata_vision_v1p4beta1.json new file mode 100644 index 00000000..8a312b70 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_vision_v1p4beta1.json @@ -0,0 +1,2031 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateFiles" + } + }, + "file": "vision_v1p4beta1_generated_image_annotator_async_batch_annotate_files_async.py", + "regionTag": "vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateFiles" + } + }, + "file": "vision_v1p4beta1_generated_image_annotator_async_batch_annotate_files_sync.py", + "regionTag": "vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateImages" + } + }, + "file": "vision_v1p4beta1_generated_image_annotator_async_batch_annotate_images_async.py", + "regionTag": "vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateImages_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "AsyncBatchAnnotateImages" + } + }, + "file": "vision_v1p4beta1_generated_image_annotator_async_batch_annotate_images_sync.py", + "regionTag": "vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateImages_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ImageAnnotator" + }, + "shortName": "BatchAnnotateFiles" + } + }, + "file": "vision_v1p4beta1_generated_image_annotator_batch_annotate_files_async.py", + "regionTag": "vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateFiles_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": "ImageAnnotator" + }, + "shortName": "BatchAnnotateFiles" + } + }, + "file": "vision_v1p4beta1_generated_image_annotator_batch_annotate_files_sync.py", + "regionTag": "vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateFiles_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": "ImageAnnotator" + }, + "shortName": "BatchAnnotateImages" + } + }, + "file": "vision_v1p4beta1_generated_image_annotator_batch_annotate_images_async.py", + "regionTag": "vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateImages_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": "ImageAnnotator" + }, + "shortName": "BatchAnnotateImages" + } + }, + "file": "vision_v1p4beta1_generated_image_annotator_batch_annotate_images_sync.py", + "regionTag": "vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateImages_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": "ProductSearch" + }, + "shortName": "AddProductToProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_add_product_to_product_set_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_AddProductToProductSet_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "AddProductToProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_add_product_to_product_set_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_AddProductToProductSet_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "CreateProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_create_product_set_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_CreateProductSet_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": "ProductSearch" + }, + "shortName": "CreateProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_create_product_set_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_CreateProductSet_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": "ProductSearch" + }, + "shortName": "CreateProduct" + } + }, + "file": "vision_v1p4beta1_generated_product_search_create_product_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_CreateProduct_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": "ProductSearch" + }, + "shortName": "CreateProduct" + } + }, + "file": "vision_v1p4beta1_generated_product_search_create_product_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_CreateProduct_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": "ProductSearch" + }, + "shortName": "CreateReferenceImage" + } + }, + "file": "vision_v1p4beta1_generated_product_search_create_reference_image_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_CreateReferenceImage_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "CreateReferenceImage" + } + }, + "file": "vision_v1p4beta1_generated_product_search_create_reference_image_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_CreateReferenceImage_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_delete_product_set_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_DeleteProductSet_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_delete_product_set_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_DeleteProductSet_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProduct" + } + }, + "file": "vision_v1p4beta1_generated_product_search_delete_product_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_DeleteProduct_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteProduct" + } + }, + "file": "vision_v1p4beta1_generated_product_search_delete_product_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_DeleteProduct_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteReferenceImage" + } + }, + "file": "vision_v1p4beta1_generated_product_search_delete_reference_image_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_DeleteReferenceImage_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "DeleteReferenceImage" + } + }, + "file": "vision_v1p4beta1_generated_product_search_delete_reference_image_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_DeleteReferenceImage_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "GetProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_get_product_set_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_GetProductSet_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": "ProductSearch" + }, + "shortName": "GetProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_get_product_set_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_GetProductSet_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": "ProductSearch" + }, + "shortName": "GetProduct" + } + }, + "file": "vision_v1p4beta1_generated_product_search_get_product_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_GetProduct_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": "ProductSearch" + }, + "shortName": "GetProduct" + } + }, + "file": "vision_v1p4beta1_generated_product_search_get_product_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_GetProduct_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": "ProductSearch" + }, + "shortName": "GetReferenceImage" + } + }, + "file": "vision_v1p4beta1_generated_product_search_get_reference_image_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_GetReferenceImage_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": "ProductSearch" + }, + "shortName": "GetReferenceImage" + } + }, + "file": "vision_v1p4beta1_generated_product_search_get_reference_image_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_GetReferenceImage_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": "ProductSearch" + }, + "shortName": "ImportProductSets" + } + }, + "file": "vision_v1p4beta1_generated_product_search_import_product_sets_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_ImportProductSets_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ImportProductSets" + } + }, + "file": "vision_v1p4beta1_generated_product_search_import_product_sets_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_ImportProductSets_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductSets" + } + }, + "file": "vision_v1p4beta1_generated_product_search_list_product_sets_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_ListProductSets_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductSets" + } + }, + "file": "vision_v1p4beta1_generated_product_search_list_product_sets_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_ListProductSets_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductsInProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_list_products_in_product_set_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_ListProductsInProductSet_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProductsInProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_list_products_in_product_set_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_ListProductsInProductSet_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProducts" + } + }, + "file": "vision_v1p4beta1_generated_product_search_list_products_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_ListProducts_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListProducts" + } + }, + "file": "vision_v1p4beta1_generated_product_search_list_products_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_ListProducts_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListReferenceImages" + } + }, + "file": "vision_v1p4beta1_generated_product_search_list_reference_images_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_ListReferenceImages_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "ListReferenceImages" + } + }, + "file": "vision_v1p4beta1_generated_product_search_list_reference_images_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_ListReferenceImages_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "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": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "PurgeProducts" + } + }, + "file": "vision_v1p4beta1_generated_product_search_purge_products_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_PurgeProducts_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "PurgeProducts" + } + }, + "file": "vision_v1p4beta1_generated_product_search_purge_products_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_PurgeProducts_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "RemoveProductFromProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_remove_product_from_product_set_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_RemoveProductFromProductSet_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "RemoveProductFromProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_remove_product_from_product_set_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_RemoveProductFromProductSet_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "ProductSearch" + }, + "shortName": "UpdateProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_update_product_set_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_UpdateProductSet_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": "ProductSearch" + }, + "shortName": "UpdateProductSet" + } + }, + "file": "vision_v1p4beta1_generated_product_search_update_product_set_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_UpdateProductSet_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": "ProductSearch" + }, + "shortName": "UpdateProduct" + } + }, + "file": "vision_v1p4beta1_generated_product_search_update_product_async.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_UpdateProduct_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": "ProductSearch" + }, + "shortName": "UpdateProduct" + } + }, + "file": "vision_v1p4beta1_generated_product_search_update_product_sync.py", + "regionTag": "vision_v1p4beta1_generated_ProductSearch_UpdateProduct_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" + } + ] + } + ] +} diff --git a/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_files_async.py b/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_files_async.py new file mode 100644 index 00000000..6226e997 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_files_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateFiles +# 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-vision + + +# [START vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async] +from google.cloud import vision_v1 + + +async def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async] diff --git a/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_files_sync.py b/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_files_sync.py new file mode 100644 index 00000000..028744c3 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_files_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateFiles +# 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-vision + + +# [START vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync] +from google.cloud import vision_v1 + + +def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync] diff --git a/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_images_async.py b/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_images_async.py new file mode 100644 index 00000000..f06f42aa --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_images_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateImages +# 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-vision + + +# [START vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateImages_async] +from google.cloud import vision_v1 + + +async def sample_async_batch_annotate_images(): + # Create a client + client = vision_v1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1.AsyncBatchAnnotateImagesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_images(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateImages_async] diff --git a/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_images_sync.py b/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_images_sync.py new file mode 100644 index 00000000..73c94918 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_image_annotator_async_batch_annotate_images_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateImages +# 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-vision + + +# [START vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateImages_sync] +from google.cloud import vision_v1 + + +def sample_async_batch_annotate_images(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.AsyncBatchAnnotateImagesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_images(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1_generated_ImageAnnotator_AsyncBatchAnnotateImages_sync] diff --git a/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_files_async.py b/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_files_async.py new file mode 100644 index 00000000..c09df6a2 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_files_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateFiles +# 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-vision + + +# [START vision_v1_generated_ImageAnnotator_BatchAnnotateFiles_async] +from google.cloud import vision_v1 + + +async def sample_batch_annotate_files(): + # Create a client + client = vision_v1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1.BatchAnnotateFilesRequest( + ) + + # Make the request + response = await client.batch_annotate_files(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ImageAnnotator_BatchAnnotateFiles_async] diff --git a/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_files_sync.py b/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_files_sync.py new file mode 100644 index 00000000..9eac77d5 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_files_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateFiles +# 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-vision + + +# [START vision_v1_generated_ImageAnnotator_BatchAnnotateFiles_sync] +from google.cloud import vision_v1 + + +def sample_batch_annotate_files(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.BatchAnnotateFilesRequest( + ) + + # Make the request + response = client.batch_annotate_files(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ImageAnnotator_BatchAnnotateFiles_sync] diff --git a/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_images_async.py b/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_images_async.py new file mode 100644 index 00000000..0e7691f5 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_images_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateImages +# 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-vision + + +# [START vision_v1_generated_ImageAnnotator_BatchAnnotateImages_async] +from google.cloud import vision_v1 + + +async def sample_batch_annotate_images(): + # Create a client + client = vision_v1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = await client.batch_annotate_images(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ImageAnnotator_BatchAnnotateImages_async] diff --git a/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_images_sync.py b/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_images_sync.py new file mode 100644 index 00000000..88a4536e --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_image_annotator_batch_annotate_images_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateImages +# 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-vision + + +# [START vision_v1_generated_ImageAnnotator_BatchAnnotateImages_sync] +from google.cloud import vision_v1 + + +def sample_batch_annotate_images(): + # Create a client + client = vision_v1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ImageAnnotator_BatchAnnotateImages_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_add_product_to_product_set_async.py b/samples/generated_samples/vision_v1_generated_product_search_add_product_to_product_set_async.py new file mode 100644 index 00000000..ed1e2bd8 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_add_product_to_product_set_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddProductToProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_AddProductToProductSet_async] +from google.cloud import vision_v1 + + +async def sample_add_product_to_product_set(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + await client.add_product_to_product_set(request=request) + + +# [END vision_v1_generated_ProductSearch_AddProductToProductSet_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_add_product_to_product_set_sync.py b/samples/generated_samples/vision_v1_generated_product_search_add_product_to_product_set_sync.py new file mode 100644 index 00000000..29fe7afb --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_add_product_to_product_set_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddProductToProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_AddProductToProductSet_sync] +from google.cloud import vision_v1 + + +def sample_add_product_to_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.add_product_to_product_set(request=request) + + +# [END vision_v1_generated_ProductSearch_AddProductToProductSet_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_create_product_async.py b/samples/generated_samples/vision_v1_generated_product_search_create_product_async.py new file mode 100644 index 00000000..bf946336 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_create_product_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProduct +# 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-vision + + +# [START vision_v1_generated_ProductSearch_CreateProduct_async] +from google.cloud import vision_v1 + + +async def sample_create_product(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_CreateProduct_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_create_product_set_async.py b/samples/generated_samples/vision_v1_generated_product_search_create_product_set_async.py new file mode 100644 index 00000000..fd46b3bd --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_create_product_set_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_CreateProductSet_async] +from google.cloud import vision_v1 + + +async def sample_create_product_set(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_CreateProductSet_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_create_product_set_sync.py b/samples/generated_samples/vision_v1_generated_product_search_create_product_set_sync.py new file mode 100644 index 00000000..581f3ca0 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_create_product_set_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_CreateProductSet_sync] +from google.cloud import vision_v1 + + +def sample_create_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_CreateProductSet_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_create_product_sync.py b/samples/generated_samples/vision_v1_generated_product_search_create_product_sync.py new file mode 100644 index 00000000..fe57e203 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_create_product_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProduct +# 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-vision + + +# [START vision_v1_generated_ProductSearch_CreateProduct_sync] +from google.cloud import vision_v1 + + +def sample_create_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_CreateProduct_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_create_reference_image_async.py b/samples/generated_samples/vision_v1_generated_product_search_create_reference_image_async.py new file mode 100644 index 00000000..18497bc0 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_create_reference_image_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateReferenceImage +# 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-vision + + +# [START vision_v1_generated_ProductSearch_CreateReferenceImage_async] +from google.cloud import vision_v1 + + +async def sample_create_reference_image(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + reference_image = vision_v1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = await client.create_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_CreateReferenceImage_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_create_reference_image_sync.py b/samples/generated_samples/vision_v1_generated_product_search_create_reference_image_sync.py new file mode 100644 index 00000000..ceae9b0a --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_create_reference_image_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateReferenceImage +# 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-vision + + +# [START vision_v1_generated_ProductSearch_CreateReferenceImage_sync] +from google.cloud import vision_v1 + + +def sample_create_reference_image(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + reference_image = vision_v1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = client.create_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_CreateReferenceImage_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_delete_product_async.py b/samples/generated_samples/vision_v1_generated_product_search_delete_product_async.py new file mode 100644 index 00000000..1831f433 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_delete_product_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProduct +# 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-vision + + +# [START vision_v1_generated_ProductSearch_DeleteProduct_async] +from google.cloud import vision_v1 + + +async def sample_delete_product(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + await client.delete_product(request=request) + + +# [END vision_v1_generated_ProductSearch_DeleteProduct_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_delete_product_set_async.py b/samples/generated_samples/vision_v1_generated_product_search_delete_product_set_async.py new file mode 100644 index 00000000..17b81593 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_delete_product_set_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_DeleteProductSet_async] +from google.cloud import vision_v1 + + +async def sample_delete_product_set(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + await client.delete_product_set(request=request) + + +# [END vision_v1_generated_ProductSearch_DeleteProductSet_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_delete_product_set_sync.py b/samples/generated_samples/vision_v1_generated_product_search_delete_product_set_sync.py new file mode 100644 index 00000000..a4481e02 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_delete_product_set_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_DeleteProductSet_sync] +from google.cloud import vision_v1 + + +def sample_delete_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + client.delete_product_set(request=request) + + +# [END vision_v1_generated_ProductSearch_DeleteProductSet_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_delete_product_sync.py b/samples/generated_samples/vision_v1_generated_product_search_delete_product_sync.py new file mode 100644 index 00000000..f8fa3fad --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_delete_product_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProduct +# 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-vision + + +# [START vision_v1_generated_ProductSearch_DeleteProduct_sync] +from google.cloud import vision_v1 + + +def sample_delete_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + client.delete_product(request=request) + + +# [END vision_v1_generated_ProductSearch_DeleteProduct_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_delete_reference_image_async.py b/samples/generated_samples/vision_v1_generated_product_search_delete_reference_image_async.py new file mode 100644 index 00000000..830b88f0 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_delete_reference_image_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteReferenceImage +# 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-vision + + +# [START vision_v1_generated_ProductSearch_DeleteReferenceImage_async] +from google.cloud import vision_v1 + + +async def sample_delete_reference_image(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + await client.delete_reference_image(request=request) + + +# [END vision_v1_generated_ProductSearch_DeleteReferenceImage_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_delete_reference_image_sync.py b/samples/generated_samples/vision_v1_generated_product_search_delete_reference_image_sync.py new file mode 100644 index 00000000..7beb3f83 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_delete_reference_image_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteReferenceImage +# 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-vision + + +# [START vision_v1_generated_ProductSearch_DeleteReferenceImage_sync] +from google.cloud import vision_v1 + + +def sample_delete_reference_image(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + client.delete_reference_image(request=request) + + +# [END vision_v1_generated_ProductSearch_DeleteReferenceImage_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_get_product_async.py b/samples/generated_samples/vision_v1_generated_product_search_get_product_async.py new file mode 100644 index 00000000..fa998b95 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_get_product_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProduct +# 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-vision + + +# [START vision_v1_generated_ProductSearch_GetProduct_async] +from google.cloud import vision_v1 + + +async def sample_get_product(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = await client.get_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_GetProduct_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_get_product_set_async.py b/samples/generated_samples/vision_v1_generated_product_search_get_product_set_async.py new file mode 100644 index 00000000..8f9862fc --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_get_product_set_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_GetProductSet_async] +from google.cloud import vision_v1 + + +async def sample_get_product_set(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = await client.get_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_GetProductSet_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_get_product_set_sync.py b/samples/generated_samples/vision_v1_generated_product_search_get_product_set_sync.py new file mode 100644 index 00000000..cd592b37 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_get_product_set_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_GetProductSet_sync] +from google.cloud import vision_v1 + + +def sample_get_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = client.get_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_GetProductSet_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_get_product_sync.py b/samples/generated_samples/vision_v1_generated_product_search_get_product_sync.py new file mode 100644 index 00000000..88b5b72b --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_get_product_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProduct +# 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-vision + + +# [START vision_v1_generated_ProductSearch_GetProduct_sync] +from google.cloud import vision_v1 + + +def sample_get_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_GetProduct_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_get_reference_image_async.py b/samples/generated_samples/vision_v1_generated_product_search_get_reference_image_async.py new file mode 100644 index 00000000..059604f9 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_get_reference_image_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetReferenceImage +# 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-vision + + +# [START vision_v1_generated_ProductSearch_GetReferenceImage_async] +from google.cloud import vision_v1 + + +async def sample_get_reference_image(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = await client.get_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_GetReferenceImage_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_get_reference_image_sync.py b/samples/generated_samples/vision_v1_generated_product_search_get_reference_image_sync.py new file mode 100644 index 00000000..cb19d1ce --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_get_reference_image_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetReferenceImage +# 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-vision + + +# [START vision_v1_generated_ProductSearch_GetReferenceImage_sync] +from google.cloud import vision_v1 + + +def sample_get_reference_image(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = client.get_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_GetReferenceImage_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_import_product_sets_async.py b/samples/generated_samples/vision_v1_generated_product_search_import_product_sets_async.py new file mode 100644 index 00000000..be8141fa --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_import_product_sets_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportProductSets +# 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-vision + + +# [START vision_v1_generated_ProductSearch_ImportProductSets_async] +from google.cloud import vision_v1 + + +async def sample_import_product_sets(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_ImportProductSets_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_import_product_sets_sync.py b/samples/generated_samples/vision_v1_generated_product_search_import_product_sets_sync.py new file mode 100644 index 00000000..6243011a --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_import_product_sets_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportProductSets +# 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-vision + + +# [START vision_v1_generated_ProductSearch_ImportProductSets_sync] +from google.cloud import vision_v1 + + +def sample_import_product_sets(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_ImportProductSets_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_list_product_sets_async.py b/samples/generated_samples/vision_v1_generated_product_search_list_product_sets_async.py new file mode 100644 index 00000000..eef8937f --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_list_product_sets_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductSets +# 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-vision + + +# [START vision_v1_generated_ProductSearch_ListProductSets_async] +from google.cloud import vision_v1 + + +async def sample_list_product_sets(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1_generated_ProductSearch_ListProductSets_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_list_product_sets_sync.py b/samples/generated_samples/vision_v1_generated_product_search_list_product_sets_sync.py new file mode 100644 index 00000000..fad94a07 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_list_product_sets_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductSets +# 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-vision + + +# [START vision_v1_generated_ProductSearch_ListProductSets_sync] +from google.cloud import vision_v1 + + +def sample_list_product_sets(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1_generated_ProductSearch_ListProductSets_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_list_products_async.py b/samples/generated_samples/vision_v1_generated_product_search_list_products_async.py new file mode 100644 index 00000000..b48b7669 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_list_products_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProducts +# 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-vision + + +# [START vision_v1_generated_ProductSearch_ListProducts_async] +from google.cloud import vision_v1 + + +async def sample_list_products(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1_generated_ProductSearch_ListProducts_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_list_products_in_product_set_async.py b/samples/generated_samples/vision_v1_generated_product_search_list_products_in_product_set_async.py new file mode 100644 index 00000000..31c269d4 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_list_products_in_product_set_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductsInProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_ListProductsInProductSet_async] +from google.cloud import vision_v1 + + +async def sample_list_products_in_product_set(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1_generated_ProductSearch_ListProductsInProductSet_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_list_products_in_product_set_sync.py b/samples/generated_samples/vision_v1_generated_product_search_list_products_in_product_set_sync.py new file mode 100644 index 00000000..5b32317c --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_list_products_in_product_set_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductsInProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_ListProductsInProductSet_sync] +from google.cloud import vision_v1 + + +def sample_list_products_in_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1_generated_ProductSearch_ListProductsInProductSet_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_list_products_sync.py b/samples/generated_samples/vision_v1_generated_product_search_list_products_sync.py new file mode 100644 index 00000000..d3516515 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_list_products_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProducts +# 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-vision + + +# [START vision_v1_generated_ProductSearch_ListProducts_sync] +from google.cloud import vision_v1 + + +def sample_list_products(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1_generated_ProductSearch_ListProducts_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_list_reference_images_async.py b/samples/generated_samples/vision_v1_generated_product_search_list_reference_images_async.py new file mode 100644 index 00000000..6394b8e7 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_list_reference_images_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListReferenceImages +# 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-vision + + +# [START vision_v1_generated_ProductSearch_ListReferenceImages_async] +from google.cloud import vision_v1 + + +async def sample_list_reference_images(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1_generated_ProductSearch_ListReferenceImages_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_list_reference_images_sync.py b/samples/generated_samples/vision_v1_generated_product_search_list_reference_images_sync.py new file mode 100644 index 00000000..1ced3d04 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_list_reference_images_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListReferenceImages +# 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-vision + + +# [START vision_v1_generated_ProductSearch_ListReferenceImages_sync] +from google.cloud import vision_v1 + + +def sample_list_reference_images(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1_generated_ProductSearch_ListReferenceImages_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_purge_products_async.py b/samples/generated_samples/vision_v1_generated_product_search_purge_products_async.py new file mode 100644 index 00000000..5d49ee36 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_purge_products_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeProducts +# 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-vision + + +# [START vision_v1_generated_ProductSearch_PurgeProducts_async] +from google.cloud import vision_v1 + + +async def sample_purge_products(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.PurgeProductsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.purge_products(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_PurgeProducts_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_purge_products_sync.py b/samples/generated_samples/vision_v1_generated_product_search_purge_products_sync.py new file mode 100644 index 00000000..a12d8e61 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_purge_products_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeProducts +# 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-vision + + +# [START vision_v1_generated_ProductSearch_PurgeProducts_sync] +from google.cloud import vision_v1 + + +def sample_purge_products(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.PurgeProductsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.purge_products(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_PurgeProducts_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_remove_product_from_product_set_async.py b/samples/generated_samples/vision_v1_generated_product_search_remove_product_from_product_set_async.py new file mode 100644 index 00000000..f6dc57c6 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_remove_product_from_product_set_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RemoveProductFromProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_RemoveProductFromProductSet_async] +from google.cloud import vision_v1 + + +async def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + await client.remove_product_from_product_set(request=request) + + +# [END vision_v1_generated_ProductSearch_RemoveProductFromProductSet_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_remove_product_from_product_set_sync.py b/samples/generated_samples/vision_v1_generated_product_search_remove_product_from_product_set_sync.py new file mode 100644 index 00000000..10e6b70f --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_remove_product_from_product_set_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RemoveProductFromProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_RemoveProductFromProductSet_sync] +from google.cloud import vision_v1 + + +def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.remove_product_from_product_set(request=request) + + +# [END vision_v1_generated_ProductSearch_RemoveProductFromProductSet_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_update_product_async.py b/samples/generated_samples/vision_v1_generated_product_search_update_product_async.py new file mode 100644 index 00000000..2387c5bd --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_update_product_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProduct +# 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-vision + + +# [START vision_v1_generated_ProductSearch_UpdateProduct_async] +from google.cloud import vision_v1 + + +async def sample_update_product(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.UpdateProductRequest( + ) + + # Make the request + response = await client.update_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_UpdateProduct_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_update_product_set_async.py b/samples/generated_samples/vision_v1_generated_product_search_update_product_set_async.py new file mode 100644 index 00000000..5706b54e --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_update_product_set_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_UpdateProductSet_async] +from google.cloud import vision_v1 + + +async def sample_update_product_set(): + # Create a client + client = vision_v1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1.UpdateProductSetRequest( + ) + + # Make the request + response = await client.update_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_UpdateProductSet_async] diff --git a/samples/generated_samples/vision_v1_generated_product_search_update_product_set_sync.py b/samples/generated_samples/vision_v1_generated_product_search_update_product_set_sync.py new file mode 100644 index 00000000..1d24cf6a --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_update_product_set_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProductSet +# 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-vision + + +# [START vision_v1_generated_ProductSearch_UpdateProductSet_sync] +from google.cloud import vision_v1 + + +def sample_update_product_set(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.UpdateProductSetRequest( + ) + + # Make the request + response = client.update_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_UpdateProductSet_sync] diff --git a/samples/generated_samples/vision_v1_generated_product_search_update_product_sync.py b/samples/generated_samples/vision_v1_generated_product_search_update_product_sync.py new file mode 100644 index 00000000..5655e9a6 --- /dev/null +++ b/samples/generated_samples/vision_v1_generated_product_search_update_product_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProduct +# 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-vision + + +# [START vision_v1_generated_ProductSearch_UpdateProduct_sync] +from google.cloud import vision_v1 + + +def sample_update_product(): + # Create a client + client = vision_v1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1.UpdateProductRequest( + ) + + # Make the request + response = client.update_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1_generated_ProductSearch_UpdateProduct_sync] diff --git a/samples/generated_samples/vision_v1p1beta1_generated_image_annotator_batch_annotate_images_async.py b/samples/generated_samples/vision_v1p1beta1_generated_image_annotator_batch_annotate_images_async.py new file mode 100644 index 00000000..3b37ba99 --- /dev/null +++ b/samples/generated_samples/vision_v1p1beta1_generated_image_annotator_batch_annotate_images_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateImages +# 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-vision + + +# [START vision_v1p1beta1_generated_ImageAnnotator_BatchAnnotateImages_async] +from google.cloud import vision_v1p1beta1 + + +async def sample_batch_annotate_images(): + # Create a client + client = vision_v1p1beta1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1p1beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = await client.batch_annotate_images(request=request) + + # Handle the response + print(response) + +# [END vision_v1p1beta1_generated_ImageAnnotator_BatchAnnotateImages_async] diff --git a/samples/generated_samples/vision_v1p1beta1_generated_image_annotator_batch_annotate_images_sync.py b/samples/generated_samples/vision_v1p1beta1_generated_image_annotator_batch_annotate_images_sync.py new file mode 100644 index 00000000..8e5f8967 --- /dev/null +++ b/samples/generated_samples/vision_v1p1beta1_generated_image_annotator_batch_annotate_images_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateImages +# 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-vision + + +# [START vision_v1p1beta1_generated_ImageAnnotator_BatchAnnotateImages_sync] +from google.cloud import vision_v1p1beta1 + + +def sample_batch_annotate_images(): + # Create a client + client = vision_v1p1beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p1beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + +# [END vision_v1p1beta1_generated_ImageAnnotator_BatchAnnotateImages_sync] diff --git a/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_async_batch_annotate_files_async.py b/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_async_batch_annotate_files_async.py new file mode 100644 index 00000000..93fbdba2 --- /dev/null +++ b/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_async_batch_annotate_files_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateFiles +# 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-vision + + +# [START vision_v1p2beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async] +from google.cloud import vision_v1p2beta1 + + +async def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p2beta1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1p2beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1p2beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async] diff --git a/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_async_batch_annotate_files_sync.py b/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_async_batch_annotate_files_sync.py new file mode 100644 index 00000000..996ade25 --- /dev/null +++ b/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_async_batch_annotate_files_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateFiles +# 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-vision + + +# [START vision_v1p2beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync] +from google.cloud import vision_v1p2beta1 + + +def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p2beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p2beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1p2beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync] diff --git a/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_batch_annotate_images_async.py b/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_batch_annotate_images_async.py new file mode 100644 index 00000000..e2b2c9d7 --- /dev/null +++ b/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_batch_annotate_images_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateImages +# 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-vision + + +# [START vision_v1p2beta1_generated_ImageAnnotator_BatchAnnotateImages_async] +from google.cloud import vision_v1p2beta1 + + +async def sample_batch_annotate_images(): + # Create a client + client = vision_v1p2beta1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1p2beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = await client.batch_annotate_images(request=request) + + # Handle the response + print(response) + +# [END vision_v1p2beta1_generated_ImageAnnotator_BatchAnnotateImages_async] diff --git a/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_batch_annotate_images_sync.py b/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_batch_annotate_images_sync.py new file mode 100644 index 00000000..04b0a807 --- /dev/null +++ b/samples/generated_samples/vision_v1p2beta1_generated_image_annotator_batch_annotate_images_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateImages +# 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-vision + + +# [START vision_v1p2beta1_generated_ImageAnnotator_BatchAnnotateImages_sync] +from google.cloud import vision_v1p2beta1 + + +def sample_batch_annotate_images(): + # Create a client + client = vision_v1p2beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p2beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + +# [END vision_v1p2beta1_generated_ImageAnnotator_BatchAnnotateImages_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_async_batch_annotate_files_async.py b/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_async_batch_annotate_files_async.py new file mode 100644 index 00000000..10b44a96 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_async_batch_annotate_files_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateFiles +# 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-vision + + +# [START vision_v1p3beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p3beta1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_async_batch_annotate_files_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_async_batch_annotate_files_sync.py new file mode 100644 index 00000000..26e1fbee --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_async_batch_annotate_files_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateFiles +# 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-vision + + +# [START vision_v1p3beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p3beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_batch_annotate_images_async.py b/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_batch_annotate_images_async.py new file mode 100644 index 00000000..45d1c1f0 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_batch_annotate_images_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateImages +# 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-vision + + +# [START vision_v1p3beta1_generated_ImageAnnotator_BatchAnnotateImages_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_batch_annotate_images(): + # Create a client + client = vision_v1p3beta1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = await client.batch_annotate_images(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ImageAnnotator_BatchAnnotateImages_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_batch_annotate_images_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_batch_annotate_images_sync.py new file mode 100644 index 00000000..f754ef17 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_image_annotator_batch_annotate_images_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateImages +# 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-vision + + +# [START vision_v1p3beta1_generated_ImageAnnotator_BatchAnnotateImages_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_batch_annotate_images(): + # Create a client + client = vision_v1p3beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ImageAnnotator_BatchAnnotateImages_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_add_product_to_product_set_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_add_product_to_product_set_async.py new file mode 100644 index 00000000..36320750 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_add_product_to_product_set_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddProductToProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_AddProductToProductSet_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_add_product_to_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + await client.add_product_to_product_set(request=request) + + +# [END vision_v1p3beta1_generated_ProductSearch_AddProductToProductSet_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_add_product_to_product_set_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_add_product_to_product_set_sync.py new file mode 100644 index 00000000..e62449f3 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_add_product_to_product_set_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddProductToProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_AddProductToProductSet_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_add_product_to_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.add_product_to_product_set(request=request) + + +# [END vision_v1p3beta1_generated_ProductSearch_AddProductToProductSet_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_async.py new file mode 100644 index 00000000..03644862 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProduct +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_CreateProduct_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_create_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_CreateProduct_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_set_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_set_async.py new file mode 100644 index 00000000..c6076ba2 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_set_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_CreateProductSet_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_create_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_CreateProductSet_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_set_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_set_sync.py new file mode 100644 index 00000000..a0e3228c --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_set_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_CreateProductSet_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_create_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_CreateProductSet_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_sync.py new file mode 100644 index 00000000..932b9396 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_product_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProduct +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_CreateProduct_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_create_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_CreateProduct_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_reference_image_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_reference_image_async.py new file mode 100644 index 00000000..7ac32420 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_reference_image_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateReferenceImage +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_CreateReferenceImage_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_create_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + reference_image = vision_v1p3beta1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1p3beta1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = await client.create_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_CreateReferenceImage_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_reference_image_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_reference_image_sync.py new file mode 100644 index 00000000..280651d3 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_create_reference_image_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateReferenceImage +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_CreateReferenceImage_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_create_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + reference_image = vision_v1p3beta1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1p3beta1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = client.create_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_CreateReferenceImage_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_async.py new file mode 100644 index 00000000..15c1bcca --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProduct +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_DeleteProduct_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_delete_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + await client.delete_product(request=request) + + +# [END vision_v1p3beta1_generated_ProductSearch_DeleteProduct_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_set_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_set_async.py new file mode 100644 index 00000000..ca8bcb35 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_set_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_DeleteProductSet_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_delete_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + await client.delete_product_set(request=request) + + +# [END vision_v1p3beta1_generated_ProductSearch_DeleteProductSet_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_set_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_set_sync.py new file mode 100644 index 00000000..023a02bb --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_set_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_DeleteProductSet_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_delete_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + client.delete_product_set(request=request) + + +# [END vision_v1p3beta1_generated_ProductSearch_DeleteProductSet_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_sync.py new file mode 100644 index 00000000..d7262f49 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_product_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProduct +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_DeleteProduct_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_delete_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + client.delete_product(request=request) + + +# [END vision_v1p3beta1_generated_ProductSearch_DeleteProduct_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_reference_image_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_reference_image_async.py new file mode 100644 index 00000000..7ad98e65 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_reference_image_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteReferenceImage +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_DeleteReferenceImage_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_delete_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + await client.delete_reference_image(request=request) + + +# [END vision_v1p3beta1_generated_ProductSearch_DeleteReferenceImage_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_reference_image_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_reference_image_sync.py new file mode 100644 index 00000000..50a1e9ff --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_delete_reference_image_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteReferenceImage +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_DeleteReferenceImage_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_delete_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + client.delete_reference_image(request=request) + + +# [END vision_v1p3beta1_generated_ProductSearch_DeleteReferenceImage_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_async.py new file mode 100644 index 00000000..9ef5bd7c --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProduct +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_GetProduct_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_get_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = await client.get_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_GetProduct_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_set_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_set_async.py new file mode 100644 index 00000000..f0b0fb00 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_set_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_GetProductSet_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_get_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = await client.get_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_GetProductSet_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_set_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_set_sync.py new file mode 100644 index 00000000..09187224 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_set_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_GetProductSet_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_get_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = client.get_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_GetProductSet_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_sync.py new file mode 100644 index 00000000..24c20878 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_product_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProduct +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_GetProduct_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_get_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_GetProduct_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_reference_image_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_reference_image_async.py new file mode 100644 index 00000000..4c9db65a --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_reference_image_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetReferenceImage +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_GetReferenceImage_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_get_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = await client.get_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_GetReferenceImage_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_reference_image_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_reference_image_sync.py new file mode 100644 index 00000000..2485d0c4 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_get_reference_image_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetReferenceImage +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_GetReferenceImage_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_get_reference_image(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = client.get_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_GetReferenceImage_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_import_product_sets_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_import_product_sets_async.py new file mode 100644 index 00000000..b805d043 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_import_product_sets_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportProductSets +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_ImportProductSets_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_import_product_sets(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_ImportProductSets_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_import_product_sets_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_import_product_sets_sync.py new file mode 100644 index 00000000..bbc33d79 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_import_product_sets_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportProductSets +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_ImportProductSets_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_import_product_sets(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_ImportProductSets_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_product_sets_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_product_sets_async.py new file mode 100644 index 00000000..00c178df --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_product_sets_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductSets +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_ListProductSets_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_list_product_sets(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_ListProductSets_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_product_sets_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_product_sets_sync.py new file mode 100644 index 00000000..3304c071 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_product_sets_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductSets +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_ListProductSets_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_list_product_sets(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_ListProductSets_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_async.py new file mode 100644 index 00000000..738e1fb8 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProducts +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_ListProducts_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_list_products(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_ListProducts_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_in_product_set_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_in_product_set_async.py new file mode 100644 index 00000000..98c1c128 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_in_product_set_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductsInProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_ListProductsInProductSet_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_list_products_in_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_ListProductsInProductSet_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_in_product_set_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_in_product_set_sync.py new file mode 100644 index 00000000..50902a45 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_in_product_set_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductsInProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_ListProductsInProductSet_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_list_products_in_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_ListProductsInProductSet_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_sync.py new file mode 100644 index 00000000..9da9d12a --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_products_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProducts +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_ListProducts_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_list_products(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_ListProducts_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_reference_images_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_reference_images_async.py new file mode 100644 index 00000000..018fbdf0 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_reference_images_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListReferenceImages +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_ListReferenceImages_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_list_reference_images(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_ListReferenceImages_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_reference_images_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_reference_images_sync.py new file mode 100644 index 00000000..83536bfe --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_list_reference_images_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListReferenceImages +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_ListReferenceImages_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_list_reference_images(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_ListReferenceImages_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_remove_product_from_product_set_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_remove_product_from_product_set_async.py new file mode 100644 index 00000000..13047fbb --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_remove_product_from_product_set_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RemoveProductFromProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_RemoveProductFromProductSet_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + await client.remove_product_from_product_set(request=request) + + +# [END vision_v1p3beta1_generated_ProductSearch_RemoveProductFromProductSet_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_remove_product_from_product_set_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_remove_product_from_product_set_sync.py new file mode 100644 index 00000000..efd01864 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_remove_product_from_product_set_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RemoveProductFromProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_RemoveProductFromProductSet_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.remove_product_from_product_set(request=request) + + +# [END vision_v1p3beta1_generated_ProductSearch_RemoveProductFromProductSet_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_async.py new file mode 100644 index 00000000..d84f1f8f --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProduct +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_UpdateProduct_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_update_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.UpdateProductRequest( + ) + + # Make the request + response = await client.update_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_UpdateProduct_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_set_async.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_set_async.py new file mode 100644 index 00000000..56687e51 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_set_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_UpdateProductSet_async] +from google.cloud import vision_v1p3beta1 + + +async def sample_update_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.UpdateProductSetRequest( + ) + + # Make the request + response = await client.update_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_UpdateProductSet_async] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_set_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_set_sync.py new file mode 100644 index 00000000..905e63f8 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_set_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProductSet +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_UpdateProductSet_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_update_product_set(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.UpdateProductSetRequest( + ) + + # Make the request + response = client.update_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_UpdateProductSet_sync] diff --git a/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_sync.py b/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_sync.py new file mode 100644 index 00000000..60c47ae2 --- /dev/null +++ b/samples/generated_samples/vision_v1p3beta1_generated_product_search_update_product_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProduct +# 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-vision + + +# [START vision_v1p3beta1_generated_ProductSearch_UpdateProduct_sync] +from google.cloud import vision_v1p3beta1 + + +def sample_update_product(): + # Create a client + client = vision_v1p3beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p3beta1.UpdateProductRequest( + ) + + # Make the request + response = client.update_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p3beta1_generated_ProductSearch_UpdateProduct_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_files_async.py b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_files_async.py new file mode 100644 index 00000000..6d8661cd --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_files_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateFiles +# 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-vision + + +# [START vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_files_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_files_sync.py new file mode 100644 index 00000000..59431046 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_files_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateFiles +# 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-vision + + +# [START vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_async_batch_annotate_files(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AsyncBatchAnnotateFilesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_files(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateFiles_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_images_async.py b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_images_async.py new file mode 100644 index 00000000..ada26db9 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_images_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateImages +# 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-vision + + +# [START vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateImages_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_async_batch_annotate_images(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AsyncBatchAnnotateImagesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_images(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateImages_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_images_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_images_sync.py new file mode 100644 index 00000000..39dfb18d --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_async_batch_annotate_images_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AsyncBatchAnnotateImages +# 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-vision + + +# [START vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateImages_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_async_batch_annotate_images(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AsyncBatchAnnotateImagesRequest( + ) + + # Make the request + operation = client.async_batch_annotate_images(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ImageAnnotator_AsyncBatchAnnotateImages_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_files_async.py b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_files_async.py new file mode 100644 index 00000000..b84e92ee --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_files_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateFiles +# 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-vision + + +# [START vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateFiles_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_batch_annotate_files(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.BatchAnnotateFilesRequest( + ) + + # Make the request + response = await client.batch_annotate_files(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateFiles_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_files_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_files_sync.py new file mode 100644 index 00000000..11c7bfdd --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_files_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateFiles +# 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-vision + + +# [START vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateFiles_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_batch_annotate_files(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.BatchAnnotateFilesRequest( + ) + + # Make the request + response = client.batch_annotate_files(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateFiles_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_images_async.py b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_images_async.py new file mode 100644 index 00000000..86725658 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_images_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateImages +# 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-vision + + +# [START vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateImages_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_batch_annotate_images(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = await client.batch_annotate_images(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateImages_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_images_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_images_sync.py new file mode 100644 index 00000000..2fef1158 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_image_annotator_batch_annotate_images_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchAnnotateImages +# 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-vision + + +# [START vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateImages_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_batch_annotate_images(): + # Create a client + client = vision_v1p4beta1.ImageAnnotatorClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.BatchAnnotateImagesRequest( + ) + + # Make the request + response = client.batch_annotate_images(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ImageAnnotator_BatchAnnotateImages_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_add_product_to_product_set_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_add_product_to_product_set_async.py new file mode 100644 index 00000000..f32ceb7c --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_add_product_to_product_set_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddProductToProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_AddProductToProductSet_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_add_product_to_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + await client.add_product_to_product_set(request=request) + + +# [END vision_v1p4beta1_generated_ProductSearch_AddProductToProductSet_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_add_product_to_product_set_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_add_product_to_product_set_sync.py new file mode 100644 index 00000000..adf51de6 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_add_product_to_product_set_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddProductToProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_AddProductToProductSet_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_add_product_to_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.AddProductToProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.add_product_to_product_set(request=request) + + +# [END vision_v1p4beta1_generated_ProductSearch_AddProductToProductSet_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_async.py new file mode 100644 index 00000000..946c2549 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProduct +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_CreateProduct_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_create_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_CreateProduct_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_set_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_set_async.py new file mode 100644 index 00000000..33e5c8e9 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_set_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_CreateProductSet_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_create_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_CreateProductSet_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_set_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_set_sync.py new file mode 100644 index 00000000..174540e7 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_set_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_CreateProductSet_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_create_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.CreateProductSetRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_CreateProductSet_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_sync.py new file mode 100644 index 00000000..5a536f9d --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_product_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateProduct +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_CreateProduct_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_create_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.CreateProductRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_CreateProduct_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_reference_image_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_reference_image_async.py new file mode 100644 index 00000000..ce9cc79f --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_reference_image_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateReferenceImage +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_CreateReferenceImage_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_create_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + reference_image = vision_v1p4beta1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1p4beta1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = await client.create_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_CreateReferenceImage_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_reference_image_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_reference_image_sync.py new file mode 100644 index 00000000..9b8f5b27 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_create_reference_image_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateReferenceImage +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_CreateReferenceImage_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_create_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + reference_image = vision_v1p4beta1.ReferenceImage() + reference_image.uri = "uri_value" + + request = vision_v1p4beta1.CreateReferenceImageRequest( + parent="parent_value", + reference_image=reference_image, + ) + + # Make the request + response = client.create_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_CreateReferenceImage_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_async.py new file mode 100644 index 00000000..b6cbae49 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProduct +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_DeleteProduct_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_delete_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + await client.delete_product(request=request) + + +# [END vision_v1p4beta1_generated_ProductSearch_DeleteProduct_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_set_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_set_async.py new file mode 100644 index 00000000..9f756fe1 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_set_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_DeleteProductSet_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_delete_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + await client.delete_product_set(request=request) + + +# [END vision_v1p4beta1_generated_ProductSearch_DeleteProductSet_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_set_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_set_sync.py new file mode 100644 index 00000000..4932e163 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_set_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_DeleteProductSet_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_delete_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteProductSetRequest( + name="name_value", + ) + + # Make the request + client.delete_product_set(request=request) + + +# [END vision_v1p4beta1_generated_ProductSearch_DeleteProductSet_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_sync.py new file mode 100644 index 00000000..f1c4ed75 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_product_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProduct +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_DeleteProduct_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_delete_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteProductRequest( + name="name_value", + ) + + # Make the request + client.delete_product(request=request) + + +# [END vision_v1p4beta1_generated_ProductSearch_DeleteProduct_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_reference_image_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_reference_image_async.py new file mode 100644 index 00000000..5be65e8e --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_reference_image_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteReferenceImage +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_DeleteReferenceImage_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_delete_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + await client.delete_reference_image(request=request) + + +# [END vision_v1p4beta1_generated_ProductSearch_DeleteReferenceImage_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_reference_image_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_reference_image_sync.py new file mode 100644 index 00000000..5aa274b0 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_delete_reference_image_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteReferenceImage +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_DeleteReferenceImage_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_delete_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.DeleteReferenceImageRequest( + name="name_value", + ) + + # Make the request + client.delete_reference_image(request=request) + + +# [END vision_v1p4beta1_generated_ProductSearch_DeleteReferenceImage_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_async.py new file mode 100644 index 00000000..40466cce --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProduct +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_GetProduct_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_get_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = await client.get_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_GetProduct_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_set_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_set_async.py new file mode 100644 index 00000000..242aae30 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_set_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_GetProductSet_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_get_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = await client.get_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_GetProductSet_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_set_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_set_sync.py new file mode 100644 index 00000000..69d04d3e --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_set_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_GetProductSet_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_get_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetProductSetRequest( + name="name_value", + ) + + # Make the request + response = client.get_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_GetProductSet_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_sync.py new file mode 100644 index 00000000..dccd9868 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_product_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProduct +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_GetProduct_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_get_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_GetProduct_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_reference_image_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_reference_image_async.py new file mode 100644 index 00000000..404cbadd --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_reference_image_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetReferenceImage +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_GetReferenceImage_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_get_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = await client.get_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_GetReferenceImage_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_reference_image_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_reference_image_sync.py new file mode 100644 index 00000000..f0ccc3a3 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_get_reference_image_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetReferenceImage +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_GetReferenceImage_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_get_reference_image(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.GetReferenceImageRequest( + name="name_value", + ) + + # Make the request + response = client.get_reference_image(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_GetReferenceImage_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_import_product_sets_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_import_product_sets_async.py new file mode 100644 index 00000000..a9bc814d --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_import_product_sets_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportProductSets +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_ImportProductSets_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_import_product_sets(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_ImportProductSets_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_import_product_sets_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_import_product_sets_sync.py new file mode 100644 index 00000000..a68c06a9 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_import_product_sets_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportProductSets +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_ImportProductSets_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_import_product_sets(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ImportProductSetsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.import_product_sets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_ImportProductSets_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_product_sets_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_product_sets_async.py new file mode 100644 index 00000000..03f1058c --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_product_sets_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductSets +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_ListProductSets_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_list_product_sets(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_ListProductSets_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_product_sets_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_product_sets_sync.py new file mode 100644 index 00000000..16f1bd6e --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_product_sets_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductSets +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_ListProductSets_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_list_product_sets(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductSetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_product_sets(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_ListProductSets_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_async.py new file mode 100644 index 00000000..f6b3187c --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProducts +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_ListProducts_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_list_products(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_ListProducts_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_in_product_set_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_in_product_set_async.py new file mode 100644 index 00000000..eca1ba75 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_in_product_set_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductsInProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_ListProductsInProductSet_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_list_products_in_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_ListProductsInProductSet_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_in_product_set_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_in_product_set_sync.py new file mode 100644 index 00000000..beec0e44 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_in_product_set_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProductsInProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_ListProductsInProductSet_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_list_products_in_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductsInProductSetRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_products_in_product_set(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_ListProductsInProductSet_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_sync.py new file mode 100644 index 00000000..27fe43d4 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_products_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProducts +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_ListProducts_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_list_products(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_ListProducts_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_reference_images_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_reference_images_async.py new file mode 100644 index 00000000..3e7d989b --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_reference_images_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListReferenceImages +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_ListReferenceImages_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_list_reference_images(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_ListReferenceImages_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_reference_images_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_reference_images_sync.py new file mode 100644 index 00000000..d97fb7c9 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_list_reference_images_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListReferenceImages +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_ListReferenceImages_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_list_reference_images(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.ListReferenceImagesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_reference_images(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_ListReferenceImages_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_purge_products_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_purge_products_async.py new file mode 100644 index 00000000..50c37226 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_purge_products_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeProducts +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_PurgeProducts_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_purge_products(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.PurgeProductsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.purge_products(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_PurgeProducts_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_purge_products_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_purge_products_sync.py new file mode 100644 index 00000000..799081e1 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_purge_products_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeProducts +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_PurgeProducts_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_purge_products(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.PurgeProductsRequest( + parent="parent_value", + ) + + # Make the request + operation = client.purge_products(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_PurgeProducts_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_remove_product_from_product_set_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_remove_product_from_product_set_async.py new file mode 100644 index 00000000..51bf3f54 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_remove_product_from_product_set_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RemoveProductFromProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_RemoveProductFromProductSet_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + await client.remove_product_from_product_set(request=request) + + +# [END vision_v1p4beta1_generated_ProductSearch_RemoveProductFromProductSet_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_remove_product_from_product_set_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_remove_product_from_product_set_sync.py new file mode 100644 index 00000000..f14e0b1d --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_remove_product_from_product_set_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RemoveProductFromProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_RemoveProductFromProductSet_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_remove_product_from_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.RemoveProductFromProductSetRequest( + name="name_value", + product="product_value", + ) + + # Make the request + client.remove_product_from_product_set(request=request) + + +# [END vision_v1p4beta1_generated_ProductSearch_RemoveProductFromProductSet_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_async.py new file mode 100644 index 00000000..44870b2e --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProduct +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_UpdateProduct_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_update_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.UpdateProductRequest( + ) + + # Make the request + response = await client.update_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_UpdateProduct_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_set_async.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_set_async.py new file mode 100644 index 00000000..92ae01f5 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_set_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_UpdateProductSet_async] +from google.cloud import vision_v1p4beta1 + + +async def sample_update_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchAsyncClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.UpdateProductSetRequest( + ) + + # Make the request + response = await client.update_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_UpdateProductSet_async] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_set_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_set_sync.py new file mode 100644 index 00000000..d403db36 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_set_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProductSet +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_UpdateProductSet_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_update_product_set(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.UpdateProductSetRequest( + ) + + # Make the request + response = client.update_product_set(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_UpdateProductSet_sync] diff --git a/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_sync.py b/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_sync.py new file mode 100644 index 00000000..92a4a617 --- /dev/null +++ b/samples/generated_samples/vision_v1p4beta1_generated_product_search_update_product_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProduct +# 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-vision + + +# [START vision_v1p4beta1_generated_ProductSearch_UpdateProduct_sync] +from google.cloud import vision_v1p4beta1 + + +def sample_update_product(): + # Create a client + client = vision_v1p4beta1.ProductSearchClient() + + # Initialize request argument(s) + request = vision_v1p4beta1.UpdateProductRequest( + ) + + # Make the request + response = client.update_product(request=request) + + # Handle the response + print(response) + +# [END vision_v1p4beta1_generated_ProductSearch_UpdateProduct_sync] diff --git a/samples/snippets/crop_hints/noxfile.py b/samples/snippets/crop_hints/noxfile.py index 93a9122c..20cdfc62 100644 --- a/samples/snippets/crop_hints/noxfile.py +++ b/samples/snippets/crop_hints/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,45 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/snippets/crop_hints/noxfile_config.py b/samples/snippets/crop_hints/noxfile_config.py new file mode 100644 index 00000000..e5578c31 --- /dev/null +++ b/samples/snippets/crop_hints/noxfile_config.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# 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. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + # Pillow 9.0.0 does not support python 3.6 + "ignored_versions": ["3.6"], +} diff --git a/samples/snippets/crop_hints/requirements-test.txt b/samples/snippets/crop_hints/requirements-test.txt index 92709451..c2845bff 100644 --- a/samples/snippets/crop_hints/requirements-test.txt +++ b/samples/snippets/crop_hints/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/crop_hints/requirements.txt b/samples/snippets/crop_hints/requirements.txt index 2a8d0f96..742d3213 100644 --- a/samples/snippets/crop_hints/requirements.txt +++ b/samples/snippets/crop_hints/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==2.6.2 -pillow==8.4.0 +google-cloud-vision==2.6.3 +pillow==9.0.1 diff --git a/samples/snippets/detect/noxfile.py b/samples/snippets/detect/noxfile.py index 93a9122c..20cdfc62 100644 --- a/samples/snippets/detect/noxfile.py +++ b/samples/snippets/detect/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,45 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/snippets/detect/requirements-test.txt b/samples/snippets/detect/requirements-test.txt index 29fa8f9f..caef7fbe 100644 --- a/samples/snippets/detect/requirements-test.txt +++ b/samples/snippets/detect/requirements-test.txt @@ -1,3 +1,3 @@ backoff==1.11.1 -pytest==6.2.5 +pytest==7.0.1 flaky==3.7.0 diff --git a/samples/snippets/detect/requirements.txt b/samples/snippets/detect/requirements.txt index a2085c26..3e120414 100644 --- a/samples/snippets/detect/requirements.txt +++ b/samples/snippets/detect/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==2.6.2 -google-cloud-storage==1.43.0 +google-cloud-vision==2.6.3 +google-cloud-storage==2.1.0 diff --git a/samples/snippets/document_text/noxfile.py b/samples/snippets/document_text/noxfile.py index 93a9122c..20cdfc62 100644 --- a/samples/snippets/document_text/noxfile.py +++ b/samples/snippets/document_text/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,45 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/snippets/document_text/noxfile_config.py b/samples/snippets/document_text/noxfile_config.py new file mode 100644 index 00000000..e5578c31 --- /dev/null +++ b/samples/snippets/document_text/noxfile_config.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# 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. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + # Pillow 9.0.0 does not support python 3.6 + "ignored_versions": ["3.6"], +} diff --git a/samples/snippets/document_text/requirements-test.txt b/samples/snippets/document_text/requirements-test.txt index 92709451..c2845bff 100644 --- a/samples/snippets/document_text/requirements-test.txt +++ b/samples/snippets/document_text/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/document_text/requirements.txt b/samples/snippets/document_text/requirements.txt index 2a8d0f96..742d3213 100644 --- a/samples/snippets/document_text/requirements.txt +++ b/samples/snippets/document_text/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==2.6.2 -pillow==8.4.0 +google-cloud-vision==2.6.3 +pillow==9.0.1 diff --git a/samples/snippets/face_detection/noxfile.py b/samples/snippets/face_detection/noxfile.py index 93a9122c..20cdfc62 100644 --- a/samples/snippets/face_detection/noxfile.py +++ b/samples/snippets/face_detection/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,45 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/snippets/face_detection/noxfile_config.py b/samples/snippets/face_detection/noxfile_config.py new file mode 100644 index 00000000..e5578c31 --- /dev/null +++ b/samples/snippets/face_detection/noxfile_config.py @@ -0,0 +1,27 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# 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. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + # Pillow 9.0.0 does not support python 3.6 + "ignored_versions": ["3.6"], +} diff --git a/samples/snippets/face_detection/requirements-test.txt b/samples/snippets/face_detection/requirements-test.txt index 92709451..c2845bff 100644 --- a/samples/snippets/face_detection/requirements-test.txt +++ b/samples/snippets/face_detection/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/face_detection/requirements.txt b/samples/snippets/face_detection/requirements.txt index 2a8d0f96..742d3213 100644 --- a/samples/snippets/face_detection/requirements.txt +++ b/samples/snippets/face_detection/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==2.6.2 -pillow==8.4.0 +google-cloud-vision==2.6.3 +pillow==9.0.1 diff --git a/samples/snippets/product_search/noxfile.py b/samples/snippets/product_search/noxfile.py index 93a9122c..20cdfc62 100644 --- a/samples/snippets/product_search/noxfile.py +++ b/samples/snippets/product_search/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,45 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/snippets/product_search/requirements-test.txt b/samples/snippets/product_search/requirements-test.txt index 627baf98..30073677 100644 --- a/samples/snippets/product_search/requirements-test.txt +++ b/samples/snippets/product_search/requirements-test.txt @@ -1,2 +1,2 @@ -pytest==6.2.5 +pytest==7.0.1 flaky==3.7.0 \ No newline at end of file diff --git a/samples/snippets/product_search/requirements.txt b/samples/snippets/product_search/requirements.txt index a2085c26..3e120414 100644 --- a/samples/snippets/product_search/requirements.txt +++ b/samples/snippets/product_search/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==2.6.2 -google-cloud-storage==1.43.0 +google-cloud-vision==2.6.3 +google-cloud-storage==2.1.0 diff --git a/samples/snippets/quickstart/noxfile.py b/samples/snippets/quickstart/noxfile.py index 93a9122c..20cdfc62 100644 --- a/samples/snippets/quickstart/noxfile.py +++ b/samples/snippets/quickstart/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,45 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/snippets/quickstart/requirements-test.txt b/samples/snippets/quickstart/requirements-test.txt index 92709451..c2845bff 100644 --- a/samples/snippets/quickstart/requirements-test.txt +++ b/samples/snippets/quickstart/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/quickstart/requirements.txt b/samples/snippets/quickstart/requirements.txt index 1856a360..88a65816 100644 --- a/samples/snippets/quickstart/requirements.txt +++ b/samples/snippets/quickstart/requirements.txt @@ -1 +1 @@ -google-cloud-vision==2.6.2 +google-cloud-vision==2.6.3 diff --git a/samples/snippets/web/noxfile.py b/samples/snippets/web/noxfile.py index 93a9122c..20cdfc62 100644 --- a/samples/snippets/web/noxfile.py +++ b/samples/snippets/web/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,45 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/snippets/web/requirements-test.txt b/samples/snippets/web/requirements-test.txt index 4b863b85..8fab5850 100644 --- a/samples/snippets/web/requirements-test.txt +++ b/samples/snippets/web/requirements-test.txt @@ -1,2 +1,2 @@ flaky==3.7.0 -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/web/requirements.txt b/samples/snippets/web/requirements.txt index 1856a360..88a65816 100644 --- a/samples/snippets/web/requirements.txt +++ b/samples/snippets/web/requirements.txt @@ -1 +1 @@ -google-cloud-vision==2.6.2 +google-cloud-vision==2.6.3 diff --git a/setup.py b/setup.py index 3104ca07..041f28cb 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ name = "google-cloud-vision" description = "Cloud Vision API API client library" -version = "2.6.3" +version = "2.7.0" release_status = "Development Status :: 5 - Production/Stable" dependencies = [ # NOTE: Maintainers, please do not require google-api-core>=2.x.x diff --git a/tests/unit/gapic/vision_v1/__init__.py b/tests/unit/gapic/vision_v1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/vision_v1/__init__.py +++ b/tests/unit/gapic/vision_v1/__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/vision_v1/test_image_annotator.py b/tests/unit/gapic/vision_v1/test_image_annotator.py index e559059e..ebf186c6 100644 --- a/tests/unit/gapic/vision_v1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1/test_image_annotator.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. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -252,20 +253,20 @@ def test_image_annotator_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, @@ -324,7 +325,7 @@ def test_image_annotator_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 @@ -401,6 +402,87 @@ def test_image_annotator_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient] +) +@mock.patch.object( + ImageAnnotatorClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ImageAnnotatorClient), +) +@mock.patch.object( + ImageAnnotatorAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ImageAnnotatorAsyncClient), +) +def test_image_annotator_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", [ @@ -419,7 +501,7 @@ def test_image_annotator_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, @@ -433,24 +515,31 @@ def test_image_annotator_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + ( + ImageAnnotatorClient, + transports.ImageAnnotatorGrpcTransport, + "grpc", + grpc_helpers, + ), ( ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_image_annotator_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", @@ -483,9 +572,79 @@ def test_image_annotator_client_client_options_from_dict(): ) -def test_batch_annotate_images( - transport: str = "grpc", request_type=image_annotator.BatchAnnotateImagesRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ImageAnnotatorClient, + transports.ImageAnnotatorGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ImageAnnotatorAsyncClient, + transports.ImageAnnotatorGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_image_annotator_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( + "vision.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-vision", + ), + scopes=None, + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [image_annotator.BatchAnnotateImagesRequest, dict,] +) +def test_batch_annotate_images(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -511,10 +670,6 @@ def test_batch_annotate_images( assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) -def test_batch_annotate_images_from_dict(): - test_batch_annotate_images(request_type=dict) - - def test_batch_annotate_images_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. @@ -675,9 +830,10 @@ async def test_batch_annotate_images_flattened_error_async(): ) -def test_batch_annotate_files( - transport: str = "grpc", request_type=image_annotator.BatchAnnotateFilesRequest -): +@pytest.mark.parametrize( + "request_type", [image_annotator.BatchAnnotateFilesRequest, dict,] +) +def test_batch_annotate_files(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -703,10 +859,6 @@ def test_batch_annotate_files( assert isinstance(response, image_annotator.BatchAnnotateFilesResponse) -def test_batch_annotate_files_from_dict(): - test_batch_annotate_files(request_type=dict) - - def test_batch_annotate_files_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. @@ -879,10 +1031,10 @@ async def test_batch_annotate_files_flattened_error_async(): ) -def test_async_batch_annotate_images( - transport: str = "grpc", - request_type=image_annotator.AsyncBatchAnnotateImagesRequest, -): +@pytest.mark.parametrize( + "request_type", [image_annotator.AsyncBatchAnnotateImagesRequest, dict,] +) +def test_async_batch_annotate_images(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -908,10 +1060,6 @@ def test_async_batch_annotate_images( assert isinstance(response, future.Future) -def test_async_batch_annotate_images_from_dict(): - test_async_batch_annotate_images(request_type=dict) - - def test_async_batch_annotate_images_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. @@ -1094,9 +1242,10 @@ async def test_async_batch_annotate_images_flattened_error_async(): ) -def test_async_batch_annotate_files( - transport: str = "grpc", request_type=image_annotator.AsyncBatchAnnotateFilesRequest -): +@pytest.mark.parametrize( + "request_type", [image_annotator.AsyncBatchAnnotateFilesRequest, dict,] +) +def test_async_batch_annotate_files(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1122,10 +1271,6 @@ def test_async_batch_annotate_files( assert isinstance(response, future.Future) -def test_async_batch_annotate_files_from_dict(): - test_async_batch_annotate_files(request_type=dict) - - def test_async_batch_annotate_files_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. @@ -1318,6 +1463,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ImageAnnotatorClient(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 = ImageAnnotatorClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.ImageAnnotatorGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1882,7 +2044,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( @@ -1947,3 +2109,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport), + ], +) +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/vision_v1/test_product_search.py b/tests/unit/gapic/vision_v1/test_product_search.py index 1dcbdba3..c5fbafc7 100644 --- a/tests/unit/gapic/vision_v1/test_product_search.py +++ b/tests/unit/gapic/vision_v1/test_product_search.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. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -255,20 +256,20 @@ def test_product_search_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, @@ -327,7 +328,7 @@ def test_product_search_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 @@ -404,6 +405,87 @@ def test_product_search_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [ProductSearchClient, ProductSearchAsyncClient] +) +@mock.patch.object( + ProductSearchClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ProductSearchClient), +) +@mock.patch.object( + ProductSearchAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ProductSearchAsyncClient), +) +def test_product_search_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", [ @@ -422,7 +504,7 @@ def test_product_search_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, @@ -436,24 +518,31 @@ def test_product_search_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + ( + ProductSearchClient, + transports.ProductSearchGrpcTransport, + "grpc", + grpc_helpers, + ), ( ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_product_search_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", @@ -486,9 +575,79 @@ def test_product_search_client_client_options_from_dict(): ) -def test_create_product_set( - transport: str = "grpc", request_type=product_search_service.CreateProductSetRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ProductSearchClient, + transports.ProductSearchGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ProductSearchAsyncClient, + transports.ProductSearchGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_product_search_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( + "vision.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-vision", + ), + scopes=None, + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [product_search_service.CreateProductSetRequest, dict,] +) +def test_create_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -518,10 +677,6 @@ def test_create_product_set( assert response.display_name == "display_name_value" -def test_create_product_set_from_dict(): - test_create_product_set(request_type=dict) - - def test_create_product_set_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. @@ -739,9 +894,10 @@ async def test_create_product_set_flattened_error_async(): ) -def test_list_product_sets( - transport: str = "grpc", request_type=product_search_service.ListProductSetsRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListProductSetsRequest, dict,] +) +def test_list_product_sets(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -770,10 +926,6 @@ def test_list_product_sets( assert response.next_page_token == "next_page_token_value" -def test_list_product_sets_from_dict(): - test_list_product_sets(request_type=dict) - - def test_list_product_sets_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. @@ -964,8 +1116,10 @@ async def test_list_product_sets_flattened_error_async(): ) -def test_list_product_sets_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_product_sets_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1010,8 +1164,10 @@ def test_list_product_sets_pager(): assert all(isinstance(i, product_search_service.ProductSet) for i in results) -def test_list_product_sets_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_product_sets_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1134,9 +1290,10 @@ async def test_list_product_sets_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_product_set( - transport: str = "grpc", request_type=product_search_service.GetProductSetRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.GetProductSetRequest, dict,] +) +def test_get_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1164,10 +1321,6 @@ def test_get_product_set( assert response.display_name == "display_name_value" -def test_get_product_set_from_dict(): - test_get_product_set(request_type=dict) - - def test_get_product_set_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. @@ -1347,9 +1500,10 @@ async def test_get_product_set_flattened_error_async(): ) -def test_update_product_set( - transport: str = "grpc", request_type=product_search_service.UpdateProductSetRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.UpdateProductSetRequest, dict,] +) +def test_update_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1379,10 +1533,6 @@ def test_update_product_set( assert response.display_name == "display_name_value" -def test_update_product_set_from_dict(): - test_update_product_set(request_type=dict) - - def test_update_product_set_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. @@ -1594,9 +1744,10 @@ async def test_update_product_set_flattened_error_async(): ) -def test_delete_product_set( - transport: str = "grpc", request_type=product_search_service.DeleteProductSetRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.DeleteProductSetRequest, dict,] +) +def test_delete_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1622,10 +1773,6 @@ def test_delete_product_set( assert response is None -def test_delete_product_set_from_dict(): - test_delete_product_set(request_type=dict) - - def test_delete_product_set_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. @@ -1807,9 +1954,10 @@ async def test_delete_product_set_flattened_error_async(): ) -def test_create_product( - transport: str = "grpc", request_type=product_search_service.CreateProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.CreateProductRequest, dict,] +) +def test_create_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1842,10 +1990,6 @@ def test_create_product( assert response.product_category == "product_category_value" -def test_create_product_from_dict(): - test_create_product(request_type=dict) - - def test_create_product_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. @@ -2056,9 +2200,10 @@ async def test_create_product_flattened_error_async(): ) -def test_list_products( - transport: str = "grpc", request_type=product_search_service.ListProductsRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListProductsRequest, dict,] +) +def test_list_products(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2085,10 +2230,6 @@ def test_list_products( assert response.next_page_token == "next_page_token_value" -def test_list_products_from_dict(): - test_list_products(request_type=dict) - - def test_list_products_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. @@ -2267,8 +2408,10 @@ async def test_list_products_flattened_error_async(): ) -def test_list_products_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_products), "__call__") as call: @@ -2310,8 +2453,10 @@ def test_list_products_pager(): assert all(isinstance(i, product_search_service.Product) for i in results) -def test_list_products_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_products), "__call__") as call: @@ -2425,9 +2570,10 @@ async def test_list_products_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_product( - transport: str = "grpc", request_type=product_search_service.GetProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.GetProductRequest, dict,] +) +def test_get_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2460,10 +2606,6 @@ def test_get_product( assert response.product_category == "product_category_value" -def test_get_product_from_dict(): - test_get_product(request_type=dict) - - def test_get_product_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. @@ -2648,9 +2790,10 @@ async def test_get_product_flattened_error_async(): ) -def test_update_product( - transport: str = "grpc", request_type=product_search_service.UpdateProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.UpdateProductRequest, dict,] +) +def test_update_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2683,10 +2826,6 @@ def test_update_product( assert response.product_category == "product_category_value" -def test_update_product_from_dict(): - test_update_product(request_type=dict) - - def test_update_product_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. @@ -2891,9 +3030,10 @@ async def test_update_product_flattened_error_async(): ) -def test_delete_product( - transport: str = "grpc", request_type=product_search_service.DeleteProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.DeleteProductRequest, dict,] +) +def test_delete_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2917,10 +3057,6 @@ def test_delete_product( assert response is None -def test_delete_product_from_dict(): - test_delete_product(request_type=dict) - - def test_delete_product_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. @@ -3090,10 +3226,10 @@ async def test_delete_product_flattened_error_async(): ) -def test_create_reference_image( - transport: str = "grpc", - request_type=product_search_service.CreateReferenceImageRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.CreateReferenceImageRequest, dict,] +) +def test_create_reference_image(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3123,10 +3259,6 @@ def test_create_reference_image( assert response.uri == "uri_value" -def test_create_reference_image_from_dict(): - test_create_reference_image(request_type=dict) - - def test_create_reference_image_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. @@ -3342,10 +3474,10 @@ async def test_create_reference_image_flattened_error_async(): ) -def test_delete_reference_image( - transport: str = "grpc", - request_type=product_search_service.DeleteReferenceImageRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.DeleteReferenceImageRequest, dict,] +) +def test_delete_reference_image(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3371,10 +3503,6 @@ def test_delete_reference_image( assert response is None -def test_delete_reference_image_from_dict(): - test_delete_reference_image(request_type=dict) - - def test_delete_reference_image_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. @@ -3556,10 +3684,10 @@ async def test_delete_reference_image_flattened_error_async(): ) -def test_list_reference_images( - transport: str = "grpc", - request_type=product_search_service.ListReferenceImagesRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListReferenceImagesRequest, dict,] +) +def test_list_reference_images(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3589,10 +3717,6 @@ def test_list_reference_images( assert response.next_page_token == "next_page_token_value" -def test_list_reference_images_from_dict(): - test_list_reference_images(request_type=dict) - - def test_list_reference_images_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. @@ -3784,8 +3908,10 @@ async def test_list_reference_images_flattened_error_async(): ) -def test_list_reference_images_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_reference_images_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3832,8 +3958,10 @@ def test_list_reference_images_pager(): ) -def test_list_reference_images_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_reference_images_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3958,10 +4086,10 @@ async def test_list_reference_images_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_reference_image( - transport: str = "grpc", - request_type=product_search_service.GetReferenceImageRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.GetReferenceImageRequest, dict,] +) +def test_get_reference_image(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3991,10 +4119,6 @@ def test_get_reference_image( assert response.uri == "uri_value" -def test_get_reference_image_from_dict(): - test_get_reference_image(request_type=dict) - - def test_get_reference_image_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. @@ -4184,10 +4308,10 @@ async def test_get_reference_image_flattened_error_async(): ) -def test_add_product_to_product_set( - transport: str = "grpc", - request_type=product_search_service.AddProductToProductSetRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.AddProductToProductSetRequest, dict,] +) +def test_add_product_to_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4213,10 +4337,6 @@ def test_add_product_to_product_set( assert response is None -def test_add_product_to_product_set_from_dict(): - test_add_product_to_product_set(request_type=dict) - - def test_add_product_to_product_set_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. @@ -4412,10 +4532,10 @@ async def test_add_product_to_product_set_flattened_error_async(): ) -def test_remove_product_from_product_set( - transport: str = "grpc", - request_type=product_search_service.RemoveProductFromProductSetRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.RemoveProductFromProductSetRequest, dict,] +) +def test_remove_product_from_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4441,10 +4561,6 @@ def test_remove_product_from_product_set( assert response is None -def test_remove_product_from_product_set_from_dict(): - test_remove_product_from_product_set(request_type=dict) - - def test_remove_product_from_product_set_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. @@ -4640,10 +4756,10 @@ async def test_remove_product_from_product_set_flattened_error_async(): ) -def test_list_products_in_product_set( - transport: str = "grpc", - request_type=product_search_service.ListProductsInProductSetRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListProductsInProductSetRequest, dict,] +) +def test_list_products_in_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4672,10 +4788,6 @@ def test_list_products_in_product_set( assert response.next_page_token == "next_page_token_value" -def test_list_products_in_product_set_from_dict(): - test_list_products_in_product_set(request_type=dict) - - def test_list_products_in_product_set_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. @@ -4866,8 +4978,10 @@ async def test_list_products_in_product_set_flattened_error_async(): ) -def test_list_products_in_product_set_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_in_product_set_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4911,8 +5025,10 @@ def test_list_products_in_product_set_pager(): assert all(isinstance(i, product_search_service.Product) for i in results) -def test_list_products_in_product_set_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_in_product_set_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5034,10 +5150,10 @@ async def test_list_products_in_product_set_async_pages(): assert page_.raw_page.next_page_token == token -def test_import_product_sets( - transport: str = "grpc", - request_type=product_search_service.ImportProductSetsRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ImportProductSetsRequest, dict,] +) +def test_import_product_sets(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5063,10 +5179,6 @@ def test_import_product_sets( assert isinstance(response, future.Future) -def test_import_product_sets_from_dict(): - test_import_product_sets(request_type=dict) - - def test_import_product_sets_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. @@ -5294,9 +5406,10 @@ async def test_import_product_sets_flattened_error_async(): ) -def test_purge_products( - transport: str = "grpc", request_type=product_search_service.PurgeProductsRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.PurgeProductsRequest, dict,] +) +def test_purge_products(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5320,10 +5433,6 @@ def test_purge_products( assert isinstance(response, future.Future) -def test_purge_products_from_dict(): - test_purge_products(request_type=dict) - - def test_purge_products_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. @@ -5519,6 +5628,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductSearchClient(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 = ProductSearchClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.ProductSearchGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -6127,7 +6253,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( @@ -6192,3 +6318,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ProductSearchClient, transports.ProductSearchGrpcTransport), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport), + ], +) +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/vision_v1p1beta1/__init__.py b/tests/unit/gapic/vision_v1p1beta1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/vision_v1p1beta1/__init__.py +++ b/tests/unit/gapic/vision_v1p1beta1/__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/vision_v1p1beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py index bb524466..ef8fe094 100644 --- a/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.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. @@ -248,20 +248,20 @@ def test_image_annotator_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, @@ -320,7 +320,7 @@ def test_image_annotator_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 @@ -397,6 +397,87 @@ def test_image_annotator_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient] +) +@mock.patch.object( + ImageAnnotatorClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ImageAnnotatorClient), +) +@mock.patch.object( + ImageAnnotatorAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ImageAnnotatorAsyncClient), +) +def test_image_annotator_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", [ @@ -415,7 +496,7 @@ def test_image_annotator_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, @@ -429,24 +510,31 @@ def test_image_annotator_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + ( + ImageAnnotatorClient, + transports.ImageAnnotatorGrpcTransport, + "grpc", + grpc_helpers, + ), ( ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_image_annotator_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", @@ -479,9 +567,79 @@ def test_image_annotator_client_client_options_from_dict(): ) -def test_batch_annotate_images( - transport: str = "grpc", request_type=image_annotator.BatchAnnotateImagesRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ImageAnnotatorClient, + transports.ImageAnnotatorGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ImageAnnotatorAsyncClient, + transports.ImageAnnotatorGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_image_annotator_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( + "vision.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-vision", + ), + scopes=None, + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [image_annotator.BatchAnnotateImagesRequest, dict,] +) +def test_batch_annotate_images(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -507,10 +665,6 @@ def test_batch_annotate_images( assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) -def test_batch_annotate_images_from_dict(): - test_batch_annotate_images(request_type=dict) - - def test_batch_annotate_images_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. @@ -691,6 +845,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ImageAnnotatorClient(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 = ImageAnnotatorClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.ImageAnnotatorGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1171,7 +1342,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( @@ -1236,3 +1407,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport), + ], +) +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/vision_v1p2beta1/__init__.py b/tests/unit/gapic/vision_v1p2beta1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/vision_v1p2beta1/__init__.py +++ b/tests/unit/gapic/vision_v1p2beta1/__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/vision_v1p2beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py index 52785a1c..69690556 100644 --- a/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.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. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -252,20 +253,20 @@ def test_image_annotator_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, @@ -324,7 +325,7 @@ def test_image_annotator_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 @@ -401,6 +402,87 @@ def test_image_annotator_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient] +) +@mock.patch.object( + ImageAnnotatorClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ImageAnnotatorClient), +) +@mock.patch.object( + ImageAnnotatorAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ImageAnnotatorAsyncClient), +) +def test_image_annotator_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", [ @@ -419,7 +501,7 @@ def test_image_annotator_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, @@ -433,24 +515,31 @@ def test_image_annotator_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + ( + ImageAnnotatorClient, + transports.ImageAnnotatorGrpcTransport, + "grpc", + grpc_helpers, + ), ( ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_image_annotator_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", @@ -483,9 +572,79 @@ def test_image_annotator_client_client_options_from_dict(): ) -def test_batch_annotate_images( - transport: str = "grpc", request_type=image_annotator.BatchAnnotateImagesRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ImageAnnotatorClient, + transports.ImageAnnotatorGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ImageAnnotatorAsyncClient, + transports.ImageAnnotatorGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_image_annotator_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( + "vision.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-vision", + ), + scopes=None, + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [image_annotator.BatchAnnotateImagesRequest, dict,] +) +def test_batch_annotate_images(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -511,10 +670,6 @@ def test_batch_annotate_images( assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) -def test_batch_annotate_images_from_dict(): - test_batch_annotate_images(request_type=dict) - - def test_batch_annotate_images_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. @@ -675,9 +830,10 @@ async def test_batch_annotate_images_flattened_error_async(): ) -def test_async_batch_annotate_files( - transport: str = "grpc", request_type=image_annotator.AsyncBatchAnnotateFilesRequest -): +@pytest.mark.parametrize( + "request_type", [image_annotator.AsyncBatchAnnotateFilesRequest, dict,] +) +def test_async_batch_annotate_files(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -703,10 +859,6 @@ def test_async_batch_annotate_files( assert isinstance(response, future.Future) -def test_async_batch_annotate_files_from_dict(): - test_async_batch_annotate_files(request_type=dict) - - def test_async_batch_annotate_files_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. @@ -899,6 +1051,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ImageAnnotatorClient(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 = ImageAnnotatorClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.ImageAnnotatorGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1413,7 +1582,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( @@ -1478,3 +1647,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport), + ], +) +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/vision_v1p3beta1/__init__.py b/tests/unit/gapic/vision_v1p3beta1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/vision_v1p3beta1/__init__.py +++ b/tests/unit/gapic/vision_v1p3beta1/__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/vision_v1p3beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py index f6aa6ce1..58d0f99c 100644 --- a/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.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. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -254,20 +255,20 @@ def test_image_annotator_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, @@ -326,7 +327,7 @@ def test_image_annotator_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 @@ -403,6 +404,87 @@ def test_image_annotator_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient] +) +@mock.patch.object( + ImageAnnotatorClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ImageAnnotatorClient), +) +@mock.patch.object( + ImageAnnotatorAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ImageAnnotatorAsyncClient), +) +def test_image_annotator_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", [ @@ -421,7 +503,7 @@ def test_image_annotator_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, @@ -435,24 +517,31 @@ def test_image_annotator_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + ( + ImageAnnotatorClient, + transports.ImageAnnotatorGrpcTransport, + "grpc", + grpc_helpers, + ), ( ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_image_annotator_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", @@ -485,9 +574,79 @@ def test_image_annotator_client_client_options_from_dict(): ) -def test_batch_annotate_images( - transport: str = "grpc", request_type=image_annotator.BatchAnnotateImagesRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ImageAnnotatorClient, + transports.ImageAnnotatorGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ImageAnnotatorAsyncClient, + transports.ImageAnnotatorGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_image_annotator_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( + "vision.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-vision", + ), + scopes=None, + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [image_annotator.BatchAnnotateImagesRequest, dict,] +) +def test_batch_annotate_images(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -513,10 +672,6 @@ def test_batch_annotate_images( assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) -def test_batch_annotate_images_from_dict(): - test_batch_annotate_images(request_type=dict) - - def test_batch_annotate_images_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. @@ -677,9 +832,10 @@ async def test_batch_annotate_images_flattened_error_async(): ) -def test_async_batch_annotate_files( - transport: str = "grpc", request_type=image_annotator.AsyncBatchAnnotateFilesRequest -): +@pytest.mark.parametrize( + "request_type", [image_annotator.AsyncBatchAnnotateFilesRequest, dict,] +) +def test_async_batch_annotate_files(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -705,10 +861,6 @@ def test_async_batch_annotate_files( assert isinstance(response, future.Future) -def test_async_batch_annotate_files_from_dict(): - test_async_batch_annotate_files(request_type=dict) - - def test_async_batch_annotate_files_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. @@ -901,6 +1053,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ImageAnnotatorClient(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 = ImageAnnotatorClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.ImageAnnotatorGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1463,7 +1632,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( @@ -1528,3 +1697,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport), + ], +) +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/vision_v1p3beta1/test_product_search.py b/tests/unit/gapic/vision_v1p3beta1/test_product_search.py index 1878ddcd..735d48a6 100644 --- a/tests/unit/gapic/vision_v1p3beta1/test_product_search.py +++ b/tests/unit/gapic/vision_v1p3beta1/test_product_search.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. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -257,20 +258,20 @@ def test_product_search_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, @@ -329,7 +330,7 @@ def test_product_search_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 @@ -406,6 +407,87 @@ def test_product_search_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [ProductSearchClient, ProductSearchAsyncClient] +) +@mock.patch.object( + ProductSearchClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ProductSearchClient), +) +@mock.patch.object( + ProductSearchAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ProductSearchAsyncClient), +) +def test_product_search_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", [ @@ -424,7 +506,7 @@ def test_product_search_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, @@ -438,24 +520,31 @@ def test_product_search_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + ( + ProductSearchClient, + transports.ProductSearchGrpcTransport, + "grpc", + grpc_helpers, + ), ( ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_product_search_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", @@ -488,9 +577,79 @@ def test_product_search_client_client_options_from_dict(): ) -def test_create_product_set( - transport: str = "grpc", request_type=product_search_service.CreateProductSetRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ProductSearchClient, + transports.ProductSearchGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ProductSearchAsyncClient, + transports.ProductSearchGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_product_search_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( + "vision.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-vision", + ), + scopes=None, + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [product_search_service.CreateProductSetRequest, dict,] +) +def test_create_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -520,10 +679,6 @@ def test_create_product_set( assert response.display_name == "display_name_value" -def test_create_product_set_from_dict(): - test_create_product_set(request_type=dict) - - def test_create_product_set_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. @@ -741,9 +896,10 @@ async def test_create_product_set_flattened_error_async(): ) -def test_list_product_sets( - transport: str = "grpc", request_type=product_search_service.ListProductSetsRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListProductSetsRequest, dict,] +) +def test_list_product_sets(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -772,10 +928,6 @@ def test_list_product_sets( assert response.next_page_token == "next_page_token_value" -def test_list_product_sets_from_dict(): - test_list_product_sets(request_type=dict) - - def test_list_product_sets_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. @@ -966,8 +1118,10 @@ async def test_list_product_sets_flattened_error_async(): ) -def test_list_product_sets_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_product_sets_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1012,8 +1166,10 @@ def test_list_product_sets_pager(): assert all(isinstance(i, product_search_service.ProductSet) for i in results) -def test_list_product_sets_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_product_sets_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1136,9 +1292,10 @@ async def test_list_product_sets_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_product_set( - transport: str = "grpc", request_type=product_search_service.GetProductSetRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.GetProductSetRequest, dict,] +) +def test_get_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1166,10 +1323,6 @@ def test_get_product_set( assert response.display_name == "display_name_value" -def test_get_product_set_from_dict(): - test_get_product_set(request_type=dict) - - def test_get_product_set_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. @@ -1349,9 +1502,10 @@ async def test_get_product_set_flattened_error_async(): ) -def test_update_product_set( - transport: str = "grpc", request_type=product_search_service.UpdateProductSetRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.UpdateProductSetRequest, dict,] +) +def test_update_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1381,10 +1535,6 @@ def test_update_product_set( assert response.display_name == "display_name_value" -def test_update_product_set_from_dict(): - test_update_product_set(request_type=dict) - - def test_update_product_set_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. @@ -1596,9 +1746,10 @@ async def test_update_product_set_flattened_error_async(): ) -def test_delete_product_set( - transport: str = "grpc", request_type=product_search_service.DeleteProductSetRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.DeleteProductSetRequest, dict,] +) +def test_delete_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1624,10 +1775,6 @@ def test_delete_product_set( assert response is None -def test_delete_product_set_from_dict(): - test_delete_product_set(request_type=dict) - - def test_delete_product_set_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. @@ -1809,9 +1956,10 @@ async def test_delete_product_set_flattened_error_async(): ) -def test_create_product( - transport: str = "grpc", request_type=product_search_service.CreateProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.CreateProductRequest, dict,] +) +def test_create_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1844,10 +1992,6 @@ def test_create_product( assert response.product_category == "product_category_value" -def test_create_product_from_dict(): - test_create_product(request_type=dict) - - def test_create_product_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. @@ -2058,9 +2202,10 @@ async def test_create_product_flattened_error_async(): ) -def test_list_products( - transport: str = "grpc", request_type=product_search_service.ListProductsRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListProductsRequest, dict,] +) +def test_list_products(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2087,10 +2232,6 @@ def test_list_products( assert response.next_page_token == "next_page_token_value" -def test_list_products_from_dict(): - test_list_products(request_type=dict) - - def test_list_products_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. @@ -2269,8 +2410,10 @@ async def test_list_products_flattened_error_async(): ) -def test_list_products_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_products), "__call__") as call: @@ -2312,8 +2455,10 @@ def test_list_products_pager(): assert all(isinstance(i, product_search_service.Product) for i in results) -def test_list_products_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_products), "__call__") as call: @@ -2427,9 +2572,10 @@ async def test_list_products_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_product( - transport: str = "grpc", request_type=product_search_service.GetProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.GetProductRequest, dict,] +) +def test_get_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2462,10 +2608,6 @@ def test_get_product( assert response.product_category == "product_category_value" -def test_get_product_from_dict(): - test_get_product(request_type=dict) - - def test_get_product_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. @@ -2650,9 +2792,10 @@ async def test_get_product_flattened_error_async(): ) -def test_update_product( - transport: str = "grpc", request_type=product_search_service.UpdateProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.UpdateProductRequest, dict,] +) +def test_update_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2685,10 +2828,6 @@ def test_update_product( assert response.product_category == "product_category_value" -def test_update_product_from_dict(): - test_update_product(request_type=dict) - - def test_update_product_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. @@ -2893,9 +3032,10 @@ async def test_update_product_flattened_error_async(): ) -def test_delete_product( - transport: str = "grpc", request_type=product_search_service.DeleteProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.DeleteProductRequest, dict,] +) +def test_delete_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2919,10 +3059,6 @@ def test_delete_product( assert response is None -def test_delete_product_from_dict(): - test_delete_product(request_type=dict) - - def test_delete_product_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. @@ -3092,10 +3228,10 @@ async def test_delete_product_flattened_error_async(): ) -def test_create_reference_image( - transport: str = "grpc", - request_type=product_search_service.CreateReferenceImageRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.CreateReferenceImageRequest, dict,] +) +def test_create_reference_image(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3125,10 +3261,6 @@ def test_create_reference_image( assert response.uri == "uri_value" -def test_create_reference_image_from_dict(): - test_create_reference_image(request_type=dict) - - def test_create_reference_image_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. @@ -3344,10 +3476,10 @@ async def test_create_reference_image_flattened_error_async(): ) -def test_delete_reference_image( - transport: str = "grpc", - request_type=product_search_service.DeleteReferenceImageRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.DeleteReferenceImageRequest, dict,] +) +def test_delete_reference_image(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3373,10 +3505,6 @@ def test_delete_reference_image( assert response is None -def test_delete_reference_image_from_dict(): - test_delete_reference_image(request_type=dict) - - def test_delete_reference_image_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. @@ -3558,10 +3686,10 @@ async def test_delete_reference_image_flattened_error_async(): ) -def test_list_reference_images( - transport: str = "grpc", - request_type=product_search_service.ListReferenceImagesRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListReferenceImagesRequest, dict,] +) +def test_list_reference_images(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3591,10 +3719,6 @@ def test_list_reference_images( assert response.next_page_token == "next_page_token_value" -def test_list_reference_images_from_dict(): - test_list_reference_images(request_type=dict) - - def test_list_reference_images_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. @@ -3786,8 +3910,10 @@ async def test_list_reference_images_flattened_error_async(): ) -def test_list_reference_images_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_reference_images_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3834,8 +3960,10 @@ def test_list_reference_images_pager(): ) -def test_list_reference_images_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_reference_images_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3960,10 +4088,10 @@ async def test_list_reference_images_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_reference_image( - transport: str = "grpc", - request_type=product_search_service.GetReferenceImageRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.GetReferenceImageRequest, dict,] +) +def test_get_reference_image(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3993,10 +4121,6 @@ def test_get_reference_image( assert response.uri == "uri_value" -def test_get_reference_image_from_dict(): - test_get_reference_image(request_type=dict) - - def test_get_reference_image_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. @@ -4186,10 +4310,10 @@ async def test_get_reference_image_flattened_error_async(): ) -def test_add_product_to_product_set( - transport: str = "grpc", - request_type=product_search_service.AddProductToProductSetRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.AddProductToProductSetRequest, dict,] +) +def test_add_product_to_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4215,10 +4339,6 @@ def test_add_product_to_product_set( assert response is None -def test_add_product_to_product_set_from_dict(): - test_add_product_to_product_set(request_type=dict) - - def test_add_product_to_product_set_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. @@ -4414,10 +4534,10 @@ async def test_add_product_to_product_set_flattened_error_async(): ) -def test_remove_product_from_product_set( - transport: str = "grpc", - request_type=product_search_service.RemoveProductFromProductSetRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.RemoveProductFromProductSetRequest, dict,] +) +def test_remove_product_from_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4443,10 +4563,6 @@ def test_remove_product_from_product_set( assert response is None -def test_remove_product_from_product_set_from_dict(): - test_remove_product_from_product_set(request_type=dict) - - def test_remove_product_from_product_set_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. @@ -4642,10 +4758,10 @@ async def test_remove_product_from_product_set_flattened_error_async(): ) -def test_list_products_in_product_set( - transport: str = "grpc", - request_type=product_search_service.ListProductsInProductSetRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListProductsInProductSetRequest, dict,] +) +def test_list_products_in_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4674,10 +4790,6 @@ def test_list_products_in_product_set( assert response.next_page_token == "next_page_token_value" -def test_list_products_in_product_set_from_dict(): - test_list_products_in_product_set(request_type=dict) - - def test_list_products_in_product_set_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. @@ -4868,8 +4980,10 @@ async def test_list_products_in_product_set_flattened_error_async(): ) -def test_list_products_in_product_set_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_in_product_set_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4913,8 +5027,10 @@ def test_list_products_in_product_set_pager(): assert all(isinstance(i, product_search_service.Product) for i in results) -def test_list_products_in_product_set_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_in_product_set_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5036,10 +5152,10 @@ async def test_list_products_in_product_set_async_pages(): assert page_.raw_page.next_page_token == token -def test_import_product_sets( - transport: str = "grpc", - request_type=product_search_service.ImportProductSetsRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ImportProductSetsRequest, dict,] +) +def test_import_product_sets(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5065,10 +5181,6 @@ def test_import_product_sets( assert isinstance(response, future.Future) -def test_import_product_sets_from_dict(): - test_import_product_sets(request_type=dict) - - def test_import_product_sets_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. @@ -5316,6 +5428,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductSearchClient(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 = ProductSearchClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.ProductSearchGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -5923,7 +6052,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( @@ -5988,3 +6117,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ProductSearchClient, transports.ProductSearchGrpcTransport), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport), + ], +) +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/vision_v1p4beta1/__init__.py b/tests/unit/gapic/vision_v1p4beta1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/vision_v1p4beta1/__init__.py +++ b/tests/unit/gapic/vision_v1p4beta1/__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/vision_v1p4beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py index 558be5c8..ab3810a9 100644 --- a/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.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. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -255,20 +256,20 @@ def test_image_annotator_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, @@ -327,7 +328,7 @@ def test_image_annotator_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 @@ -404,6 +405,87 @@ def test_image_annotator_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [ImageAnnotatorClient, ImageAnnotatorAsyncClient] +) +@mock.patch.object( + ImageAnnotatorClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ImageAnnotatorClient), +) +@mock.patch.object( + ImageAnnotatorAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ImageAnnotatorAsyncClient), +) +def test_image_annotator_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", [ @@ -422,7 +504,7 @@ def test_image_annotator_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, @@ -436,24 +518,31 @@ def test_image_annotator_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + ( + ImageAnnotatorClient, + transports.ImageAnnotatorGrpcTransport, + "grpc", + grpc_helpers, + ), ( ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_image_annotator_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", @@ -486,9 +575,79 @@ def test_image_annotator_client_client_options_from_dict(): ) -def test_batch_annotate_images( - transport: str = "grpc", request_type=image_annotator.BatchAnnotateImagesRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ImageAnnotatorClient, + transports.ImageAnnotatorGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ImageAnnotatorAsyncClient, + transports.ImageAnnotatorGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_image_annotator_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( + "vision.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-vision", + ), + scopes=None, + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [image_annotator.BatchAnnotateImagesRequest, dict,] +) +def test_batch_annotate_images(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -514,10 +673,6 @@ def test_batch_annotate_images( assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) -def test_batch_annotate_images_from_dict(): - test_batch_annotate_images(request_type=dict) - - def test_batch_annotate_images_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. @@ -678,9 +833,10 @@ async def test_batch_annotate_images_flattened_error_async(): ) -def test_batch_annotate_files( - transport: str = "grpc", request_type=image_annotator.BatchAnnotateFilesRequest -): +@pytest.mark.parametrize( + "request_type", [image_annotator.BatchAnnotateFilesRequest, dict,] +) +def test_batch_annotate_files(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -706,10 +862,6 @@ def test_batch_annotate_files( assert isinstance(response, image_annotator.BatchAnnotateFilesResponse) -def test_batch_annotate_files_from_dict(): - test_batch_annotate_files(request_type=dict) - - def test_batch_annotate_files_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. @@ -882,10 +1034,10 @@ async def test_batch_annotate_files_flattened_error_async(): ) -def test_async_batch_annotate_images( - transport: str = "grpc", - request_type=image_annotator.AsyncBatchAnnotateImagesRequest, -): +@pytest.mark.parametrize( + "request_type", [image_annotator.AsyncBatchAnnotateImagesRequest, dict,] +) +def test_async_batch_annotate_images(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -911,10 +1063,6 @@ def test_async_batch_annotate_images( assert isinstance(response, future.Future) -def test_async_batch_annotate_images_from_dict(): - test_async_batch_annotate_images(request_type=dict) - - def test_async_batch_annotate_images_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. @@ -1097,9 +1245,10 @@ async def test_async_batch_annotate_images_flattened_error_async(): ) -def test_async_batch_annotate_files( - transport: str = "grpc", request_type=image_annotator.AsyncBatchAnnotateFilesRequest -): +@pytest.mark.parametrize( + "request_type", [image_annotator.AsyncBatchAnnotateFilesRequest, dict,] +) +def test_async_batch_annotate_files(request_type, transport: str = "grpc"): client = ImageAnnotatorClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1125,10 +1274,6 @@ def test_async_batch_annotate_files( assert isinstance(response, future.Future) -def test_async_batch_annotate_files_from_dict(): - test_async_batch_annotate_files(request_type=dict) - - def test_async_batch_annotate_files_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. @@ -1321,6 +1466,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ImageAnnotatorClient(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 = ImageAnnotatorClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.ImageAnnotatorGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1885,7 +2047,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( @@ -1950,3 +2112,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport), + ], +) +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/vision_v1p4beta1/test_product_search.py b/tests/unit/gapic/vision_v1p4beta1/test_product_search.py index fafdeef8..73f016a4 100644 --- a/tests/unit/gapic/vision_v1p4beta1/test_product_search.py +++ b/tests/unit/gapic/vision_v1p4beta1/test_product_search.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. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -257,20 +258,20 @@ def test_product_search_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, @@ -329,7 +330,7 @@ def test_product_search_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 @@ -406,6 +407,87 @@ def test_product_search_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [ProductSearchClient, ProductSearchAsyncClient] +) +@mock.patch.object( + ProductSearchClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ProductSearchClient), +) +@mock.patch.object( + ProductSearchAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ProductSearchAsyncClient), +) +def test_product_search_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", [ @@ -424,7 +506,7 @@ def test_product_search_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, @@ -438,24 +520,31 @@ def test_product_search_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + ( + ProductSearchClient, + transports.ProductSearchGrpcTransport, + "grpc", + grpc_helpers, + ), ( ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_product_search_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", @@ -488,9 +577,79 @@ def test_product_search_client_client_options_from_dict(): ) -def test_create_product_set( - transport: str = "grpc", request_type=product_search_service.CreateProductSetRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ProductSearchClient, + transports.ProductSearchGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ProductSearchAsyncClient, + transports.ProductSearchGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_product_search_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( + "vision.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-vision", + ), + scopes=None, + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [product_search_service.CreateProductSetRequest, dict,] +) +def test_create_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -520,10 +679,6 @@ def test_create_product_set( assert response.display_name == "display_name_value" -def test_create_product_set_from_dict(): - test_create_product_set(request_type=dict) - - def test_create_product_set_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. @@ -741,9 +896,10 @@ async def test_create_product_set_flattened_error_async(): ) -def test_list_product_sets( - transport: str = "grpc", request_type=product_search_service.ListProductSetsRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListProductSetsRequest, dict,] +) +def test_list_product_sets(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -772,10 +928,6 @@ def test_list_product_sets( assert response.next_page_token == "next_page_token_value" -def test_list_product_sets_from_dict(): - test_list_product_sets(request_type=dict) - - def test_list_product_sets_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. @@ -966,8 +1118,10 @@ async def test_list_product_sets_flattened_error_async(): ) -def test_list_product_sets_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_product_sets_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1012,8 +1166,10 @@ def test_list_product_sets_pager(): assert all(isinstance(i, product_search_service.ProductSet) for i in results) -def test_list_product_sets_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_product_sets_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1136,9 +1292,10 @@ async def test_list_product_sets_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_product_set( - transport: str = "grpc", request_type=product_search_service.GetProductSetRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.GetProductSetRequest, dict,] +) +def test_get_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1166,10 +1323,6 @@ def test_get_product_set( assert response.display_name == "display_name_value" -def test_get_product_set_from_dict(): - test_get_product_set(request_type=dict) - - def test_get_product_set_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. @@ -1349,9 +1502,10 @@ async def test_get_product_set_flattened_error_async(): ) -def test_update_product_set( - transport: str = "grpc", request_type=product_search_service.UpdateProductSetRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.UpdateProductSetRequest, dict,] +) +def test_update_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1381,10 +1535,6 @@ def test_update_product_set( assert response.display_name == "display_name_value" -def test_update_product_set_from_dict(): - test_update_product_set(request_type=dict) - - def test_update_product_set_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. @@ -1596,9 +1746,10 @@ async def test_update_product_set_flattened_error_async(): ) -def test_delete_product_set( - transport: str = "grpc", request_type=product_search_service.DeleteProductSetRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.DeleteProductSetRequest, dict,] +) +def test_delete_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1624,10 +1775,6 @@ def test_delete_product_set( assert response is None -def test_delete_product_set_from_dict(): - test_delete_product_set(request_type=dict) - - def test_delete_product_set_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. @@ -1809,9 +1956,10 @@ async def test_delete_product_set_flattened_error_async(): ) -def test_create_product( - transport: str = "grpc", request_type=product_search_service.CreateProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.CreateProductRequest, dict,] +) +def test_create_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1844,10 +1992,6 @@ def test_create_product( assert response.product_category == "product_category_value" -def test_create_product_from_dict(): - test_create_product(request_type=dict) - - def test_create_product_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. @@ -2058,9 +2202,10 @@ async def test_create_product_flattened_error_async(): ) -def test_list_products( - transport: str = "grpc", request_type=product_search_service.ListProductsRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListProductsRequest, dict,] +) +def test_list_products(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2087,10 +2232,6 @@ def test_list_products( assert response.next_page_token == "next_page_token_value" -def test_list_products_from_dict(): - test_list_products(request_type=dict) - - def test_list_products_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. @@ -2269,8 +2410,10 @@ async def test_list_products_flattened_error_async(): ) -def test_list_products_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_products), "__call__") as call: @@ -2312,8 +2455,10 @@ def test_list_products_pager(): assert all(isinstance(i, product_search_service.Product) for i in results) -def test_list_products_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_products), "__call__") as call: @@ -2427,9 +2572,10 @@ async def test_list_products_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_product( - transport: str = "grpc", request_type=product_search_service.GetProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.GetProductRequest, dict,] +) +def test_get_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2462,10 +2608,6 @@ def test_get_product( assert response.product_category == "product_category_value" -def test_get_product_from_dict(): - test_get_product(request_type=dict) - - def test_get_product_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. @@ -2650,9 +2792,10 @@ async def test_get_product_flattened_error_async(): ) -def test_update_product( - transport: str = "grpc", request_type=product_search_service.UpdateProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.UpdateProductRequest, dict,] +) +def test_update_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2685,10 +2828,6 @@ def test_update_product( assert response.product_category == "product_category_value" -def test_update_product_from_dict(): - test_update_product(request_type=dict) - - def test_update_product_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. @@ -2893,9 +3032,10 @@ async def test_update_product_flattened_error_async(): ) -def test_delete_product( - transport: str = "grpc", request_type=product_search_service.DeleteProductRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.DeleteProductRequest, dict,] +) +def test_delete_product(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2919,10 +3059,6 @@ def test_delete_product( assert response is None -def test_delete_product_from_dict(): - test_delete_product(request_type=dict) - - def test_delete_product_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. @@ -3092,10 +3228,10 @@ async def test_delete_product_flattened_error_async(): ) -def test_create_reference_image( - transport: str = "grpc", - request_type=product_search_service.CreateReferenceImageRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.CreateReferenceImageRequest, dict,] +) +def test_create_reference_image(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3125,10 +3261,6 @@ def test_create_reference_image( assert response.uri == "uri_value" -def test_create_reference_image_from_dict(): - test_create_reference_image(request_type=dict) - - def test_create_reference_image_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. @@ -3344,10 +3476,10 @@ async def test_create_reference_image_flattened_error_async(): ) -def test_delete_reference_image( - transport: str = "grpc", - request_type=product_search_service.DeleteReferenceImageRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.DeleteReferenceImageRequest, dict,] +) +def test_delete_reference_image(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3373,10 +3505,6 @@ def test_delete_reference_image( assert response is None -def test_delete_reference_image_from_dict(): - test_delete_reference_image(request_type=dict) - - def test_delete_reference_image_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. @@ -3558,10 +3686,10 @@ async def test_delete_reference_image_flattened_error_async(): ) -def test_list_reference_images( - transport: str = "grpc", - request_type=product_search_service.ListReferenceImagesRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListReferenceImagesRequest, dict,] +) +def test_list_reference_images(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3591,10 +3719,6 @@ def test_list_reference_images( assert response.next_page_token == "next_page_token_value" -def test_list_reference_images_from_dict(): - test_list_reference_images(request_type=dict) - - def test_list_reference_images_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. @@ -3786,8 +3910,10 @@ async def test_list_reference_images_flattened_error_async(): ) -def test_list_reference_images_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_reference_images_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3834,8 +3960,10 @@ def test_list_reference_images_pager(): ) -def test_list_reference_images_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_reference_images_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3960,10 +4088,10 @@ async def test_list_reference_images_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_reference_image( - transport: str = "grpc", - request_type=product_search_service.GetReferenceImageRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.GetReferenceImageRequest, dict,] +) +def test_get_reference_image(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3993,10 +4121,6 @@ def test_get_reference_image( assert response.uri == "uri_value" -def test_get_reference_image_from_dict(): - test_get_reference_image(request_type=dict) - - def test_get_reference_image_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. @@ -4186,10 +4310,10 @@ async def test_get_reference_image_flattened_error_async(): ) -def test_add_product_to_product_set( - transport: str = "grpc", - request_type=product_search_service.AddProductToProductSetRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.AddProductToProductSetRequest, dict,] +) +def test_add_product_to_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4215,10 +4339,6 @@ def test_add_product_to_product_set( assert response is None -def test_add_product_to_product_set_from_dict(): - test_add_product_to_product_set(request_type=dict) - - def test_add_product_to_product_set_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. @@ -4414,10 +4534,10 @@ async def test_add_product_to_product_set_flattened_error_async(): ) -def test_remove_product_from_product_set( - transport: str = "grpc", - request_type=product_search_service.RemoveProductFromProductSetRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.RemoveProductFromProductSetRequest, dict,] +) +def test_remove_product_from_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4443,10 +4563,6 @@ def test_remove_product_from_product_set( assert response is None -def test_remove_product_from_product_set_from_dict(): - test_remove_product_from_product_set(request_type=dict) - - def test_remove_product_from_product_set_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. @@ -4642,10 +4758,10 @@ async def test_remove_product_from_product_set_flattened_error_async(): ) -def test_list_products_in_product_set( - transport: str = "grpc", - request_type=product_search_service.ListProductsInProductSetRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ListProductsInProductSetRequest, dict,] +) +def test_list_products_in_product_set(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4674,10 +4790,6 @@ def test_list_products_in_product_set( assert response.next_page_token == "next_page_token_value" -def test_list_products_in_product_set_from_dict(): - test_list_products_in_product_set(request_type=dict) - - def test_list_products_in_product_set_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. @@ -4868,8 +4980,10 @@ async def test_list_products_in_product_set_flattened_error_async(): ) -def test_list_products_in_product_set_pager(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_in_product_set_pager(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4913,8 +5027,10 @@ def test_list_products_in_product_set_pager(): assert all(isinstance(i, product_search_service.Product) for i in results) -def test_list_products_in_product_set_pages(): - client = ProductSearchClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_products_in_product_set_pages(transport_name: str = "grpc"): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5036,10 +5152,10 @@ async def test_list_products_in_product_set_async_pages(): assert page_.raw_page.next_page_token == token -def test_import_product_sets( - transport: str = "grpc", - request_type=product_search_service.ImportProductSetsRequest, -): +@pytest.mark.parametrize( + "request_type", [product_search_service.ImportProductSetsRequest, dict,] +) +def test_import_product_sets(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5065,10 +5181,6 @@ def test_import_product_sets( assert isinstance(response, future.Future) -def test_import_product_sets_from_dict(): - test_import_product_sets(request_type=dict) - - def test_import_product_sets_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. @@ -5296,9 +5408,10 @@ async def test_import_product_sets_flattened_error_async(): ) -def test_purge_products( - transport: str = "grpc", request_type=product_search_service.PurgeProductsRequest -): +@pytest.mark.parametrize( + "request_type", [product_search_service.PurgeProductsRequest, dict,] +) +def test_purge_products(request_type, transport: str = "grpc"): client = ProductSearchClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5322,10 +5435,6 @@ def test_purge_products( assert isinstance(response, future.Future) -def test_purge_products_from_dict(): - test_purge_products(request_type=dict) - - def test_purge_products_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. @@ -5521,6 +5630,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductSearchClient(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 = ProductSearchClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.ProductSearchGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -6129,7 +6255,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( @@ -6194,3 +6320,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ProductSearchClient, transports.ProductSearchGrpcTransport), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport), + ], +) +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, + )