diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index cb89b2e3..39ad3cec 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,16 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:ec49167c606648a063d1222220b48119c912562849a0528f35bfb592a9f72737 + digest: sha256:d22cd2ddce65fdac6986f115563faf2fc81482b09dfbea83ac2808c92ecfdff0 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 5a36ced7..e446644f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,9 +3,10 @@ # # For syntax help see: # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax +# Note: This file is autogenerated. To make changes to the codeowner team, please update .repo-metadata.json. -# The @googleapis/yoshi-python is the default owner for changes in this repo -* @googleapis/yoshi-python +# @googleapis/yoshi-python is the default owner for changes in this repo +* @googleapis/yoshi-python - -/samples/**/*.py @googleapis/python-samples-owners +# @googleapis/python-samples-reviewers is the default owner for samples changes +/samples/ @googleapis/python-samples-reviewers diff --git a/.github/release-please.yml b/.github/release-please.yml index 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 0119b788..3e859d95 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -10,7 +10,6 @@ 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..074ee250 --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,57 @@ +on: + pull_request: + branches: + - main +name: unittest +jobs: + unit: + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.6', '3.7', '3.8', '3.9', '3.10'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run unit tests + env: + COVERAGE_FILE: .coverage-${{ matrix.python }} + run: | + nox -s unit-${{ matrix.python }} + - name: Upload coverage results + uses: actions/upload-artifact@v2 + with: + name: coverage-artifacts + path: .coverage-${{ matrix.python }} + + cover: + runs-on: ubuntu-latest + needs: + - unit + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install coverage + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install coverage + - name: Download coverage results + uses: actions/download-artifact@v2 + with: + name: coverage-artifacts + path: .coverage-results/ + - name: Report coverage results + run: | + coverage combine .coverage-results/.coverage* + coverage report --show-missing --fail-under=100 diff --git a/.kokoro/release.sh b/.kokoro/release.sh index fd054d30..8d8aa969 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-asset 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 bb08ee8c..7ddba4bd 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,8 +23,18 @@ env_vars: { value: "github/python-asset/.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 8f946e8d..454329ac 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -2,9 +2,9 @@ "name": "cloudasset", "name_pretty": "Cloud Asset Inventory", "product_documentation": "https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview", - "client_documentation": "https://googleapis.dev/python/cloudasset/latest", + "client_documentation": "https://cloud.google.com/python/docs/reference/cloudasset/latest", "issue_tracker": "https://issuetracker.google.com/savedsearches/559757", - "release_level": "ga", + "release_level": "stable", "language": "python", "library_type": "GAPIC_AUTO", "repo": "googleapis/python-asset", @@ -12,5 +12,6 @@ "api_id": "cloudasset.googleapis.com", "requires_billing": true, "default_version": "v1", - "codeowner_team": "" + "codeowner_team": "", + "api_shortname": "cloudasset" } diff --git a/CHANGELOG.md b/CHANGELOG.md index cede86c4..79b51439 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ [1]: https://pypi.org/project/google-cloud-asset/#history +## [3.8.0](https://github.com/googleapis/python-asset/compare/v3.7.1...v3.8.0) (2022-02-26) + + +### Features + +* add api key support ([#361](https://github.com/googleapis/python-asset/issues/361)) ([6d03a57](https://github.com/googleapis/python-asset/commit/6d03a57e37387342c047ca76f9e6c15941390ad6)) + + +### Bug Fixes + +* resolve DuplicateCredentialArgs error when using credentials_file ([e5a9160](https://github.com/googleapis/python-asset/commit/e5a91606d50937583718d97e1e3027498c86ace1)) + + +### Documentation + +* add autogenerated code snippets ([8e6877d](https://github.com/googleapis/python-asset/commit/8e6877de9c5969d493e67f545b93d0059c8ca182)) + ### [3.7.1](https://www.github.com/googleapis/python-asset/compare/v3.7.0...v3.7.1) (2021-11-02) diff --git a/README.rst b/README.rst index 834a9dbe..b582fd7d 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,7 @@ Python Client for Cloud Asset API .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-asset.svg :target: https://pypi.org/project/google-cloud-asset/ .. _Cloud Asset API: https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/reference/rest/ -.. _Client Library Documentation: https://googleapis.dev/python/cloudasset/latest +.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/cloudasset/latest .. _Product Documentation: https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview Quick Start diff --git a/google/cloud/asset/__init__.py b/google/cloud/asset/__init__.py index d8b042e9..86224474 100644 --- a/google/cloud/asset/__init__.py +++ b/google/cloud/asset/__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/asset_v1/__init__.py b/google/cloud/asset_v1/__init__.py index 1dfd90c9..e3b64ace 100644 --- a/google/cloud/asset_v1/__init__.py +++ b/google/cloud/asset_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/asset_v1/services/__init__.py b/google/cloud/asset_v1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/asset_v1/services/__init__.py +++ b/google/cloud/asset_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/asset_v1/services/asset_service/__init__.py b/google/cloud/asset_v1/services/asset_service/__init__.py index cb995a56..4af01a66 100644 --- a/google/cloud/asset_v1/services/asset_service/__init__.py +++ b/google/cloud/asset_v1/services/asset_service/__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/asset_v1/services/asset_service/async_client.py b/google/cloud/asset_v1/services/asset_service/async_client.py index aa28e9dd..1426560c 100644 --- a/google/cloud/asset_v1/services/asset_service/async_client.py +++ b/google/cloud/asset_v1/services/asset_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -115,6 +118,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 AssetServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> AssetServiceTransport: """Returns the transport used by the client instance. @@ -197,6 +236,34 @@ async def export_assets( the export operation result. For regular-size resource parent, the export operation usually finishes within 5 minutes. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_export_assets(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + output_config = asset_v1.OutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1.ExportAssetsRequest( + parent="parent_value", + output_config=output_config, + ) + + # Make the request + operation = client.export_assets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.ExportAssetsRequest, dict]): The request object. Export asset request. @@ -260,6 +327,27 @@ async def list_assets( r"""Lists assets with time and resource types and returns paged results in response. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_list_assets(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.ListAssetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_assets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1.types.ListAssetsRequest, dict]): The request object. ListAssets request. @@ -288,7 +376,7 @@ async def list_assets( """ # 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: @@ -356,6 +444,26 @@ async def batch_get_assets_history( specified asset does not exist, this API returns an INVALID_ARGUMENT error. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_batch_get_assets_history(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.BatchGetAssetsHistoryRequest( + parent="parent_value", + ) + + # Make the request + response = client.batch_get_assets_history(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.BatchGetAssetsHistoryRequest, dict]): The request object. Batch get assets history request. @@ -415,6 +523,31 @@ async def create_feed( project/folder/organization to listen to its asset updates. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_create_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1.Feed() + feed.name = "name_value" + + request = asset_v1.CreateFeedRequest( + parent="parent_value", + feed_id="feed_id_value", + feed=feed, + ) + + # Make the request + response = client.create_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.CreateFeedRequest, dict]): The request object. Create asset feed request. @@ -450,7 +583,7 @@ async def create_feed( """ # 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: @@ -497,6 +630,25 @@ async def get_feed( ) -> asset_service.Feed: r"""Gets details about an asset feed. + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_get_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.GetFeedRequest( + name="name_value", + ) + + # Make the request + response = client.get_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.GetFeedRequest, dict]): The request object. Get asset feed request. @@ -527,7 +679,7 @@ async def get_feed( """ # 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: @@ -585,6 +737,26 @@ async def list_feeds( r"""Lists all asset feeds in a parent project/folder/organization. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_list_feeds(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.ListFeedsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_feeds(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.ListFeedsRequest, dict]): The request object. List asset feeds request. @@ -610,7 +782,7 @@ async def list_feeds( """ # 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: @@ -667,6 +839,28 @@ async def update_feed( ) -> asset_service.Feed: r"""Updates an asset feed configuration. + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_update_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1.Feed() + feed.name = "name_value" + + request = asset_v1.UpdateFeedRequest( + feed=feed, + ) + + # Make the request + response = client.update_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.UpdateFeedRequest, dict]): The request object. Update asset feed request. @@ -698,7 +892,7 @@ async def update_feed( """ # 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([feed]) if request is not None and has_flattened_params: @@ -747,6 +941,22 @@ async def delete_feed( ) -> None: r"""Deletes an asset feed. + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_delete_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.DeleteFeedRequest( + name="name_value", + ) + + # Make the request + client.delete_feed(request=request) + Args: request (Union[google.cloud.asset_v1.types.DeleteFeedRequest, dict]): The request object. @@ -766,7 +976,7 @@ async def delete_feed( 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: @@ -827,6 +1037,27 @@ async def search_all_resources( the ``cloudasset.assets.searchAllResources`` permission on the desired scope, otherwise the request will be rejected. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_search_all_resources(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.SearchAllResourcesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1.types.SearchAllResourcesRequest, dict]): The request object. Search all resources request. @@ -938,7 +1169,7 @@ async def search_all_resources( """ # 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([scope, query, asset_types]) if request is not None and has_flattened_params: @@ -1008,6 +1239,27 @@ async def search_all_iam_policies( ``cloudasset.assets.searchAllIamPolicies`` permission on the desired scope, otherwise the request will be rejected. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_search_all_iam_policies(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.SearchAllIamPoliciesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_iam_policies(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1.types.SearchAllIamPoliciesRequest, dict]): The request object. Search all IAM policies request. @@ -1101,7 +1353,7 @@ async def search_all_iam_policies( """ # 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([scope, query]) if request is not None and has_flattened_params: @@ -1165,6 +1417,29 @@ async def analyze_iam_policy( r"""Analyzes IAM policies to answer which identities have what accesses on which resources. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_analyze_iam_policy(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1.IamPolicyAnalysisQuery() + analysis_query.scope = "scope_value" + + request = asset_v1.AnalyzeIamPolicyRequest( + analysis_query=analysis_query, + ) + + # Make the request + response = client.analyze_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.AnalyzeIamPolicyRequest, dict]): The request object. A request message for @@ -1236,6 +1511,37 @@ async def analyze_iam_policy_longrunning( to poll the operation result. The metadata contains the metadata for the long-running operation. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_analyze_iam_policy_longrunning(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1.IamPolicyAnalysisQuery() + analysis_query.scope = "scope_value" + + output_config = asset_v1.IamPolicyAnalysisOutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1.AnalyzeIamPolicyLongrunningRequest( + analysis_query=analysis_query, + output_config=output_config, + ) + + # Make the request + operation = client.analyze_iam_policy_longrunning(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.AnalyzeIamPolicyLongrunningRequest, dict]): The request object. A request message for @@ -1305,6 +1611,27 @@ async def analyze_move( subject to change before the actual resource migration takes place. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_analyze_move(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.AnalyzeMoveRequest( + resource="resource_value", + destination_parent="destination_parent_value", + ) + + # Make the request + response = client.analyze_move(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.AnalyzeMoveRequest, dict]): The request object. The request message for performing diff --git a/google/cloud/asset_v1/services/asset_service/client.py b/google/cloud/asset_v1/services/asset_service/client.py index 7938ab49..05684ef9 100644 --- a/google/cloud/asset_v1/services/asset_service/client.py +++ b/google/cloud/asset_v1/services/asset_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -293,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, *, @@ -343,50 +412,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, AssetServiceTransport): # transport is a AssetServiceTransport 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." @@ -398,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, @@ -432,6 +482,34 @@ def export_assets( the export operation result. For regular-size resource parent, the export operation usually finishes within 5 minutes. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_export_assets(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + output_config = asset_v1.OutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1.ExportAssetsRequest( + parent="parent_value", + output_config=output_config, + ) + + # Make the request + operation = client.export_assets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.ExportAssetsRequest, dict]): The request object. Export asset request. @@ -496,6 +574,27 @@ def list_assets( r"""Lists assets with time and resource types and returns paged results in response. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_list_assets(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.ListAssetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_assets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1.types.ListAssetsRequest, dict]): The request object. ListAssets request. @@ -524,7 +623,7 @@ def list_assets( """ # 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: @@ -582,6 +681,26 @@ def batch_get_assets_history( specified asset does not exist, this API returns an INVALID_ARGUMENT error. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_batch_get_assets_history(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.BatchGetAssetsHistoryRequest( + parent="parent_value", + ) + + # Make the request + response = client.batch_get_assets_history(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.BatchGetAssetsHistoryRequest, dict]): The request object. Batch get assets history request. @@ -632,6 +751,31 @@ def create_feed( project/folder/organization to listen to its asset updates. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_create_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1.Feed() + feed.name = "name_value" + + request = asset_v1.CreateFeedRequest( + parent="parent_value", + feed_id="feed_id_value", + feed=feed, + ) + + # Make the request + response = client.create_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.CreateFeedRequest, dict]): The request object. Create asset feed request. @@ -667,7 +811,7 @@ def create_feed( """ # 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: @@ -714,6 +858,25 @@ def get_feed( ) -> asset_service.Feed: r"""Gets details about an asset feed. + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_get_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.GetFeedRequest( + name="name_value", + ) + + # Make the request + response = client.get_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.GetFeedRequest, dict]): The request object. Get asset feed request. @@ -744,7 +907,7 @@ def get_feed( """ # 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: @@ -792,6 +955,26 @@ def list_feeds( r"""Lists all asset feeds in a parent project/folder/organization. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_list_feeds(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.ListFeedsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_feeds(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.ListFeedsRequest, dict]): The request object. List asset feeds request. @@ -817,7 +1000,7 @@ def list_feeds( """ # 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: @@ -864,6 +1047,28 @@ def update_feed( ) -> asset_service.Feed: r"""Updates an asset feed configuration. + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_update_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1.Feed() + feed.name = "name_value" + + request = asset_v1.UpdateFeedRequest( + feed=feed, + ) + + # Make the request + response = client.update_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.UpdateFeedRequest, dict]): The request object. Update asset feed request. @@ -895,7 +1100,7 @@ def update_feed( """ # 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([feed]) if request is not None and has_flattened_params: @@ -944,6 +1149,22 @@ def delete_feed( ) -> None: r"""Deletes an asset feed. + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_delete_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.DeleteFeedRequest( + name="name_value", + ) + + # Make the request + client.delete_feed(request=request) + Args: request (Union[google.cloud.asset_v1.types.DeleteFeedRequest, dict]): The request object. @@ -963,7 +1184,7 @@ def delete_feed( 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: @@ -1014,6 +1235,27 @@ def search_all_resources( the ``cloudasset.assets.searchAllResources`` permission on the desired scope, otherwise the request will be rejected. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_search_all_resources(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.SearchAllResourcesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1.types.SearchAllResourcesRequest, dict]): The request object. Search all resources request. @@ -1125,7 +1367,7 @@ def search_all_resources( """ # 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([scope, query, asset_types]) if request is not None and has_flattened_params: @@ -1186,6 +1428,27 @@ def search_all_iam_policies( ``cloudasset.assets.searchAllIamPolicies`` permission on the desired scope, otherwise the request will be rejected. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_search_all_iam_policies(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.SearchAllIamPoliciesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_iam_policies(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1.types.SearchAllIamPoliciesRequest, dict]): The request object. Search all IAM policies request. @@ -1279,7 +1542,7 @@ def search_all_iam_policies( """ # 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([scope, query]) if request is not None and has_flattened_params: @@ -1334,6 +1597,29 @@ def analyze_iam_policy( r"""Analyzes IAM policies to answer which identities have what accesses on which resources. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_analyze_iam_policy(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1.IamPolicyAnalysisQuery() + analysis_query.scope = "scope_value" + + request = asset_v1.AnalyzeIamPolicyRequest( + analysis_query=analysis_query, + ) + + # Make the request + response = client.analyze_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.AnalyzeIamPolicyRequest, dict]): The request object. A request message for @@ -1397,6 +1683,37 @@ def analyze_iam_policy_longrunning( to poll the operation result. The metadata contains the metadata for the long-running operation. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_analyze_iam_policy_longrunning(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1.IamPolicyAnalysisQuery() + analysis_query.scope = "scope_value" + + output_config = asset_v1.IamPolicyAnalysisOutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1.AnalyzeIamPolicyLongrunningRequest( + analysis_query=analysis_query, + output_config=output_config, + ) + + # Make the request + operation = client.analyze_iam_policy_longrunning(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.AnalyzeIamPolicyLongrunningRequest, dict]): The request object. A request message for @@ -1469,6 +1786,27 @@ def analyze_move( subject to change before the actual resource migration takes place. + + .. code-block:: python + + from google.cloud import asset_v1 + + def sample_analyze_move(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.AnalyzeMoveRequest( + resource="resource_value", + destination_parent="destination_parent_value", + ) + + # Make the request + response = client.analyze_move(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1.types.AnalyzeMoveRequest, dict]): The request object. The request message for performing diff --git a/google/cloud/asset_v1/services/asset_service/pagers.py b/google/cloud/asset_v1/services/asset_service/pagers.py index 26c8eff6..7b035da0 100644 --- a/google/cloud/asset_v1/services/asset_service/pagers.py +++ b/google/cloud/asset_v1/services/asset_service/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/asset_v1/services/asset_service/transports/__init__.py b/google/cloud/asset_v1/services/asset_service/transports/__init__.py index 9158fc25..c3ef619a 100644 --- a/google/cloud/asset_v1/services/asset_service/transports/__init__.py +++ b/google/cloud/asset_v1/services/asset_service/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/asset_v1/services/asset_service/transports/base.py b/google/cloud/asset_v1/services/asset_service/transports/base.py index 004ef6b7..8b071d9f 100644 --- a/google/cloud/asset_v1/services/asset_service/transports/base.py +++ b/google/cloud/asset_v1/services/asset_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,11 +18,11 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -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/asset_v1/services/asset_service/transports/grpc.py b/google/cloud/asset_v1/services/asset_service/transports/grpc.py index 6be0a437..d4f96195 100644 --- a/google/cloud/asset_v1/services/asset_service/transports/grpc.py +++ b/google/cloud/asset_v1/services/asset_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -162,8 +162,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, @@ -236,7 +239,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/asset_v1/services/asset_service/transports/grpc_asyncio.py b/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py index 173bb97d..b05e4bd1 100644 --- a/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py +++ b/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -207,8 +207,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.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/asset_v1/types/__init__.py b/google/cloud/asset_v1/types/__init__.py index 43e76c1e..a9710b67 100644 --- a/google/cloud/asset_v1/types/__init__.py +++ b/google/cloud/asset_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/asset_v1/types/asset_service.py b/google/cloud/asset_v1/types/asset_service.py index 0a20700c..1362c0cd 100644 --- a/google/cloud/asset_v1/types/asset_service.py +++ b/google/cloud/asset_v1/types/asset_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. @@ -493,11 +493,13 @@ class OutputConfig(proto.Message): Attributes: gcs_destination (google.cloud.asset_v1.types.GcsDestination): Destination on Cloud Storage. + This field is a member of `oneof`_ ``destination``. bigquery_destination (google.cloud.asset_v1.types.BigQueryDestination): Destination on BigQuery. The output table stores the fields in asset proto as columns in BigQuery. + This field is a member of `oneof`_ ``destination``. """ @@ -517,6 +519,7 @@ class OutputResult(proto.Message): Attributes: gcs_result (google.cloud.asset_v1.types.GcsOutputResult): Export result on Cloud Storage. + This field is a member of `oneof`_ ``result``. """ @@ -559,6 +562,7 @@ class GcsDestination(proto.Message): there is no `hold `__, it will be overwritten with the exported result. + This field is a member of `oneof`_ ``object_uri``. uri_prefix (str): The uri prefix of all generated Cloud Storage objects. @@ -570,6 +574,7 @@ class GcsDestination(proto.Message): compute.googleapis.com/Disk assets. An INVALID_ARGUMENT error will be returned if file with the same name "gs://bucket_name/object_name_prefix" already exists. + This field is a member of `oneof`_ ``object_uri``. """ @@ -706,6 +711,7 @@ class FeedOutputConfig(proto.Message): Attributes: pubsub_destination (google.cloud.asset_v1.types.PubsubDestination): Destination on Pub/Sub. + This field is a member of `oneof`_ ``destination``. """ @@ -1336,6 +1342,7 @@ class ConditionContext(proto.Message): conditions. Note that this value must not be earlier than the current time; otherwise, an INVALID_ARGUMENT error will be returned. + This field is a member of `oneof`_ ``TimeContext``. """ @@ -1456,9 +1463,11 @@ class IamPolicyAnalysisOutputConfig(proto.Message): Attributes: gcs_destination (google.cloud.asset_v1.types.IamPolicyAnalysisOutputConfig.GcsDestination): Destination on Cloud Storage. + This field is a member of `oneof`_ ``destination``. bigquery_destination (google.cloud.asset_v1.types.IamPolicyAnalysisOutputConfig.BigQueryDestination): Destination on BigQuery. + This field is a member of `oneof`_ ``destination``. """ @@ -1648,10 +1657,12 @@ class MoveAnalysis(proto.Message): analysis (google.cloud.asset_v1.types.MoveAnalysisResult): Analysis result of moving the target resource. + This field is a member of `oneof`_ ``result``. error (google.rpc.status_pb2.Status): Description of error encountered when performing the analysis. + This field is a member of `oneof`_ ``result``. """ diff --git a/google/cloud/asset_v1/types/assets.py b/google/cloud/asset_v1/types/assets.py index bf4e868d..61e9c175 100644 --- a/google/cloud/asset_v1/types/assets.py +++ b/google/cloud/asset_v1/types/assets.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. @@ -159,14 +159,17 @@ class Asset(proto.Message): access_policy (google.identity.accesscontextmanager.v1.access_policy_pb2.AccessPolicy): Please also refer to the `access policy user guide `__. + This field is a member of `oneof`_ ``access_context_policy``. access_level (google.identity.accesscontextmanager.v1.access_level_pb2.AccessLevel): Please also refer to the `access level user guide `__. + This field is a member of `oneof`_ ``access_context_policy``. service_perimeter (google.identity.accesscontextmanager.v1.service_perimeter_pb2.ServicePerimeter): Please also refer to the `service perimeter user guide `__. + This field is a member of `oneof`_ ``access_context_policy``. os_inventory (google.cloud.osconfig_v1.Inventory): A representation of runtime OS Inventory information. See @@ -957,9 +960,11 @@ class Access(proto.Message): Attributes: role (str): The role. + This field is a member of `oneof`_ ``oneof_access``. permission (str): The permission. + This field is a member of `oneof`_ ``oneof_access``. analysis_state (google.cloud.asset_v1.types.IamPolicyAnalysisState): The analysis state of this access. diff --git a/google/cloud/asset_v1p1beta1/__init__.py b/google/cloud/asset_v1p1beta1/__init__.py index e8433f15..f2d3b6ae 100644 --- a/google/cloud/asset_v1p1beta1/__init__.py +++ b/google/cloud/asset_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/asset_v1p1beta1/services/__init__.py b/google/cloud/asset_v1p1beta1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/asset_v1p1beta1/services/__init__.py +++ b/google/cloud/asset_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/asset_v1p1beta1/services/asset_service/__init__.py b/google/cloud/asset_v1p1beta1/services/asset_service/__init__.py index cb995a56..4af01a66 100644 --- a/google/cloud/asset_v1p1beta1/services/asset_service/__init__.py +++ b/google/cloud/asset_v1p1beta1/services/asset_service/__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/asset_v1p1beta1/services/asset_service/async_client.py b/google/cloud/asset_v1p1beta1/services/asset_service/async_client.py index 98dd7848..ce4f8da1 100644 --- a/google/cloud/asset_v1p1beta1/services/asset_service/async_client.py +++ b/google/cloud/asset_v1p1beta1/services/asset_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.asset_v1p1beta1.services.asset_service import pagers from google.cloud.asset_v1p1beta1.types import asset_service @@ -98,6 +101,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 AssetServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> AssetServiceTransport: """Returns the transport used by the client instance. @@ -177,6 +216,27 @@ async def search_all_resources( cloud.assets.SearchAllResources permission on the requested scope, otherwise it will be rejected. + + .. code-block:: python + + from google.cloud import asset_v1p1beta1 + + def sample_search_all_resources(): + # Create a client + client = asset_v1p1beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p1beta1.SearchAllResourcesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1p1beta1.types.SearchAllResourcesRequest, dict]): The request object. Search all resources request. @@ -222,7 +282,7 @@ async def search_all_resources( """ # 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([scope, query, asset_types]) if request is not None and has_flattened_params: @@ -297,6 +357,27 @@ async def search_all_iam_policies( cloud.assets.SearchAllIamPolicies permission on the requested scope, otherwise it will be rejected. + + .. code-block:: python + + from google.cloud import asset_v1p1beta1 + + def sample_search_all_iam_policies(): + # Create a client + client = asset_v1p1beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p1beta1.SearchAllIamPoliciesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_iam_policies(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1p1beta1.types.SearchAllIamPoliciesRequest, dict]): The request object. Search all IAM policies request. @@ -337,7 +418,7 @@ async def search_all_iam_policies( """ # 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([scope, query]) if request is not None and has_flattened_params: diff --git a/google/cloud/asset_v1p1beta1/services/asset_service/client.py b/google/cloud/asset_v1p1beta1/services/asset_service/client.py index 9778d40a..2a782cf8 100644 --- a/google/cloud/asset_v1p1beta1/services/asset_service/client.py +++ b/google/cloud/asset_v1p1beta1/services/asset_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.asset_v1p1beta1.services.asset_service import pagers from google.cloud.asset_v1p1beta1.types import asset_service @@ -215,6 +217,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, *, @@ -265,50 +334,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, AssetServiceTransport): # transport is a AssetServiceTransport 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." @@ -320,6 +361,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, @@ -351,6 +401,27 @@ def search_all_resources( cloud.assets.SearchAllResources permission on the requested scope, otherwise it will be rejected. + + .. code-block:: python + + from google.cloud import asset_v1p1beta1 + + def sample_search_all_resources(): + # Create a client + client = asset_v1p1beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p1beta1.SearchAllResourcesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1p1beta1.types.SearchAllResourcesRequest, dict]): The request object. Search all resources request. @@ -396,7 +467,7 @@ def search_all_resources( """ # 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([scope, query, asset_types]) if request is not None and has_flattened_params: @@ -461,6 +532,27 @@ def search_all_iam_policies( cloud.assets.SearchAllIamPolicies permission on the requested scope, otherwise it will be rejected. + + .. code-block:: python + + from google.cloud import asset_v1p1beta1 + + def sample_search_all_iam_policies(): + # Create a client + client = asset_v1p1beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p1beta1.SearchAllIamPoliciesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_iam_policies(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1p1beta1.types.SearchAllIamPoliciesRequest, dict]): The request object. Search all IAM policies request. @@ -501,7 +593,7 @@ def search_all_iam_policies( """ # 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([scope, query]) if request is not None and has_flattened_params: diff --git a/google/cloud/asset_v1p1beta1/services/asset_service/pagers.py b/google/cloud/asset_v1p1beta1/services/asset_service/pagers.py index efe8ab77..a2aea41b 100644 --- a/google/cloud/asset_v1p1beta1/services/asset_service/pagers.py +++ b/google/cloud/asset_v1p1beta1/services/asset_service/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/asset_v1p1beta1/services/asset_service/transports/__init__.py b/google/cloud/asset_v1p1beta1/services/asset_service/transports/__init__.py index 9158fc25..c3ef619a 100644 --- a/google/cloud/asset_v1p1beta1/services/asset_service/transports/__init__.py +++ b/google/cloud/asset_v1p1beta1/services/asset_service/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/asset_v1p1beta1/services/asset_service/transports/base.py b/google/cloud/asset_v1p1beta1/services/asset_service/transports/base.py index 21bcf429..5983397f 100644 --- a/google/cloud/asset_v1p1beta1/services/asset_service/transports/base.py +++ b/google/cloud/asset_v1p1beta1/services/asset_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -99,7 +99,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/asset_v1p1beta1/services/asset_service/transports/grpc.py b/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc.py index 5b4b5960..4577e66b 100644 --- a/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc.py +++ b/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -158,8 +158,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/asset_v1p1beta1/services/asset_service/transports/grpc_asyncio.py b/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc_asyncio.py index 62c7b9f6..ee2ed890 100644 --- a/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc_asyncio.py +++ b/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -203,8 +203,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/asset_v1p1beta1/types/__init__.py b/google/cloud/asset_v1p1beta1/types/__init__.py index c70c551c..467f8a85 100644 --- a/google/cloud/asset_v1p1beta1/types/__init__.py +++ b/google/cloud/asset_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/asset_v1p1beta1/types/asset_service.py b/google/cloud/asset_v1p1beta1/types/asset_service.py index d30eff30..4fecd5f4 100644 --- a/google/cloud/asset_v1p1beta1/types/asset_service.py +++ b/google/cloud/asset_v1p1beta1/types/asset_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. diff --git a/google/cloud/asset_v1p1beta1/types/assets.py b/google/cloud/asset_v1p1beta1/types/assets.py index 120da83c..ed04df76 100644 --- a/google/cloud/asset_v1p1beta1/types/assets.py +++ b/google/cloud/asset_v1p1beta1/types/assets.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. @@ -52,8 +52,8 @@ class StandardResourceMetadata(proto.Message): attributes is subject to change. For example: project id, DNS name etc. location (str): - Location can be "global", regional like "us- - ast1", or zonal like "us-west1-b". + Location can be "global", regional like + "us-east1", or zonal like "us-west1-b". labels (Sequence[google.cloud.asset_v1p1beta1.types.StandardResourceMetadata.LabelsEntry]): Labels associated with this resource. See `Labelling and grouping GCP diff --git a/google/cloud/asset_v1p2beta1/__init__.py b/google/cloud/asset_v1p2beta1/__init__.py index 8a77ccdd..c1bf761f 100644 --- a/google/cloud/asset_v1p2beta1/__init__.py +++ b/google/cloud/asset_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/asset_v1p2beta1/services/__init__.py b/google/cloud/asset_v1p2beta1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/asset_v1p2beta1/services/__init__.py +++ b/google/cloud/asset_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/asset_v1p2beta1/services/asset_service/__init__.py b/google/cloud/asset_v1p2beta1/services/asset_service/__init__.py index cb995a56..4af01a66 100644 --- a/google/cloud/asset_v1p2beta1/services/asset_service/__init__.py +++ b/google/cloud/asset_v1p2beta1/services/asset_service/__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/asset_v1p2beta1/services/asset_service/async_client.py b/google/cloud/asset_v1p2beta1/services/asset_service/async_client.py index 5fc78da3..32c171a4 100644 --- a/google/cloud/asset_v1p2beta1/services/asset_service/async_client.py +++ b/google/cloud/asset_v1p2beta1/services/asset_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.asset_v1p2beta1.types import asset_service from .transports.base import AssetServiceTransport, DEFAULT_CLIENT_INFO @@ -98,6 +101,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 AssetServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> AssetServiceTransport: """Returns the transport used by the client instance. @@ -171,6 +210,31 @@ async def create_feed( project/folder/organization to listen to its asset updates. + + .. code-block:: python + + from google.cloud import asset_v1p2beta1 + + def sample_create_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1p2beta1.Feed() + feed.name = "name_value" + + request = asset_v1p2beta1.CreateFeedRequest( + parent="parent_value", + feed_id="feed_id_value", + feed=feed, + ) + + # Make the request + response = client.create_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p2beta1.types.CreateFeedRequest, dict]): The request object. Create asset feed request. @@ -206,7 +270,7 @@ async def create_feed( """ # 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: @@ -253,6 +317,25 @@ async def get_feed( ) -> asset_service.Feed: r"""Gets details about an asset feed. + .. code-block:: python + + from google.cloud import asset_v1p2beta1 + + def sample_get_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.GetFeedRequest( + name="name_value", + ) + + # Make the request + response = client.get_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p2beta1.types.GetFeedRequest, dict]): The request object. Get asset feed request. @@ -283,7 +366,7 @@ async def get_feed( """ # 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: @@ -341,6 +424,26 @@ async def list_feeds( r"""Lists all asset feeds in a parent project/folder/organization. + + .. code-block:: python + + from google.cloud import asset_v1p2beta1 + + def sample_list_feeds(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.ListFeedsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_feeds(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p2beta1.types.ListFeedsRequest, dict]): The request object. List asset feeds request. @@ -366,7 +469,7 @@ async def list_feeds( """ # 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: @@ -423,6 +526,28 @@ async def update_feed( ) -> asset_service.Feed: r"""Updates an asset feed configuration. + .. code-block:: python + + from google.cloud import asset_v1p2beta1 + + def sample_update_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1p2beta1.Feed() + feed.name = "name_value" + + request = asset_v1p2beta1.UpdateFeedRequest( + feed=feed, + ) + + # Make the request + response = client.update_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p2beta1.types.UpdateFeedRequest, dict]): The request object. Update asset feed request. @@ -454,7 +579,7 @@ async def update_feed( """ # 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([feed]) if request is not None and has_flattened_params: @@ -503,6 +628,22 @@ async def delete_feed( ) -> None: r"""Deletes an asset feed. + .. code-block:: python + + from google.cloud import asset_v1p2beta1 + + def sample_delete_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.DeleteFeedRequest( + name="name_value", + ) + + # Make the request + client.delete_feed(request=request) + Args: request (Union[google.cloud.asset_v1p2beta1.types.DeleteFeedRequest, dict]): The request object. @@ -522,7 +663,7 @@ async def delete_feed( 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: diff --git a/google/cloud/asset_v1p2beta1/services/asset_service/client.py b/google/cloud/asset_v1p2beta1/services/asset_service/client.py index b2174f2b..4c905406 100644 --- a/google/cloud/asset_v1p2beta1/services/asset_service/client.py +++ b/google/cloud/asset_v1p2beta1/services/asset_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.asset_v1p2beta1.types import asset_service from .transports.base import AssetServiceTransport, DEFAULT_CLIENT_INFO @@ -224,6 +226,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, *, @@ -274,50 +343,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, AssetServiceTransport): # transport is a AssetServiceTransport 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." @@ -329,6 +370,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, @@ -354,6 +404,31 @@ def create_feed( project/folder/organization to listen to its asset updates. + + .. code-block:: python + + from google.cloud import asset_v1p2beta1 + + def sample_create_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1p2beta1.Feed() + feed.name = "name_value" + + request = asset_v1p2beta1.CreateFeedRequest( + parent="parent_value", + feed_id="feed_id_value", + feed=feed, + ) + + # Make the request + response = client.create_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p2beta1.types.CreateFeedRequest, dict]): The request object. Create asset feed request. @@ -389,7 +464,7 @@ def create_feed( """ # 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: @@ -436,6 +511,25 @@ def get_feed( ) -> asset_service.Feed: r"""Gets details about an asset feed. + .. code-block:: python + + from google.cloud import asset_v1p2beta1 + + def sample_get_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.GetFeedRequest( + name="name_value", + ) + + # Make the request + response = client.get_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p2beta1.types.GetFeedRequest, dict]): The request object. Get asset feed request. @@ -466,7 +560,7 @@ def get_feed( """ # 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 +608,26 @@ def list_feeds( r"""Lists all asset feeds in a parent project/folder/organization. + + .. code-block:: python + + from google.cloud import asset_v1p2beta1 + + def sample_list_feeds(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.ListFeedsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_feeds(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p2beta1.types.ListFeedsRequest, dict]): The request object. List asset feeds request. @@ -539,7 +653,7 @@ def list_feeds( """ # 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: @@ -586,6 +700,28 @@ def update_feed( ) -> asset_service.Feed: r"""Updates an asset feed configuration. + .. code-block:: python + + from google.cloud import asset_v1p2beta1 + + def sample_update_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1p2beta1.Feed() + feed.name = "name_value" + + request = asset_v1p2beta1.UpdateFeedRequest( + feed=feed, + ) + + # Make the request + response = client.update_feed(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p2beta1.types.UpdateFeedRequest, dict]): The request object. Update asset feed request. @@ -617,7 +753,7 @@ def update_feed( """ # 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([feed]) if request is not None and has_flattened_params: @@ -666,6 +802,22 @@ def delete_feed( ) -> None: r"""Deletes an asset feed. + .. code-block:: python + + from google.cloud import asset_v1p2beta1 + + def sample_delete_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.DeleteFeedRequest( + name="name_value", + ) + + # Make the request + client.delete_feed(request=request) + Args: request (Union[google.cloud.asset_v1p2beta1.types.DeleteFeedRequest, dict]): The request object. @@ -685,7 +837,7 @@ def delete_feed( 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: diff --git a/google/cloud/asset_v1p2beta1/services/asset_service/transports/__init__.py b/google/cloud/asset_v1p2beta1/services/asset_service/transports/__init__.py index 9158fc25..c3ef619a 100644 --- a/google/cloud/asset_v1p2beta1/services/asset_service/transports/__init__.py +++ b/google/cloud/asset_v1p2beta1/services/asset_service/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/asset_v1p2beta1/services/asset_service/transports/base.py b/google/cloud/asset_v1p2beta1/services/asset_service/transports/base.py index 2d9ec603..bc16b6fb 100644 --- a/google/cloud/asset_v1p2beta1/services/asset_service/transports/base.py +++ b/google/cloud/asset_v1p2beta1/services/asset_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -100,7 +100,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/asset_v1p2beta1/services/asset_service/transports/grpc.py b/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc.py index fd9bcd45..9896364e 100644 --- a/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc.py +++ b/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -159,8 +159,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/asset_v1p2beta1/services/asset_service/transports/grpc_asyncio.py b/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc_asyncio.py index 8e9b18f9..6ef1381b 100644 --- a/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc_asyncio.py +++ b/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -204,8 +204,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/asset_v1p2beta1/types/__init__.py b/google/cloud/asset_v1p2beta1/types/__init__.py index a4ac7216..90bd5612 100644 --- a/google/cloud/asset_v1p2beta1/types/__init__.py +++ b/google/cloud/asset_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/asset_v1p2beta1/types/asset_service.py b/google/cloud/asset_v1p2beta1/types/asset_service.py index e153d6e1..64fcda03 100644 --- a/google/cloud/asset_v1p2beta1/types/asset_service.py +++ b/google/cloud/asset_v1p2beta1/types/asset_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. @@ -159,6 +159,7 @@ class OutputConfig(proto.Message): Attributes: gcs_destination (google.cloud.asset_v1p2beta1.types.GcsDestination): Destination on Cloud Storage. + This field is a member of `oneof`_ ``destination``. """ @@ -180,6 +181,7 @@ class GcsDestination(proto.Message): Object Metadata `__ for more information. + This field is a member of `oneof`_ ``object_uri``. """ @@ -206,6 +208,7 @@ class FeedOutputConfig(proto.Message): Attributes: pubsub_destination (google.cloud.asset_v1p2beta1.types.PubsubDestination): Destination on Cloud Pubsub. + This field is a member of `oneof`_ ``destination``. """ diff --git a/google/cloud/asset_v1p2beta1/types/assets.py b/google/cloud/asset_v1p2beta1/types/assets.py index bbb85ca5..cf7791d6 100644 --- a/google/cloud/asset_v1p2beta1/types/assets.py +++ b/google/cloud/asset_v1p2beta1/types/assets.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/asset_v1p4beta1/__init__.py b/google/cloud/asset_v1p4beta1/__init__.py index 4852a868..d6caf0e2 100644 --- a/google/cloud/asset_v1p4beta1/__init__.py +++ b/google/cloud/asset_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/asset_v1p4beta1/services/__init__.py b/google/cloud/asset_v1p4beta1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/asset_v1p4beta1/services/__init__.py +++ b/google/cloud/asset_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/asset_v1p4beta1/services/asset_service/__init__.py b/google/cloud/asset_v1p4beta1/services/asset_service/__init__.py index cb995a56..4af01a66 100644 --- a/google/cloud/asset_v1p4beta1/services/asset_service/__init__.py +++ b/google/cloud/asset_v1p4beta1/services/asset_service/__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/asset_v1p4beta1/services/asset_service/async_client.py b/google/cloud/asset_v1p4beta1/services/asset_service/async_client.py index 9c2b1a20..8240dfef 100644 --- a/google/cloud/asset_v1p4beta1/services/asset_service/async_client.py +++ b/google/cloud/asset_v1p4beta1/services/asset_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -99,6 +102,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 AssetServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> AssetServiceTransport: """Returns the transport used by the client instance. @@ -172,6 +211,29 @@ async def analyze_iam_policy( [IamPolicyAnalysisResult][google.cloud.asset.v1p4beta1.IamPolicyAnalysisResult] matching the request. + + .. code-block:: python + + from google.cloud import asset_v1p4beta1 + + def sample_analyze_iam_policy(): + # Create a client + client = asset_v1p4beta1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1p4beta1.IamPolicyAnalysisQuery() + analysis_query.parent = "parent_value" + + request = asset_v1p4beta1.AnalyzeIamPolicyRequest( + analysis_query=analysis_query, + ) + + # Make the request + response = client.analyze_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p4beta1.types.AnalyzeIamPolicyRequest, dict]): The request object. A request message for @@ -236,6 +298,37 @@ async def export_iam_policy_analysis( allowing you to keep track of the export. The metadata contains the request to help callers to map responses to requests. + + .. code-block:: python + + from google.cloud import asset_v1p4beta1 + + def sample_export_iam_policy_analysis(): + # Create a client + client = asset_v1p4beta1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1p4beta1.IamPolicyAnalysisQuery() + analysis_query.parent = "parent_value" + + output_config = asset_v1p4beta1.IamPolicyAnalysisOutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1p4beta1.ExportIamPolicyAnalysisRequest( + analysis_query=analysis_query, + output_config=output_config, + ) + + # Make the request + operation = client.export_iam_policy_analysis(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p4beta1.types.ExportIamPolicyAnalysisRequest, dict]): The request object. A request message for diff --git a/google/cloud/asset_v1p4beta1/services/asset_service/client.py b/google/cloud/asset_v1p4beta1/services/asset_service/client.py index f0952ed3..feefa82d 100644 --- a/google/cloud/asset_v1p4beta1/services/asset_service/client.py +++ b/google/cloud/asset_v1p4beta1/services/asset_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -216,6 +218,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, *, @@ -266,50 +335,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, AssetServiceTransport): # transport is a AssetServiceTransport 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." @@ -321,6 +362,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, @@ -346,6 +396,29 @@ def analyze_iam_policy( [IamPolicyAnalysisResult][google.cloud.asset.v1p4beta1.IamPolicyAnalysisResult] matching the request. + + .. code-block:: python + + from google.cloud import asset_v1p4beta1 + + def sample_analyze_iam_policy(): + # Create a client + client = asset_v1p4beta1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1p4beta1.IamPolicyAnalysisQuery() + analysis_query.parent = "parent_value" + + request = asset_v1p4beta1.AnalyzeIamPolicyRequest( + analysis_query=analysis_query, + ) + + # Make the request + response = client.analyze_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p4beta1.types.AnalyzeIamPolicyRequest, dict]): The request object. A request message for @@ -402,6 +475,37 @@ def export_iam_policy_analysis( allowing you to keep track of the export. The metadata contains the request to help callers to map responses to requests. + + .. code-block:: python + + from google.cloud import asset_v1p4beta1 + + def sample_export_iam_policy_analysis(): + # Create a client + client = asset_v1p4beta1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1p4beta1.IamPolicyAnalysisQuery() + analysis_query.parent = "parent_value" + + output_config = asset_v1p4beta1.IamPolicyAnalysisOutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1p4beta1.ExportIamPolicyAnalysisRequest( + analysis_query=analysis_query, + output_config=output_config, + ) + + # Make the request + operation = client.export_iam_policy_analysis(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.asset_v1p4beta1.types.ExportIamPolicyAnalysisRequest, dict]): The request object. A request message for diff --git a/google/cloud/asset_v1p4beta1/services/asset_service/transports/__init__.py b/google/cloud/asset_v1p4beta1/services/asset_service/transports/__init__.py index 9158fc25..c3ef619a 100644 --- a/google/cloud/asset_v1p4beta1/services/asset_service/transports/__init__.py +++ b/google/cloud/asset_v1p4beta1/services/asset_service/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/asset_v1p4beta1/services/asset_service/transports/base.py b/google/cloud/asset_v1p4beta1/services/asset_service/transports/base.py index 54e6267e..eebdaa0a 100644 --- a/google/cloud/asset_v1p4beta1/services/asset_service/transports/base.py +++ b/google/cloud/asset_v1p4beta1/services/asset_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,11 +18,11 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -101,7 +101,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/asset_v1p4beta1/services/asset_service/transports/grpc.py b/google/cloud/asset_v1p4beta1/services/asset_service/transports/grpc.py index 9a6bb977..333d88da 100644 --- a/google/cloud/asset_v1p4beta1/services/asset_service/transports/grpc.py +++ b/google/cloud/asset_v1p4beta1/services/asset_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -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, @@ -235,7 +238,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/asset_v1p4beta1/services/asset_service/transports/grpc_asyncio.py b/google/cloud/asset_v1p4beta1/services/asset_service/transports/grpc_asyncio.py index eedf154c..ed3d3b14 100644 --- a/google/cloud/asset_v1p4beta1/services/asset_service/transports/grpc_asyncio.py +++ b/google/cloud/asset_v1p4beta1/services/asset_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -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, @@ -237,7 +240,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/asset_v1p4beta1/types/__init__.py b/google/cloud/asset_v1p4beta1/types/__init__.py index 19b3df43..7e854ed0 100644 --- a/google/cloud/asset_v1p4beta1/types/__init__.py +++ b/google/cloud/asset_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/asset_v1p4beta1/types/asset_service.py b/google/cloud/asset_v1p4beta1/types/asset_service.py index f29125fd..021dd41a 100644 --- a/google/cloud/asset_v1p4beta1/types/asset_service.py +++ b/google/cloud/asset_v1p4beta1/types/asset_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. @@ -293,6 +293,7 @@ class IamPolicyAnalysisOutputConfig(proto.Message): Attributes: gcs_destination (google.cloud.asset_v1p4beta1.types.IamPolicyAnalysisOutputConfig.GcsDestination): Destination on Cloud Storage. + This field is a member of `oneof`_ ``destination``. """ diff --git a/google/cloud/asset_v1p4beta1/types/assets.py b/google/cloud/asset_v1p4beta1/types/assets.py index 9fcb1961..e7ffb3db 100644 --- a/google/cloud/asset_v1p4beta1/types/assets.py +++ b/google/cloud/asset_v1p4beta1/types/assets.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. @@ -103,9 +103,11 @@ class Access(proto.Message): Attributes: role (str): The role. + This field is a member of `oneof`_ ``oneof_access``. permission (str): The permission. + This field is a member of `oneof`_ ``oneof_access``. analysis_state (google.cloud.asset_v1p4beta1.types.IamPolicyAnalysisResult.AnalysisState): The analysis state of this access node. diff --git a/google/cloud/asset_v1p5beta1/__init__.py b/google/cloud/asset_v1p5beta1/__init__.py index 59a33bb0..0d0790a9 100644 --- a/google/cloud/asset_v1p5beta1/__init__.py +++ b/google/cloud/asset_v1p5beta1/__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/asset_v1p5beta1/services/__init__.py b/google/cloud/asset_v1p5beta1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/asset_v1p5beta1/services/__init__.py +++ b/google/cloud/asset_v1p5beta1/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/asset_v1p5beta1/services/asset_service/__init__.py b/google/cloud/asset_v1p5beta1/services/asset_service/__init__.py index cb995a56..4af01a66 100644 --- a/google/cloud/asset_v1p5beta1/services/asset_service/__init__.py +++ b/google/cloud/asset_v1p5beta1/services/asset_service/__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/asset_v1p5beta1/services/asset_service/async_client.py b/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py index 100870d1..feb60f77 100644 --- a/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py +++ b/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.asset_v1p5beta1.services.asset_service import pagers from google.cloud.asset_v1p5beta1.types import asset_service @@ -108,6 +111,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return AssetServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> AssetServiceTransport: """Returns the transport used by the client instance. @@ -179,6 +218,27 @@ async def list_assets( r"""Lists assets with time and resource types and returns paged results in response. + + .. code-block:: python + + from google.cloud import asset_v1p5beta1 + + def sample_list_assets(): + # Create a client + client = asset_v1p5beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p5beta1.ListAssetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_assets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1p5beta1.types.ListAssetsRequest, dict]): The request object. ListAssets request. diff --git a/google/cloud/asset_v1p5beta1/services/asset_service/client.py b/google/cloud/asset_v1p5beta1/services/asset_service/client.py index 7e551fb0..fa01fbd7 100644 --- a/google/cloud/asset_v1p5beta1/services/asset_service/client.py +++ b/google/cloud/asset_v1p5beta1/services/asset_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.asset_v1p5beta1.services.asset_service import pagers from google.cloud.asset_v1p5beta1.types import asset_service @@ -263,6 +265,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, *, @@ -313,50 +382,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, AssetServiceTransport): # transport is a AssetServiceTransport 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." @@ -368,6 +409,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 +441,27 @@ def list_assets( r"""Lists assets with time and resource types and returns paged results in response. + + .. code-block:: python + + from google.cloud import asset_v1p5beta1 + + def sample_list_assets(): + # Create a client + client = asset_v1p5beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p5beta1.ListAssetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_assets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.asset_v1p5beta1.types.ListAssetsRequest, dict]): The request object. ListAssets request. diff --git a/google/cloud/asset_v1p5beta1/services/asset_service/pagers.py b/google/cloud/asset_v1p5beta1/services/asset_service/pagers.py index 47062e8a..026619cb 100644 --- a/google/cloud/asset_v1p5beta1/services/asset_service/pagers.py +++ b/google/cloud/asset_v1p5beta1/services/asset_service/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/asset_v1p5beta1/services/asset_service/transports/__init__.py b/google/cloud/asset_v1p5beta1/services/asset_service/transports/__init__.py index 9158fc25..c3ef619a 100644 --- a/google/cloud/asset_v1p5beta1/services/asset_service/transports/__init__.py +++ b/google/cloud/asset_v1p5beta1/services/asset_service/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/asset_v1p5beta1/services/asset_service/transports/base.py b/google/cloud/asset_v1p5beta1/services/asset_service/transports/base.py index 7ac6d3b2..125ee3f8 100644 --- a/google/cloud/asset_v1p5beta1/services/asset_service/transports/base.py +++ b/google/cloud/asset_v1p5beta1/services/asset_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -99,7 +99,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/asset_v1p5beta1/services/asset_service/transports/grpc.py b/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc.py index 1d6bac4a..3efedfdc 100644 --- a/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc.py +++ b/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -158,8 +158,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/asset_v1p5beta1/services/asset_service/transports/grpc_asyncio.py b/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc_asyncio.py index fa53920d..b9e9a144 100644 --- a/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc_asyncio.py +++ b/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -203,8 +203,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/asset_v1p5beta1/types/__init__.py b/google/cloud/asset_v1p5beta1/types/__init__.py index d26c148b..fbb8dc99 100644 --- a/google/cloud/asset_v1p5beta1/types/__init__.py +++ b/google/cloud/asset_v1p5beta1/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/asset_v1p5beta1/types/asset_service.py b/google/cloud/asset_v1p5beta1/types/asset_service.py index 0a261d3d..cefe2637 100644 --- a/google/cloud/asset_v1p5beta1/types/asset_service.py +++ b/google/cloud/asset_v1p5beta1/types/asset_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. diff --git a/google/cloud/asset_v1p5beta1/types/assets.py b/google/cloud/asset_v1p5beta1/types/assets.py index 988c127a..18203a95 100644 --- a/google/cloud/asset_v1p5beta1/types/assets.py +++ b/google/cloud/asset_v1p5beta1/types/assets.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 bcb9de31..4cc0734e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -175,7 +175,7 @@ def cover(session): test runs (not system test runs), and then erases coverage data. """ session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=98") + session.run("coverage", "report", "--show-missing", "--fail-under=100") session.run("coverage", "erase") diff --git a/owlbot.py b/owlbot.py index 4dddc69a..86060d8a 100644 --- a/owlbot.py +++ b/owlbot.py @@ -78,7 +78,7 @@ def parse_asset_path.*?@staticmethod""", templated_files = common.py_library( samples=True, # set to True only if there are samples microgenerator=True, - cov_level=98, + cov_level=100, ) s.move(templated_files, excludes=[".coveragerc"]) # microgenerator has a good .coveragerc file diff --git a/samples/AUTHORING_GUIDE.md b/samples/AUTHORING_GUIDE.md index 55c97b32..8249522f 100644 --- a/samples/AUTHORING_GUIDE.md +++ b/samples/AUTHORING_GUIDE.md @@ -1 +1 @@ -See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md \ No newline at end of file +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md \ No newline at end of file diff --git a/samples/CONTRIBUTING.md b/samples/CONTRIBUTING.md index 34c882b6..f5fe2e6b 100644 --- a/samples/CONTRIBUTING.md +++ b/samples/CONTRIBUTING.md @@ -1 +1 @@ -See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md \ No newline at end of file +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md \ No newline at end of file diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_async.py new file mode 100644 index 00000000..46380a92 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeIamPolicy +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_AnalyzeIamPolicy_async] +from google.cloud import asset_v1 + + +async def sample_analyze_iam_policy(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + analysis_query = asset_v1.IamPolicyAnalysisQuery() + analysis_query.scope = "scope_value" + + request = asset_v1.AnalyzeIamPolicyRequest( + analysis_query=analysis_query, + ) + + # Make the request + response = await client.analyze_iam_policy(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_AnalyzeIamPolicy_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_longrunning_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_longrunning_async.py new file mode 100644 index 00000000..db412762 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_longrunning_async.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeIamPolicyLongrunning +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_AnalyzeIamPolicyLongrunning_async] +from google.cloud import asset_v1 + + +async def sample_analyze_iam_policy_longrunning(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + analysis_query = asset_v1.IamPolicyAnalysisQuery() + analysis_query.scope = "scope_value" + + output_config = asset_v1.IamPolicyAnalysisOutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1.AnalyzeIamPolicyLongrunningRequest( + analysis_query=analysis_query, + output_config=output_config, + ) + + # Make the request + operation = client.analyze_iam_policy_longrunning(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_AnalyzeIamPolicyLongrunning_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_longrunning_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_longrunning_sync.py new file mode 100644 index 00000000..c3aa1406 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_longrunning_sync.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeIamPolicyLongrunning +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_AnalyzeIamPolicyLongrunning_sync] +from google.cloud import asset_v1 + + +def sample_analyze_iam_policy_longrunning(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1.IamPolicyAnalysisQuery() + analysis_query.scope = "scope_value" + + output_config = asset_v1.IamPolicyAnalysisOutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1.AnalyzeIamPolicyLongrunningRequest( + analysis_query=analysis_query, + output_config=output_config, + ) + + # Make the request + operation = client.analyze_iam_policy_longrunning(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_AnalyzeIamPolicyLongrunning_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_sync.py new file mode 100644 index 00000000..9a0a2e54 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeIamPolicy +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_AnalyzeIamPolicy_sync] +from google.cloud import asset_v1 + + +def sample_analyze_iam_policy(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1.IamPolicyAnalysisQuery() + analysis_query.scope = "scope_value" + + request = asset_v1.AnalyzeIamPolicyRequest( + analysis_query=analysis_query, + ) + + # Make the request + response = client.analyze_iam_policy(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_AnalyzeIamPolicy_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_move_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_move_async.py new file mode 100644 index 00000000..683e076e --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_move_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeMove +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_AnalyzeMove_async] +from google.cloud import asset_v1 + + +async def sample_analyze_move(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1.AnalyzeMoveRequest( + resource="resource_value", + destination_parent="destination_parent_value", + ) + + # Make the request + response = await client.analyze_move(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_AnalyzeMove_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_move_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_move_sync.py new file mode 100644 index 00000000..41e5bd20 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_move_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeMove +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_AnalyzeMove_sync] +from google.cloud import asset_v1 + + +def sample_analyze_move(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.AnalyzeMoveRequest( + resource="resource_value", + destination_parent="destination_parent_value", + ) + + # Make the request + response = client.analyze_move(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_AnalyzeMove_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_batch_get_assets_history_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_batch_get_assets_history_async.py new file mode 100644 index 00000000..36489d63 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_batch_get_assets_history_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchGetAssetsHistory +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_async] +from google.cloud import asset_v1 + + +async def sample_batch_get_assets_history(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1.BatchGetAssetsHistoryRequest( + parent="parent_value", + ) + + # Make the request + response = await client.batch_get_assets_history(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_batch_get_assets_history_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_batch_get_assets_history_sync.py new file mode 100644 index 00000000..680f02c0 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_batch_get_assets_history_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchGetAssetsHistory +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_sync] +from google.cloud import asset_v1 + + +def sample_batch_get_assets_history(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.BatchGetAssetsHistoryRequest( + parent="parent_value", + ) + + # Make the request + response = client.batch_get_assets_history(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_create_feed_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_create_feed_async.py new file mode 100644 index 00000000..7a0a5bf4 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_create_feed_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeed +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_CreateFeed_async] +from google.cloud import asset_v1 + + +async def sample_create_feed(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + feed = asset_v1.Feed() + feed.name = "name_value" + + request = asset_v1.CreateFeedRequest( + parent="parent_value", + feed_id="feed_id_value", + feed=feed, + ) + + # Make the request + response = await client.create_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_CreateFeed_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_create_feed_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_create_feed_sync.py new file mode 100644 index 00000000..612e6e13 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_create_feed_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeed +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_CreateFeed_sync] +from google.cloud import asset_v1 + + +def sample_create_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1.Feed() + feed.name = "name_value" + + request = asset_v1.CreateFeedRequest( + parent="parent_value", + feed_id="feed_id_value", + feed=feed, + ) + + # Make the request + response = client.create_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_CreateFeed_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_delete_feed_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_delete_feed_async.py new file mode 100644 index 00000000..86660f4f --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_delete_feed_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeed +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_DeleteFeed_async] +from google.cloud import asset_v1 + + +async def sample_delete_feed(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1.DeleteFeedRequest( + name="name_value", + ) + + # Make the request + await client.delete_feed(request=request) + + +# [END cloudasset_v1_generated_AssetService_DeleteFeed_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_delete_feed_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_delete_feed_sync.py new file mode 100644 index 00000000..ec710e64 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_delete_feed_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeed +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_DeleteFeed_sync] +from google.cloud import asset_v1 + + +def sample_delete_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.DeleteFeedRequest( + name="name_value", + ) + + # Make the request + client.delete_feed(request=request) + + +# [END cloudasset_v1_generated_AssetService_DeleteFeed_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_export_assets_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_export_assets_async.py new file mode 100644 index 00000000..aea177ab --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_export_assets_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportAssets +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_ExportAssets_async] +from google.cloud import asset_v1 + + +async def sample_export_assets(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + output_config = asset_v1.OutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1.ExportAssetsRequest( + parent="parent_value", + output_config=output_config, + ) + + # Make the request + operation = client.export_assets(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_ExportAssets_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_export_assets_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_export_assets_sync.py new file mode 100644 index 00000000..c536997d --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_export_assets_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportAssets +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_ExportAssets_sync] +from google.cloud import asset_v1 + + +def sample_export_assets(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + output_config = asset_v1.OutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1.ExportAssetsRequest( + parent="parent_value", + output_config=output_config, + ) + + # Make the request + operation = client.export_assets(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_ExportAssets_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_get_feed_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_get_feed_async.py new file mode 100644 index 00000000..d9adab2a --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_get_feed_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeed +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_GetFeed_async] +from google.cloud import asset_v1 + + +async def sample_get_feed(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1.GetFeedRequest( + name="name_value", + ) + + # Make the request + response = await client.get_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_GetFeed_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_get_feed_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_get_feed_sync.py new file mode 100644 index 00000000..81b3b9ad --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_get_feed_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeed +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_GetFeed_sync] +from google.cloud import asset_v1 + + +def sample_get_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.GetFeedRequest( + name="name_value", + ) + + # Make the request + response = client.get_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_GetFeed_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_list_assets_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_list_assets_async.py new file mode 100644 index 00000000..2e48093c --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_list_assets_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAssets +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_ListAssets_async] +from google.cloud import asset_v1 + + +async def sample_list_assets(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1.ListAssetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_assets(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END cloudasset_v1_generated_AssetService_ListAssets_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_list_assets_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_list_assets_sync.py new file mode 100644 index 00000000..ed898181 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_list_assets_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAssets +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_ListAssets_sync] +from google.cloud import asset_v1 + + +def sample_list_assets(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.ListAssetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_assets(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END cloudasset_v1_generated_AssetService_ListAssets_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_list_feeds_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_list_feeds_async.py new file mode 100644 index 00000000..ec138b73 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_list_feeds_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeeds +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_ListFeeds_async] +from google.cloud import asset_v1 + + +async def sample_list_feeds(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1.ListFeedsRequest( + parent="parent_value", + ) + + # Make the request + response = await client.list_feeds(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_ListFeeds_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_list_feeds_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_list_feeds_sync.py new file mode 100644 index 00000000..2822c78b --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_list_feeds_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeeds +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_ListFeeds_sync] +from google.cloud import asset_v1 + + +def sample_list_feeds(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.ListFeedsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_feeds(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_ListFeeds_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_iam_policies_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_iam_policies_async.py new file mode 100644 index 00000000..282ea53b --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_iam_policies_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchAllIamPolicies +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_SearchAllIamPolicies_async] +from google.cloud import asset_v1 + + +async def sample_search_all_iam_policies(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1.SearchAllIamPoliciesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_iam_policies(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END cloudasset_v1_generated_AssetService_SearchAllIamPolicies_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_iam_policies_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_iam_policies_sync.py new file mode 100644 index 00000000..542da876 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_iam_policies_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchAllIamPolicies +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_SearchAllIamPolicies_sync] +from google.cloud import asset_v1 + + +def sample_search_all_iam_policies(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.SearchAllIamPoliciesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_iam_policies(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END cloudasset_v1_generated_AssetService_SearchAllIamPolicies_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_resources_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_resources_async.py new file mode 100644 index 00000000..c4322644 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_resources_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchAllResources +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_SearchAllResources_async] +from google.cloud import asset_v1 + + +async def sample_search_all_resources(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1.SearchAllResourcesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_resources(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END cloudasset_v1_generated_AssetService_SearchAllResources_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_resources_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_resources_sync.py new file mode 100644 index 00000000..c2bf1402 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_search_all_resources_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchAllResources +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_SearchAllResources_sync] +from google.cloud import asset_v1 + + +def sample_search_all_resources(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1.SearchAllResourcesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END cloudasset_v1_generated_AssetService_SearchAllResources_sync] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_update_feed_async.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_update_feed_async.py new file mode 100644 index 00000000..1d8dc82b --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_update_feed_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeed +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_UpdateFeed_async] +from google.cloud import asset_v1 + + +async def sample_update_feed(): + # Create a client + client = asset_v1.AssetServiceAsyncClient() + + # Initialize request argument(s) + feed = asset_v1.Feed() + feed.name = "name_value" + + request = asset_v1.UpdateFeedRequest( + feed=feed, + ) + + # Make the request + response = await client.update_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_UpdateFeed_async] diff --git a/samples/generated_samples/cloudasset_v1_generated_asset_service_update_feed_sync.py b/samples/generated_samples/cloudasset_v1_generated_asset_service_update_feed_sync.py new file mode 100644 index 00000000..e48a0b66 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1_generated_asset_service_update_feed_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeed +# 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-asset + + +# [START cloudasset_v1_generated_AssetService_UpdateFeed_sync] +from google.cloud import asset_v1 + + +def sample_update_feed(): + # Create a client + client = asset_v1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1.Feed() + feed.name = "name_value" + + request = asset_v1.UpdateFeedRequest( + feed=feed, + ) + + # Make the request + response = client.update_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1_generated_AssetService_UpdateFeed_sync] diff --git a/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_iam_policies_async.py b/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_iam_policies_async.py new file mode 100644 index 00000000..2c21eaf2 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_iam_policies_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchAllIamPolicies +# 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-asset + + +# [START cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_async] +from google.cloud import asset_v1p1beta1 + + +async def sample_search_all_iam_policies(): + # Create a client + client = asset_v1p1beta1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1p1beta1.SearchAllIamPoliciesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_iam_policies(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_async] diff --git a/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_iam_policies_sync.py b/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_iam_policies_sync.py new file mode 100644 index 00000000..d055c5f0 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_iam_policies_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchAllIamPolicies +# 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-asset + + +# [START cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_sync] +from google.cloud import asset_v1p1beta1 + + +def sample_search_all_iam_policies(): + # Create a client + client = asset_v1p1beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p1beta1.SearchAllIamPoliciesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_iam_policies(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_sync] diff --git a/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_resources_async.py b/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_resources_async.py new file mode 100644 index 00000000..ccf3fd82 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_resources_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchAllResources +# 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-asset + + +# [START cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_async] +from google.cloud import asset_v1p1beta1 + + +async def sample_search_all_resources(): + # Create a client + client = asset_v1p1beta1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1p1beta1.SearchAllResourcesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_resources(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_async] diff --git a/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_resources_sync.py b/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_resources_sync.py new file mode 100644 index 00000000..45a0edf5 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p1beta1_generated_asset_service_search_all_resources_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchAllResources +# 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-asset + + +# [START cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_sync] +from google.cloud import asset_v1p1beta1 + + +def sample_search_all_resources(): + # Create a client + client = asset_v1p1beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p1beta1.SearchAllResourcesRequest( + scope="scope_value", + ) + + # Make the request + page_result = client.search_all_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_sync] diff --git a/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_create_feed_async.py b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_create_feed_async.py new file mode 100644 index 00000000..d42eae09 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_create_feed_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeed +# 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-asset + + +# [START cloudasset_v1p2beta1_generated_AssetService_CreateFeed_async] +from google.cloud import asset_v1p2beta1 + + +async def sample_create_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceAsyncClient() + + # Initialize request argument(s) + feed = asset_v1p2beta1.Feed() + feed.name = "name_value" + + request = asset_v1p2beta1.CreateFeedRequest( + parent="parent_value", + feed_id="feed_id_value", + feed=feed, + ) + + # Make the request + response = await client.create_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1p2beta1_generated_AssetService_CreateFeed_async] diff --git a/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_create_feed_sync.py b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_create_feed_sync.py new file mode 100644 index 00000000..85eed9c9 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_create_feed_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeed +# 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-asset + + +# [START cloudasset_v1p2beta1_generated_AssetService_CreateFeed_sync] +from google.cloud import asset_v1p2beta1 + + +def sample_create_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1p2beta1.Feed() + feed.name = "name_value" + + request = asset_v1p2beta1.CreateFeedRequest( + parent="parent_value", + feed_id="feed_id_value", + feed=feed, + ) + + # Make the request + response = client.create_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1p2beta1_generated_AssetService_CreateFeed_sync] diff --git a/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_delete_feed_async.py b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_delete_feed_async.py new file mode 100644 index 00000000..1aeaec6c --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_delete_feed_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeed +# 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-asset + + +# [START cloudasset_v1p2beta1_generated_AssetService_DeleteFeed_async] +from google.cloud import asset_v1p2beta1 + + +async def sample_delete_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.DeleteFeedRequest( + name="name_value", + ) + + # Make the request + await client.delete_feed(request=request) + + +# [END cloudasset_v1p2beta1_generated_AssetService_DeleteFeed_async] diff --git a/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_delete_feed_sync.py b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_delete_feed_sync.py new file mode 100644 index 00000000..c50ffb1b --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_delete_feed_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeed +# 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-asset + + +# [START cloudasset_v1p2beta1_generated_AssetService_DeleteFeed_sync] +from google.cloud import asset_v1p2beta1 + + +def sample_delete_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.DeleteFeedRequest( + name="name_value", + ) + + # Make the request + client.delete_feed(request=request) + + +# [END cloudasset_v1p2beta1_generated_AssetService_DeleteFeed_sync] diff --git a/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_get_feed_async.py b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_get_feed_async.py new file mode 100644 index 00000000..3fcef144 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_get_feed_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeed +# 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-asset + + +# [START cloudasset_v1p2beta1_generated_AssetService_GetFeed_async] +from google.cloud import asset_v1p2beta1 + + +async def sample_get_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.GetFeedRequest( + name="name_value", + ) + + # Make the request + response = await client.get_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1p2beta1_generated_AssetService_GetFeed_async] diff --git a/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_get_feed_sync.py b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_get_feed_sync.py new file mode 100644 index 00000000..6daf97d7 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_get_feed_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeed +# 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-asset + + +# [START cloudasset_v1p2beta1_generated_AssetService_GetFeed_sync] +from google.cloud import asset_v1p2beta1 + + +def sample_get_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.GetFeedRequest( + name="name_value", + ) + + # Make the request + response = client.get_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1p2beta1_generated_AssetService_GetFeed_sync] diff --git a/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_list_feeds_async.py b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_list_feeds_async.py new file mode 100644 index 00000000..b3963d08 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_list_feeds_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeeds +# 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-asset + + +# [START cloudasset_v1p2beta1_generated_AssetService_ListFeeds_async] +from google.cloud import asset_v1p2beta1 + + +async def sample_list_feeds(): + # Create a client + client = asset_v1p2beta1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.ListFeedsRequest( + parent="parent_value", + ) + + # Make the request + response = await client.list_feeds(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1p2beta1_generated_AssetService_ListFeeds_async] diff --git a/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_list_feeds_sync.py b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_list_feeds_sync.py new file mode 100644 index 00000000..50b3dad3 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_list_feeds_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeeds +# 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-asset + + +# [START cloudasset_v1p2beta1_generated_AssetService_ListFeeds_sync] +from google.cloud import asset_v1p2beta1 + + +def sample_list_feeds(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p2beta1.ListFeedsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_feeds(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1p2beta1_generated_AssetService_ListFeeds_sync] diff --git a/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_update_feed_async.py b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_update_feed_async.py new file mode 100644 index 00000000..1f7490f4 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_update_feed_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeed +# 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-asset + + +# [START cloudasset_v1p2beta1_generated_AssetService_UpdateFeed_async] +from google.cloud import asset_v1p2beta1 + + +async def sample_update_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceAsyncClient() + + # Initialize request argument(s) + feed = asset_v1p2beta1.Feed() + feed.name = "name_value" + + request = asset_v1p2beta1.UpdateFeedRequest( + feed=feed, + ) + + # Make the request + response = await client.update_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1p2beta1_generated_AssetService_UpdateFeed_async] diff --git a/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_update_feed_sync.py b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_update_feed_sync.py new file mode 100644 index 00000000..bcd82af3 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p2beta1_generated_asset_service_update_feed_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeed +# 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-asset + + +# [START cloudasset_v1p2beta1_generated_AssetService_UpdateFeed_sync] +from google.cloud import asset_v1p2beta1 + + +def sample_update_feed(): + # Create a client + client = asset_v1p2beta1.AssetServiceClient() + + # Initialize request argument(s) + feed = asset_v1p2beta1.Feed() + feed.name = "name_value" + + request = asset_v1p2beta1.UpdateFeedRequest( + feed=feed, + ) + + # Make the request + response = client.update_feed(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1p2beta1_generated_AssetService_UpdateFeed_sync] diff --git a/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_analyze_iam_policy_async.py b/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_analyze_iam_policy_async.py new file mode 100644 index 00000000..d7aed0d4 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_analyze_iam_policy_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeIamPolicy +# 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-asset + + +# [START cloudasset_v1p4beta1_generated_AssetService_AnalyzeIamPolicy_async] +from google.cloud import asset_v1p4beta1 + + +async def sample_analyze_iam_policy(): + # Create a client + client = asset_v1p4beta1.AssetServiceAsyncClient() + + # Initialize request argument(s) + analysis_query = asset_v1p4beta1.IamPolicyAnalysisQuery() + analysis_query.parent = "parent_value" + + request = asset_v1p4beta1.AnalyzeIamPolicyRequest( + analysis_query=analysis_query, + ) + + # Make the request + response = await client.analyze_iam_policy(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1p4beta1_generated_AssetService_AnalyzeIamPolicy_async] diff --git a/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_analyze_iam_policy_sync.py b/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_analyze_iam_policy_sync.py new file mode 100644 index 00000000..6ce8dda4 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_analyze_iam_policy_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeIamPolicy +# 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-asset + + +# [START cloudasset_v1p4beta1_generated_AssetService_AnalyzeIamPolicy_sync] +from google.cloud import asset_v1p4beta1 + + +def sample_analyze_iam_policy(): + # Create a client + client = asset_v1p4beta1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1p4beta1.IamPolicyAnalysisQuery() + analysis_query.parent = "parent_value" + + request = asset_v1p4beta1.AnalyzeIamPolicyRequest( + analysis_query=analysis_query, + ) + + # Make the request + response = client.analyze_iam_policy(request=request) + + # Handle the response + print(response) + +# [END cloudasset_v1p4beta1_generated_AssetService_AnalyzeIamPolicy_sync] diff --git a/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_export_iam_policy_analysis_async.py b/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_export_iam_policy_analysis_async.py new file mode 100644 index 00000000..2859417c --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_export_iam_policy_analysis_async.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportIamPolicyAnalysis +# 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-asset + + +# [START cloudasset_v1p4beta1_generated_AssetService_ExportIamPolicyAnalysis_async] +from google.cloud import asset_v1p4beta1 + + +async def sample_export_iam_policy_analysis(): + # Create a client + client = asset_v1p4beta1.AssetServiceAsyncClient() + + # Initialize request argument(s) + analysis_query = asset_v1p4beta1.IamPolicyAnalysisQuery() + analysis_query.parent = "parent_value" + + output_config = asset_v1p4beta1.IamPolicyAnalysisOutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1p4beta1.ExportIamPolicyAnalysisRequest( + analysis_query=analysis_query, + output_config=output_config, + ) + + # Make the request + operation = client.export_iam_policy_analysis(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END cloudasset_v1p4beta1_generated_AssetService_ExportIamPolicyAnalysis_async] diff --git a/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_export_iam_policy_analysis_sync.py b/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_export_iam_policy_analysis_sync.py new file mode 100644 index 00000000..05c73b3e --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p4beta1_generated_asset_service_export_iam_policy_analysis_sync.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportIamPolicyAnalysis +# 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-asset + + +# [START cloudasset_v1p4beta1_generated_AssetService_ExportIamPolicyAnalysis_sync] +from google.cloud import asset_v1p4beta1 + + +def sample_export_iam_policy_analysis(): + # Create a client + client = asset_v1p4beta1.AssetServiceClient() + + # Initialize request argument(s) + analysis_query = asset_v1p4beta1.IamPolicyAnalysisQuery() + analysis_query.parent = "parent_value" + + output_config = asset_v1p4beta1.IamPolicyAnalysisOutputConfig() + output_config.gcs_destination.uri = "uri_value" + + request = asset_v1p4beta1.ExportIamPolicyAnalysisRequest( + analysis_query=analysis_query, + output_config=output_config, + ) + + # Make the request + operation = client.export_iam_policy_analysis(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END cloudasset_v1p4beta1_generated_AssetService_ExportIamPolicyAnalysis_sync] diff --git a/samples/generated_samples/cloudasset_v1p5beta1_generated_asset_service_list_assets_async.py b/samples/generated_samples/cloudasset_v1p5beta1_generated_asset_service_list_assets_async.py new file mode 100644 index 00000000..2757f970 --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p5beta1_generated_asset_service_list_assets_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAssets +# 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-asset + + +# [START cloudasset_v1p5beta1_generated_AssetService_ListAssets_async] +from google.cloud import asset_v1p5beta1 + + +async def sample_list_assets(): + # Create a client + client = asset_v1p5beta1.AssetServiceAsyncClient() + + # Initialize request argument(s) + request = asset_v1p5beta1.ListAssetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_assets(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END cloudasset_v1p5beta1_generated_AssetService_ListAssets_async] diff --git a/samples/generated_samples/cloudasset_v1p5beta1_generated_asset_service_list_assets_sync.py b/samples/generated_samples/cloudasset_v1p5beta1_generated_asset_service_list_assets_sync.py new file mode 100644 index 00000000..f983764a --- /dev/null +++ b/samples/generated_samples/cloudasset_v1p5beta1_generated_asset_service_list_assets_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAssets +# 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-asset + + +# [START cloudasset_v1p5beta1_generated_AssetService_ListAssets_sync] +from google.cloud import asset_v1p5beta1 + + +def sample_list_assets(): + # Create a client + client = asset_v1p5beta1.AssetServiceClient() + + # Initialize request argument(s) + request = asset_v1p5beta1.ListAssetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_assets(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END cloudasset_v1p5beta1_generated_AssetService_ListAssets_sync] diff --git a/samples/generated_samples/snippet_metadata_asset_v1.json b/samples/generated_samples/snippet_metadata_asset_v1.json new file mode 100644 index 00000000..1d3a68fd --- /dev/null +++ b/samples/generated_samples/snippet_metadata_asset_v1.json @@ -0,0 +1,1157 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "AnalyzeIamPolicyLongrunning" + } + }, + "file": "cloudasset_v1_generated_asset_service_analyze_iam_policy_longrunning_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_AnalyzeIamPolicyLongrunning_async", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "AnalyzeIamPolicyLongrunning" + } + }, + "file": "cloudasset_v1_generated_asset_service_analyze_iam_policy_longrunning_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_AnalyzeIamPolicyLongrunning_sync", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "AnalyzeIamPolicy" + } + }, + "file": "cloudasset_v1_generated_asset_service_analyze_iam_policy_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_AnalyzeIamPolicy_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "AnalyzeIamPolicy" + } + }, + "file": "cloudasset_v1_generated_asset_service_analyze_iam_policy_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_AnalyzeIamPolicy_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "AnalyzeMove" + } + }, + "file": "cloudasset_v1_generated_asset_service_analyze_move_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_AnalyzeMove_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "AnalyzeMove" + } + }, + "file": "cloudasset_v1_generated_asset_service_analyze_move_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_AnalyzeMove_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "BatchGetAssetsHistory" + } + }, + "file": "cloudasset_v1_generated_asset_service_batch_get_assets_history_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_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": "AssetService" + }, + "shortName": "BatchGetAssetsHistory" + } + }, + "file": "cloudasset_v1_generated_asset_service_batch_get_assets_history_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_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": "AssetService" + }, + "shortName": "CreateFeed" + } + }, + "file": "cloudasset_v1_generated_asset_service_create_feed_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_CreateFeed_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "CreateFeed" + } + }, + "file": "cloudasset_v1_generated_asset_service_create_feed_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_CreateFeed_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "DeleteFeed" + } + }, + "file": "cloudasset_v1_generated_asset_service_delete_feed_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_DeleteFeed_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": "AssetService" + }, + "shortName": "DeleteFeed" + } + }, + "file": "cloudasset_v1_generated_asset_service_delete_feed_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_DeleteFeed_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": "AssetService" + }, + "shortName": "ExportAssets" + } + }, + "file": "cloudasset_v1_generated_asset_service_export_assets_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_ExportAssets_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "ExportAssets" + } + }, + "file": "cloudasset_v1_generated_asset_service_export_assets_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_ExportAssets_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "GetFeed" + } + }, + "file": "cloudasset_v1_generated_asset_service_get_feed_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_GetFeed_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": "AssetService" + }, + "shortName": "GetFeed" + } + }, + "file": "cloudasset_v1_generated_asset_service_get_feed_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_GetFeed_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": "AssetService" + }, + "shortName": "ListAssets" + } + }, + "file": "cloudasset_v1_generated_asset_service_list_assets_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_ListAssets_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": "AssetService" + }, + "shortName": "ListAssets" + } + }, + "file": "cloudasset_v1_generated_asset_service_list_assets_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_ListAssets_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": "AssetService" + }, + "shortName": "ListFeeds" + } + }, + "file": "cloudasset_v1_generated_asset_service_list_feeds_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_ListFeeds_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": "AssetService" + }, + "shortName": "ListFeeds" + } + }, + "file": "cloudasset_v1_generated_asset_service_list_feeds_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_ListFeeds_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": "AssetService" + }, + "shortName": "SearchAllIamPolicies" + } + }, + "file": "cloudasset_v1_generated_asset_service_search_all_iam_policies_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_SearchAllIamPolicies_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": "AssetService" + }, + "shortName": "SearchAllIamPolicies" + } + }, + "file": "cloudasset_v1_generated_asset_service_search_all_iam_policies_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_SearchAllIamPolicies_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": "AssetService" + }, + "shortName": "SearchAllResources" + } + }, + "file": "cloudasset_v1_generated_asset_service_search_all_resources_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_SearchAllResources_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": "AssetService" + }, + "shortName": "SearchAllResources" + } + }, + "file": "cloudasset_v1_generated_asset_service_search_all_resources_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_SearchAllResources_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": "AssetService" + }, + "shortName": "UpdateFeed" + } + }, + "file": "cloudasset_v1_generated_asset_service_update_feed_async.py", + "regionTag": "cloudasset_v1_generated_AssetService_UpdateFeed_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "UpdateFeed" + } + }, + "file": "cloudasset_v1_generated_asset_service_update_feed_sync.py", + "regionTag": "cloudasset_v1_generated_AssetService_UpdateFeed_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_asset_v1p1beta1.json b/samples/generated_samples/snippet_metadata_asset_v1p1beta1.json new file mode 100644 index 00000000..f9a3789f --- /dev/null +++ b/samples/generated_samples/snippet_metadata_asset_v1p1beta1.json @@ -0,0 +1,182 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "SearchAllIamPolicies" + } + }, + "file": "cloudasset_v1p1beta1_generated_asset_service_search_all_iam_policies_async.py", + "regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_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": "AssetService" + }, + "shortName": "SearchAllIamPolicies" + } + }, + "file": "cloudasset_v1p1beta1_generated_asset_service_search_all_iam_policies_sync.py", + "regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_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": "AssetService" + }, + "shortName": "SearchAllResources" + } + }, + "file": "cloudasset_v1p1beta1_generated_asset_service_search_all_resources_async.py", + "regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_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": "AssetService" + }, + "shortName": "SearchAllResources" + } + }, + "file": "cloudasset_v1p1beta1_generated_asset_service_search_all_resources_sync.py", + "regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_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" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_asset_v1p2beta1.json b/samples/generated_samples/snippet_metadata_asset_v1p2beta1.json new file mode 100644 index 00000000..0c20c26d --- /dev/null +++ b/samples/generated_samples/snippet_metadata_asset_v1p2beta1.json @@ -0,0 +1,445 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "CreateFeed" + } + }, + "file": "cloudasset_v1p2beta1_generated_asset_service_create_feed_async.py", + "regionTag": "cloudasset_v1p2beta1_generated_AssetService_CreateFeed_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "CreateFeed" + } + }, + "file": "cloudasset_v1p2beta1_generated_asset_service_create_feed_sync.py", + "regionTag": "cloudasset_v1p2beta1_generated_AssetService_CreateFeed_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "DeleteFeed" + } + }, + "file": "cloudasset_v1p2beta1_generated_asset_service_delete_feed_async.py", + "regionTag": "cloudasset_v1p2beta1_generated_AssetService_DeleteFeed_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": "AssetService" + }, + "shortName": "DeleteFeed" + } + }, + "file": "cloudasset_v1p2beta1_generated_asset_service_delete_feed_sync.py", + "regionTag": "cloudasset_v1p2beta1_generated_AssetService_DeleteFeed_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": "AssetService" + }, + "shortName": "GetFeed" + } + }, + "file": "cloudasset_v1p2beta1_generated_asset_service_get_feed_async.py", + "regionTag": "cloudasset_v1p2beta1_generated_AssetService_GetFeed_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": "AssetService" + }, + "shortName": "GetFeed" + } + }, + "file": "cloudasset_v1p2beta1_generated_asset_service_get_feed_sync.py", + "regionTag": "cloudasset_v1p2beta1_generated_AssetService_GetFeed_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": "AssetService" + }, + "shortName": "ListFeeds" + } + }, + "file": "cloudasset_v1p2beta1_generated_asset_service_list_feeds_async.py", + "regionTag": "cloudasset_v1p2beta1_generated_AssetService_ListFeeds_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": "AssetService" + }, + "shortName": "ListFeeds" + } + }, + "file": "cloudasset_v1p2beta1_generated_asset_service_list_feeds_sync.py", + "regionTag": "cloudasset_v1p2beta1_generated_AssetService_ListFeeds_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": "AssetService" + }, + "shortName": "UpdateFeed" + } + }, + "file": "cloudasset_v1p2beta1_generated_asset_service_update_feed_async.py", + "regionTag": "cloudasset_v1p2beta1_generated_AssetService_UpdateFeed_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "UpdateFeed" + } + }, + "file": "cloudasset_v1p2beta1_generated_asset_service_update_feed_sync.py", + "regionTag": "cloudasset_v1p2beta1_generated_AssetService_UpdateFeed_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_asset_v1p4beta1.json b/samples/generated_samples/snippet_metadata_asset_v1p4beta1.json new file mode 100644 index 00000000..a91113b4 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_asset_v1p4beta1.json @@ -0,0 +1,182 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "AnalyzeIamPolicy" + } + }, + "file": "cloudasset_v1p4beta1_generated_asset_service_analyze_iam_policy_async.py", + "regionTag": "cloudasset_v1p4beta1_generated_AssetService_AnalyzeIamPolicy_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "AnalyzeIamPolicy" + } + }, + "file": "cloudasset_v1p4beta1_generated_asset_service_analyze_iam_policy_sync.py", + "regionTag": "cloudasset_v1p4beta1_generated_AssetService_AnalyzeIamPolicy_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "ExportIamPolicyAnalysis" + } + }, + "file": "cloudasset_v1p4beta1_generated_asset_service_export_iam_policy_analysis_async.py", + "regionTag": "cloudasset_v1p4beta1_generated_AssetService_ExportIamPolicyAnalysis_async", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "ExportIamPolicyAnalysis" + } + }, + "file": "cloudasset_v1p4beta1_generated_asset_service_export_iam_policy_analysis_sync.py", + "regionTag": "cloudasset_v1p4beta1_generated_AssetService_ExportIamPolicyAnalysis_sync", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_asset_v1p5beta1.json b/samples/generated_samples/snippet_metadata_asset_v1p5beta1.json new file mode 100644 index 00000000..291cde2d --- /dev/null +++ b/samples/generated_samples/snippet_metadata_asset_v1p5beta1.json @@ -0,0 +1,93 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "AssetService" + }, + "shortName": "ListAssets" + } + }, + "file": "cloudasset_v1p5beta1_generated_asset_service_list_assets_async.py", + "regionTag": "cloudasset_v1p5beta1_generated_AssetService_ListAssets_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": "AssetService" + }, + "shortName": "ListAssets" + } + }, + "file": "cloudasset_v1p5beta1_generated_asset_service_list_assets_sync.py", + "regionTag": "cloudasset_v1p5beta1_generated_AssetService_ListAssets_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" + } + ] + } + ] +} diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index 93a9122c..20cdfc62 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/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/noxfile_config.py b/samples/snippets/noxfile_config.py index 4a4db8c2..5c3e8031 100644 --- a/samples/snippets/noxfile_config.py +++ b/samples/snippets/noxfile_config.py @@ -18,7 +18,7 @@ # the noxfile.py. # The source of truth: -# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py TEST_CONFIG_OVERRIDE = { # You can opt out from the test for specific Python versions. diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index 23bba2f0..c4bb1f1c 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1,3 +1,3 @@ backoff==1.11.1 flaky==3.7.0 -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index c4c7c4ca..94f97086 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,5 +1,5 @@ -google-cloud-storage==1.42.3 -google-cloud-asset==3.7.0 -google-cloud-resource-manager==1.3.1 -google-cloud-pubsub==2.8.0 -google-cloud-bigquery==2.29.0 +google-cloud-storage==2.1.0 +google-cloud-asset==3.7.1 +google-cloud-resource-manager==1.3.3 +google-cloud-pubsub==2.9.0 +google-cloud-bigquery==2.34.0 diff --git a/scripts/fixup_asset_v1_keywords.py b/scripts/fixup_asset_v1_keywords.py index acc493bd..5bdce0c3 100644 --- a/scripts/fixup_asset_v1_keywords.py +++ b/scripts/fixup_asset_v1_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/fixup_asset_v1p1beta1_keywords.py b/scripts/fixup_asset_v1p1beta1_keywords.py index a35ed7a0..3a8adae1 100644 --- a/scripts/fixup_asset_v1p1beta1_keywords.py +++ b/scripts/fixup_asset_v1p1beta1_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/fixup_asset_v1p2beta1_keywords.py b/scripts/fixup_asset_v1p2beta1_keywords.py index ade1ee3e..cde2d7d3 100644 --- a/scripts/fixup_asset_v1p2beta1_keywords.py +++ b/scripts/fixup_asset_v1p2beta1_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/fixup_asset_v1p4beta1_keywords.py b/scripts/fixup_asset_v1p4beta1_keywords.py index bcbd8c93..8ec156da 100644 --- a/scripts/fixup_asset_v1p4beta1_keywords.py +++ b/scripts/fixup_asset_v1p4beta1_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/fixup_asset_v1p5beta1_keywords.py b/scripts/fixup_asset_v1p5beta1_keywords.py index 987edff8..70552c56 100644 --- a/scripts/fixup_asset_v1p5beta1_keywords.py +++ b/scripts/fixup_asset_v1p5beta1_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/setup.py b/setup.py index 556a4054..60fb7da3 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ name = "google-cloud-asset" description = "Cloud Asset API API client library" -version = "3.7.1" +version = "3.8.0" # Should be one of: # 'Development Status :: 3 - Alpha' # 'Development Status :: 4 - Beta' diff --git a/tests/__init__.py b/tests/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/__init__.py +++ b/tests/unit/gapic/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/asset_v1/__init__.py b/tests/unit/gapic/asset_v1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/asset_v1/__init__.py +++ b/tests/unit/gapic/asset_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/asset_v1/test_asset_service.py b/tests/unit/gapic/asset_v1/test_asset_service.py index 4ad014a4..76997532 100644 --- a/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/unit/gapic/asset_v1/test_asset_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. @@ -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 @@ -246,20 +247,20 @@ def test_asset_service_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, @@ -316,7 +317,7 @@ def test_asset_service_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 @@ -393,6 +394,83 @@ def test_asset_service_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [AssetServiceClient, AssetServiceAsyncClient]) +@mock.patch.object( + AssetServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AssetServiceClient) +) +@mock.patch.object( + AssetServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(AssetServiceAsyncClient), +) +def test_asset_service_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", [ @@ -411,7 +489,7 @@ def test_asset_service_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, @@ -425,24 +503,31 @@ def test_asset_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (AssetServiceClient, transports.AssetServiceGrpcTransport, "grpc"), + ( + AssetServiceClient, + transports.AssetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_asset_service_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", @@ -473,9 +558,74 @@ def test_asset_service_client_client_options_from_dict(): ) -def test_export_assets( - transport: str = "grpc", request_type=asset_service.ExportAssetsRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + AssetServiceClient, + transports.AssetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + AssetServiceAsyncClient, + transports.AssetServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_asset_service_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( + "cloudasset.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="cloudasset.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [asset_service.ExportAssetsRequest, dict,]) +def test_export_assets(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -499,10 +649,6 @@ def test_export_assets( assert isinstance(response, future.Future) -def test_export_assets_from_dict(): - test_export_assets(request_type=dict) - - def test_export_assets_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. @@ -603,9 +749,8 @@ async def test_export_assets_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_assets( - transport: str = "grpc", request_type=asset_service.ListAssetsRequest -): +@pytest.mark.parametrize("request_type", [asset_service.ListAssetsRequest, dict,]) +def test_list_assets(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -632,10 +777,6 @@ def test_list_assets( assert response.next_page_token == "next_page_token_value" -def test_list_assets_from_dict(): - test_list_assets(request_type=dict) - - def test_list_assets_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. @@ -752,7 +893,9 @@ def test_list_assets_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_assets_flattened_error(): @@ -786,7 +929,9 @@ async def test_list_assets_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -801,8 +946,10 @@ async def test_list_assets_flattened_error_async(): ) -def test_list_assets_pager(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_assets_pager(transport_name: str = "grpc"): + client = AssetServiceClient( + 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_assets), "__call__") as call: @@ -833,8 +980,10 @@ def test_list_assets_pager(): assert all(isinstance(i, assets.Asset) for i in results) -def test_list_assets_pages(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_assets_pages(transport_name: str = "grpc"): + client = AssetServiceClient( + 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_assets), "__call__") as call: @@ -915,9 +1064,10 @@ async def test_list_assets_async_pages(): assert page_.raw_page.next_page_token == token -def test_batch_get_assets_history( - transport: str = "grpc", request_type=asset_service.BatchGetAssetsHistoryRequest -): +@pytest.mark.parametrize( + "request_type", [asset_service.BatchGetAssetsHistoryRequest, dict,] +) +def test_batch_get_assets_history(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -943,10 +1093,6 @@ def test_batch_get_assets_history( assert isinstance(response, asset_service.BatchGetAssetsHistoryResponse) -def test_batch_get_assets_history_from_dict(): - test_batch_get_assets_history(request_type=dict) - - def test_batch_get_assets_history_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. @@ -1056,9 +1202,8 @@ async def test_batch_get_assets_history_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_create_feed( - transport: str = "grpc", request_type=asset_service.CreateFeedRequest -): +@pytest.mark.parametrize("request_type", [asset_service.CreateFeedRequest, dict,]) +def test_create_feed(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1093,10 +1238,6 @@ def test_create_feed( assert response.relationship_types == ["relationship_types_value"] -def test_create_feed_from_dict(): - test_create_feed(request_type=dict) - - def test_create_feed_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. @@ -1221,7 +1362,9 @@ def test_create_feed_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_create_feed_flattened_error(): @@ -1253,7 +1396,9 @@ async def test_create_feed_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1268,7 +1413,8 @@ async def test_create_feed_flattened_error_async(): ) -def test_get_feed(transport: str = "grpc", request_type=asset_service.GetFeedRequest): +@pytest.mark.parametrize("request_type", [asset_service.GetFeedRequest, dict,]) +def test_get_feed(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1303,10 +1449,6 @@ def test_get_feed(transport: str = "grpc", request_type=asset_service.GetFeedReq assert response.relationship_types == ["relationship_types_value"] -def test_get_feed_from_dict(): - test_get_feed(request_type=dict) - - def test_get_feed_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. @@ -1431,7 +1573,9 @@ def test_get_feed_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_feed_flattened_error(): @@ -1463,7 +1607,9 @@ async def test_get_feed_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1478,9 +1624,8 @@ async def test_get_feed_flattened_error_async(): ) -def test_list_feeds( - transport: str = "grpc", request_type=asset_service.ListFeedsRequest -): +@pytest.mark.parametrize("request_type", [asset_service.ListFeedsRequest, dict,]) +def test_list_feeds(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1504,10 +1649,6 @@ def test_list_feeds( assert isinstance(response, asset_service.ListFeedsResponse) -def test_list_feeds_from_dict(): - test_list_feeds(request_type=dict) - - def test_list_feeds_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. @@ -1623,7 +1764,9 @@ def test_list_feeds_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_feeds_flattened_error(): @@ -1657,7 +1800,9 @@ async def test_list_feeds_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1672,9 +1817,8 @@ async def test_list_feeds_flattened_error_async(): ) -def test_update_feed( - transport: str = "grpc", request_type=asset_service.UpdateFeedRequest -): +@pytest.mark.parametrize("request_type", [asset_service.UpdateFeedRequest, dict,]) +def test_update_feed(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1709,10 +1853,6 @@ def test_update_feed( assert response.relationship_types == ["relationship_types_value"] -def test_update_feed_from_dict(): - test_update_feed(request_type=dict) - - def test_update_feed_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. @@ -1837,7 +1977,9 @@ def test_update_feed_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].feed == asset_service.Feed(name="name_value") + arg = args[0].feed + mock_val = asset_service.Feed(name="name_value") + assert arg == mock_val def test_update_feed_flattened_error(): @@ -1870,7 +2012,9 @@ async def test_update_feed_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].feed == asset_service.Feed(name="name_value") + arg = args[0].feed + mock_val = asset_service.Feed(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -1886,9 +2030,8 @@ async def test_update_feed_flattened_error_async(): ) -def test_delete_feed( - transport: str = "grpc", request_type=asset_service.DeleteFeedRequest -): +@pytest.mark.parametrize("request_type", [asset_service.DeleteFeedRequest, dict,]) +def test_delete_feed(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1912,10 +2055,6 @@ def test_delete_feed( assert response is None -def test_delete_feed_from_dict(): - test_delete_feed(request_type=dict) - - def test_delete_feed_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. @@ -2027,7 +2166,9 @@ def test_delete_feed_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_feed_flattened_error(): @@ -2059,7 +2200,9 @@ async def test_delete_feed_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2074,9 +2217,10 @@ async def test_delete_feed_flattened_error_async(): ) -def test_search_all_resources( - transport: str = "grpc", request_type=asset_service.SearchAllResourcesRequest -): +@pytest.mark.parametrize( + "request_type", [asset_service.SearchAllResourcesRequest, dict,] +) +def test_search_all_resources(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2105,10 +2249,6 @@ def test_search_all_resources( assert response.next_page_token == "next_page_token_value" -def test_search_all_resources_from_dict(): - test_search_all_resources(request_type=dict) - - def test_search_all_resources_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. @@ -2240,9 +2380,15 @@ def test_search_all_resources_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].scope == "scope_value" - assert args[0].query == "query_value" - assert args[0].asset_types == ["asset_types_value"] + arg = args[0].scope + mock_val = "scope_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val + arg = args[0].asset_types + mock_val = ["asset_types_value"] + assert arg == mock_val def test_search_all_resources_flattened_error(): @@ -2283,9 +2429,15 @@ async def test_search_all_resources_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].scope == "scope_value" - assert args[0].query == "query_value" - assert args[0].asset_types == ["asset_types_value"] + arg = args[0].scope + mock_val = "scope_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val + arg = args[0].asset_types + mock_val = ["asset_types_value"] + assert arg == mock_val @pytest.mark.asyncio @@ -2303,8 +2455,10 @@ async def test_search_all_resources_flattened_error_async(): ) -def test_search_all_resources_pager(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_all_resources_pager(transport_name: str = "grpc"): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2345,8 +2499,10 @@ def test_search_all_resources_pager(): assert all(isinstance(i, assets.ResourceSearchResult) for i in results) -def test_search_all_resources_pages(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_all_resources_pages(transport_name: str = "grpc"): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2457,9 +2613,10 @@ async def test_search_all_resources_async_pages(): assert page_.raw_page.next_page_token == token -def test_search_all_iam_policies( - transport: str = "grpc", request_type=asset_service.SearchAllIamPoliciesRequest -): +@pytest.mark.parametrize( + "request_type", [asset_service.SearchAllIamPoliciesRequest, dict,] +) +def test_search_all_iam_policies(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2488,10 +2645,6 @@ def test_search_all_iam_policies( assert response.next_page_token == "next_page_token_value" -def test_search_all_iam_policies_from_dict(): - test_search_all_iam_policies(request_type=dict) - - def test_search_all_iam_policies_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. @@ -2623,8 +2776,12 @@ def test_search_all_iam_policies_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].scope == "scope_value" - assert args[0].query == "query_value" + arg = args[0].scope + mock_val = "scope_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val def test_search_all_iam_policies_flattened_error(): @@ -2664,8 +2821,12 @@ async def test_search_all_iam_policies_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].scope == "scope_value" - assert args[0].query == "query_value" + arg = args[0].scope + mock_val = "scope_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2682,8 +2843,10 @@ async def test_search_all_iam_policies_flattened_error_async(): ) -def test_search_all_iam_policies_pager(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_all_iam_policies_pager(transport_name: str = "grpc"): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2727,8 +2890,10 @@ def test_search_all_iam_policies_pager(): assert all(isinstance(i, assets.IamPolicySearchResult) for i in results) -def test_search_all_iam_policies_pages(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_all_iam_policies_pages(transport_name: str = "grpc"): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2848,9 +3013,8 @@ async def test_search_all_iam_policies_async_pages(): assert page_.raw_page.next_page_token == token -def test_analyze_iam_policy( - transport: str = "grpc", request_type=asset_service.AnalyzeIamPolicyRequest -): +@pytest.mark.parametrize("request_type", [asset_service.AnalyzeIamPolicyRequest, dict,]) +def test_analyze_iam_policy(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2877,10 +3041,6 @@ def test_analyze_iam_policy( assert response.fully_explored is True -def test_analyze_iam_policy_from_dict(): - test_analyze_iam_policy(request_type=dict) - - def test_analyze_iam_policy_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. @@ -2996,10 +3156,10 @@ async def test_analyze_iam_policy_field_headers_async(): ) in kw["metadata"] -def test_analyze_iam_policy_longrunning( - transport: str = "grpc", - request_type=asset_service.AnalyzeIamPolicyLongrunningRequest, -): +@pytest.mark.parametrize( + "request_type", [asset_service.AnalyzeIamPolicyLongrunningRequest, dict,] +) +def test_analyze_iam_policy_longrunning(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3025,10 +3185,6 @@ def test_analyze_iam_policy_longrunning( assert isinstance(response, future.Future) -def test_analyze_iam_policy_longrunning_from_dict(): - test_analyze_iam_policy_longrunning(request_type=dict) - - def test_analyze_iam_policy_longrunning_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. @@ -3144,9 +3300,8 @@ async def test_analyze_iam_policy_longrunning_field_headers_async(): ) in kw["metadata"] -def test_analyze_move( - transport: str = "grpc", request_type=asset_service.AnalyzeMoveRequest -): +@pytest.mark.parametrize("request_type", [asset_service.AnalyzeMoveRequest, dict,]) +def test_analyze_move(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3170,10 +3325,6 @@ def test_analyze_move( assert isinstance(response, asset_service.AnalyzeMoveResponse) -def test_analyze_move_from_dict(): - test_analyze_move(request_type=dict) - - def test_analyze_move_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. @@ -3294,6 +3445,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.AssetServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = AssetServiceClient(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 = AssetServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.AssetServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -3908,7 +4076,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( @@ -3973,3 +4141,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (AssetServiceClient, transports.AssetServiceGrpcTransport), + (AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport), + ], +) +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/asset_v1p1beta1/__init__.py b/tests/unit/gapic/asset_v1p1beta1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/asset_v1p1beta1/__init__.py +++ b/tests/unit/gapic/asset_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/asset_v1p1beta1/test_asset_service.py b/tests/unit/gapic/asset_v1p1beta1/test_asset_service.py index abe7fa94..c7e5c348 100644 --- a/tests/unit/gapic/asset_v1p1beta1/test_asset_service.py +++ b/tests/unit/gapic/asset_v1p1beta1/test_asset_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. @@ -238,20 +238,20 @@ def test_asset_service_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, @@ -308,7 +308,7 @@ def test_asset_service_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 @@ -385,6 +385,83 @@ def test_asset_service_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [AssetServiceClient, AssetServiceAsyncClient]) +@mock.patch.object( + AssetServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AssetServiceClient) +) +@mock.patch.object( + AssetServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(AssetServiceAsyncClient), +) +def test_asset_service_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", [ @@ -403,7 +480,7 @@ def test_asset_service_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, @@ -417,24 +494,31 @@ def test_asset_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (AssetServiceClient, transports.AssetServiceGrpcTransport, "grpc"), + ( + AssetServiceClient, + transports.AssetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_asset_service_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", @@ -465,9 +549,76 @@ def test_asset_service_client_client_options_from_dict(): ) -def test_search_all_resources( - transport: str = "grpc", request_type=asset_service.SearchAllResourcesRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + AssetServiceClient, + transports.AssetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + AssetServiceAsyncClient, + transports.AssetServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_asset_service_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( + "cloudasset.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="cloudasset.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [asset_service.SearchAllResourcesRequest, dict,] +) +def test_search_all_resources(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -496,10 +647,6 @@ def test_search_all_resources( assert response.next_page_token == "next_page_token_value" -def test_search_all_resources_from_dict(): - test_search_all_resources(request_type=dict) - - def test_search_all_resources_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. @@ -631,9 +778,15 @@ def test_search_all_resources_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].scope == "scope_value" - assert args[0].query == "query_value" - assert args[0].asset_types == ["asset_types_value"] + arg = args[0].scope + mock_val = "scope_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val + arg = args[0].asset_types + mock_val = ["asset_types_value"] + assert arg == mock_val def test_search_all_resources_flattened_error(): @@ -674,9 +827,15 @@ async def test_search_all_resources_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].scope == "scope_value" - assert args[0].query == "query_value" - assert args[0].asset_types == ["asset_types_value"] + arg = args[0].scope + mock_val = "scope_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val + arg = args[0].asset_types + mock_val = ["asset_types_value"] + assert arg == mock_val @pytest.mark.asyncio @@ -694,8 +853,10 @@ async def test_search_all_resources_flattened_error_async(): ) -def test_search_all_resources_pager(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_all_resources_pager(transport_name: str = "grpc"): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -739,8 +900,10 @@ def test_search_all_resources_pager(): assert all(isinstance(i, assets.StandardResourceMetadata) for i in results) -def test_search_all_resources_pages(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_all_resources_pages(transport_name: str = "grpc"): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -860,9 +1023,10 @@ async def test_search_all_resources_async_pages(): assert page_.raw_page.next_page_token == token -def test_search_all_iam_policies( - transport: str = "grpc", request_type=asset_service.SearchAllIamPoliciesRequest -): +@pytest.mark.parametrize( + "request_type", [asset_service.SearchAllIamPoliciesRequest, dict,] +) +def test_search_all_iam_policies(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -891,10 +1055,6 @@ def test_search_all_iam_policies( assert response.next_page_token == "next_page_token_value" -def test_search_all_iam_policies_from_dict(): - test_search_all_iam_policies(request_type=dict) - - def test_search_all_iam_policies_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. @@ -1026,8 +1186,12 @@ def test_search_all_iam_policies_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].scope == "scope_value" - assert args[0].query == "query_value" + arg = args[0].scope + mock_val = "scope_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val def test_search_all_iam_policies_flattened_error(): @@ -1067,8 +1231,12 @@ async def test_search_all_iam_policies_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].scope == "scope_value" - assert args[0].query == "query_value" + arg = args[0].scope + mock_val = "scope_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1085,8 +1253,10 @@ async def test_search_all_iam_policies_flattened_error_async(): ) -def test_search_all_iam_policies_pager(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_all_iam_policies_pager(transport_name: str = "grpc"): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1130,8 +1300,10 @@ def test_search_all_iam_policies_pager(): assert all(isinstance(i, assets.IamPolicySearchResult) for i in results) -def test_search_all_iam_policies_pages(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_all_iam_policies_pages(transport_name: str = "grpc"): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1271,6 +1443,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.AssetServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = AssetServiceClient(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 = AssetServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.AssetServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1731,7 +1920,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( @@ -1796,3 +1985,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (AssetServiceClient, transports.AssetServiceGrpcTransport), + (AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport), + ], +) +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/asset_v1p2beta1/__init__.py b/tests/unit/gapic/asset_v1p2beta1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/asset_v1p2beta1/__init__.py +++ b/tests/unit/gapic/asset_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/asset_v1p2beta1/test_asset_service.py b/tests/unit/gapic/asset_v1p2beta1/test_asset_service.py index 6997e64b..9d92e6a5 100644 --- a/tests/unit/gapic/asset_v1p2beta1/test_asset_service.py +++ b/tests/unit/gapic/asset_v1p2beta1/test_asset_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. @@ -237,20 +237,20 @@ def test_asset_service_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, @@ -307,7 +307,7 @@ def test_asset_service_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 @@ -384,6 +384,83 @@ def test_asset_service_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [AssetServiceClient, AssetServiceAsyncClient]) +@mock.patch.object( + AssetServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AssetServiceClient) +) +@mock.patch.object( + AssetServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(AssetServiceAsyncClient), +) +def test_asset_service_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", [ @@ -402,7 +479,7 @@ def test_asset_service_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, @@ -416,24 +493,31 @@ def test_asset_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (AssetServiceClient, transports.AssetServiceGrpcTransport, "grpc"), + ( + AssetServiceClient, + transports.AssetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_asset_service_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", @@ -464,9 +548,74 @@ def test_asset_service_client_client_options_from_dict(): ) -def test_create_feed( - transport: str = "grpc", request_type=asset_service.CreateFeedRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + AssetServiceClient, + transports.AssetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + AssetServiceAsyncClient, + transports.AssetServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_asset_service_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( + "cloudasset.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="cloudasset.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [asset_service.CreateFeedRequest, dict,]) +def test_create_feed(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -499,10 +648,6 @@ def test_create_feed( assert response.content_type == asset_service.ContentType.RESOURCE -def test_create_feed_from_dict(): - test_create_feed(request_type=dict) - - def test_create_feed_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. @@ -625,7 +770,9 @@ def test_create_feed_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_create_feed_flattened_error(): @@ -657,7 +804,9 @@ async def test_create_feed_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -672,7 +821,8 @@ async def test_create_feed_flattened_error_async(): ) -def test_get_feed(transport: str = "grpc", request_type=asset_service.GetFeedRequest): +@pytest.mark.parametrize("request_type", [asset_service.GetFeedRequest, dict,]) +def test_get_feed(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -705,10 +855,6 @@ def test_get_feed(transport: str = "grpc", request_type=asset_service.GetFeedReq assert response.content_type == asset_service.ContentType.RESOURCE -def test_get_feed_from_dict(): - test_get_feed(request_type=dict) - - def test_get_feed_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. @@ -831,7 +977,9 @@ def test_get_feed_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_feed_flattened_error(): @@ -863,7 +1011,9 @@ async def test_get_feed_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -878,9 +1028,8 @@ async def test_get_feed_flattened_error_async(): ) -def test_list_feeds( - transport: str = "grpc", request_type=asset_service.ListFeedsRequest -): +@pytest.mark.parametrize("request_type", [asset_service.ListFeedsRequest, dict,]) +def test_list_feeds(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -904,10 +1053,6 @@ def test_list_feeds( assert isinstance(response, asset_service.ListFeedsResponse) -def test_list_feeds_from_dict(): - test_list_feeds(request_type=dict) - - def test_list_feeds_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. @@ -1023,7 +1168,9 @@ def test_list_feeds_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_feeds_flattened_error(): @@ -1057,7 +1204,9 @@ async def test_list_feeds_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1072,9 +1221,8 @@ async def test_list_feeds_flattened_error_async(): ) -def test_update_feed( - transport: str = "grpc", request_type=asset_service.UpdateFeedRequest -): +@pytest.mark.parametrize("request_type", [asset_service.UpdateFeedRequest, dict,]) +def test_update_feed(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1107,10 +1255,6 @@ def test_update_feed( assert response.content_type == asset_service.ContentType.RESOURCE -def test_update_feed_from_dict(): - test_update_feed(request_type=dict) - - def test_update_feed_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. @@ -1233,7 +1377,9 @@ def test_update_feed_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].feed == asset_service.Feed(name="name_value") + arg = args[0].feed + mock_val = asset_service.Feed(name="name_value") + assert arg == mock_val def test_update_feed_flattened_error(): @@ -1266,7 +1412,9 @@ async def test_update_feed_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].feed == asset_service.Feed(name="name_value") + arg = args[0].feed + mock_val = asset_service.Feed(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -1282,9 +1430,8 @@ async def test_update_feed_flattened_error_async(): ) -def test_delete_feed( - transport: str = "grpc", request_type=asset_service.DeleteFeedRequest -): +@pytest.mark.parametrize("request_type", [asset_service.DeleteFeedRequest, dict,]) +def test_delete_feed(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1308,10 +1455,6 @@ def test_delete_feed( assert response is None -def test_delete_feed_from_dict(): - test_delete_feed(request_type=dict) - - def test_delete_feed_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. @@ -1423,7 +1566,9 @@ def test_delete_feed_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_feed_flattened_error(): @@ -1455,7 +1600,9 @@ async def test_delete_feed_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1490,6 +1637,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.AssetServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = AssetServiceClient(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 = AssetServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.AssetServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1973,7 +2137,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( @@ -2038,3 +2202,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (AssetServiceClient, transports.AssetServiceGrpcTransport), + (AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport), + ], +) +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/asset_v1p4beta1/__init__.py b/tests/unit/gapic/asset_v1p4beta1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/asset_v1p4beta1/__init__.py +++ b/tests/unit/gapic/asset_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/asset_v1p4beta1/test_asset_service.py b/tests/unit/gapic/asset_v1p4beta1/test_asset_service.py index 4a7de233..9ba521be 100644 --- a/tests/unit/gapic/asset_v1p4beta1/test_asset_service.py +++ b/tests/unit/gapic/asset_v1p4beta1/test_asset_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. @@ -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 @@ -242,20 +243,20 @@ def test_asset_service_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, @@ -312,7 +313,7 @@ def test_asset_service_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 @@ -389,6 +390,83 @@ def test_asset_service_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [AssetServiceClient, AssetServiceAsyncClient]) +@mock.patch.object( + AssetServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AssetServiceClient) +) +@mock.patch.object( + AssetServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(AssetServiceAsyncClient), +) +def test_asset_service_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", [ @@ -407,7 +485,7 @@ def test_asset_service_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, @@ -421,24 +499,31 @@ def test_asset_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (AssetServiceClient, transports.AssetServiceGrpcTransport, "grpc"), + ( + AssetServiceClient, + transports.AssetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_asset_service_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", @@ -469,9 +554,74 @@ def test_asset_service_client_client_options_from_dict(): ) -def test_analyze_iam_policy( - transport: str = "grpc", request_type=asset_service.AnalyzeIamPolicyRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + AssetServiceClient, + transports.AssetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + AssetServiceAsyncClient, + transports.AssetServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_asset_service_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( + "cloudasset.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="cloudasset.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [asset_service.AnalyzeIamPolicyRequest, dict,]) +def test_analyze_iam_policy(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -498,10 +648,6 @@ def test_analyze_iam_policy( assert response.fully_explored is True -def test_analyze_iam_policy_from_dict(): - test_analyze_iam_policy(request_type=dict) - - def test_analyze_iam_policy_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. @@ -617,9 +763,10 @@ async def test_analyze_iam_policy_field_headers_async(): ) in kw["metadata"] -def test_export_iam_policy_analysis( - transport: str = "grpc", request_type=asset_service.ExportIamPolicyAnalysisRequest -): +@pytest.mark.parametrize( + "request_type", [asset_service.ExportIamPolicyAnalysisRequest, dict,] +) +def test_export_iam_policy_analysis(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -645,10 +792,6 @@ def test_export_iam_policy_analysis( assert isinstance(response, future.Future) -def test_export_iam_policy_analysis_from_dict(): - test_export_iam_policy_analysis(request_type=dict) - - def test_export_iam_policy_analysis_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. @@ -784,6 +927,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.AssetServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = AssetServiceClient(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 = AssetServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.AssetServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1275,7 +1435,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( @@ -1340,3 +1500,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (AssetServiceClient, transports.AssetServiceGrpcTransport), + (AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport), + ], +) +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/asset_v1p5beta1/__init__.py b/tests/unit/gapic/asset_v1p5beta1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/asset_v1p5beta1/__init__.py +++ b/tests/unit/gapic/asset_v1p5beta1/__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/asset_v1p5beta1/test_asset_service.py b/tests/unit/gapic/asset_v1p5beta1/test_asset_service.py index ea6b47da..ef94c5ce 100644 --- a/tests/unit/gapic/asset_v1p5beta1/test_asset_service.py +++ b/tests/unit/gapic/asset_v1p5beta1/test_asset_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. @@ -239,20 +239,20 @@ def test_asset_service_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, @@ -309,7 +309,7 @@ def test_asset_service_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 @@ -386,6 +386,83 @@ def test_asset_service_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [AssetServiceClient, AssetServiceAsyncClient]) +@mock.patch.object( + AssetServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AssetServiceClient) +) +@mock.patch.object( + AssetServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(AssetServiceAsyncClient), +) +def test_asset_service_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", [ @@ -404,7 +481,7 @@ def test_asset_service_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, @@ -418,24 +495,31 @@ def test_asset_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (AssetServiceClient, transports.AssetServiceGrpcTransport, "grpc"), + ( + AssetServiceClient, + transports.AssetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_asset_service_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", @@ -466,9 +550,74 @@ def test_asset_service_client_client_options_from_dict(): ) -def test_list_assets( - transport: str = "grpc", request_type=asset_service.ListAssetsRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + AssetServiceClient, + transports.AssetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + AssetServiceAsyncClient, + transports.AssetServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_asset_service_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( + "cloudasset.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="cloudasset.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [asset_service.ListAssetsRequest, dict,]) +def test_list_assets(request_type, transport: str = "grpc"): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -495,10 +644,6 @@ def test_list_assets( assert response.next_page_token == "next_page_token_value" -def test_list_assets_from_dict(): - test_list_assets(request_type=dict) - - def test_list_assets_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. @@ -600,8 +745,10 @@ async def test_list_assets_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_assets_pager(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_assets_pager(transport_name: str = "grpc"): + client = AssetServiceClient( + 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_assets), "__call__") as call: @@ -632,8 +779,10 @@ def test_list_assets_pager(): assert all(isinstance(i, assets.Asset) for i in results) -def test_list_assets_pages(): - client = AssetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_assets_pages(transport_name: str = "grpc"): + client = AssetServiceClient( + 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_assets), "__call__") as call: @@ -734,6 +883,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.AssetServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = AssetServiceClient(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 = AssetServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.AssetServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1259,7 +1425,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( @@ -1324,3 +1490,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (AssetServiceClient, transports.AssetServiceGrpcTransport), + (AssetServiceAsyncClient, transports.AssetServiceGrpcAsyncIOTransport), + ], +) +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, + ) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy