From 00dcd068b0a08425f981c8b6b7a7f8d79f931504 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 30 Mar 2023 20:32:51 -0400 Subject: [PATCH 1/3] feat: Add client library support for AnalyzeOrgPolicies API (#560) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add client library support for AssetService v1 AnalyzeOrgPolicies API feat: Add client library support for AssetService v1 AnalyzeOrgPolicyGovernedContainers API feat: Add client library support for AssetService v1 AnalyzeOrgPolicyGovernedAssets API PiperOrigin-RevId: 520696122 Source-Link: https://github.com/googleapis/googleapis/commit/fb446a2f9b93ddc39f4417d65e0334e71908811d Source-Link: https://github.com/googleapis/googleapis-gen/commit/f4b9936403faf847180a353636be515d21d5cac4 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZjRiOTkzNjQwM2ZhZjg0NzE4MGEzNTM2MzZiZTUxNWQyMWQ1Y2FjNCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- .../services/asset_service/async_client.py | 42 ++++++++++++++++--- .../asset_v1/services/asset_service/client.py | 6 +-- .../services/asset_service/transports/base.py | 36 ++++++++++++++-- google/cloud/asset_v1/types/asset_service.py | 39 +++++++++-------- google/cloud/asset_v1/types/assets.py | 2 +- ...nippet_metadata_google.cloud.asset.v1.json | 2 +- ...metadata_google.cloud.asset.v1p1beta1.json | 2 +- ...metadata_google.cloud.asset.v1p2beta1.json | 2 +- ...metadata_google.cloud.asset.v1p5beta1.json | 2 +- 9 files changed, 96 insertions(+), 37 deletions(-) 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 3fd04b30..dcb187bc 100644 --- a/google/cloud/asset_v1/services/asset_service/async_client.py +++ b/google/cloud/asset_v1/services/asset_service/async_client.py @@ -621,8 +621,8 @@ async def sample_create_feed(): be an organization number (such as "organizations/123"), a folder number (such as "folders/123"), a project ID - (such as "projects/my-project-id")", or - a project number (such as + (such as "projects/my-project-id"), or a + project number (such as "projects/12345"). This corresponds to the ``parent`` field @@ -2016,7 +2016,7 @@ async def sample_create_saved_query(): where this saved_query should be created in. It can only be an organization number (such as "organizations/123"), a folder number (such as "folders/123"), a project ID - (such as "projects/my-project-id")", or a project number + (such as "projects/my-project-id"), or a project number (such as "projects/12345"). This corresponds to the ``parent`` field @@ -2779,7 +2779,17 @@ async def sample_analyze_org_policies(): # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.analyze_org_policies, - default_timeout=None, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -2930,7 +2940,17 @@ async def sample_analyze_org_policy_governed_containers(): # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.analyze_org_policy_governed_containers, - default_timeout=None, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -3110,7 +3130,17 @@ async def sample_analyze_org_policy_governed_assets(): # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.analyze_org_policy_governed_assets, - default_timeout=None, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) diff --git a/google/cloud/asset_v1/services/asset_service/client.py b/google/cloud/asset_v1/services/asset_service/client.py index 002888ab..0f4b3911 100644 --- a/google/cloud/asset_v1/services/asset_service/client.py +++ b/google/cloud/asset_v1/services/asset_service/client.py @@ -916,8 +916,8 @@ def sample_create_feed(): be an organization number (such as "organizations/123"), a folder number (such as "folders/123"), a project ID - (such as "projects/my-project-id")", or - a project number (such as + (such as "projects/my-project-id"), or a + project number (such as "projects/12345"). This corresponds to the ``parent`` field @@ -2251,7 +2251,7 @@ def sample_create_saved_query(): where this saved_query should be created in. It can only be an organization number (such as "organizations/123"), a folder number (such as "folders/123"), a project ID - (such as "projects/my-project-id")", or a project number + (such as "projects/my-project-id"), or a project number (such as "projects/12345"). This corresponds to the ``parent`` field 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 8e6f88fe..2290dd69 100644 --- a/google/cloud/asset_v1/services/asset_service/transports/base.py +++ b/google/cloud/asset_v1/services/asset_service/transports/base.py @@ -354,17 +354,47 @@ def _prep_wrapped_messages(self, client_info): ), self.analyze_org_policies: gapic_v1.method.wrap_method( self.analyze_org_policies, - default_timeout=None, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, client_info=client_info, ), self.analyze_org_policy_governed_containers: gapic_v1.method.wrap_method( self.analyze_org_policy_governed_containers, - default_timeout=None, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, client_info=client_info, ), self.analyze_org_policy_governed_assets: gapic_v1.method.wrap_method( self.analyze_org_policy_governed_assets, - default_timeout=None, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, client_info=client_info, ), } diff --git a/google/cloud/asset_v1/types/asset_service.py b/google/cloud/asset_v1/types/asset_service.py index 6b0457d9..681a81c1 100644 --- a/google/cloud/asset_v1/types/asset_service.py +++ b/google/cloud/asset_v1/types/asset_service.py @@ -521,7 +521,7 @@ class CreateFeedRequest(proto.Message): organization number (such as "organizations/123"), a folder number (such as "folders/123"), a project ID (such as - "projects/my-project-id")", or a project number + "projects/my-project-id"), or a project number (such as "projects/12345"). feed_id (str): Required. This is the client-assigned asset @@ -2202,7 +2202,7 @@ class CreateSavedQueryRequest(proto.Message): this saved_query should be created in. It can only be an organization number (such as "organizations/123"), a folder number (such as "folders/123"), a project ID (such as - "projects/my-project-id")", or a project number (such as + "projects/my-project-id"), or a project number (such as "projects/12345"). saved_query (google.cloud.asset_v1.types.SavedQuery): Required. The saved_query details. The ``name`` field must @@ -2280,9 +2280,8 @@ class ListSavedQueriesRequest(proto.Message): Optional. The maximum number of saved queries to return per page. The service may return fewer than this value. If unspecified, at most 50 will - be returned. - The maximum value is 1000; values above 1000 - will be coerced to 1000. + be returned. The maximum value is 1000; values + above 1000 will be coerced to 1000. page_token (str): Optional. A page token, received from a previous ``ListSavedQueries`` call. Provide this to retrieve the @@ -3855,19 +3854,19 @@ class GovernedResource(proto.Message): of the parent of [AnalyzeOrgPolicyGovernedAssetsResponse.GovernedResource.full_resource_name][google.cloud.asset.v1.AnalyzeOrgPolicyGovernedAssetsResponse.GovernedResource.full_resource_name]. project (str): - The project that this resource belongs to, in the form of + The project that this resource belongs to, in the format of projects/{PROJECT_NUMBER}. This field is available when the resource belongs to a project. folders (MutableSequence[str]): - The folder(s) that this resource belongs to, in the form of - folders/{FOLDER_NUMBER}. This field is available when the - resource belongs(directly or cascadingly) to one or more + The folder(s) that this resource belongs to, in the format + of folders/{FOLDER_NUMBER}. This field is available when the + resource belongs (directly or cascadingly) to one or more folders. organization (str): - The organization that this resource belongs to, in the form - of organizations/{ORGANIZATION_NUMBER}. This field is - available when the resource belongs(directly or cascadingly) - to an organization. + The organization that this resource belongs to, in the + format of organizations/{ORGANIZATION_NUMBER}. This field is + available when the resource belongs (directly or + cascadingly) to an organization. """ full_resource_name: str = proto.Field( @@ -3907,18 +3906,18 @@ class GovernedIamPolicy(proto.Message): The IAM policy directly set on the given resource. project (str): - The project that this IAM policy belongs to, in the form of - projects/{PROJECT_NUMBER}. This field is available when the - IAM policy belongs to a project. + The project that this IAM policy belongs to, in the format + of projects/{PROJECT_NUMBER}. This field is available when + the IAM policy belongs to a project. folders (MutableSequence[str]): - The folder(s) that this IAM policy belongs to, in the form + The folder(s) that this IAM policy belongs to, in the format of folders/{FOLDER_NUMBER}. This field is available when the - IAM policy belongs(directly or cascadingly) to one or more + IAM policy belongs (directly or cascadingly) to one or more folders. organization (str): The organization that this IAM policy belongs to, in the - form of organizations/{ORGANIZATION_NUMBER}. This field is - available when the IAM policy belongs(directly or + format of organizations/{ORGANIZATION_NUMBER}. This field is + available when the IAM policy belongs (directly or cascadingly) to an organization. """ diff --git a/google/cloud/asset_v1/types/assets.py b/google/cloud/asset_v1/types/assets.py index 6afa852d..419d51de 100644 --- a/google/cloud/asset_v1/types/assets.py +++ b/google/cloud/asset_v1/types/assets.py @@ -512,7 +512,7 @@ class RelatedAsset(proto.Message): class ResourceSearchResult(proto.Message): r"""A result of Resource Search, containing information of a - cloud resource. Next ID: 31 + cloud resource. Next ID: 32 Attributes: name (str): diff --git a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1.json b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1.json index ba5ccbbc..5a90dfa8 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-asset", - "version": "3.18.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p1beta1.json b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p1beta1.json index ea2c737d..dcbeb822 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p1beta1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-asset", - "version": "3.18.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p2beta1.json b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p2beta1.json index 0b16d867..38eaede8 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p2beta1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p2beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-asset", - "version": "3.18.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p5beta1.json b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p5beta1.json index f4c9ffba..13ffc229 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p5beta1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p5beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-asset", - "version": "3.18.1" + "version": "0.1.0" }, "snippets": [ { From 4e4fa94adec58bb0f991805455b2a15fff12b81f Mon Sep 17 00:00:00 2001 From: meredithslota Date: Sat, 1 Apr 2023 00:29:40 +0000 Subject: [PATCH 2/3] chore(docs): remove samples (#561) --- samples/snippets/conftest.py | 129 -------- samples/snippets/noxfile.py | 293 ------------------ samples/snippets/noxfile_config.py | 38 --- .../snippets/quickstart_analyzeiampolicy.py | 59 ---- .../quickstart_analyzeiampolicy_test.py | 29 -- .../quickstart_analyzeiampolicylongrunning.py | 136 -------- ...kstart_analyzeiampolicylongrunning_test.py | 86 ----- .../quickstart_batchgetassetshistory.py | 72 ----- .../quickstart_batchgetassetshistory_test.py | 64 ---- .../quickstart_batchgeteffectiveiampolicy.py | 63 ---- ...ckstart_batchgeteffectiveiampolicy_test.py | 37 --- .../snippets/quickstart_create_saved_query.py | 71 ----- .../quickstart_create_saved_query_test.py | 38 --- samples/snippets/quickstart_createfeed.py | 77 ----- .../snippets/quickstart_createfeed_test.py | 56 ---- .../snippets/quickstart_delete_saved_query.py | 46 --- .../quickstart_delete_saved_query_test.py | 32 -- samples/snippets/quickstart_deletefeed.py | 46 --- .../snippets/quickstart_deletefeed_test.py | 29 -- samples/snippets/quickstart_exportassets.py | 105 ------- .../snippets/quickstart_exportassets_test.py | 97 ------ .../snippets/quickstart_get_saved_query.py | 40 --- .../quickstart_get_saved_query_test.py | 29 -- samples/snippets/quickstart_getfeed.py | 40 --- samples/snippets/quickstart_getfeed_test.py | 27 -- .../snippets/quickstart_list_saved_queries.py | 42 --- .../quickstart_list_saved_queries_test.py | 32 -- samples/snippets/quickstart_listassets.py | 77 ----- .../snippets/quickstart_listassets_test.py | 47 --- samples/snippets/quickstart_listfeeds.py | 42 --- samples/snippets/quickstart_listfeeds_test.py | 30 -- .../quickstart_searchalliampolicies.py | 52 ---- .../quickstart_searchalliampolicies_test.py | 33 -- .../snippets/quickstart_searchallresources.py | 78 ----- .../quickstart_searchallresources_test.py | 65 ---- .../snippets/quickstart_update_saved_query.py | 59 ---- .../quickstart_update_saved_query_test.py | 29 -- samples/snippets/quickstart_updatefeed.py | 56 ---- .../snippets/quickstart_updatefeed_test.py | 31 -- samples/snippets/requirements-test.txt | 3 - samples/snippets/requirements.txt | 5 - 41 files changed, 2420 deletions(-) delete mode 100644 samples/snippets/conftest.py delete mode 100644 samples/snippets/noxfile.py delete mode 100644 samples/snippets/noxfile_config.py delete mode 100644 samples/snippets/quickstart_analyzeiampolicy.py delete mode 100644 samples/snippets/quickstart_analyzeiampolicy_test.py delete mode 100644 samples/snippets/quickstart_analyzeiampolicylongrunning.py delete mode 100644 samples/snippets/quickstart_analyzeiampolicylongrunning_test.py delete mode 100644 samples/snippets/quickstart_batchgetassetshistory.py delete mode 100644 samples/snippets/quickstart_batchgetassetshistory_test.py delete mode 100644 samples/snippets/quickstart_batchgeteffectiveiampolicy.py delete mode 100644 samples/snippets/quickstart_batchgeteffectiveiampolicy_test.py delete mode 100644 samples/snippets/quickstart_create_saved_query.py delete mode 100644 samples/snippets/quickstart_create_saved_query_test.py delete mode 100644 samples/snippets/quickstart_createfeed.py delete mode 100644 samples/snippets/quickstart_createfeed_test.py delete mode 100644 samples/snippets/quickstart_delete_saved_query.py delete mode 100644 samples/snippets/quickstart_delete_saved_query_test.py delete mode 100644 samples/snippets/quickstart_deletefeed.py delete mode 100644 samples/snippets/quickstart_deletefeed_test.py delete mode 100644 samples/snippets/quickstart_exportassets.py delete mode 100644 samples/snippets/quickstart_exportassets_test.py delete mode 100644 samples/snippets/quickstart_get_saved_query.py delete mode 100644 samples/snippets/quickstart_get_saved_query_test.py delete mode 100644 samples/snippets/quickstart_getfeed.py delete mode 100644 samples/snippets/quickstart_getfeed_test.py delete mode 100644 samples/snippets/quickstart_list_saved_queries.py delete mode 100644 samples/snippets/quickstart_list_saved_queries_test.py delete mode 100644 samples/snippets/quickstart_listassets.py delete mode 100644 samples/snippets/quickstart_listassets_test.py delete mode 100644 samples/snippets/quickstart_listfeeds.py delete mode 100644 samples/snippets/quickstart_listfeeds_test.py delete mode 100644 samples/snippets/quickstart_searchalliampolicies.py delete mode 100644 samples/snippets/quickstart_searchalliampolicies_test.py delete mode 100644 samples/snippets/quickstart_searchallresources.py delete mode 100644 samples/snippets/quickstart_searchallresources_test.py delete mode 100644 samples/snippets/quickstart_update_saved_query.py delete mode 100644 samples/snippets/quickstart_update_saved_query_test.py delete mode 100644 samples/snippets/quickstart_updatefeed.py delete mode 100644 samples/snippets/quickstart_updatefeed_test.py delete mode 100644 samples/snippets/requirements-test.txt delete mode 100644 samples/snippets/requirements.txt diff --git a/samples/snippets/conftest.py b/samples/snippets/conftest.py deleted file mode 100644 index 54199ab9..00000000 --- a/samples/snippets/conftest.py +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import uuid - -import backoff -from google.api_core.exceptions import InternalServerError -from google.api_core.exceptions import NotFound -from google.cloud import pubsub_v1 -import pytest - -import quickstart_create_saved_query -import quickstart_createfeed -import quickstart_delete_saved_query -import quickstart_deletefeed - - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -@pytest.fixture(scope="module") -def test_topic(): - topic_id = f"topic-{uuid.uuid4().hex}" - publisher = pubsub_v1.PublisherClient() - topic_path = publisher.topic_path(PROJECT, topic_id) - topic = publisher.create_topic(request={"name": topic_path}) - - yield topic - - publisher.delete_topic(request={"topic": topic_path}) - - -@pytest.fixture(scope="module") -def another_topic(): - topic_id = f"topic-{uuid.uuid4().hex}" - publisher = pubsub_v1.PublisherClient() - topic_path = publisher.topic_path(PROJECT, topic_id) - topic = publisher.create_topic(request={"name": topic_path}) - - yield topic - - publisher.delete_topic(request={"topic": topic_path}) - - -@pytest.fixture(scope="module") -def test_feed(test_topic): - from google.cloud import asset_v1 - - feed_id = f"feed-{uuid.uuid4().hex}" - asset_name = f"assets-{uuid.uuid4().hex}" - - @backoff.on_exception(backoff.expo, InternalServerError, max_time=60) - def create_feed(): - return quickstart_createfeed.create_feed( - PROJECT, - feed_id, - [asset_name], - test_topic.name, - asset_v1.ContentType.RESOURCE, - ) - - feed = create_feed() - - yield feed - - try: - quickstart_deletefeed.delete_feed(feed.name) - except NotFound as e: - print(f"Ignoring NotFound: {e}") - - -@pytest.fixture(scope="module") -def deleter(): - feeds_to_delete = [] - - yield feeds_to_delete - - for feed_name in feeds_to_delete: - try: - quickstart_deletefeed.delete_feed(feed_name) - except NotFound as e: - print(f"Ignoring NotFound: {e}") - - -@pytest.fixture(scope="module") -def test_saved_query(): - saved_query_id = f"saved-query-{uuid.uuid4().hex}" - - @backoff.on_exception(backoff.expo, InternalServerError, max_time=60) - def create_saved_query(): - return quickstart_create_saved_query.create_saved_query( - PROJECT, saved_query_id, "description foo" - ) - - saved_query = create_saved_query() - - yield saved_query - - try: - quickstart_delete_saved_query.delete_saved_query(saved_query.name) - except NotFound as e: - print(f"Ignoring NotFound: {e}") - - -@pytest.fixture(scope="module") -def saved_query_deleter(): - saved_querys_to_delete = [] - - yield saved_querys_to_delete - - for saved_query_name in saved_querys_to_delete: - try: - quickstart_delete_saved_query.delete_saved_query(saved_query_name) - except NotFound as e: - print(f"Ignoring NotFound: {e}") diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py deleted file mode 100644 index 1224cbe2..00000000 --- a/samples/snippets/noxfile.py +++ /dev/null @@ -1,293 +0,0 @@ -# Copyright 2019 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. - -from __future__ import print_function - -import glob -import os -from pathlib import Path -import sys -from typing import Callable, Dict, Optional - -import nox - - -# WARNING - WARNING - WARNING - WARNING - WARNING -# WARNING - WARNING - WARNING - WARNING - WARNING -# DO NOT EDIT THIS FILE EVER! -# WARNING - WARNING - WARNING - WARNING - WARNING -# WARNING - WARNING - WARNING - WARNING - WARNING - -BLACK_VERSION = "black==22.3.0" -ISORT_VERSION = "isort==5.10.1" - -# Copy `noxfile_config.py` to your directory and modify it instead. - -# `TEST_CONFIG` dict is a configuration hook that allows users to -# modify the test configurations. The values here should be in sync -# with `noxfile_config.py`. Users will copy `noxfile_config.py` into -# their directory and modify it. - -TEST_CONFIG = { - # You can opt out from the test for specific Python versions. - "ignored_versions": [], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": False, - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # If you need to use a specific version of pip, - # change pip_version_override to the string representation - # of the version number, for example, "20.2.4" - "pip_version_override": None, - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, -} - - -try: - # Ensure we can import noxfile_config in the project's directory. - sys.path.append(".") - from noxfile_config import TEST_CONFIG_OVERRIDE -except ImportError as e: - print("No user noxfile_config found: detail: {}".format(e)) - TEST_CONFIG_OVERRIDE = {} - -# Update the TEST_CONFIG with the user supplied values. -TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) - - -def get_pytest_env_vars() -> Dict[str, str]: - """Returns a dict for pytest invocation.""" - ret = {} - - # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG["gcloud_project_env"] - # This should error out if not set. - ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] - - # Apply user supplied envs. - ret.update(TEST_CONFIG["envs"]) - return ret - - -# DO NOT EDIT - automatically generated. -# All versions used to test samples. -ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11"] - -# Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] - -TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) - -INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( - "True", - "true", -) - -# Error if a python version is missing -nox.options.error_on_missing_interpreters = True - -# -# Style Checks -# - - -# Linting with flake8. -# -# We ignore the following rules: -# E203: whitespace before ‘:’ -# E266: too many leading ‘#’ for block comment -# E501: line too long -# I202: Additional newline in a section of imports -# -# We also need to specify the rules which are ignored by default: -# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] -FLAKE8_COMMON_ARGS = [ - "--show-source", - "--builtin=gettext", - "--max-complexity=20", - "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", - "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", - "--max-line-length=88", -] - - -@nox.session -def lint(session: nox.sessions.Session) -> None: - if not TEST_CONFIG["enforce_type_hints"]: - session.install("flake8") - else: - session.install("flake8", "flake8-annotations") - - args = FLAKE8_COMMON_ARGS + [ - ".", - ] - session.run("flake8", *args) - - -# -# Black -# - - -@nox.session -def blacken(session: nox.sessions.Session) -> None: - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - session.run("black", *python_files) - - -# -# format = isort + black -# - - -@nox.session -def format(session: nox.sessions.Session) -> None: - """ - Run isort to sort imports. Then run black - to format code to uniform standard. - """ - session.install(BLACK_VERSION, ISORT_VERSION) - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections - session.run("isort", "--fss", *python_files) - session.run("black", *python_files) - - -# -# Sample Tests -# - - -PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] - - -def _session_tests( - session: nox.sessions.Session, post_install: Callable = None -) -> None: - # check for presence of tests - test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob( - "**/test_*.py", recursive=True - ) - test_list.extend(glob.glob("**/tests", recursive=True)) - - if len(test_list) == 0: - print("No tests found, skipping directory.") - return - - 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.""" - concurrent_args = [] - 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") - with open("requirements.txt") as rfile: - packages = rfile.read() - - 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") - with open("requirements-test.txt") as rtfile: - packages += rtfile.read() - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - if "pytest-parallel" in packages: - concurrent_args.extend(["--workers", "auto", "--tests-per-worker", "auto"]) - elif "pytest-xdist" in packages: - concurrent_args.extend(["-n", "auto"]) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), - # 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) -def py(session: nox.sessions.Session) -> None: - """Runs py.test for a sample using the specified version of Python.""" - if session.python in TESTED_VERSIONS: - _session_tests(session) - else: - session.skip( - "SKIPPED: {} tests are disabled for this sample.".format(session.python) - ) - - -# -# Readmegen -# - - -def _get_repo_root() -> Optional[str]: - """Returns the root folder of the project.""" - # Get root of this repository. Assume we don't have directories nested deeper than 10 items. - p = Path(os.getcwd()) - for i in range(10): - if p is None: - break - if Path(p / ".git").exists(): - return str(p) - # .git is not available in repos cloned via Cloud Build - # setup.py is always in the library's root, so use that instead - # https://github.com/googleapis/synthtool/issues/792 - if Path(p / "setup.py").exists(): - return str(p) - p = p.parent - raise Exception("Unable to detect repository root.") - - -GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) - - -@nox.session -@nox.parametrize("path", GENERATED_READMES) -def readmegen(session: nox.sessions.Session, path: str) -> None: - """(Re-)generates the readme for a sample.""" - session.install("jinja2", "pyyaml") - dir_ = os.path.dirname(path) - - if os.path.exists(os.path.join(dir_, "requirements.txt")): - session.install("-r", os.path.join(dir_, "requirements.txt")) - - in_file = os.path.join(dir_, "README.rst.in") - session.run( - "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file - ) diff --git a/samples/snippets/noxfile_config.py b/samples/snippets/noxfile_config.py deleted file mode 100644 index 5c3e8031..00000000 --- a/samples/snippets/noxfile_config.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2021 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Default TEST_CONFIG_OVERRIDE for python repos. - -# You can copy this file into your directory, then it will be inported from -# the noxfile.py. - -# The source of truth: -# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py - -TEST_CONFIG_OVERRIDE = { - # You can opt out from the test for specific Python versions. - "ignored_versions": ["2.7"], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": False, - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - # "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - "gcloud_project_env": "BUILD_SPECIFIC_GCLOUD_PROJECT", - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, -} diff --git a/samples/snippets/quickstart_analyzeiampolicy.py b/samples/snippets/quickstart_analyzeiampolicy.py deleted file mode 100644 index feb23926..00000000 --- a/samples/snippets/quickstart_analyzeiampolicy.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2020 Google LLC. All Rights Reserved. -# -# 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. - - -import argparse - - -def analyze_iam_policy(project_id: str, transport: str = "None") -> None: - """ - Args: - project_id(str): The project id. - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - # [START asset_quickstart_analyze_iam_policy] - from google.cloud import asset_v1 - - # TODO project_id = 'Your Google Cloud Project ID' - - client = asset_v1.AssetServiceClient(transport=transport) - parent = "projects/{}".format(project_id) - - # Build analysis query - analysis_query = asset_v1.IamPolicyAnalysisQuery() - analysis_query.scope = parent - analysis_query.resource_selector.full_resource_name = ( - f"//cloudresourcemanager.googleapis.com/{parent}" - ) - analysis_query.options.expand_groups = True - analysis_query.options.output_group_edges = True - - response = client.analyze_iam_policy(request={"analysis_query": analysis_query}) - print(response) - # [END asset_quickstart_analyze_iam_policy] - - -if __name__ == "__main__": - - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("project_id", help="Your Google Cloud project ID") - - args = parser.parse_args() - - analyze_iam_policy(args.project_id) diff --git a/samples/snippets/quickstart_analyzeiampolicy_test.py b/samples/snippets/quickstart_analyzeiampolicy_test.py deleted file mode 100644 index e05cdfb5..00000000 --- a/samples/snippets/quickstart_analyzeiampolicy_test.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2020 Google LLC. All Rights Reserved. -# -# 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. - -import os -import pytest - -import quickstart_analyzeiampolicy - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_analyze_iam_policy(transport, capsys): - quickstart_analyzeiampolicy.analyze_iam_policy(PROJECT, transport=transport) - out, _ = capsys.readouterr() - assert "fully_explored: true" in out diff --git a/samples/snippets/quickstart_analyzeiampolicylongrunning.py b/samples/snippets/quickstart_analyzeiampolicylongrunning.py deleted file mode 100644 index c26ad8dc..00000000 --- a/samples/snippets/quickstart_analyzeiampolicylongrunning.py +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2020 Google LLC. All Rights Reserved. -# -# 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. - - -import argparse - - -def analyze_iam_policy_longrunning_gcs( - project_id: str, dump_file_path: str, transport: str = None -) -> None: - """ - Args: - - project_id(str): Your Google Cloud Project ID - dump_file_path(str): Your analysis dump file path - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - - # [START asset_quickstart_analyze_iam_policy_longrunning_gcs] - from google.cloud import asset_v1 - - # TODO project_id = 'Your Google Cloud Project ID' - # TODO dump_file_path = 'Your analysis dump file path' - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - parent = "projects/{}".format(project_id) - - # Build analysis query - analysis_query = asset_v1.IamPolicyAnalysisQuery() - analysis_query.scope = parent - analysis_query.resource_selector.full_resource_name = ( - f"//cloudresourcemanager.googleapis.com/{parent}" - ) - analysis_query.options.expand_groups = True - analysis_query.options.output_group_edges = True - - output_config = asset_v1.IamPolicyAnalysisOutputConfig() - output_config.gcs_destination.uri = dump_file_path - operation = client.analyze_iam_policy_longrunning( - request={"analysis_query": analysis_query, "output_config": output_config} - ) - - operation.result(300) - print(operation.done()) - # [END asset_quickstart_analyze_iam_policy_longrunning_gcs] - - -def analyze_iam_policy_longrunning_bigquery( - project_id: str, dataset: str, table, transport: str = None -) -> None: - """ - Args: - - project_id(str): Your Google Cloud Project ID - dataset(str): 'Your BigQuery dataset path' - table(str): 'Your BigQuery table name' - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - - """ - # [START asset_quickstart_analyze_iam_policy_longrunning_bigquery] - from google.cloud import asset_v1 - - # TODO project_id = 'Your Google Cloud Project ID' - # TODO dataset = 'Your BigQuery dataset path' - # TODO table = 'Your BigQuery table name' - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - parent = "projects/{}".format(project_id) - - # Build analysis query - analysis_query = asset_v1.IamPolicyAnalysisQuery() - analysis_query.scope = parent - analysis_query.resource_selector.full_resource_name = ( - f"//cloudresourcemanager.googleapis.com/{parent}" - ) - analysis_query.options.expand_groups = True - analysis_query.options.output_group_edges = True - - output_config = asset_v1.IamPolicyAnalysisOutputConfig() - output_config.bigquery_destination.dataset = dataset - output_config.bigquery_destination.table_prefix = table - output_config.bigquery_destination.write_disposition = "WRITE_TRUNCATE" - operation = client.analyze_iam_policy_longrunning( - request={"analysis_query": analysis_query, "output_config": output_config} - ) - - operation.result(300) - print(operation.done()) - # [END asset_quickstart_analyze_iam_policy_longrunning_bigquery] - - -if __name__ == "__main__": - - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("project_id", help="Your Google Cloud project ID") - parser.add_argument( - "dump_file_path", - help="The GCS file that the analysis results will be dumped to, " - "e.g.: gs:///analysis_dump_file", - ) - parser.add_argument( - "dataset", - help="The BigQuery dataset that analysis results will be exported to, " - "e.g.: my_dataset", - ) - parser.add_argument( - "table_prefix", - help="The prefix of the BigQuery table that analysis results will be exported to, " - "e.g.: my_table", - ) - - args = parser.parse_args() - - analyze_iam_policy_longrunning_gcs(args.project_id, args.dump_file_path) - analyze_iam_policy_longrunning_bigquery( - args.project_id, args.dataset, args.table_prefix - ) diff --git a/samples/snippets/quickstart_analyzeiampolicylongrunning_test.py b/samples/snippets/quickstart_analyzeiampolicylongrunning_test.py deleted file mode 100644 index 0da9e243..00000000 --- a/samples/snippets/quickstart_analyzeiampolicylongrunning_test.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2020 Google LLC. All Rights Reserved. -# -# 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. - -import os -import uuid - -from google.cloud import bigquery -from google.cloud import storage - -import pytest - -import quickstart_analyzeiampolicylongrunning - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] -BUCKET = "analysis-{}".format(int(uuid.uuid4())) -DATASET = "analysis_{}".format(int(uuid.uuid4())) - - -@pytest.fixture(scope="module") -def storage_client(): - yield storage.Client() - - -@pytest.fixture(scope="module") -def bigquery_client(): - yield bigquery.Client() - - -@pytest.fixture(scope="module") -def analysis_bucket(storage_client): - bucket = storage_client.create_bucket(BUCKET) - - yield BUCKET - - try: - bucket.delete(force=True) - except Exception as e: - print("Failed to delete bucket{}".format(BUCKET)) - raise e - - -@pytest.fixture(scope="module") -def dataset(bigquery_client): - dataset_id = "{}.{}".format(PROJECT, DATASET) - dataset = bigquery.Dataset(dataset_id) - dataset.location = "US" - dataset = bigquery_client.create_dataset(dataset) - - yield DATASET - - bigquery_client.delete_dataset(dataset_id, delete_contents=True, not_found_ok=False) - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_analyze_iam_policy_longrunning(analysis_bucket, dataset, capsys, transport): - dump_file_path = "gs://{}/analysis-dump.txt".format(analysis_bucket) - quickstart_analyzeiampolicylongrunning.analyze_iam_policy_longrunning_gcs( - project_id=PROJECT, - dump_file_path=dump_file_path, - transport=transport, - ) - out, _ = capsys.readouterr() - assert "True" in out - - dataset_id = "projects/{}/datasets/{}".format(PROJECT, dataset) - quickstart_analyzeiampolicylongrunning.analyze_iam_policy_longrunning_bigquery( - project_id=PROJECT, - dataset=dataset_id, - table="analysis_", - transport=transport, - ) - out, _ = capsys.readouterr() - assert "True" in out diff --git a/samples/snippets/quickstart_batchgetassetshistory.py b/samples/snippets/quickstart_batchgetassetshistory.py deleted file mode 100644 index d159d7ff..00000000 --- a/samples/snippets/quickstart_batchgetassetshistory.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - - -import argparse -from typing import List - - -def batch_get_assets_history( - project_id: str, asset_names: List[str], transport: str = None -): - """ - Args: - project_id(str): Your Google Cloud Project ID - asset_names(List[str]): Your asset names list. - For example: ["//storage.googleapis.com/[BUCKET_NAME]",] - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - # [START asset_quickstart_batch_get_assets_history] - from google.cloud import asset_v1 - - # TODO project_id = 'Your Google Cloud Project ID' - # TODO asset_names = 'Your asset names list, e.g.: - # ["//storage.googleapis.com/[BUCKET_NAME]",]' - # TODO transport = 'The transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - parent = "projects/{}".format(project_id) - content_type = asset_v1.ContentType.RESOURCE - read_time_window = asset_v1.TimeWindow() - response = client.batch_get_assets_history( - request={ - "parent": parent, - "asset_names": asset_names, - "content_type": content_type, - "read_time_window": read_time_window, - } - ) - print("assets: {}".format(response.assets)) - # [END asset_quickstart_batch_get_assets_history] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("project_id", help="Your Google Cloud project ID") - parser.add_argument( - "asset_names", - help="The asset names for which history will be fetched, comma " - "delimited, e.g.: //storage.googleapis.com/[BUCKET_NAME]", - ) - - args = parser.parse_args() - - asset_name_list = args.asset_names.split(",") - - batch_get_assets_history(args.project_id, asset_name_list) diff --git a/samples/snippets/quickstart_batchgetassetshistory_test.py b/samples/snippets/quickstart_batchgetassetshistory_test.py deleted file mode 100644 index 6ed604a1..00000000 --- a/samples/snippets/quickstart_batchgetassetshistory_test.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - -import os -import uuid - -import backoff -from google.api_core.exceptions import InvalidArgument -from google.cloud import storage -import pytest - -import quickstart_batchgetassetshistory - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] -BUCKET = "assets-{}".format(uuid.uuid4().hex) - - -@pytest.fixture(scope="module") -def storage_client(): - yield storage.Client(project=PROJECT) - - -@pytest.fixture(scope="module") -def asset_bucket(storage_client): - bucket = storage_client.create_bucket(BUCKET, project=PROJECT) - - yield BUCKET - - try: - bucket.delete(force=True) - except Exception as e: - print("Failed to delete bucket{}".format(BUCKET)) - raise e - - -def test_batch_get_assets_history(asset_bucket, capsys): - bucket_asset_name = "//storage.googleapis.com/{}".format(BUCKET) - asset_names = [ - bucket_asset_name, - ] - - @backoff.on_exception(backoff.expo, (AssertionError, InvalidArgument), max_time=60) - def eventually_consistent_test(): - quickstart_batchgetassetshistory.batch_get_assets_history( - project_id=PROJECT, asset_names=asset_names, transport="grpc" - ) - out, _ = capsys.readouterr() - - assert bucket_asset_name in out - - eventually_consistent_test() diff --git a/samples/snippets/quickstart_batchgeteffectiveiampolicy.py b/samples/snippets/quickstart_batchgeteffectiveiampolicy.py deleted file mode 100644 index 0b98f5c7..00000000 --- a/samples/snippets/quickstart_batchgeteffectiveiampolicy.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 Google LLC. All Rights Reserved. -# -# 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. - - -import argparse -from typing import List - - -def batch_get_effective_iam_policies( - resource_names: List[str], scope: str, transport: str = None -): - """ - Args: - resource_names(List[str]): List of resource names - scope(str): project ID/number, folder number or org number - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - - # [START asset_quickstart_batch_get_effective_iam_policies] - from google.cloud import asset_v1 - - # TODO resource_names = 'List of resource names' - # TODO scope = 'project ID/number, folder number or org number' - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - - response = client.batch_get_effective_iam_policies( - request={"scope": scope, "names": resource_names} - ) - print(response) - # [END asset_quickstart_batch_get_effective_iam_policies] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument( - "resource_names", - help="Your specified accessible " - "scope, such as a project, " - "folder or organization", - ) - parser.add_argument("scope", help="Your specified list of resource names") - - args = parser.parse_args() - - batch_get_effective_iam_policies(args.resource_names, args.scope) diff --git a/samples/snippets/quickstart_batchgeteffectiveiampolicy_test.py b/samples/snippets/quickstart_batchgeteffectiveiampolicy_test.py deleted file mode 100644 index e15d5715..00000000 --- a/samples/snippets/quickstart_batchgeteffectiveiampolicy_test.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - -import os -import pytest - -import quickstart_batchgeteffectiveiampolicy - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_batch_get_effective_iam_policies(transport, capsys): - scope = "projects/{}".format(PROJECT) - resource_names = [ - "//cloudresourcemanager.googleapis.com/projects/{}".format(PROJECT) - ] - quickstart_batchgeteffectiveiampolicy.batch_get_effective_iam_policies( - resource_names=resource_names, - scope=scope, - transport=transport, - ) - out, _ = capsys.readouterr() - assert resource_names[0] in out diff --git a/samples/snippets/quickstart_create_saved_query.py b/samples/snippets/quickstart_create_saved_query.py deleted file mode 100644 index 904f2a23..00000000 --- a/samples/snippets/quickstart_create_saved_query.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - - -import argparse - - -def create_saved_query( - project_id: str, saved_query_id: str, description: str, transport: str = None -): - """ - Args: - project_id(str): Your Google Cloud Project ID - saved_query_id(str): SavedQuery ID you want to create - description(str): The description for the query. - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - # [START asset_quickstart_create_saved_query] - from google.cloud import asset_v1 - - # TODO project_id = 'Your Google Cloud Project ID' - # TODO saved_query_id = 'SavedQuery ID you want to create' - - client = asset_v1.AssetServiceClient(transport=transport) - parent = f"projects/{project_id}" - saved_query = asset_v1.SavedQuery() - saved_query.description = description - - # TODO: customize your saved query based on the guide below. - # https://cloud.google.com/asset-inventory/docs/reference/rest/v1/savedQueries#IamPolicyAnalysisQuery - saved_query.content.iam_policy_analysis_query.scope = parent - query_access_selector = ( - saved_query.content.iam_policy_analysis_query.access_selector - ) - query_access_selector.permissions.append("iam.serviceAccounts.actAs") - - response = client.create_saved_query( - request={ - "parent": parent, - "saved_query_id": saved_query_id, - "saved_query": saved_query, - } - ) - print(f"saved_query: {response}") - # [END asset_quickstart_create_saved_query] - return response - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("project_id", help="Your Google Cloud project ID") - parser.add_argument("saved_query_id", help="SavedQuery ID you want to create") - parser.add_argument("description", help="The description of the saved_query") - args = parser.parse_args() - create_saved_query(args.project_id, args.saved_query_id, args.description) diff --git a/samples/snippets/quickstart_create_saved_query_test.py b/samples/snippets/quickstart_create_saved_query_test.py deleted file mode 100644 index 30a7785d..00000000 --- a/samples/snippets/quickstart_create_saved_query_test.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - -import os -import pytest -import uuid - -import quickstart_create_saved_query - - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] -SAVED_QUERY_ID = f"saved-query-{uuid.uuid4().hex}" - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_create_saved_query(transport, capsys, saved_query_deleter): - saved_query = quickstart_create_saved_query.create_saved_query( - project_id=PROJECT, - saved_query_id=f"{SAVED_QUERY_ID}-{transport}", - description="saved query foo", - transport=transport, - ) - saved_query_deleter.append(saved_query.name) - expected_resource_name_suffix = f"savedQueries/{SAVED_QUERY_ID}-{transport}" - assert saved_query.name.endswith(expected_resource_name_suffix) diff --git a/samples/snippets/quickstart_createfeed.py b/samples/snippets/quickstart_createfeed.py deleted file mode 100644 index 3f70b5f5..00000000 --- a/samples/snippets/quickstart_createfeed.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2019 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. - - -import argparse -from typing import List -from google.cloud.asset_v1 import ContentType - - -def create_feed( - project_id: str, - feed_id: str, - asset_names: List[str], - topic: str, - content_type: ContentType, - transport: str = None, -): - """ - Args: - project_id(str): The project id. - feed_id(str): Feed ID you want to create - asset_names(List[str]): List of asset names the feed listen to - topic(str): Topic name of the feed. - content_type[google.cloud.asset_v1.ContentType]: Content type of the feed. - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - # [START asset_quickstart_create_feed] - from google.cloud import asset_v1 - - # TODO project_id = 'Your Google Cloud Project ID' - # TODO feed_id = 'Feed ID you want to create' - # TODO asset_names = 'List of asset names the feed listen to' - # TODO topic = "Topic name of the feed" - # TODO content_type ="Content type of the feed" - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - parent = "projects/{}".format(project_id) - feed = asset_v1.Feed() - feed.asset_names.extend(asset_names) - feed.feed_output_config.pubsub_destination.topic = topic - feed.content_type = content_type - response = client.create_feed( - request={"parent": parent, "feed_id": feed_id, "feed": feed} - ) - print("feed: {}".format(response)) - # [END asset_quickstart_create_feed] - return response - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("project_id", help="Your Google Cloud project ID") - parser.add_argument("feed_id", help="Feed ID you want to create") - parser.add_argument("asset_names", help="List of asset names the feed listen to") - parser.add_argument("topic", help="Topic name of the feed") - parser.add_argument("content_type", help="Content type of the feed") - args = parser.parse_args() - create_feed( - args.project_id, args.feed_id, args.asset_names, args.topic, args.content_type - ) diff --git a/samples/snippets/quickstart_createfeed_test.py b/samples/snippets/quickstart_createfeed_test.py deleted file mode 100644 index 8d7eb559..00000000 --- a/samples/snippets/quickstart_createfeed_test.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - -import os -import pytest -import uuid - -import quickstart_createfeed - - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] -ASSET_NAME = "assets-{}".format(uuid.uuid4().hex) -FEED_ID = "feed-{}".format(uuid.uuid4().hex) -FEED_ID_R = "feed-{}".format(uuid.uuid4().hex) - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_create_feed(transport, capsys, test_topic, deleter): - from google.cloud import asset_v1 - - feed = quickstart_createfeed.create_feed( - project_id=PROJECT, - feed_id=f"{FEED_ID}-{transport}", - asset_names=[f"{ASSET_NAME}"], - topic=test_topic.name, - content_type=asset_v1.ContentType.RESOURCE, - transport=transport, - ) - deleter.append(feed.name) - out, _ = capsys.readouterr() - assert "feed" in out - - feed_r = quickstart_createfeed.create_feed( - project_id=PROJECT, - feed_id=f"{FEED_ID_R}-{transport}", - asset_names=[f"{ASSET_NAME}"], - topic=test_topic.name, - content_type=asset_v1.ContentType.RELATIONSHIP, - transport=transport, - ) - deleter.append(feed_r.name) - out_r, _ = capsys.readouterr() - assert "feed" in out_r diff --git a/samples/snippets/quickstart_delete_saved_query.py b/samples/snippets/quickstart_delete_saved_query.py deleted file mode 100644 index 219df620..00000000 --- a/samples/snippets/quickstart_delete_saved_query.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - - -import argparse - - -def delete_saved_query(saved_query_name: str, transport: str = None): - """ - Args: - saved_query_name(str): SavedQuery name you want to delete - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - # [START asset_quickstart_delete_saved_query] - from google.cloud import asset_v1 - - # TODO saved_query_name = 'SavedQuery name you want to delete' - # TODO tranport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - client.delete_saved_query(request={"name": saved_query_name}) - print("deleted_saved_query") - # [END asset_quickstart_delete_saved_query] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("saved_query_name", help="SavedQuery name you want to delete") - args = parser.parse_args() - delete_saved_query(args.saved_query_name) diff --git a/samples/snippets/quickstart_delete_saved_query_test.py b/samples/snippets/quickstart_delete_saved_query_test.py deleted file mode 100644 index e8b03d1b..00000000 --- a/samples/snippets/quickstart_delete_saved_query_test.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - -import os - -import quickstart_delete_saved_query - - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -def test_delete_saved_query(capsys, test_saved_query): - - quickstart_delete_saved_query.delete_saved_query( - saved_query_name=test_saved_query.name, transport="grpc" - ) - - out, _ = capsys.readouterr() - assert "deleted_saved_query" in out diff --git a/samples/snippets/quickstart_deletefeed.py b/samples/snippets/quickstart_deletefeed.py deleted file mode 100644 index c85759a8..00000000 --- a/samples/snippets/quickstart_deletefeed.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - - -import argparse - - -def delete_feed(feed_name: str, transport: str = None): - """ - Args: - feed_name(str): Feed name you want to delete. - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - # [START asset_quickstart_delete_feed] - from google.cloud import asset_v1 - - # TODO feed_name = 'Feed name you want to delete' - # TODO transport = 'Transport that you want to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - client.delete_feed(request={"name": feed_name}) - print("deleted_feed") - # [END asset_quickstart_delete_feed] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("feed_name", help="Feed name you want to delete") - args = parser.parse_args() - delete_feed(args.feed_name) diff --git a/samples/snippets/quickstart_deletefeed_test.py b/samples/snippets/quickstart_deletefeed_test.py deleted file mode 100644 index 137bde0b..00000000 --- a/samples/snippets/quickstart_deletefeed_test.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - -import os - -import quickstart_deletefeed - - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -def test_delete_feed(capsys, test_feed): - quickstart_deletefeed.delete_feed(feed_name=test_feed.name, transport="grpc") - - out, _ = capsys.readouterr() - assert "deleted_feed" in out diff --git a/samples/snippets/quickstart_exportassets.py b/samples/snippets/quickstart_exportassets.py deleted file mode 100644 index 71a04771..00000000 --- a/samples/snippets/quickstart_exportassets.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - - -import argparse -from google.cloud.asset_v1 import ContentType - - -def export_assets(project_id: str, dump_file_path: str, transport: str = None): - """ - Args: - - project_id(str): Your Google Cloud Project ID - dump_file_path(str): Your analysis dump file path - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - # [START asset_quickstart_export_assets] - from google.cloud import asset_v1 - - # TODO project_id = 'Your Google Cloud Project ID' - # TODO dump_file_path = 'Your asset dump file path' - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - parent = "projects/{}".format(project_id) - output_config = asset_v1.OutputConfig() - output_config.gcs_destination.uri = dump_file_path - response = client.export_assets( - request={"parent": parent, "output_config": output_config} - ) - print(response.result()) - # [END asset_quickstart_export_assets] - - -def export_assets_bigquery( - project_id: str, - dataset: str, - table: str, - content_type: ContentType, - transport: str = None, -): - """ - Args: - project_id(str): The project id. - dataset(str): Your BigQuery dataset path. - table(str): Your BigQuery table name. - content_type[google.cloud.asset_v1.ContentType]: Content type of the feed. - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - # [START asset_quickstart_export_assets_bigquery] - from google.cloud import asset_v1 - - # TODO project_id = 'Your Google Cloud Project ID' - # TODO dataset = 'Your BigQuery dataset path' - # TODO table = 'Your BigQuery table name' - # TODO content_type ="Content type to export" - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - parent = "projects/{}".format(project_id) - output_config = asset_v1.OutputConfig() - output_config.bigquery_destination.dataset = dataset - output_config.bigquery_destination.table = table - output_config.bigquery_destination.force = True - response = client.export_assets( - request={ - "parent": parent, - "content_type": content_type, - "output_config": output_config, - } - ) - print(response.result()) - # [END asset_quickstart_export_assets_bigquery] - - -if __name__ == "__main__": - - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("project_id", help="Your Google Cloud project ID") - parser.add_argument( - "dump_file_path", - help="The file ExportAssets API will dump assets to, " - "e.g.: gs:///asset_dump_file", - ) - - args = parser.parse_args() - - export_assets(args.project_id, args.dump_file_path) diff --git a/samples/snippets/quickstart_exportassets_test.py b/samples/snippets/quickstart_exportassets_test.py deleted file mode 100644 index b0494c95..00000000 --- a/samples/snippets/quickstart_exportassets_test.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 Google LLC. All Rights Reserved. -# -# 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. - -import os -import uuid - -from google.cloud import asset_v1 -from google.cloud import bigquery -from google.cloud import storage -import pytest - -import quickstart_exportassets - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] -BUCKET = "assets-{}".format(uuid.uuid4().hex) -DATASET = "assets_{}".format(int(uuid.uuid4())) - - -@pytest.fixture(scope="module") -def storage_client(): - yield storage.Client() - - -@pytest.fixture(scope="module") -def bigquery_client(): - yield bigquery.Client() - - -@pytest.fixture(scope="module") -def asset_bucket(storage_client): - bucket = storage_client.create_bucket(BUCKET) - - yield BUCKET - - try: - bucket.delete(force=True) - except Exception as e: - print("Failed to delete bucket{}".format(BUCKET)) - raise e - - -@pytest.fixture(scope="module") -def dataset(bigquery_client): - dataset_id = "{}.{}".format(PROJECT, DATASET) - dataset = bigquery.Dataset(dataset_id) - dataset.location = "US" - dataset = bigquery_client.create_dataset(dataset) - - yield DATASET - - bigquery_client.delete_dataset(dataset_id, delete_contents=True, not_found_ok=False) - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_export_assets(transport, asset_bucket, dataset, capsys): - dump_file_path = "gs://{}/assets-dump.txt".format(asset_bucket) - quickstart_exportassets.export_assets( - project_id=PROJECT, dump_file_path=dump_file_path, transport=transport - ) - out, _ = capsys.readouterr() - assert dump_file_path in out - - content_type = asset_v1.ContentType.RESOURCE - dataset_id = "projects/{}/datasets/{}".format(PROJECT, dataset) - quickstart_exportassets.export_assets_bigquery( - project_id=PROJECT, - dataset=dataset_id, - table="assettable", - content_type=content_type, - transport=transport, - ) - out, _ = capsys.readouterr() - assert dataset_id in out - - content_type_r = asset_v1.ContentType.RELATIONSHIP - quickstart_exportassets.export_assets_bigquery( - project_id=PROJECT, - dataset=dataset_id, - table="assettable", - content_type=content_type_r, - transport=transport, - ) - out_r, _ = capsys.readouterr() - assert dataset_id in out_r diff --git a/samples/snippets/quickstart_get_saved_query.py b/samples/snippets/quickstart_get_saved_query.py deleted file mode 100644 index 54bcb24d..00000000 --- a/samples/snippets/quickstart_get_saved_query.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - - -import argparse - - -def get_saved_query(saved_query_name, transport: str = None): - # [START asset_quickstart_get_saved_query] - from google.cloud import asset_v1 - - # TODO saved_query_name = 'SavedQuery Name you want to get' - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - response = client.get_saved_query(request={"name": saved_query_name}) - print(f"gotten_saved_query: {response}") - # [END asset_quickstart_get_saved_query] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("saved_query_name", help="SavedQuery Name you want to get") - args = parser.parse_args() - get_saved_query(args.saved_query_name) diff --git a/samples/snippets/quickstart_get_saved_query_test.py b/samples/snippets/quickstart_get_saved_query_test.py deleted file mode 100644 index 45868531..00000000 --- a/samples/snippets/quickstart_get_saved_query_test.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - -import pytest - -import quickstart_get_saved_query - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_get_saved_query(transport, capsys, test_saved_query): - quickstart_get_saved_query.get_saved_query( - test_saved_query.name, transport=transport - ) - out, _ = capsys.readouterr() - - assert "gotten_saved_query" in out diff --git a/samples/snippets/quickstart_getfeed.py b/samples/snippets/quickstart_getfeed.py deleted file mode 100644 index a43874eb..00000000 --- a/samples/snippets/quickstart_getfeed.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - - -import argparse - - -def get_feed(feed_name, transport: str = None): - # [START asset_quickstart_get_feed] - from google.cloud import asset_v1 - - # TODO feed_name = 'Feed Name you want to get' - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - response = client.get_feed(request={"name": feed_name}) - print("gotten_feed: {}".format(response)) - # [START asset_quickstart_get_feed] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("feed_name", help="Feed Name you want to get") - args = parser.parse_args() - get_feed(args.feed_name) diff --git a/samples/snippets/quickstart_getfeed_test.py b/samples/snippets/quickstart_getfeed_test.py deleted file mode 100644 index 76b3502e..00000000 --- a/samples/snippets/quickstart_getfeed_test.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - -import pytest - -import quickstart_getfeed - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_get_feed(transport, capsys, test_feed): - quickstart_getfeed.get_feed(test_feed.name, transport=transport) - out, _ = capsys.readouterr() - - assert "gotten_feed" in out diff --git a/samples/snippets/quickstart_list_saved_queries.py b/samples/snippets/quickstart_list_saved_queries.py deleted file mode 100644 index f4402d67..00000000 --- a/samples/snippets/quickstart_list_saved_queries.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - - -import argparse - - -def list_saved_queries(parent_resource, transport: str = None): - # [START asset_quickstart_list_saved_queries] - from google.cloud import asset_v1 - - # TODO parent_resource = 'Parent resource you want to list all saved_queries' - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - response = client.list_saved_queries(request={"parent": parent_resource}) - print(f"saved_queries: {response.saved_queries}") - # [END asset_quickstart_list_saved_queries] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument( - "parent_resource", help="Parent resource you want to list all saved_queries" - ) - args = parser.parse_args() - list_saved_queries(args.parent_resource) diff --git a/samples/snippets/quickstart_list_saved_queries_test.py b/samples/snippets/quickstart_list_saved_queries_test.py deleted file mode 100644 index 63d81c49..00000000 --- a/samples/snippets/quickstart_list_saved_queries_test.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - -import os -import pytest - -import quickstart_list_saved_queries - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_list_saved_queries(transport, capsys): - parent_resource = f"projects/{PROJECT}" - quickstart_list_saved_queries.list_saved_queries( - parent_resource, transport=transport - ) - out, _ = capsys.readouterr() - assert "saved_queries" in out diff --git a/samples/snippets/quickstart_listassets.py b/samples/snippets/quickstart_listassets.py deleted file mode 100644 index 074bd7e8..00000000 --- a/samples/snippets/quickstart_listassets.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2020 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import argparse - - -def list_assets( - project_id, asset_types, page_size, content_type, transport: str = None -): - # [START asset_quickstart_list_assets] - from google.cloud import asset_v1 - - # TODO project_id = 'Your Google Cloud Project ID' - # TODO asset_types = 'Your asset type list, e.g., - # ["storage.googleapis.com/Bucket","bigquery.googleapis.com/Table"]' - # TODO page_size = 'Num of assets in one page, which must be between 1 and - # 1000 (both inclusively)' - # TODO content_type ="Content type to list" - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - project_resource = "projects/{}".format(project_id) - client = asset_v1.AssetServiceClient(transport=transport) - - # Call ListAssets v1 to list assets. - response = client.list_assets( - request={ - "parent": project_resource, - "read_time": None, - "asset_types": asset_types, - "content_type": content_type, - "page_size": page_size, - } - ) - - for asset in response: - print(asset) - # [END asset_quickstart_list_assets] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("project_id", help="Your Google Cloud project ID") - parser.add_argument( - "asset_types", - help="The types of the assets to list, comma delimited, e.g., " - "storage.googleapis.com/Bucket", - ) - parser.add_argument( - "page_size", - help="Num of assets in one page, which must be between 1 and 1000 " - "(both inclusively)", - ) - parser.add_argument("content_type", help="Content type to list") - - args = parser.parse_args() - - asset_type_list = args.asset_types.split(",") - - list_assets( - args.project_id, asset_type_list, int(args.page_size), args.content_type - ) diff --git a/samples/snippets/quickstart_listassets_test.py b/samples/snippets/quickstart_listassets_test.py deleted file mode 100644 index 1d41e509..00000000 --- a/samples/snippets/quickstart_listassets_test.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2020 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import pytest - -import quickstart_listassets - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_list_assets(transport, capsys): - from google.cloud import asset_v1 - - quickstart_listassets.list_assets( - project_id=PROJECT, - asset_types=["iam.googleapis.com/Role"], - page_size=10, - content_type=asset_v1.ContentType.RESOURCE, - transport=transport, - ) - out, _ = capsys.readouterr() - assert "asset" in out - - quickstart_listassets.list_assets( - project_id=PROJECT, - asset_types=[], - page_size=10, - content_type=asset_v1.ContentType.RELATIONSHIP, - transport=transport, - ) - out_r, _ = capsys.readouterr() - assert "asset" in out_r diff --git a/samples/snippets/quickstart_listfeeds.py b/samples/snippets/quickstart_listfeeds.py deleted file mode 100644 index d1dd8a20..00000000 --- a/samples/snippets/quickstart_listfeeds.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - - -import argparse - - -def list_feeds(parent_resource, transport: str = None): - # [START asset_quickstart_list_feeds] - from google.cloud import asset_v1 - - # TODO parent_resource = 'Parent resource you want to list all feeds' - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - response = client.list_feeds(request={"parent": parent_resource}) - print("feeds: {}".format(response.feeds)) - # [END asset_quickstart_list_feeds] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument( - "parent_resource", help="Parent resource you want to list all feeds" - ) - args = parser.parse_args() - list_feeds(args.parent_resource) diff --git a/samples/snippets/quickstart_listfeeds_test.py b/samples/snippets/quickstart_listfeeds_test.py deleted file mode 100644 index c50743f2..00000000 --- a/samples/snippets/quickstart_listfeeds_test.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - -import os -import pytest - -import quickstart_listfeeds - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_list_feeds(transport, capsys): - parent_resource = "projects/{}".format(PROJECT) - quickstart_listfeeds.list_feeds(parent_resource, transport=transport) - out, _ = capsys.readouterr() - assert "feeds" in out diff --git a/samples/snippets/quickstart_searchalliampolicies.py b/samples/snippets/quickstart_searchalliampolicies.py deleted file mode 100644 index ee5d2ee3..00000000 --- a/samples/snippets/quickstart_searchalliampolicies.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2020 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import argparse - - -def search_all_iam_policies(scope, query=None, page_size=None, transport: str = None): - # [START asset_quickstart_search_all_iam_policies] - from google.cloud import asset_v1 - - # TODO scope = 'Scope of the search' - # TODO query = 'Query statement' - # TODO page_size = Size of each result page - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - response = client.search_all_iam_policies( - request={"scope": scope, "query": query, "page_size": page_size} - ) - for policy in response: - print(policy) - break - # [END asset_quickstart_search_all_iam_policies] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument( - "scope", help="The search is limited to the resources within the scope." - ) - parser.add_argument("--query", help="The query statement.") - parser.add_argument( - "--page_size", type=int, help="The page size for search result pagination." - ) - args = parser.parse_args() - search_all_iam_policies(args.scope, args.query, args.page_size) diff --git a/samples/snippets/quickstart_searchalliampolicies_test.py b/samples/snippets/quickstart_searchalliampolicies_test.py deleted file mode 100644 index c33b120e..00000000 --- a/samples/snippets/quickstart_searchalliampolicies_test.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2020 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import pytest - -import quickstart_searchalliampolicies - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_search_all_iam_policies(transport, capsys): - scope = "projects/{}".format(PROJECT) - query = "policy:roles/owner" - quickstart_searchalliampolicies.search_all_iam_policies( - scope=scope, query=query, transport=transport - ) - out, _ = capsys.readouterr() - assert "roles/owner" in out diff --git a/samples/snippets/quickstart_searchallresources.py b/samples/snippets/quickstart_searchallresources.py deleted file mode 100644 index c595ea08..00000000 --- a/samples/snippets/quickstart_searchallresources.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2020 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import argparse -from typing import List - -from google.cloud.asset_v1 import ContentType - - -def search_all_resources( - scope: str, - query: str = None, - asset_types: List[ContentType] = None, - page_size: int = None, - order_by: List[str] = None, - transport: str = None, -): - # [START asset_quickstart_search_all_resources] - from google.cloud import asset_v1 - - # TODO scope = 'Scope of the search' - # TODO query = 'Query statement' - # TODO asset_types = 'List of asset types to search for' - # TODO page_size = Size of each result page - # TODO order_by = 'Fields to sort the results' - # TODO transport= 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - response = client.search_all_resources( - request={ - "scope": scope, - "query": query, - "asset_types": asset_types, - "page_size": page_size, - "order_by": order_by, - } - ) - for resource in response: - print(resource) - break - # [END asset_quickstart_search_all_resources] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument( - "scope", help="The search is limited to the resources within the scope." - ) - parser.add_argument("--query", help="The query statement.") - parser.add_argument( - "--asset_types", nargs="+", help="A list of asset types to search for." - ) - parser.add_argument( - "--page_size", type=int, help="The page size for search result pagination." - ) - parser.add_argument( - "--order_by", help="Fields specifying the sorting order of the results." - ) - args = parser.parse_args() - search_all_resources( - args.scope, args.query, args.asset_types, args.page_size, args.order_by - ) diff --git a/samples/snippets/quickstart_searchallresources_test.py b/samples/snippets/quickstart_searchallresources_test.py deleted file mode 100644 index 02098c30..00000000 --- a/samples/snippets/quickstart_searchallresources_test.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2020 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import uuid - -import backoff -from google.api_core.exceptions import NotFound -from google.cloud import bigquery -import pytest - -import quickstart_searchallresources - -PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] -DATASET = "dataset_{}".format(uuid.uuid4().hex) - - -@pytest.fixture(scope="module") -def bigquery_client(): - yield bigquery.Client() - - -@pytest.fixture(scope="module") -def asset_dataset(bigquery_client): - dataset = bigquery_client.create_dataset(DATASET) - - yield DATASET - - try: - bigquery_client.delete_dataset(dataset) - except NotFound as e: - print("Failed to delete dataset {}".format(DATASET)) - raise e - - -@pytest.mark.flaky(max_runs=3, min_passes=1) -def test_search_all_resources(asset_dataset, capsys): - scope = "projects/{}".format(PROJECT) - query = "name:{}".format(DATASET) - - # Dataset creation takes some time to propagate, so the dataset is not - # immediately searchable. Need some time before the snippet will pass. - @backoff.on_exception(backoff.expo, (AssertionError), max_time=240) - def eventually_consistent_test(): - quickstart_searchallresources.search_all_resources( - scope=scope, query=query, transport="grpc" - ) - out, _ = capsys.readouterr() - - assert DATASET in out - - eventually_consistent_test() diff --git a/samples/snippets/quickstart_update_saved_query.py b/samples/snippets/quickstart_update_saved_query.py deleted file mode 100644 index 028a6b70..00000000 --- a/samples/snippets/quickstart_update_saved_query.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - - -import argparse - - -def update_saved_query(saved_query_name: str, description: str, transport: str = None): - """ - Args: - saved_query_name(str): SavedQuery Name you want to update - description(str): New description - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - # [START asset_quickstart_update_saved_query] - from google.cloud import asset_v1 - from google.protobuf import field_mask_pb2 - - # TODO saved_query_name = 'SavedQuery Name you want to update' - # TODO description = "New description' - # TODO transport = 'The transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - saved_query = asset_v1.SavedQuery() - saved_query.name = saved_query_name - saved_query.description = description - update_mask = field_mask_pb2.FieldMask() - # In this example, we only update description of the saved_query. - # You can update other content of the saved query. - update_mask.paths.append("description") - response = client.update_saved_query( - request={"saved_query": saved_query, "update_mask": update_mask} - ) - print(f"updated_saved_query: {response}") - # [END asset_quickstart_update_saved_query] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("saved_query_name", help="SavedQuery Name you want to update") - parser.add_argument("description", help="The description you want to update with") - args = parser.parse_args() - update_saved_query(args.saved_query_name, args.description) diff --git a/samples/snippets/quickstart_update_saved_query_test.py b/samples/snippets/quickstart_update_saved_query_test.py deleted file mode 100644 index 360a4cc5..00000000 --- a/samples/snippets/quickstart_update_saved_query_test.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2022 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. - -import pytest - -import quickstart_update_saved_query - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_update_saved_query(transport, capsys, test_saved_query): - quickstart_update_saved_query.update_saved_query( - saved_query_name=test_saved_query.name, description="bar", transport=transport - ) - out, _ = capsys.readouterr() - - assert "updated_saved_query" in out diff --git a/samples/snippets/quickstart_updatefeed.py b/samples/snippets/quickstart_updatefeed.py deleted file mode 100644 index c20496fc..00000000 --- a/samples/snippets/quickstart_updatefeed.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - - -import argparse - - -def update_feed(feed_name: str, topic: str, transport: str = None): - """ - Args: - feed_name(str): Feed Name you want to update - topic(str): Topic name you want to update with - transport(str): The transport to use. For example, "grpc" - or "rest". If set to None, a transport is chosen automatically. - """ - # [START asset_quickstart_update_feed] - from google.cloud import asset_v1 - from google.protobuf import field_mask_pb2 - - # TODO feed_name = 'Feed Name you want to update' - # TODO topic = "Topic name you want to update with" - # TODO transport = 'Transport to use. Either "grpc" or "rest"' - - client = asset_v1.AssetServiceClient(transport=transport) - feed = asset_v1.Feed() - feed.name = feed_name - feed.feed_output_config.pubsub_destination.topic = topic - update_mask = field_mask_pb2.FieldMask() - # In this example, we update topic of the feed - update_mask.paths.append("feed_output_config.pubsub_destination.topic") - response = client.update_feed(request={"feed": feed, "update_mask": update_mask}) - print("updated_feed: {}".format(response)) - # [END asset_quickstart_update_feed] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter - ) - parser.add_argument("feed_name", help="Feed Name you want to update") - parser.add_argument("topic", help="Topic name you want to update with") - args = parser.parse_args() - update_feed(args.feed_name, args.topic) diff --git a/samples/snippets/quickstart_updatefeed_test.py b/samples/snippets/quickstart_updatefeed_test.py deleted file mode 100644 index d910c329..00000000 --- a/samples/snippets/quickstart_updatefeed_test.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - -import pytest - -import quickstart_updatefeed - - -@pytest.mark.parametrize("transport", ["grpc", "rest"]) -def test_update_feed(transport, capsys, test_feed, another_topic): - quickstart_updatefeed.update_feed( - feed_name=test_feed.name, - topic=another_topic.name, - transport=transport, - ) - out, _ = capsys.readouterr() - - assert "updated_feed" in out diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt deleted file mode 100644 index bd8239eb..00000000 --- a/samples/snippets/requirements-test.txt +++ /dev/null @@ -1,3 +0,0 @@ -backoff==2.2.1 -flaky==3.7.0 -pytest==7.2.2 diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt deleted file mode 100644 index 34920f45..00000000 --- a/samples/snippets/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -google-cloud-storage==2.7.0 -google-cloud-asset==3.18.0 -google-cloud-resource-manager==1.9.0 -google-cloud-pubsub==2.15.0 -google-cloud-bigquery==3.6.0 From caf3792f6fba42db3a31408537e5572b618f9f78 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 09:54:38 -0400 Subject: [PATCH 3/3] chore(main): release 3.19.0 (#562) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- .release-please-manifest.json | 2 +- CHANGELOG.md | 9 +++++++++ google/cloud/asset/gapic_version.py | 2 +- google/cloud/asset_v1/gapic_version.py | 2 +- google/cloud/asset_v1p1beta1/gapic_version.py | 2 +- google/cloud/asset_v1p2beta1/gapic_version.py | 2 +- google/cloud/asset_v1p4beta1/gapic_version.py | 2 +- google/cloud/asset_v1p5beta1/gapic_version.py | 2 +- .../snippet_metadata_google.cloud.asset.v1.json | 2 +- .../snippet_metadata_google.cloud.asset.v1p1beta1.json | 2 +- .../snippet_metadata_google.cloud.asset.v1p2beta1.json | 2 +- .../snippet_metadata_google.cloud.asset.v1p5beta1.json | 2 +- 12 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6499a6af..60a50ee6 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "3.18.1" + ".": "3.19.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index edfafe1b..a584362a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ [1]: https://pypi.org/project/google-cloud-asset/#history +## [3.19.0](https://github.com/googleapis/python-asset/compare/v3.18.1...v3.19.0) (2023-04-01) + + +### Features + +* Add support for AnalyzeOrgPolicies API ([00dcd06](https://github.com/googleapis/python-asset/commit/00dcd068b0a08425f981c8b6b7a7f8d79f931504)) +* Add support for AnalyzeOrgPolicyGovernedAssets API ([00dcd06](https://github.com/googleapis/python-asset/commit/00dcd068b0a08425f981c8b6b7a7f8d79f931504)) +* Add support for AnalyzeOrgPolicyGovernedContainers API ([00dcd06](https://github.com/googleapis/python-asset/commit/00dcd068b0a08425f981c8b6b7a7f8d79f931504)) + ## [3.18.1](https://github.com/googleapis/python-asset/compare/v3.18.0...v3.18.1) (2023-03-24) diff --git a/google/cloud/asset/gapic_version.py b/google/cloud/asset/gapic_version.py index 6ee02bdd..4e343f66 100644 --- a/google/cloud/asset/gapic_version.py +++ b/google/cloud/asset/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "3.18.1" # {x-release-please-version} +__version__ = "3.19.0" # {x-release-please-version} diff --git a/google/cloud/asset_v1/gapic_version.py b/google/cloud/asset_v1/gapic_version.py index 6ee02bdd..4e343f66 100644 --- a/google/cloud/asset_v1/gapic_version.py +++ b/google/cloud/asset_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "3.18.1" # {x-release-please-version} +__version__ = "3.19.0" # {x-release-please-version} diff --git a/google/cloud/asset_v1p1beta1/gapic_version.py b/google/cloud/asset_v1p1beta1/gapic_version.py index 6ee02bdd..4e343f66 100644 --- a/google/cloud/asset_v1p1beta1/gapic_version.py +++ b/google/cloud/asset_v1p1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "3.18.1" # {x-release-please-version} +__version__ = "3.19.0" # {x-release-please-version} diff --git a/google/cloud/asset_v1p2beta1/gapic_version.py b/google/cloud/asset_v1p2beta1/gapic_version.py index 6ee02bdd..4e343f66 100644 --- a/google/cloud/asset_v1p2beta1/gapic_version.py +++ b/google/cloud/asset_v1p2beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "3.18.1" # {x-release-please-version} +__version__ = "3.19.0" # {x-release-please-version} diff --git a/google/cloud/asset_v1p4beta1/gapic_version.py b/google/cloud/asset_v1p4beta1/gapic_version.py index 6ee02bdd..4e343f66 100644 --- a/google/cloud/asset_v1p4beta1/gapic_version.py +++ b/google/cloud/asset_v1p4beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "3.18.1" # {x-release-please-version} +__version__ = "3.19.0" # {x-release-please-version} diff --git a/google/cloud/asset_v1p5beta1/gapic_version.py b/google/cloud/asset_v1p5beta1/gapic_version.py index 6ee02bdd..4e343f66 100644 --- a/google/cloud/asset_v1p5beta1/gapic_version.py +++ b/google/cloud/asset_v1p5beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "3.18.1" # {x-release-please-version} +__version__ = "3.19.0" # {x-release-please-version} diff --git a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1.json b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1.json index 5a90dfa8..e5f891ab 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-asset", - "version": "0.1.0" + "version": "3.19.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p1beta1.json b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p1beta1.json index dcbeb822..636cbe45 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p1beta1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-asset", - "version": "0.1.0" + "version": "3.19.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p2beta1.json b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p2beta1.json index 38eaede8..4506ea37 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p2beta1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p2beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-asset", - "version": "0.1.0" + "version": "3.19.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p5beta1.json b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p5beta1.json index 13ffc229..eabd0c73 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p5beta1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.asset.v1p5beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-asset", - "version": "0.1.0" + "version": "3.19.0" }, "snippets": [ {