From 6472a2d563c9071cfa1bea577786f2292963cc20 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 11 Oct 2021 21:42:11 +0200 Subject: [PATCH 01/19] chore(deps): update dependency google-cloud-securitycenter to v1.7.0 (#237) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-securitycenter](https://togithub.com/googleapis/python-securitycenter) | `==1.6.0` -> `==1.7.0` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-securitycenter/1.7.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-securitycenter/1.7.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-securitycenter/1.7.0/compatibility-slim/1.6.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-securitycenter/1.7.0/confidence-slim/1.6.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-securitycenter ### [`v1.7.0`](https://togithub.com/googleapis/python-securitycenter/blob/master/CHANGELOG.md#​170-httpswwwgithubcomgoogleapispython-securitycentercomparev160v170-2021-10-08) [Compare Source](https://togithub.com/googleapis/python-securitycenter/compare/v1.6.0...v1.7.0) ##### Features - Added type field to the resource which is surfaced in NotificationMessage ([a233f7a](https://www.github.com/googleapis/python-securitycenter/commit/a233f7a0d85ba1a2932a1ee8305e48eda5aafa75)) - Added vulnerability field to Finding ([#​235](https://www.togithub.com/googleapis/python-securitycenter/issues/235)) ([a233f7a](https://www.github.com/googleapis/python-securitycenter/commit/a233f7a0d85ba1a2932a1ee8305e48eda5aafa75))
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-securitycenter). --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 0f2be554..994b0b5f 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ google-cloud-pubsub==2.8.0 -google-cloud-securitycenter==1.6.0 \ No newline at end of file +google-cloud-securitycenter==1.7.0 \ No newline at end of file From ac857bfdb489348b7769548956a3d08820c72382 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 25 Oct 2021 17:49:19 -0400 Subject: [PATCH 02/19] chore(python): push cloud library docs to staging bucket for Cloud RAD (#240) Source-Link: https://github.com/googleapis/synthtool/commit/7fd61f8efae782a7cfcecc599faf52f9737fe584 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:4ee57a76a176ede9087c14330c625a71553cf9c72828b2c0ca12f5338171ba60 Co-authored-by: Owl Bot --- .github/.OwlBot.lock.yaml | 2 +- .kokoro/docs/common.cfg | 1 + noxfile.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 7d98291c..108063d4 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:58f73ba196b5414782605236dd0712a73541b44ff2ff4d3a36ec41092dd6fa5b + digest: sha256:4ee57a76a176ede9087c14330c625a71553cf9c72828b2c0ca12f5338171ba60 diff --git a/.kokoro/docs/common.cfg b/.kokoro/docs/common.cfg index 2b6c6e51..8420ed19 100644 --- a/.kokoro/docs/common.cfg +++ b/.kokoro/docs/common.cfg @@ -30,6 +30,7 @@ env_vars: { env_vars: { key: "V2_STAGING_BUCKET" + # Push google cloud library docs to the Cloud RAD bucket `docs-staging-v2` value: "docs-staging-v2" } diff --git a/noxfile.py b/noxfile.py index 672b28d6..f041f1f5 100644 --- a/noxfile.py +++ b/noxfile.py @@ -101,7 +101,7 @@ def default(session): "py.test", "--quiet", f"--junitxml=unit_{session.python}_sponge_log.xml", - "--cov=google/cloud", + "--cov=google", "--cov=tests/unit", "--cov-append", "--cov-config=.coveragerc", From d477b96c4de26adc282b41c16240fe0e38689320 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 1 Nov 2021 11:33:59 -0400 Subject: [PATCH 03/19] fix: fix extras_require typo in setup.py (#242) --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 731c6f7d..08df2507 100644 --- a/setup.py +++ b/setup.py @@ -75,7 +75,7 @@ packages=packages, namespace_packages=namespaces, install_requires=dependencies, - extras_requires=extras, + extras_require=extras, python_requires=">=3.6", scripts=[ "scripts/fixup_securitycenter_v1_keywords.py", From 718652639dafd4121391c642d55d9347c66bf5cb Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 5 Nov 2021 07:21:03 -0400 Subject: [PATCH 04/19] feat: add support for python 3.10 (#238) * feat: add support for python 3.10 * ci: opt in to use multiple projects --- samples/snippets/noxfile_config.py | 1 + setup.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/samples/snippets/noxfile_config.py b/samples/snippets/noxfile_config.py index 8e6ed132..daf5c43a 100644 --- a/samples/snippets/noxfile_config.py +++ b/samples/snippets/noxfile_config.py @@ -28,6 +28,7 @@ # 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/setup.py b/setup.py index 08df2507..0c269586 100644 --- a/setup.py +++ b/setup.py @@ -68,6 +68,8 @@ "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Operating System :: OS Independent", "Topic :: Internet", ], From f28a8fe8a3732e327543255475cef997ffbfaba9 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 9 Nov 2021 11:24:11 +0000 Subject: [PATCH 05/19] feat: Added resource type and display_name field to the FindingResult (#248) ...and supported them in the filter for ListFindings and GroupFindings. - [ ] Regenerate this pull request now. PiperOrigin-RevId: 408362247 Source-Link: https://github.com/googleapis/googleapis/commit/4d71c45d9ed0bc82d0c76064fda6937985e0938f Source-Link: https://github.com/googleapis/googleapis-gen/commit/058c44989ddba953aa1cc674866242a8677fe33a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMDU4YzQ0OTg5ZGRiYTk1M2FhMWNjNjc0ODY2MjQyYTg2NzdmZTMzYSJ9 docs: list oneofs in docstring fix(deps): require google-api-core >= 1.28.0 fix(deps): drop packaging dependency feat: add display_name to the resource which is surfaced in NotificationMessage --- .../services/security_center/async_client.py | 156 ++++++++++-------- .../services/security_center/client.py | 48 +++--- .../security_center/transports/base.py | 37 +---- .../security_center/transports/grpc.py | 2 +- .../transports/grpc_asyncio.py | 3 +- .../types/notification_config.py | 4 + .../types/notification_message.py | 3 + .../cloud/securitycenter_v1/types/resource.py | 3 + .../types/securitycenter_service.py | 7 + .../services/security_center/async_client.py | 116 +++++++------ .../services/security_center/client.py | 38 +++-- .../security_center/transports/base.py | 37 +---- .../security_center/transports/grpc.py | 2 +- .../transports/grpc_asyncio.py | 3 +- .../services/security_center/async_client.py | 156 ++++++++++-------- .../services/security_center/client.py | 48 +++--- .../security_center/transports/base.py | 37 +---- .../security_center/transports/grpc.py | 2 +- .../transports/grpc_asyncio.py | 3 +- .../types/notification_config.py | 4 + .../types/notification_message.py | 3 + setup.py | 3 +- testing/constraints-3.6.txt | 4 +- .../securitycenter_v1/test_security_center.py | 91 +--------- .../test_security_center.py | 91 +--------- .../test_security_center.py | 91 +--------- 26 files changed, 368 insertions(+), 624 deletions(-) diff --git a/google/cloud/securitycenter_v1/services/security_center/async_client.py b/google/cloud/securitycenter_v1/services/security_center/async_client.py index ec6ffd95..abdcf3e8 100644 --- a/google/cloud/securitycenter_v1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1/services/security_center/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.securitycenter_v1.services.security_center import pagers @@ -209,18 +211,18 @@ def __init__( async def create_source( self, - request: securitycenter_service.CreateSourceRequest = None, + request: Union[securitycenter_service.CreateSourceRequest, dict] = None, *, parent: str = None, source: gcs_source.Source = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: r"""Creates a source. Args: - request (:class:`google.cloud.securitycenter_v1.types.CreateSourceRequest`): + request (Union[google.cloud.securitycenter_v1.types.CreateSourceRequest, dict]): The request object. Request message for creating a source. parent (:class:`str`): @@ -295,12 +297,12 @@ async def create_source( async def create_finding( self, - request: securitycenter_service.CreateFindingRequest = None, + request: Union[securitycenter_service.CreateFindingRequest, dict] = None, *, parent: str = None, finding_id: str = None, finding: gcs_finding.Finding = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -308,7 +310,7 @@ async def create_finding( exist for finding creation to succeed. Args: - request (:class:`google.cloud.securitycenter_v1.types.CreateFindingRequest`): + request (Union[google.cloud.securitycenter_v1.types.CreateFindingRequest, dict]): The request object. Request message for creating a finding. parent (:class:`str`): @@ -399,19 +401,21 @@ async def create_finding( async def create_notification_config( self, - request: securitycenter_service.CreateNotificationConfigRequest = None, + request: Union[ + securitycenter_service.CreateNotificationConfigRequest, dict + ] = None, *, parent: str = None, config_id: str = None, notification_config: gcs_notification_config.NotificationConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_notification_config.NotificationConfig: r"""Creates a notification config. Args: - request (:class:`google.cloud.securitycenter_v1.types.CreateNotificationConfigRequest`): + request (Union[google.cloud.securitycenter_v1.types.CreateNotificationConfigRequest, dict]): The request object. Request message for creating a notification config. parent (:class:`str`): @@ -500,17 +504,19 @@ async def create_notification_config( async def delete_notification_config( self, - request: securitycenter_service.DeleteNotificationConfigRequest = None, + request: Union[ + securitycenter_service.DeleteNotificationConfigRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a notification config. Args: - request (:class:`google.cloud.securitycenter_v1.types.DeleteNotificationConfigRequest`): + request (Union[google.cloud.securitycenter_v1.types.DeleteNotificationConfigRequest, dict]): The request object. Request message for deleting a notification config. name (:class:`str`): @@ -565,10 +571,10 @@ async def delete_notification_config( async def get_iam_policy( self, - request: iam_policy_pb2.GetIamPolicyRequest = None, + request: Union[iam_policy_pb2.GetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -576,7 +582,7 @@ async def get_iam_policy( Source. Args: - request (:class:`google.iam.v1.iam_policy_pb2.GetIamPolicyRequest`): + request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): The request object. Request message for `GetIamPolicy` method. resource (:class:`str`): @@ -702,17 +708,19 @@ async def get_iam_policy( async def get_notification_config( self, - request: securitycenter_service.GetNotificationConfigRequest = None, + request: Union[ + securitycenter_service.GetNotificationConfigRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> notification_config.NotificationConfig: r"""Gets a notification config. Args: - request (:class:`google.cloud.securitycenter_v1.types.GetNotificationConfigRequest`): + request (Union[google.cloud.securitycenter_v1.types.GetNotificationConfigRequest, dict]): The request object. Request message for getting a notification config. name (:class:`str`): @@ -788,17 +796,19 @@ async def get_notification_config( async def get_organization_settings( self, - request: securitycenter_service.GetOrganizationSettingsRequest = None, + request: Union[ + securitycenter_service.GetOrganizationSettingsRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> organization_settings.OrganizationSettings: r"""Gets the settings for an organization. Args: - request (:class:`google.cloud.securitycenter_v1.types.GetOrganizationSettingsRequest`): + request (Union[google.cloud.securitycenter_v1.types.GetOrganizationSettingsRequest, dict]): The request object. Request message for getting organization settings. name (:class:`str`): @@ -871,17 +881,17 @@ async def get_organization_settings( async def get_source( self, - request: securitycenter_service.GetSourceRequest = None, + request: Union[securitycenter_service.GetSourceRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> source.Source: r"""Gets a source. Args: - request (:class:`google.cloud.securitycenter_v1.types.GetSourceRequest`): + request (Union[google.cloud.securitycenter_v1.types.GetSourceRequest, dict]): The request object. Request message for getting a source. name (:class:`str`): @@ -957,9 +967,9 @@ async def get_source( async def group_assets( self, - request: securitycenter_service.GroupAssetsRequest = None, + request: Union[securitycenter_service.GroupAssetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupAssetsAsyncPager: @@ -967,7 +977,7 @@ async def group_assets( their specified properties. Args: - request (:class:`google.cloud.securitycenter_v1.types.GroupAssetsRequest`): + request (Union[google.cloud.securitycenter_v1.types.GroupAssetsRequest, dict]): The request object. Request message for grouping by assets. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1026,11 +1036,11 @@ async def group_assets( async def group_findings( self, - request: securitycenter_service.GroupFindingsRequest = None, + request: Union[securitycenter_service.GroupFindingsRequest, dict] = None, *, parent: str = None, group_by: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupFindingsAsyncPager: @@ -1043,7 +1053,7 @@ async def group_findings( /v1/projects/{project_id}/sources/-/findings Args: - request (:class:`google.cloud.securitycenter_v1.types.GroupFindingsRequest`): + request (Union[google.cloud.securitycenter_v1.types.GroupFindingsRequest, dict]): The request object. Request message for grouping by findings. parent (:class:`str`): @@ -1153,16 +1163,16 @@ async def group_findings( async def list_assets( self, - request: securitycenter_service.ListAssetsRequest = None, + request: Union[securitycenter_service.ListAssetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAssetsAsyncPager: r"""Lists an organization's assets. Args: - request (:class:`google.cloud.securitycenter_v1.types.ListAssetsRequest`): + request (Union[google.cloud.securitycenter_v1.types.ListAssetsRequest, dict]): The request object. Request message for listing assets. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -1219,9 +1229,9 @@ async def list_assets( async def list_findings( self, - request: securitycenter_service.ListFindingsRequest = None, + request: Union[securitycenter_service.ListFindingsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFindingsAsyncPager: @@ -1231,7 +1241,7 @@ async def list_findings( Example: /v1/organizations/{organization_id}/sources/-/findings Args: - request (:class:`google.cloud.securitycenter_v1.types.ListFindingsRequest`): + request (Union[google.cloud.securitycenter_v1.types.ListFindingsRequest, dict]): The request object. Request message for listing findings. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1290,17 +1300,19 @@ async def list_findings( async def list_notification_configs( self, - request: securitycenter_service.ListNotificationConfigsRequest = None, + request: Union[ + securitycenter_service.ListNotificationConfigsRequest, dict + ] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListNotificationConfigsAsyncPager: r"""Lists notification configs. Args: - request (:class:`google.cloud.securitycenter_v1.types.ListNotificationConfigsRequest`): + request (Union[google.cloud.securitycenter_v1.types.ListNotificationConfigsRequest, dict]): The request object. Request message for listing notification configs. parent (:class:`str`): @@ -1381,17 +1393,17 @@ async def list_notification_configs( async def list_sources( self, - request: securitycenter_service.ListSourcesRequest = None, + request: Union[securitycenter_service.ListSourcesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSourcesAsyncPager: r"""Lists all sources belonging to an organization. Args: - request (:class:`google.cloud.securitycenter_v1.types.ListSourcesRequest`): + request (Union[google.cloud.securitycenter_v1.types.ListSourcesRequest, dict]): The request object. Request message for listing sources. parent (:class:`str`): Required. Resource name of the parent of sources to @@ -1471,10 +1483,10 @@ async def list_sources( async def run_asset_discovery( self, - request: securitycenter_service.RunAssetDiscoveryRequest = None, + request: Union[securitycenter_service.RunAssetDiscoveryRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1486,7 +1498,7 @@ async def run_asset_discovery( receive a TOO_MANY_REQUESTS error. Args: - request (:class:`google.cloud.securitycenter_v1.types.RunAssetDiscoveryRequest`): + request (Union[google.cloud.securitycenter_v1.types.RunAssetDiscoveryRequest, dict]): The request object. Request message for running asset discovery for an organization. parent (:class:`str`): @@ -1559,19 +1571,19 @@ async def run_asset_discovery( async def set_finding_state( self, - request: securitycenter_service.SetFindingStateRequest = None, + request: Union[securitycenter_service.SetFindingStateRequest, dict] = None, *, name: str = None, state: finding.Finding.State = None, start_time: timestamp_pb2.Timestamp = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> finding.Finding: r"""Updates the state of a finding. Args: - request (:class:`google.cloud.securitycenter_v1.types.SetFindingStateRequest`): + request (Union[google.cloud.securitycenter_v1.types.SetFindingStateRequest, dict]): The request object. Request message for updating a finding's state. name (:class:`str`): @@ -1660,10 +1672,10 @@ async def set_finding_state( async def set_iam_policy( self, - request: iam_policy_pb2.SetIamPolicyRequest = None, + request: Union[iam_policy_pb2.SetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1671,7 +1683,7 @@ async def set_iam_policy( Source. Args: - request (:class:`google.iam.v1.iam_policy_pb2.SetIamPolicyRequest`): + request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): The request object. Request message for `SetIamPolicy` method. resource (:class:`str`): @@ -1787,11 +1799,11 @@ async def set_iam_policy( async def test_iam_permissions( self, - request: iam_policy_pb2.TestIamPermissionsRequest = None, + request: Union[iam_policy_pb2.TestIamPermissionsRequest, dict] = None, *, resource: str = None, permissions: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: @@ -1799,7 +1811,7 @@ async def test_iam_permissions( specified source. Args: - request (:class:`google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest`): + request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): The request object. Request message for `TestIamPermissions` method. resource (:class:`str`): @@ -1881,10 +1893,10 @@ async def test_iam_permissions( async def update_finding( self, - request: securitycenter_service.UpdateFindingRequest = None, + request: Union[securitycenter_service.UpdateFindingRequest, dict] = None, *, finding: gcs_finding.Finding = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -1892,7 +1904,7 @@ async def update_finding( source must exist for a finding creation to succeed. Args: - request (:class:`google.cloud.securitycenter_v1.types.UpdateFindingRequest`): + request (Union[google.cloud.securitycenter_v1.types.UpdateFindingRequest, dict]): The request object. Request message for updating or creating a finding. finding (:class:`google.cloud.securitycenter_v1.types.Finding`): @@ -1967,11 +1979,13 @@ async def update_finding( async def update_notification_config( self, - request: securitycenter_service.UpdateNotificationConfigRequest = None, + request: Union[ + securitycenter_service.UpdateNotificationConfigRequest, dict + ] = None, *, notification_config: gcs_notification_config.NotificationConfig = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_notification_config.NotificationConfig: @@ -1979,7 +1993,7 @@ async def update_notification_config( allowed: description, pubsub_topic, streaming_config.filter Args: - request (:class:`google.cloud.securitycenter_v1.types.UpdateNotificationConfigRequest`): + request (Union[google.cloud.securitycenter_v1.types.UpdateNotificationConfigRequest, dict]): The request object. Request message for updating a notification config. notification_config (:class:`google.cloud.securitycenter_v1.types.NotificationConfig`): @@ -2057,17 +2071,19 @@ async def update_notification_config( async def update_organization_settings( self, - request: securitycenter_service.UpdateOrganizationSettingsRequest = None, + request: Union[ + securitycenter_service.UpdateOrganizationSettingsRequest, dict + ] = None, *, organization_settings: gcs_organization_settings.OrganizationSettings = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_organization_settings.OrganizationSettings: r"""Updates an organization's settings. Args: - request (:class:`google.cloud.securitycenter_v1.types.UpdateOrganizationSettingsRequest`): + request (Union[google.cloud.securitycenter_v1.types.UpdateOrganizationSettingsRequest, dict]): The request object. Request message for updating an organization's settings. organization_settings (:class:`google.cloud.securitycenter_v1.types.OrganizationSettings`): @@ -2131,17 +2147,17 @@ async def update_organization_settings( async def update_source( self, - request: securitycenter_service.UpdateSourceRequest = None, + request: Union[securitycenter_service.UpdateSourceRequest, dict] = None, *, source: gcs_source.Source = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: r"""Updates a source. Args: - request (:class:`google.cloud.securitycenter_v1.types.UpdateSourceRequest`): + request (Union[google.cloud.securitycenter_v1.types.UpdateSourceRequest, dict]): The request object. Request message for updating a source. source (:class:`google.cloud.securitycenter_v1.types.Source`): @@ -2208,17 +2224,17 @@ async def update_source( async def update_security_marks( self, - request: securitycenter_service.UpdateSecurityMarksRequest = None, + request: Union[securitycenter_service.UpdateSecurityMarksRequest, dict] = None, *, security_marks: gcs_security_marks.SecurityMarks = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_security_marks.SecurityMarks: r"""Updates security marks. Args: - request (:class:`google.cloud.securitycenter_v1.types.UpdateSecurityMarksRequest`): + request (Union[google.cloud.securitycenter_v1.types.UpdateSecurityMarksRequest, dict]): The request object. Request message for updating a SecurityMarks resource. security_marks (:class:`google.cloud.securitycenter_v1.types.SecurityMarks`): diff --git a/google/cloud/securitycenter_v1/services/security_center/client.py b/google/cloud/securitycenter_v1/services/security_center/client.py index 5e7c6216..8cf8848a 100644 --- a/google/cloud/securitycenter_v1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1/services/security_center/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.securitycenter_v1.services.security_center import pagers @@ -465,7 +467,7 @@ def create_source( *, parent: str = None, source: gcs_source.Source = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: @@ -552,7 +554,7 @@ def create_finding( parent: str = None, finding_id: str = None, finding: gcs_finding.Finding = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -658,7 +660,7 @@ def create_notification_config( parent: str = None, config_id: str = None, notification_config: gcs_notification_config.NotificationConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_notification_config.NotificationConfig: @@ -763,7 +765,7 @@ def delete_notification_config( ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -832,7 +834,7 @@ def get_iam_policy( request: Union[iam_policy_pb2.GetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -960,7 +962,7 @@ def get_notification_config( ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> notification_config.NotificationConfig: @@ -1038,7 +1040,7 @@ def get_organization_settings( ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> organization_settings.OrganizationSettings: @@ -1115,7 +1117,7 @@ def get_source( request: Union[securitycenter_service.GetSourceRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> source.Source: @@ -1190,7 +1192,7 @@ def group_assets( self, request: Union[securitycenter_service.GroupAssetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupAssetsPager: @@ -1252,7 +1254,7 @@ def group_findings( *, parent: str = None, group_by: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupFindingsPager: @@ -1367,7 +1369,7 @@ def list_assets( self, request: Union[securitycenter_service.ListAssetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAssetsPager: @@ -1424,7 +1426,7 @@ def list_findings( self, request: Union[securitycenter_service.ListFindingsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFindingsPager: @@ -1489,7 +1491,7 @@ def list_notification_configs( ] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListNotificationConfigsPager: @@ -1574,7 +1576,7 @@ def list_sources( request: Union[securitycenter_service.ListSourcesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSourcesPager: @@ -1654,7 +1656,7 @@ def run_asset_discovery( request: Union[securitycenter_service.RunAssetDiscoveryRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1744,7 +1746,7 @@ def set_finding_state( name: str = None, state: finding.Finding.State = None, start_time: timestamp_pb2.Timestamp = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> finding.Finding: @@ -1843,7 +1845,7 @@ def set_iam_policy( request: Union[iam_policy_pb2.SetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1970,7 +1972,7 @@ def test_iam_permissions( *, resource: str = None, permissions: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: @@ -2052,7 +2054,7 @@ def update_finding( request: Union[securitycenter_service.UpdateFindingRequest, dict] = None, *, finding: gcs_finding.Finding = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -2141,7 +2143,7 @@ def update_notification_config( *, notification_config: gcs_notification_config.NotificationConfig = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_notification_config.NotificationConfig: @@ -2236,7 +2238,7 @@ def update_organization_settings( ] = None, *, organization_settings: gcs_organization_settings.OrganizationSettings = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_organization_settings.OrganizationSettings: @@ -2314,7 +2316,7 @@ def update_source( request: Union[securitycenter_service.UpdateSourceRequest, dict] = None, *, source: gcs_source.Source = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: @@ -2391,7 +2393,7 @@ def update_security_marks( request: Union[securitycenter_service.UpdateSecurityMarksRequest, dict] = None, *, security_marks: gcs_security_marks.SecurityMarks = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_security_marks.SecurityMarks: diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1/services/security_center/transports/base.py index 78032152..591078b6 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -55,15 +54,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class SecurityCenterTransport(abc.ABC): """Abstract transport class for SecurityCenter.""" @@ -113,7 +103,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -146,29 +136,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -395,7 +362,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py index 78767185..89a4bd1b 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py @@ -128,7 +128,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py index e5cc5011..b1ccfbdd 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -175,7 +174,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/securitycenter_v1/types/notification_config.py b/google/cloud/securitycenter_v1/types/notification_config.py index 921a6854..b418cf26 100644 --- a/google/cloud/securitycenter_v1/types/notification_config.py +++ b/google/cloud/securitycenter_v1/types/notification_config.py @@ -28,6 +28,9 @@ class NotificationConfig(proto.Message): configuration to send notifications for create/update events of findings, assets and etc. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): The relative resource name of this notification config. See: @@ -47,6 +50,7 @@ class NotificationConfig(proto.Message): streaming_config (google.cloud.securitycenter_v1.types.NotificationConfig.StreamingConfig): The config for triggering streaming-based notifications. + This field is a member of `oneof`_ ``notify_config``. """ class StreamingConfig(proto.Message): diff --git a/google/cloud/securitycenter_v1/types/notification_message.py b/google/cloud/securitycenter_v1/types/notification_message.py index d63c2606..05faa567 100644 --- a/google/cloud/securitycenter_v1/types/notification_message.py +++ b/google/cloud/securitycenter_v1/types/notification_message.py @@ -27,6 +27,8 @@ class NotificationMessage(proto.Message): r"""Cloud SCC's Notification + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: notification_config_name (str): Name of the notification config that @@ -34,6 +36,7 @@ class NotificationMessage(proto.Message): finding (google.cloud.securitycenter_v1.types.Finding): If it's a Finding based notification config, this field will be populated. + This field is a member of `oneof`_ ``event``. resource (google.cloud.securitycenter_v1.types.Resource): The Cloud resource tied to this notification's Finding. diff --git a/google/cloud/securitycenter_v1/types/resource.py b/google/cloud/securitycenter_v1/types/resource.py index b1b58044..38aa4d02 100644 --- a/google/cloud/securitycenter_v1/types/resource.py +++ b/google/cloud/securitycenter_v1/types/resource.py @@ -48,6 +48,8 @@ class Resource(proto.Message): folder is the deepest nested folder, and the last folder is the folder directly under the Organization. + display_name (str): + The human readable name of the resource. """ name = proto.Field(proto.STRING, number=1,) @@ -57,6 +59,7 @@ class Resource(proto.Message): parent_display_name = proto.Field(proto.STRING, number=5,) type_ = proto.Field(proto.STRING, number=6,) folders = proto.RepeatedField(proto.MESSAGE, number=7, message=folder.Folder,) + display_name = proto.Field(proto.STRING, number=8,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/securitycenter_v1/types/securitycenter_service.py b/google/cloud/securitycenter_v1/types/securitycenter_service.py index 9f14b1c4..7dbbd37d 100644 --- a/google/cloud/securitycenter_v1/types/securitycenter_service.py +++ b/google/cloud/securitycenter_v1/types/securitycenter_service.py @@ -1023,6 +1023,7 @@ class ListFindingsRequest(proto.Message): - resource.project_display_name: ``=``, ``:`` - resource.type: ``=``, ``:`` - resource.folders.resource_folder: ``=``, ``:`` + - resource.display_name: ``=``, ``:`` order_by (str): Expression that defines what fields and order to use for sorting. The string value should follow SQL syntax: comma @@ -1169,11 +1170,15 @@ class Resource(proto.Message): The full resource name of resource's parent. parent_display_name (str): The human readable name of resource's parent. + type_ (str): + The full resource type of the resource. folders (Sequence[google.cloud.securitycenter_v1.types.Folder]): Contains a Folder message for each folder in the assets ancestry. The first folder is the deepest nested folder, and the last folder is the folder directly under the Organization. + display_name (str): + The human readable name of the resource. """ name = proto.Field(proto.STRING, number=1,) @@ -1181,9 +1186,11 @@ class Resource(proto.Message): project_display_name = proto.Field(proto.STRING, number=3,) parent_name = proto.Field(proto.STRING, number=4,) parent_display_name = proto.Field(proto.STRING, number=5,) + type_ = proto.Field(proto.STRING, number=6,) folders = proto.RepeatedField( proto.MESSAGE, number=7, message=folder.Folder, ) + display_name = proto.Field(proto.STRING, number=8,) finding = proto.Field(proto.MESSAGE, number=1, message=gcs_finding.Finding,) state_change = proto.Field( diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py b/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py index 6da78690..210980bb 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.securitycenter_v1beta1.services.security_center import pagers @@ -195,18 +197,18 @@ def __init__( async def create_source( self, - request: securitycenter_service.CreateSourceRequest = None, + request: Union[securitycenter_service.CreateSourceRequest, dict] = None, *, parent: str = None, source: gcs_source.Source = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: r"""Creates a source. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.CreateSourceRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.CreateSourceRequest, dict]): The request object. Request message for creating a source. parent (:class:`str`): @@ -281,12 +283,12 @@ async def create_source( async def create_finding( self, - request: securitycenter_service.CreateFindingRequest = None, + request: Union[securitycenter_service.CreateFindingRequest, dict] = None, *, parent: str = None, finding_id: str = None, finding: gcs_finding.Finding = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -294,7 +296,7 @@ async def create_finding( exist for finding creation to succeed. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.CreateFindingRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.CreateFindingRequest, dict]): The request object. Request message for creating a finding. parent (:class:`str`): @@ -385,10 +387,10 @@ async def create_finding( async def get_iam_policy( self, - request: iam_policy_pb2.GetIamPolicyRequest = None, + request: Union[iam_policy_pb2.GetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -396,7 +398,7 @@ async def get_iam_policy( Source. Args: - request (:class:`google.iam.v1.iam_policy_pb2.GetIamPolicyRequest`): + request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): The request object. Request message for `GetIamPolicy` method. resource (:class:`str`): @@ -522,17 +524,19 @@ async def get_iam_policy( async def get_organization_settings( self, - request: securitycenter_service.GetOrganizationSettingsRequest = None, + request: Union[ + securitycenter_service.GetOrganizationSettingsRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> organization_settings.OrganizationSettings: r"""Gets the settings for an organization. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.GetOrganizationSettingsRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.GetOrganizationSettingsRequest, dict]): The request object. Request message for getting organization settings. name (:class:`str`): @@ -605,17 +609,17 @@ async def get_organization_settings( async def get_source( self, - request: securitycenter_service.GetSourceRequest = None, + request: Union[securitycenter_service.GetSourceRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> source.Source: r"""Gets a source. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.GetSourceRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.GetSourceRequest, dict]): The request object. Request message for getting a source. name (:class:`str`): @@ -691,9 +695,9 @@ async def get_source( async def group_assets( self, - request: securitycenter_service.GroupAssetsRequest = None, + request: Union[securitycenter_service.GroupAssetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupAssetsAsyncPager: @@ -701,7 +705,7 @@ async def group_assets( their specified properties. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.GroupAssetsRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.GroupAssetsRequest, dict]): The request object. Request message for grouping by assets. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -760,11 +764,11 @@ async def group_assets( async def group_findings( self, - request: securitycenter_service.GroupFindingsRequest = None, + request: Union[securitycenter_service.GroupFindingsRequest, dict] = None, *, parent: str = None, group_by: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupFindingsAsyncPager: @@ -776,7 +780,7 @@ async def group_findings( /v1beta1/organizations/{organization_id}/sources/-/findings Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.GroupFindingsRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.GroupFindingsRequest, dict]): The request object. Request message for grouping by findings. parent (:class:`str`): @@ -877,16 +881,16 @@ async def group_findings( async def list_assets( self, - request: securitycenter_service.ListAssetsRequest = None, + request: Union[securitycenter_service.ListAssetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAssetsAsyncPager: r"""Lists an organization's assets. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.ListAssetsRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.ListAssetsRequest, dict]): The request object. Request message for listing assets. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -943,9 +947,9 @@ async def list_assets( async def list_findings( self, - request: securitycenter_service.ListFindingsRequest = None, + request: Union[securitycenter_service.ListFindingsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFindingsAsyncPager: @@ -956,7 +960,7 @@ async def list_findings( /v1beta1/organizations/{organization_id}/sources/-/findings Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.ListFindingsRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.ListFindingsRequest, dict]): The request object. Request message for listing findings. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1015,17 +1019,17 @@ async def list_findings( async def list_sources( self, - request: securitycenter_service.ListSourcesRequest = None, + request: Union[securitycenter_service.ListSourcesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSourcesAsyncPager: r"""Lists all sources belonging to an organization. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.ListSourcesRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.ListSourcesRequest, dict]): The request object. Request message for listing sources. parent (:class:`str`): Required. Resource name of the parent of sources to @@ -1104,10 +1108,10 @@ async def list_sources( async def run_asset_discovery( self, - request: securitycenter_service.RunAssetDiscoveryRequest = None, + request: Union[securitycenter_service.RunAssetDiscoveryRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1119,7 +1123,7 @@ async def run_asset_discovery( receive a TOO_MANY_REQUESTS error. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.RunAssetDiscoveryRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.RunAssetDiscoveryRequest, dict]): The request object. Request message for running asset discovery for an organization. parent (:class:`str`): @@ -1202,19 +1206,19 @@ async def run_asset_discovery( async def set_finding_state( self, - request: securitycenter_service.SetFindingStateRequest = None, + request: Union[securitycenter_service.SetFindingStateRequest, dict] = None, *, name: str = None, state: finding.Finding.State = None, start_time: timestamp_pb2.Timestamp = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> finding.Finding: r"""Updates the state of a finding. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.SetFindingStateRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.SetFindingStateRequest, dict]): The request object. Request message for updating a finding's state. name (:class:`str`): @@ -1303,10 +1307,10 @@ async def set_finding_state( async def set_iam_policy( self, - request: iam_policy_pb2.SetIamPolicyRequest = None, + request: Union[iam_policy_pb2.SetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1314,7 +1318,7 @@ async def set_iam_policy( Source. Args: - request (:class:`google.iam.v1.iam_policy_pb2.SetIamPolicyRequest`): + request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): The request object. Request message for `SetIamPolicy` method. resource (:class:`str`): @@ -1430,11 +1434,11 @@ async def set_iam_policy( async def test_iam_permissions( self, - request: iam_policy_pb2.TestIamPermissionsRequest = None, + request: Union[iam_policy_pb2.TestIamPermissionsRequest, dict] = None, *, resource: str = None, permissions: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: @@ -1442,7 +1446,7 @@ async def test_iam_permissions( specified source. Args: - request (:class:`google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest`): + request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): The request object. Request message for `TestIamPermissions` method. resource (:class:`str`): @@ -1524,10 +1528,10 @@ async def test_iam_permissions( async def update_finding( self, - request: securitycenter_service.UpdateFindingRequest = None, + request: Union[securitycenter_service.UpdateFindingRequest, dict] = None, *, finding: gcs_finding.Finding = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -1535,7 +1539,7 @@ async def update_finding( source must exist for a finding creation to succeed. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.UpdateFindingRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.UpdateFindingRequest, dict]): The request object. Request message for updating or creating a finding. finding (:class:`google.cloud.securitycenter_v1beta1.types.Finding`): @@ -1610,17 +1614,19 @@ async def update_finding( async def update_organization_settings( self, - request: securitycenter_service.UpdateOrganizationSettingsRequest = None, + request: Union[ + securitycenter_service.UpdateOrganizationSettingsRequest, dict + ] = None, *, organization_settings: gcs_organization_settings.OrganizationSettings = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_organization_settings.OrganizationSettings: r"""Updates an organization's settings. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.UpdateOrganizationSettingsRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.UpdateOrganizationSettingsRequest, dict]): The request object. Request message for updating an organization's settings. organization_settings (:class:`google.cloud.securitycenter_v1beta1.types.OrganizationSettings`): @@ -1684,17 +1690,17 @@ async def update_organization_settings( async def update_source( self, - request: securitycenter_service.UpdateSourceRequest = None, + request: Union[securitycenter_service.UpdateSourceRequest, dict] = None, *, source: gcs_source.Source = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: r"""Updates a source. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.UpdateSourceRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.UpdateSourceRequest, dict]): The request object. Request message for updating a source. source (:class:`google.cloud.securitycenter_v1beta1.types.Source`): @@ -1761,17 +1767,17 @@ async def update_source( async def update_security_marks( self, - request: securitycenter_service.UpdateSecurityMarksRequest = None, + request: Union[securitycenter_service.UpdateSecurityMarksRequest, dict] = None, *, security_marks: gcs_security_marks.SecurityMarks = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_security_marks.SecurityMarks: r"""Updates security marks. Args: - request (:class:`google.cloud.securitycenter_v1beta1.types.UpdateSecurityMarksRequest`): + request (Union[google.cloud.securitycenter_v1beta1.types.UpdateSecurityMarksRequest, dict]): The request object. Request message for updating a SecurityMarks resource. security_marks (:class:`google.cloud.securitycenter_v1beta1.types.SecurityMarks`): diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/client.py b/google/cloud/securitycenter_v1beta1/services/security_center/client.py index e9317e89..a04ad549 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.securitycenter_v1beta1.services.security_center import pagers @@ -432,7 +434,7 @@ def create_source( *, parent: str = None, source: gcs_source.Source = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: @@ -519,7 +521,7 @@ def create_finding( parent: str = None, finding_id: str = None, finding: gcs_finding.Finding = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -621,7 +623,7 @@ def get_iam_policy( request: Union[iam_policy_pb2.GetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -749,7 +751,7 @@ def get_organization_settings( ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> organization_settings.OrganizationSettings: @@ -826,7 +828,7 @@ def get_source( request: Union[securitycenter_service.GetSourceRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> source.Source: @@ -901,7 +903,7 @@ def group_assets( self, request: Union[securitycenter_service.GroupAssetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupAssetsPager: @@ -963,7 +965,7 @@ def group_findings( *, parent: str = None, group_by: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupFindingsPager: @@ -1068,7 +1070,7 @@ def list_assets( self, request: Union[securitycenter_service.ListAssetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAssetsPager: @@ -1125,7 +1127,7 @@ def list_findings( self, request: Union[securitycenter_service.ListFindingsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFindingsPager: @@ -1189,7 +1191,7 @@ def list_sources( request: Union[securitycenter_service.ListSourcesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSourcesPager: @@ -1268,7 +1270,7 @@ def run_asset_discovery( request: Union[securitycenter_service.RunAssetDiscoveryRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1368,7 +1370,7 @@ def set_finding_state( name: str = None, state: finding.Finding.State = None, start_time: timestamp_pb2.Timestamp = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> finding.Finding: @@ -1467,7 +1469,7 @@ def set_iam_policy( request: Union[iam_policy_pb2.SetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1594,7 +1596,7 @@ def test_iam_permissions( *, resource: str = None, permissions: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: @@ -1676,7 +1678,7 @@ def update_finding( request: Union[securitycenter_service.UpdateFindingRequest, dict] = None, *, finding: gcs_finding.Finding = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -1764,7 +1766,7 @@ def update_organization_settings( ] = None, *, organization_settings: gcs_organization_settings.OrganizationSettings = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_organization_settings.OrganizationSettings: @@ -1842,7 +1844,7 @@ def update_source( request: Union[securitycenter_service.UpdateSourceRequest, dict] = None, *, source: gcs_source.Source = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: @@ -1919,7 +1921,7 @@ def update_security_marks( request: Union[securitycenter_service.UpdateSecurityMarksRequest, dict] = None, *, security_marks: gcs_security_marks.SecurityMarks = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_security_marks.SecurityMarks: diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py index 06fe9815..427b2ed4 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -52,15 +51,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class SecurityCenterTransport(abc.ABC): """Abstract transport class for SecurityCenter.""" @@ -110,7 +100,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -143,29 +133,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -347,7 +314,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py index 816497c0..7e36de4f 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py @@ -125,7 +125,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py index 70547c00..25fb565a 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -172,7 +171,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py index f906a8b7..d00b4f58 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.securitycenter_v1p1beta1.services.security_center import pagers @@ -209,18 +211,18 @@ def __init__( async def create_source( self, - request: securitycenter_service.CreateSourceRequest = None, + request: Union[securitycenter_service.CreateSourceRequest, dict] = None, *, parent: str = None, source: gcs_source.Source = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: r"""Creates a source. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.CreateSourceRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.CreateSourceRequest, dict]): The request object. Request message for creating a source. parent (:class:`str`): @@ -295,12 +297,12 @@ async def create_source( async def create_finding( self, - request: securitycenter_service.CreateFindingRequest = None, + request: Union[securitycenter_service.CreateFindingRequest, dict] = None, *, parent: str = None, finding_id: str = None, finding: gcs_finding.Finding = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -308,7 +310,7 @@ async def create_finding( exist for finding creation to succeed. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.CreateFindingRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.CreateFindingRequest, dict]): The request object. Request message for creating a finding. parent (:class:`str`): @@ -396,19 +398,21 @@ async def create_finding( async def create_notification_config( self, - request: securitycenter_service.CreateNotificationConfigRequest = None, + request: Union[ + securitycenter_service.CreateNotificationConfigRequest, dict + ] = None, *, parent: str = None, config_id: str = None, notification_config: gcs_notification_config.NotificationConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_notification_config.NotificationConfig: r"""Creates a notification config. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.CreateNotificationConfigRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.CreateNotificationConfigRequest, dict]): The request object. Request message for creating a notification config. parent (:class:`str`): @@ -497,17 +501,19 @@ async def create_notification_config( async def delete_notification_config( self, - request: securitycenter_service.DeleteNotificationConfigRequest = None, + request: Union[ + securitycenter_service.DeleteNotificationConfigRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a notification config. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.DeleteNotificationConfigRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.DeleteNotificationConfigRequest, dict]): The request object. Request message for deleting a notification config. name (:class:`str`): @@ -562,10 +568,10 @@ async def delete_notification_config( async def get_iam_policy( self, - request: iam_policy_pb2.GetIamPolicyRequest = None, + request: Union[iam_policy_pb2.GetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -573,7 +579,7 @@ async def get_iam_policy( Source. Args: - request (:class:`google.iam.v1.iam_policy_pb2.GetIamPolicyRequest`): + request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): The request object. Request message for `GetIamPolicy` method. resource (:class:`str`): @@ -699,17 +705,19 @@ async def get_iam_policy( async def get_notification_config( self, - request: securitycenter_service.GetNotificationConfigRequest = None, + request: Union[ + securitycenter_service.GetNotificationConfigRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> notification_config.NotificationConfig: r"""Gets a notification config. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.GetNotificationConfigRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.GetNotificationConfigRequest, dict]): The request object. Request message for getting a notification config. name (:class:`str`): @@ -786,17 +794,19 @@ async def get_notification_config( async def get_organization_settings( self, - request: securitycenter_service.GetOrganizationSettingsRequest = None, + request: Union[ + securitycenter_service.GetOrganizationSettingsRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> organization_settings.OrganizationSettings: r"""Gets the settings for an organization. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.GetOrganizationSettingsRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.GetOrganizationSettingsRequest, dict]): The request object. Request message for getting organization settings. name (:class:`str`): @@ -869,17 +879,17 @@ async def get_organization_settings( async def get_source( self, - request: securitycenter_service.GetSourceRequest = None, + request: Union[securitycenter_service.GetSourceRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> source.Source: r"""Gets a source. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.GetSourceRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.GetSourceRequest, dict]): The request object. Request message for getting a source. name (:class:`str`): @@ -955,9 +965,9 @@ async def get_source( async def group_assets( self, - request: securitycenter_service.GroupAssetsRequest = None, + request: Union[securitycenter_service.GroupAssetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupAssetsAsyncPager: @@ -965,7 +975,7 @@ async def group_assets( their specified properties. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.GroupAssetsRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.GroupAssetsRequest, dict]): The request object. Request message for grouping by assets. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1024,11 +1034,11 @@ async def group_assets( async def group_findings( self, - request: securitycenter_service.GroupFindingsRequest = None, + request: Union[securitycenter_service.GroupFindingsRequest, dict] = None, *, parent: str = None, group_by: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupFindingsAsyncPager: @@ -1041,7 +1051,7 @@ async def group_findings( /v1/projects/{project_id}/sources/-/findings Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.GroupFindingsRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.GroupFindingsRequest, dict]): The request object. Request message for grouping by findings. parent (:class:`str`): @@ -1151,17 +1161,17 @@ async def group_findings( async def list_assets( self, - request: securitycenter_service.ListAssetsRequest = None, + request: Union[securitycenter_service.ListAssetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAssetsAsyncPager: r"""Lists an organization's assets. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.ListAssetsRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.ListAssetsRequest, dict]): The request object. Request message for listing assets. parent (:class:`str`): Required. Name of the organization assets should belong @@ -1240,10 +1250,10 @@ async def list_assets( async def list_findings( self, - request: securitycenter_service.ListFindingsRequest = None, + request: Union[securitycenter_service.ListFindingsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFindingsAsyncPager: @@ -1254,7 +1264,7 @@ async def list_findings( /v1p1beta1/organizations/{organization_id}/sources/-/findings Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.ListFindingsRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.ListFindingsRequest, dict]): The request object. Request message for listing findings. parent (:class:`str`): @@ -1341,17 +1351,19 @@ async def list_findings( async def list_notification_configs( self, - request: securitycenter_service.ListNotificationConfigsRequest = None, + request: Union[ + securitycenter_service.ListNotificationConfigsRequest, dict + ] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListNotificationConfigsAsyncPager: r"""Lists notification configs. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.ListNotificationConfigsRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.ListNotificationConfigsRequest, dict]): The request object. Request message for listing notification configs. parent (:class:`str`): @@ -1432,17 +1444,17 @@ async def list_notification_configs( async def list_sources( self, - request: securitycenter_service.ListSourcesRequest = None, + request: Union[securitycenter_service.ListSourcesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSourcesAsyncPager: r"""Lists all sources belonging to an organization. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.ListSourcesRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.ListSourcesRequest, dict]): The request object. Request message for listing sources. parent (:class:`str`): Required. Resource name of the parent of sources to @@ -1522,10 +1534,10 @@ async def list_sources( async def run_asset_discovery( self, - request: securitycenter_service.RunAssetDiscoveryRequest = None, + request: Union[securitycenter_service.RunAssetDiscoveryRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1537,7 +1549,7 @@ async def run_asset_discovery( receive a TOO_MANY_REQUESTS error. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.RunAssetDiscoveryRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.RunAssetDiscoveryRequest, dict]): The request object. Request message for running asset discovery for an organization. parent (:class:`str`): @@ -1610,19 +1622,19 @@ async def run_asset_discovery( async def set_finding_state( self, - request: securitycenter_service.SetFindingStateRequest = None, + request: Union[securitycenter_service.SetFindingStateRequest, dict] = None, *, name: str = None, state: finding.Finding.State = None, start_time: timestamp_pb2.Timestamp = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> finding.Finding: r"""Updates the state of a finding. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.SetFindingStateRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.SetFindingStateRequest, dict]): The request object. Request message for updating a finding's state. name (:class:`str`): @@ -1711,10 +1723,10 @@ async def set_finding_state( async def set_iam_policy( self, - request: iam_policy_pb2.SetIamPolicyRequest = None, + request: Union[iam_policy_pb2.SetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1722,7 +1734,7 @@ async def set_iam_policy( Source. Args: - request (:class:`google.iam.v1.iam_policy_pb2.SetIamPolicyRequest`): + request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): The request object. Request message for `SetIamPolicy` method. resource (:class:`str`): @@ -1838,11 +1850,11 @@ async def set_iam_policy( async def test_iam_permissions( self, - request: iam_policy_pb2.TestIamPermissionsRequest = None, + request: Union[iam_policy_pb2.TestIamPermissionsRequest, dict] = None, *, resource: str = None, permissions: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: @@ -1850,7 +1862,7 @@ async def test_iam_permissions( specified source. Args: - request (:class:`google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest`): + request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): The request object. Request message for `TestIamPermissions` method. resource (:class:`str`): @@ -1932,11 +1944,11 @@ async def test_iam_permissions( async def update_finding( self, - request: securitycenter_service.UpdateFindingRequest = None, + request: Union[securitycenter_service.UpdateFindingRequest, dict] = None, *, finding: gcs_finding.Finding = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -1944,7 +1956,7 @@ async def update_finding( source must exist for a finding creation to succeed. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.UpdateFindingRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.UpdateFindingRequest, dict]): The request object. Request message for updating or creating a finding. finding (:class:`google.cloud.securitycenter_v1p1beta1.types.Finding`): @@ -2035,11 +2047,13 @@ async def update_finding( async def update_notification_config( self, - request: securitycenter_service.UpdateNotificationConfigRequest = None, + request: Union[ + securitycenter_service.UpdateNotificationConfigRequest, dict + ] = None, *, notification_config: gcs_notification_config.NotificationConfig = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_notification_config.NotificationConfig: @@ -2047,7 +2061,7 @@ async def update_notification_config( allowed: description, pubsub_topic, streaming_config.filter Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.UpdateNotificationConfigRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.UpdateNotificationConfigRequest, dict]): The request object. Request message for updating a notification config. notification_config (:class:`google.cloud.securitycenter_v1p1beta1.types.NotificationConfig`): @@ -2126,17 +2140,19 @@ async def update_notification_config( async def update_organization_settings( self, - request: securitycenter_service.UpdateOrganizationSettingsRequest = None, + request: Union[ + securitycenter_service.UpdateOrganizationSettingsRequest, dict + ] = None, *, organization_settings: gcs_organization_settings.OrganizationSettings = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_organization_settings.OrganizationSettings: r"""Updates an organization's settings. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.UpdateOrganizationSettingsRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.UpdateOrganizationSettingsRequest, dict]): The request object. Request message for updating an organization's settings. organization_settings (:class:`google.cloud.securitycenter_v1p1beta1.types.OrganizationSettings`): @@ -2200,18 +2216,18 @@ async def update_organization_settings( async def update_source( self, - request: securitycenter_service.UpdateSourceRequest = None, + request: Union[securitycenter_service.UpdateSourceRequest, dict] = None, *, source: gcs_source.Source = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: r"""Updates a source. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.UpdateSourceRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.UpdateSourceRequest, dict]): The request object. Request message for updating a source. source (:class:`google.cloud.securitycenter_v1p1beta1.types.Source`): @@ -2289,18 +2305,18 @@ async def update_source( async def update_security_marks( self, - request: securitycenter_service.UpdateSecurityMarksRequest = None, + request: Union[securitycenter_service.UpdateSecurityMarksRequest, dict] = None, *, security_marks: gcs_security_marks.SecurityMarks = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_security_marks.SecurityMarks: r"""Updates security marks. Args: - request (:class:`google.cloud.securitycenter_v1p1beta1.types.UpdateSecurityMarksRequest`): + request (Union[google.cloud.securitycenter_v1p1beta1.types.UpdateSecurityMarksRequest, dict]): The request object. Request message for updating a SecurityMarks resource. security_marks (:class:`google.cloud.securitycenter_v1p1beta1.types.SecurityMarks`): diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py index cd4b4be0..31496f5c 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.securitycenter_v1p1beta1.services.security_center import pagers @@ -465,7 +467,7 @@ def create_source( *, parent: str = None, source: gcs_source.Source = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: @@ -552,7 +554,7 @@ def create_finding( parent: str = None, finding_id: str = None, finding: gcs_finding.Finding = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -655,7 +657,7 @@ def create_notification_config( parent: str = None, config_id: str = None, notification_config: gcs_notification_config.NotificationConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_notification_config.NotificationConfig: @@ -760,7 +762,7 @@ def delete_notification_config( ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -829,7 +831,7 @@ def get_iam_policy( request: Union[iam_policy_pb2.GetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -957,7 +959,7 @@ def get_notification_config( ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> notification_config.NotificationConfig: @@ -1036,7 +1038,7 @@ def get_organization_settings( ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> organization_settings.OrganizationSettings: @@ -1113,7 +1115,7 @@ def get_source( request: Union[securitycenter_service.GetSourceRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> source.Source: @@ -1188,7 +1190,7 @@ def group_assets( self, request: Union[securitycenter_service.GroupAssetsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupAssetsPager: @@ -1250,7 +1252,7 @@ def group_findings( *, parent: str = None, group_by: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.GroupFindingsPager: @@ -1366,7 +1368,7 @@ def list_assets( request: Union[securitycenter_service.ListAssetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAssetsPager: @@ -1445,7 +1447,7 @@ def list_findings( request: Union[securitycenter_service.ListFindingsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFindingsPager: @@ -1538,7 +1540,7 @@ def list_notification_configs( ] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListNotificationConfigsPager: @@ -1623,7 +1625,7 @@ def list_sources( request: Union[securitycenter_service.ListSourcesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSourcesPager: @@ -1703,7 +1705,7 @@ def run_asset_discovery( request: Union[securitycenter_service.RunAssetDiscoveryRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1793,7 +1795,7 @@ def set_finding_state( name: str = None, state: finding.Finding.State = None, start_time: timestamp_pb2.Timestamp = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> finding.Finding: @@ -1892,7 +1894,7 @@ def set_iam_policy( request: Union[iam_policy_pb2.SetIamPolicyRequest, dict] = None, *, resource: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -2019,7 +2021,7 @@ def test_iam_permissions( *, resource: str = None, permissions: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: @@ -2102,7 +2104,7 @@ def update_finding( *, finding: gcs_finding.Finding = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_finding.Finding: @@ -2207,7 +2209,7 @@ def update_notification_config( *, notification_config: gcs_notification_config.NotificationConfig = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_notification_config.NotificationConfig: @@ -2303,7 +2305,7 @@ def update_organization_settings( ] = None, *, organization_settings: gcs_organization_settings.OrganizationSettings = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_organization_settings.OrganizationSettings: @@ -2382,7 +2384,7 @@ def update_source( *, source: gcs_source.Source = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_source.Source: @@ -2471,7 +2473,7 @@ def update_security_marks( *, security_marks: gcs_security_marks.SecurityMarks = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcs_security_marks.SecurityMarks: diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py index 2e0ba33f..3a58cab6 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -57,15 +56,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class SecurityCenterTransport(abc.ABC): """Abstract transport class for SecurityCenter.""" @@ -115,7 +105,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -148,29 +138,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -397,7 +364,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py index fcec5523..6922e230 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py @@ -130,7 +130,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py index 8ffec364..951c44e7 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -177,7 +176,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/securitycenter_v1p1beta1/types/notification_config.py b/google/cloud/securitycenter_v1p1beta1/types/notification_config.py index f9f720a8..955af043 100644 --- a/google/cloud/securitycenter_v1p1beta1/types/notification_config.py +++ b/google/cloud/securitycenter_v1p1beta1/types/notification_config.py @@ -27,6 +27,9 @@ class NotificationConfig(proto.Message): contains the configuration to send notifications for create/update events of findings, assets and etc. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): The relative resource name of this notification config. See: @@ -49,6 +52,7 @@ class NotificationConfig(proto.Message): streaming_config (google.cloud.securitycenter_v1p1beta1.types.NotificationConfig.StreamingConfig): The config for triggering streaming-based notifications. + This field is a member of `oneof`_ ``notify_config``. """ class EventType(proto.Enum): diff --git a/google/cloud/securitycenter_v1p1beta1/types/notification_message.py b/google/cloud/securitycenter_v1p1beta1/types/notification_message.py index ca4d470e..2e0e16e2 100644 --- a/google/cloud/securitycenter_v1p1beta1/types/notification_message.py +++ b/google/cloud/securitycenter_v1p1beta1/types/notification_message.py @@ -27,6 +27,8 @@ class NotificationMessage(proto.Message): r"""Security Command Center's Notification + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: notification_config_name (str): Name of the notification config that @@ -34,6 +36,7 @@ class NotificationMessage(proto.Message): finding (google.cloud.securitycenter_v1p1beta1.types.Finding): If it's a Finding based notification config, this field will be populated. + This field is a member of `oneof`_ ``event``. resource (google.cloud.securitycenter_v1p1beta1.types.Resource): The Cloud resource tied to the notification. """ diff --git a/setup.py b/setup.py index 0c269586..20cdbe83 100644 --- a/setup.py +++ b/setup.py @@ -27,10 +27,9 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", "grpc-google-iam-v1 >= 0.12.3, < 0.13dev", "proto-plus >= 1.10.0", - "packaging >= 14.3", ] extras = {"libcst": "libcst >= 0.2.5"} diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index a10f570b..02028c8a 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,9 +5,7 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 grpc-google-iam-v1==0.12.3 proto-plus==1.10.0 libcst==0.2.5 -packaging==14.3 -google-auth==1.24.0 # TODO: Remove when google-auth >= 1.25.0 is transitively required through google-api-core diff --git a/tests/unit/gapic/securitycenter_v1/test_security_center.py b/tests/unit/gapic/securitycenter_v1/test_security_center.py index 54222717..f85a6757 100644 --- a/tests/unit/gapic/securitycenter_v1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1/test_security_center.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -41,9 +40,6 @@ from google.cloud.securitycenter_v1.services.security_center import SecurityCenterClient from google.cloud.securitycenter_v1.services.security_center import pagers from google.cloud.securitycenter_v1.services.security_center import transports -from google.cloud.securitycenter_v1.services.security_center.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import indicator @@ -75,20 +71,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -245,7 +227,7 @@ def test_security_center_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -262,7 +244,7 @@ def test_security_center_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -279,7 +261,7 @@ def test_security_center_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -308,7 +290,7 @@ def test_security_center_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -367,7 +349,7 @@ def test_security_center_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -409,7 +391,7 @@ def test_security_center_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -431,7 +413,7 @@ def test_security_center_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -462,7 +444,7 @@ def test_security_center_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -493,7 +475,7 @@ def test_security_center_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -6742,7 +6724,6 @@ def test_security_center_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_security_center_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -6763,26 +6744,6 @@ def test_security_center_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_security_center_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.securitycenter_v1.services.security_center.transports.SecurityCenterTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SecurityCenterTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_security_center_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -6794,7 +6755,6 @@ def test_security_center_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_security_center_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -6807,18 +6767,6 @@ def test_security_center_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_security_center_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - SecurityCenterClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -6826,7 +6774,6 @@ def test_security_center_auth_adc_old_google_auth(): transports.SecurityCenterGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_security_center_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -6840,26 +6787,6 @@ def test_security_center_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.SecurityCenterGrpcTransport, - transports.SecurityCenterGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_security_center_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py b/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py index c9da493d..80a707ad 100644 --- a/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -43,9 +42,6 @@ ) from google.cloud.securitycenter_v1beta1.services.security_center import pagers from google.cloud.securitycenter_v1beta1.services.security_center import transports -from google.cloud.securitycenter_v1beta1.services.security_center.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.securitycenter_v1beta1.types import finding from google.cloud.securitycenter_v1beta1.types import finding as gcs_finding from google.cloud.securitycenter_v1beta1.types import organization_settings @@ -72,20 +68,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -242,7 +224,7 @@ def test_security_center_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -259,7 +241,7 @@ def test_security_center_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -276,7 +258,7 @@ def test_security_center_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -305,7 +287,7 @@ def test_security_center_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -364,7 +346,7 @@ def test_security_center_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -406,7 +388,7 @@ def test_security_center_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -428,7 +410,7 @@ def test_security_center_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -459,7 +441,7 @@ def test_security_center_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -490,7 +472,7 @@ def test_security_center_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -5239,7 +5221,6 @@ def test_security_center_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_security_center_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -5260,26 +5241,6 @@ def test_security_center_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_security_center_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.securitycenter_v1beta1.services.security_center.transports.SecurityCenterTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SecurityCenterTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_security_center_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -5291,7 +5252,6 @@ def test_security_center_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_security_center_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -5304,18 +5264,6 @@ def test_security_center_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_security_center_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - SecurityCenterClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -5323,7 +5271,6 @@ def test_security_center_auth_adc_old_google_auth(): transports.SecurityCenterGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_security_center_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -5337,26 +5284,6 @@ def test_security_center_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.SecurityCenterGrpcTransport, - transports.SecurityCenterGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_security_center_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py b/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py index 7e3c717f..0641cd18 100644 --- a/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -43,9 +42,6 @@ ) from google.cloud.securitycenter_v1p1beta1.services.security_center import pagers from google.cloud.securitycenter_v1p1beta1.services.security_center import transports -from google.cloud.securitycenter_v1p1beta1.services.security_center.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.securitycenter_v1p1beta1.types import finding from google.cloud.securitycenter_v1p1beta1.types import finding as gcs_finding from google.cloud.securitycenter_v1p1beta1.types import notification_config @@ -77,20 +73,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -247,7 +229,7 @@ def test_security_center_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -264,7 +246,7 @@ def test_security_center_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -281,7 +263,7 @@ def test_security_center_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -310,7 +292,7 @@ def test_security_center_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -369,7 +351,7 @@ def test_security_center_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -411,7 +393,7 @@ def test_security_center_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -433,7 +415,7 @@ def test_security_center_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -464,7 +446,7 @@ def test_security_center_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -495,7 +477,7 @@ def test_security_center_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -6918,7 +6900,6 @@ def test_security_center_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_security_center_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -6939,26 +6920,6 @@ def test_security_center_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_security_center_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.securitycenter_v1p1beta1.services.security_center.transports.SecurityCenterTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SecurityCenterTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_security_center_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -6970,7 +6931,6 @@ def test_security_center_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_security_center_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -6983,18 +6943,6 @@ def test_security_center_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_security_center_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - SecurityCenterClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -7002,7 +6950,6 @@ def test_security_center_auth_adc_old_google_auth(): transports.SecurityCenterGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_security_center_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -7016,26 +6963,6 @@ def test_security_center_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.SecurityCenterGrpcTransport, - transports.SecurityCenterGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_security_center_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ From 5acb94645e20520ace749fe8dff7d65262af1b46 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:36:44 -0500 Subject: [PATCH 06/19] chore: use gapic-generator-python 0.56.2 (#249) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: update Java and Python dependencies PiperOrigin-RevId: 408420890 Source-Link: https://github.com/googleapis/googleapis/commit/2921f9fb3bfbd16f6b2da0104373e2b47a80a65e Source-Link: https://github.com/googleapis/googleapis-gen/commit/6598ca8cbbf5226733a099c4506518a5af6ff74c Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNjU5OGNhOGNiYmY1MjI2NzMzYTA5OWM0NTA2NTE4YTVhZjZmZjc0YyJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../services/security_center/async_client.py | 13 +- .../services/security_center/client.py | 25 +- .../security_center/transports/base.py | 10 +- .../security_center/transports/grpc.py | 6 +- .../transports/grpc_asyncio.py | 6 +- .../types/notification_config.py | 1 + .../types/notification_message.py | 1 + .../services/security_center/async_client.py | 13 +- .../services/security_center/client.py | 25 +- .../security_center/transports/base.py | 10 +- .../security_center/transports/grpc.py | 6 +- .../transports/grpc_asyncio.py | 6 +- .../services/security_center/async_client.py | 13 +- .../services/security_center/client.py | 25 +- .../security_center/transports/base.py | 10 +- .../security_center/transports/grpc.py | 6 +- .../transports/grpc_asyncio.py | 6 +- .../types/notification_config.py | 1 + .../types/notification_message.py | 1 + .../securitycenter_v1/test_security_center.py | 260 ++++++++++----- .../test_security_center.py | 180 +++++++---- .../test_security_center.py | 300 ++++++++++++------ 22 files changed, 616 insertions(+), 308 deletions(-) diff --git a/google/cloud/securitycenter_v1/services/security_center/async_client.py b/google/cloud/securitycenter_v1/services/security_center/async_client.py index abdcf3e8..df613923 100644 --- a/google/cloud/securitycenter_v1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1/services/security_center/async_client.py @@ -19,14 +19,17 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore diff --git a/google/cloud/securitycenter_v1/services/security_center/client.py b/google/cloud/securitycenter_v1/services/security_center/client.py index 8cf8848a..6722a340 100644 --- a/google/cloud/securitycenter_v1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1/services/security_center/client.py @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -395,8 +397,15 @@ def __init__( client_options = client_options_lib.ClientOptions() # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( + "true", + "false", + ): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + use_client_cert = ( + os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" ) client_cert_source_func = None diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1/services/security_center/transports/base.py index 591078b6..c2d136f9 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/base.py @@ -18,11 +18,11 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py index 89a4bd1b..ee3d341b 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py index b1ccfbdd..5d756b54 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py @@ -16,9 +16,9 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore diff --git a/google/cloud/securitycenter_v1/types/notification_config.py b/google/cloud/securitycenter_v1/types/notification_config.py index b418cf26..416be74e 100644 --- a/google/cloud/securitycenter_v1/types/notification_config.py +++ b/google/cloud/securitycenter_v1/types/notification_config.py @@ -50,6 +50,7 @@ class NotificationConfig(proto.Message): streaming_config (google.cloud.securitycenter_v1.types.NotificationConfig.StreamingConfig): The config for triggering streaming-based notifications. + This field is a member of `oneof`_ ``notify_config``. """ diff --git a/google/cloud/securitycenter_v1/types/notification_message.py b/google/cloud/securitycenter_v1/types/notification_message.py index 05faa567..5c196a41 100644 --- a/google/cloud/securitycenter_v1/types/notification_message.py +++ b/google/cloud/securitycenter_v1/types/notification_message.py @@ -36,6 +36,7 @@ class NotificationMessage(proto.Message): finding (google.cloud.securitycenter_v1.types.Finding): If it's a Finding based notification config, this field will be populated. + This field is a member of `oneof`_ ``event``. resource (google.cloud.securitycenter_v1.types.Resource): The Cloud resource tied to this diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py b/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py index 210980bb..42802436 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py @@ -19,14 +19,17 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/client.py b/google/cloud/securitycenter_v1beta1/services/security_center/client.py index a04ad549..86603ac3 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/client.py @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -362,8 +364,15 @@ def __init__( client_options = client_options_lib.ClientOptions() # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( + "true", + "false", + ): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + use_client_cert = ( + os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" ) client_cert_source_func = None diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py index 427b2ed4..38abc3d0 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py @@ -18,11 +18,11 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py index 7e36de4f..75366c1c 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py index 25fb565a..2da70f82 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py @@ -16,9 +16,9 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py index d00b4f58..d5495087 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py @@ -19,14 +19,17 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py index 31496f5c..c14b89c2 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -395,8 +397,15 @@ def __init__( client_options = client_options_lib.ClientOptions() # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( + "true", + "false", + ): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + use_client_cert = ( + os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" ) client_cert_source_func = None diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py index 3a58cab6..1913413f 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py @@ -18,11 +18,11 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py index 6922e230..85c22589 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py index 951c44e7..9a73a6f3 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py @@ -16,9 +16,9 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore diff --git a/google/cloud/securitycenter_v1p1beta1/types/notification_config.py b/google/cloud/securitycenter_v1p1beta1/types/notification_config.py index 955af043..b7ff626e 100644 --- a/google/cloud/securitycenter_v1p1beta1/types/notification_config.py +++ b/google/cloud/securitycenter_v1p1beta1/types/notification_config.py @@ -52,6 +52,7 @@ class NotificationConfig(proto.Message): streaming_config (google.cloud.securitycenter_v1p1beta1.types.NotificationConfig.StreamingConfig): The config for triggering streaming-based notifications. + This field is a member of `oneof`_ ``notify_config``. """ diff --git a/google/cloud/securitycenter_v1p1beta1/types/notification_message.py b/google/cloud/securitycenter_v1p1beta1/types/notification_message.py index 2e0e16e2..5b0beec7 100644 --- a/google/cloud/securitycenter_v1p1beta1/types/notification_message.py +++ b/google/cloud/securitycenter_v1p1beta1/types/notification_message.py @@ -36,6 +36,7 @@ class NotificationMessage(proto.Message): finding (google.cloud.securitycenter_v1p1beta1.types.Finding): If it's a Finding based notification config, this field will be populated. + This field is a member of `oneof`_ ``event``. resource (google.cloud.securitycenter_v1p1beta1.types.Resource): The Cloud resource tied to the notification. diff --git a/tests/unit/gapic/securitycenter_v1/test_security_center.py b/tests/unit/gapic/securitycenter_v1/test_security_center.py index f85a6757..19610e18 100644 --- a/tests/unit/gapic/securitycenter_v1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1/test_security_center.py @@ -674,8 +674,12 @@ def test_create_source_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].source == gcs_source.Source(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val def test_create_source_flattened_error(): @@ -713,8 +717,12 @@ async def test_create_source_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].source == gcs_source.Source(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -921,9 +929,15 @@ def test_create_finding_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].finding_id == "finding_id_value" - assert args[0].finding == gcs_finding.Finding(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].finding_id + mock_val = "finding_id_value" + assert arg == mock_val + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val def test_create_finding_flattened_error(): @@ -964,9 +978,15 @@ async def test_create_finding_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].finding_id == "finding_id_value" - assert args[0].finding == gcs_finding.Finding(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].finding_id + mock_val = "finding_id_value" + assert arg == mock_val + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -1174,13 +1194,15 @@ def test_create_notification_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].config_id == "config_id_value" - assert args[ - 0 - ].notification_config == gcs_notification_config.NotificationConfig( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].config_id + mock_val = "config_id_value" + assert arg == mock_val + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") + assert arg == mock_val def test_create_notification_config_flattened_error(): @@ -1229,13 +1251,15 @@ async def test_create_notification_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].config_id == "config_id_value" - assert args[ - 0 - ].notification_config == gcs_notification_config.NotificationConfig( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].config_id + mock_val = "config_id_value" + assert arg == mock_val + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -1414,7 +1438,9 @@ def test_delete_notification_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_notification_config_flattened_error(): @@ -1450,7 +1476,9 @@ async def test_delete_notification_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1631,7 +1659,9 @@ def test_get_iam_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val def test_get_iam_policy_flattened_error(): @@ -1665,7 +1695,9 @@ async def test_get_iam_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1864,7 +1896,9 @@ def test_get_notification_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_notification_config_flattened_error(): @@ -1902,7 +1936,9 @@ async def test_get_notification_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2088,7 +2124,9 @@ def test_get_organization_settings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_organization_settings_flattened_error(): @@ -2126,7 +2164,9 @@ async def test_get_organization_settings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2307,7 +2347,9 @@ def test_get_source_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_source_flattened_error(): @@ -2341,7 +2383,9 @@ async def test_get_source_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2819,8 +2863,12 @@ def test_group_findings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].group_by == "group_by_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].group_by + mock_val = "group_by_value" + assert arg == mock_val def test_group_findings_flattened_error(): @@ -2860,8 +2908,12 @@ async def test_group_findings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].group_by == "group_by_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].group_by + mock_val = "group_by_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3847,7 +3899,9 @@ def test_list_notification_configs_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_notification_configs_flattened_error(): @@ -3886,7 +3940,9 @@ async def test_list_notification_configs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4232,7 +4288,9 @@ def test_list_sources_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_sources_flattened_error(): @@ -4268,7 +4326,9 @@ async def test_list_sources_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4576,7 +4636,9 @@ def test_run_asset_discovery_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_run_asset_discovery_flattened_error(): @@ -4614,7 +4676,9 @@ async def test_run_asset_discovery_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4831,8 +4895,12 @@ def test_set_finding_state_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].state == finding.Finding.State.ACTIVE + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].state + mock_val = finding.Finding.State.ACTIVE + assert arg == mock_val assert TimestampRule().to_proto(args[0].start_time) == timestamp_pb2.Timestamp( seconds=751 ) @@ -4878,8 +4946,12 @@ async def test_set_finding_state_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].state == finding.Finding.State.ACTIVE + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].state + mock_val = finding.Finding.State.ACTIVE + assert arg == mock_val assert TimestampRule().to_proto(args[0].start_time) == timestamp_pb2.Timestamp( seconds=751 ) @@ -5066,7 +5138,9 @@ def test_set_iam_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val def test_set_iam_policy_flattened_error(): @@ -5100,7 +5174,9 @@ async def test_set_iam_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val @pytest.mark.asyncio @@ -5302,8 +5378,12 @@ def test_test_iam_permissions_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" - assert args[0].permissions == ["permissions_value"] + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val + arg = args[0].permissions + mock_val = ["permissions_value"] + assert arg == mock_val def test_test_iam_permissions_flattened_error(): @@ -5345,8 +5425,12 @@ async def test_test_iam_permissions_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" - assert args[0].permissions == ["permissions_value"] + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val + arg = args[0].permissions + mock_val = ["permissions_value"] + assert arg == mock_val @pytest.mark.asyncio @@ -5553,7 +5637,9 @@ def test_update_finding_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].finding == gcs_finding.Finding(name="name_value") + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val def test_update_finding_flattened_error(): @@ -5590,7 +5676,9 @@ async def test_update_finding_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].finding == gcs_finding.Finding(name="name_value") + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -5801,12 +5889,12 @@ def test_update_notification_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].notification_config == gcs_notification_config.NotificationConfig( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_notification_config_flattened_error(): @@ -5853,12 +5941,12 @@ async def test_update_notification_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].notification_config == gcs_notification_config.NotificationConfig( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -6058,11 +6146,9 @@ def test_update_organization_settings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].organization_settings == gcs_organization_settings.OrganizationSettings( - name="name_value" - ) + arg = args[0].organization_settings + mock_val = gcs_organization_settings.OrganizationSettings(name="name_value") + assert arg == mock_val def test_update_organization_settings_flattened_error(): @@ -6107,11 +6193,9 @@ async def test_update_organization_settings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].organization_settings == gcs_organization_settings.OrganizationSettings( - name="name_value" - ) + arg = args[0].organization_settings + mock_val = gcs_organization_settings.OrganizationSettings(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -6295,7 +6379,9 @@ def test_update_source_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].source == gcs_source.Source(name="name_value") + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val def test_update_source_flattened_error(): @@ -6332,7 +6418,9 @@ async def test_update_source_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].source == gcs_source.Source(name="name_value") + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -6527,9 +6615,9 @@ def test_update_security_marks_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].security_marks == gcs_security_marks.SecurityMarks( - name="name_value" - ) + arg = args[0].security_marks + mock_val = gcs_security_marks.SecurityMarks(name="name_value") + assert arg == mock_val def test_update_security_marks_flattened_error(): @@ -6570,9 +6658,9 @@ async def test_update_security_marks_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].security_marks == gcs_security_marks.SecurityMarks( - name="name_value" - ) + arg = args[0].security_marks + mock_val = gcs_security_marks.SecurityMarks(name="name_value") + assert arg == mock_val @pytest.mark.asyncio diff --git a/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py b/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py index 80a707ad..6924631f 100644 --- a/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py @@ -667,8 +667,12 @@ def test_create_source_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].source == gcs_source.Source(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val def test_create_source_flattened_error(): @@ -706,8 +710,12 @@ async def test_create_source_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].source == gcs_source.Source(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -902,9 +910,15 @@ def test_create_finding_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].finding_id == "finding_id_value" - assert args[0].finding == gcs_finding.Finding(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].finding_id + mock_val = "finding_id_value" + assert arg == mock_val + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val def test_create_finding_flattened_error(): @@ -945,9 +959,15 @@ async def test_create_finding_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].finding_id == "finding_id_value" - assert args[0].finding == gcs_finding.Finding(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].finding_id + mock_val = "finding_id_value" + assert arg == mock_val + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -1131,7 +1151,9 @@ def test_get_iam_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val def test_get_iam_policy_flattened_error(): @@ -1165,7 +1187,9 @@ async def test_get_iam_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1351,7 +1375,9 @@ def test_get_organization_settings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_organization_settings_flattened_error(): @@ -1389,7 +1415,9 @@ async def test_get_organization_settings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1566,7 +1594,9 @@ def test_get_source_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_source_flattened_error(): @@ -1600,7 +1630,9 @@ async def test_get_source_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2074,8 +2106,12 @@ def test_group_findings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].group_by == "group_by_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].group_by + mock_val = "group_by_value" + assert arg == mock_val def test_group_findings_flattened_error(): @@ -2115,8 +2151,12 @@ async def test_group_findings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].group_by == "group_by_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].group_by + mock_val = "group_by_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3039,7 +3079,9 @@ def test_list_sources_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_sources_flattened_error(): @@ -3075,7 +3117,9 @@ async def test_list_sources_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3383,7 +3427,9 @@ def test_run_asset_discovery_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_run_asset_discovery_flattened_error(): @@ -3421,7 +3467,9 @@ async def test_run_asset_discovery_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3626,8 +3674,12 @@ def test_set_finding_state_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].state == finding.Finding.State.ACTIVE + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].state + mock_val = finding.Finding.State.ACTIVE + assert arg == mock_val assert TimestampRule().to_proto(args[0].start_time) == timestamp_pb2.Timestamp( seconds=751 ) @@ -3673,8 +3725,12 @@ async def test_set_finding_state_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].state == finding.Finding.State.ACTIVE + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].state + mock_val = finding.Finding.State.ACTIVE + assert arg == mock_val assert TimestampRule().to_proto(args[0].start_time) == timestamp_pb2.Timestamp( seconds=751 ) @@ -3861,7 +3917,9 @@ def test_set_iam_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val def test_set_iam_policy_flattened_error(): @@ -3895,7 +3953,9 @@ async def test_set_iam_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4097,8 +4157,12 @@ def test_test_iam_permissions_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" - assert args[0].permissions == ["permissions_value"] + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val + arg = args[0].permissions + mock_val = ["permissions_value"] + assert arg == mock_val def test_test_iam_permissions_flattened_error(): @@ -4140,8 +4204,12 @@ async def test_test_iam_permissions_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" - assert args[0].permissions == ["permissions_value"] + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val + arg = args[0].permissions + mock_val = ["permissions_value"] + assert arg == mock_val @pytest.mark.asyncio @@ -4336,7 +4404,9 @@ def test_update_finding_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].finding == gcs_finding.Finding(name="name_value") + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val def test_update_finding_flattened_error(): @@ -4373,7 +4443,9 @@ async def test_update_finding_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].finding == gcs_finding.Finding(name="name_value") + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -4570,11 +4642,9 @@ def test_update_organization_settings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].organization_settings == gcs_organization_settings.OrganizationSettings( - name="name_value" - ) + arg = args[0].organization_settings + mock_val = gcs_organization_settings.OrganizationSettings(name="name_value") + assert arg == mock_val def test_update_organization_settings_flattened_error(): @@ -4619,11 +4689,9 @@ async def test_update_organization_settings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].organization_settings == gcs_organization_settings.OrganizationSettings( - name="name_value" - ) + arg = args[0].organization_settings + mock_val = gcs_organization_settings.OrganizationSettings(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -4803,7 +4871,9 @@ def test_update_source_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].source == gcs_source.Source(name="name_value") + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val def test_update_source_flattened_error(): @@ -4840,7 +4910,9 @@ async def test_update_source_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].source == gcs_source.Source(name="name_value") + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -5029,9 +5101,9 @@ def test_update_security_marks_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].security_marks == gcs_security_marks.SecurityMarks( - name="name_value" - ) + arg = args[0].security_marks + mock_val = gcs_security_marks.SecurityMarks(name="name_value") + assert arg == mock_val def test_update_security_marks_flattened_error(): @@ -5072,9 +5144,9 @@ async def test_update_security_marks_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].security_marks == gcs_security_marks.SecurityMarks( - name="name_value" - ) + arg = args[0].security_marks + mock_val = gcs_security_marks.SecurityMarks(name="name_value") + assert arg == mock_val @pytest.mark.asyncio diff --git a/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py b/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py index 0641cd18..06d66f84 100644 --- a/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py @@ -676,8 +676,12 @@ def test_create_source_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].source == gcs_source.Source(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val def test_create_source_flattened_error(): @@ -715,8 +719,12 @@ async def test_create_source_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].source == gcs_source.Source(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -919,9 +927,15 @@ def test_create_finding_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].finding_id == "finding_id_value" - assert args[0].finding == gcs_finding.Finding(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].finding_id + mock_val = "finding_id_value" + assert arg == mock_val + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val def test_create_finding_flattened_error(): @@ -962,9 +976,15 @@ async def test_create_finding_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].finding_id == "finding_id_value" - assert args[0].finding == gcs_finding.Finding(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].finding_id + mock_val = "finding_id_value" + assert arg == mock_val + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -1182,13 +1202,15 @@ def test_create_notification_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].config_id == "config_id_value" - assert args[ - 0 - ].notification_config == gcs_notification_config.NotificationConfig( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].config_id + mock_val = "config_id_value" + assert arg == mock_val + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") + assert arg == mock_val def test_create_notification_config_flattened_error(): @@ -1237,13 +1259,15 @@ async def test_create_notification_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].config_id == "config_id_value" - assert args[ - 0 - ].notification_config == gcs_notification_config.NotificationConfig( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].config_id + mock_val = "config_id_value" + assert arg == mock_val + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -1422,7 +1446,9 @@ def test_delete_notification_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_notification_config_flattened_error(): @@ -1458,7 +1484,9 @@ async def test_delete_notification_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1639,7 +1667,9 @@ def test_get_iam_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val def test_get_iam_policy_flattened_error(): @@ -1673,7 +1703,9 @@ async def test_get_iam_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1880,7 +1912,9 @@ def test_get_notification_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_notification_config_flattened_error(): @@ -1918,7 +1952,9 @@ async def test_get_notification_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2104,7 +2140,9 @@ def test_get_organization_settings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_organization_settings_flattened_error(): @@ -2142,7 +2180,9 @@ async def test_get_organization_settings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2323,7 +2363,9 @@ def test_get_source_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_source_flattened_error(): @@ -2357,7 +2399,9 @@ async def test_get_source_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2835,8 +2879,12 @@ def test_group_findings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].group_by == "group_by_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].group_by + mock_val = "group_by_value" + assert arg == mock_val def test_group_findings_flattened_error(): @@ -2876,8 +2924,12 @@ async def test_group_findings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].group_by == "group_by_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].group_by + mock_val = "group_by_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3214,7 +3266,9 @@ def test_list_assets_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_assets_flattened_error(): @@ -3250,7 +3304,9 @@ async def test_list_assets_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3599,7 +3655,9 @@ def test_list_findings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_findings_flattened_error(): @@ -3635,7 +3693,9 @@ async def test_list_findings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3999,7 +4059,9 @@ def test_list_notification_configs_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_notification_configs_flattened_error(): @@ -4038,7 +4100,9 @@ async def test_list_notification_configs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4384,7 +4448,9 @@ def test_list_sources_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_sources_flattened_error(): @@ -4420,7 +4486,9 @@ async def test_list_sources_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4728,7 +4796,9 @@ def test_run_asset_discovery_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_run_asset_discovery_flattened_error(): @@ -4766,7 +4836,9 @@ async def test_run_asset_discovery_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4979,8 +5051,12 @@ def test_set_finding_state_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].state == finding.Finding.State.ACTIVE + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].state + mock_val = finding.Finding.State.ACTIVE + assert arg == mock_val assert TimestampRule().to_proto(args[0].start_time) == timestamp_pb2.Timestamp( seconds=751 ) @@ -5026,8 +5102,12 @@ async def test_set_finding_state_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].state == finding.Finding.State.ACTIVE + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].state + mock_val = finding.Finding.State.ACTIVE + assert arg == mock_val assert TimestampRule().to_proto(args[0].start_time) == timestamp_pb2.Timestamp( seconds=751 ) @@ -5214,7 +5294,9 @@ def test_set_iam_policy_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val def test_set_iam_policy_flattened_error(): @@ -5248,7 +5330,9 @@ async def test_set_iam_policy_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val @pytest.mark.asyncio @@ -5450,8 +5534,12 @@ def test_test_iam_permissions_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" - assert args[0].permissions == ["permissions_value"] + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val + arg = args[0].permissions + mock_val = ["permissions_value"] + assert arg == mock_val def test_test_iam_permissions_flattened_error(): @@ -5493,8 +5581,12 @@ async def test_test_iam_permissions_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].resource == "resource_value" - assert args[0].permissions == ["permissions_value"] + arg = args[0].resource + mock_val = "resource_value" + assert arg == mock_val + arg = args[0].permissions + mock_val = ["permissions_value"] + assert arg == mock_val @pytest.mark.asyncio @@ -5700,8 +5792,12 @@ def test_update_finding_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].finding == gcs_finding.Finding(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_finding_flattened_error(): @@ -5740,8 +5836,12 @@ async def test_update_finding_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].finding == gcs_finding.Finding(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -5963,12 +6063,12 @@ def test_update_notification_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].notification_config == gcs_notification_config.NotificationConfig( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_notification_config_flattened_error(): @@ -6015,12 +6115,12 @@ async def test_update_notification_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].notification_config == gcs_notification_config.NotificationConfig( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -6220,11 +6320,9 @@ def test_update_organization_settings_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].organization_settings == gcs_organization_settings.OrganizationSettings( - name="name_value" - ) + arg = args[0].organization_settings + mock_val = gcs_organization_settings.OrganizationSettings(name="name_value") + assert arg == mock_val def test_update_organization_settings_flattened_error(): @@ -6269,11 +6367,9 @@ async def test_update_organization_settings_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].organization_settings == gcs_organization_settings.OrganizationSettings( - name="name_value" - ) + arg = args[0].organization_settings + mock_val = gcs_organization_settings.OrganizationSettings(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -6460,8 +6556,12 @@ def test_update_source_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].source == gcs_source.Source(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_source_flattened_error(): @@ -6500,8 +6600,12 @@ async def test_update_source_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].source == gcs_source.Source(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -6698,10 +6802,12 @@ def test_update_security_marks_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].security_marks == gcs_security_marks.SecurityMarks( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].security_marks + mock_val = gcs_security_marks.SecurityMarks(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_security_marks_flattened_error(): @@ -6744,10 +6850,12 @@ async def test_update_security_marks_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].security_marks == gcs_security_marks.SecurityMarks( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].security_marks + mock_val = gcs_security_marks.SecurityMarks(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio From 4fed14e1d24f5e3c4a7f307580a79b3510c261c2 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 11 Nov 2021 22:40:16 -0500 Subject: [PATCH 07/19] chore: delete owlbot.py (#243) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: delete owlbot.py * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- docs/index.rst | 27 ++++++++++++----------- noxfile.py | 2 +- owlbot.py | 59 -------------------------------------------------- 3 files changed, 15 insertions(+), 73 deletions(-) delete mode 100644 owlbot.py diff --git a/docs/index.rst b/docs/index.rst index 02ac87bb..436b070b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -2,51 +2,52 @@ .. include:: multiprocessing.rst -Api Reference -------------- +This package includes clients for multiple versions of Google Cloud Security Command Center. +By default, you will get version ``securitycenter_v1``. + -v1 -~~~ +API Reference +------------- .. toctree:: :maxdepth: 2 securitycenter_v1/services securitycenter_v1/types -v1beta1 -~~~~~~~ +API Reference +------------- .. toctree:: :maxdepth: 2 securitycenter_v1beta1/services securitycenter_v1beta1/types - -v1p1beta1 -~~~~~~~~~ +API Reference +------------- .. toctree:: :maxdepth: 2 securitycenter_v1p1beta1/services securitycenter_v1p1beta1/types + Migration Guide --------------- -See the guide below for instructions on migrating to the 2.x release of this library. +See the guide below for instructions on migrating to the latest version. .. toctree:: :maxdepth: 2 - UPGRADING +  UPGRADING Changelog ----------- +--------- For a list of all ``google-cloud-securitycenter`` releases: .. toctree:: :maxdepth: 2 - changelog \ No newline at end of file + changelog diff --git a/noxfile.py b/noxfile.py index f041f1f5..2a2001c4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -175,7 +175,7 @@ def cover(session): test runs (not system test runs), and then erases coverage data. """ session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=98") + session.run("coverage", "report", "--show-missing", "--fail-under=100") session.run("coverage", "erase") diff --git a/owlbot.py b/owlbot.py deleted file mode 100644 index 43fcd8d8..00000000 --- a/owlbot.py +++ /dev/null @@ -1,59 +0,0 @@ -# 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. - -"""This script is used to synthesize generated parts of this library.""" -import synthtool as s -from synthtool import gcp -from synthtool.languages import python - -common = gcp.CommonTemplates() - -default_version = "v1" - -for library in s.get_staging_dirs(default_version): - # fix bad indentation - s.replace(library / "google/**/*service.py", - r"(\s+)settings resource.\n" - r"\s+If empty all mutable fields will be updated.", - r"\g<1>settings resource.\n" - r"\g<1>If empty all mutable fields will be updated.", - ) - - # Comment out broken assertion in unit test - # https://github.com/googleapis/gapic-generator-python/issues/897 - s.replace( - library / "tests/**/*.py", - "assert args\[0\]\.start_time == timestamp_pb2\.Timestamp\(seconds=751\)", - "# assert args[0].start_time == timestamp_pb2.Timestamp(seconds=751)" - ) - - s.move(library, excludes=["README.rst", "docs/index.rst", "setup.py"]) - -s.remove_staging_dirs() - -# ---------------------------------------------------------------------------- -# Add templated files -# ---------------------------------------------------------------------------- -templated_files = common.py_library( - samples=True, - microgenerator=True, # set to True only if there are samples - cov_level=98, -) -s.move( - templated_files, excludes=[".coveragerc"] -) # microgenerator has a good .coveragerc file - -python.py_samples(skip_readmes=True) - -s.shell.run(["nox", "-s", "blacken"], hide_output=False) From 821f3018ac66ca4dd7f095cd5cd038121291d266 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 12 Nov 2021 04:51:05 +0100 Subject: [PATCH 08/19] chore(deps): update dependency google-cloud-pubsub to v2.9.0 (#251) --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 994b0b5f..e89ff56a 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-pubsub==2.8.0 +google-cloud-pubsub==2.9.0 google-cloud-securitycenter==1.7.0 \ No newline at end of file From 8a6aa11cf74440166b4fabb01d72cb25284e1f0d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 11 Nov 2021 23:23:57 -0500 Subject: [PATCH 09/19] chore(python): add .github/CODEOWNERS as a templated file (#252) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(python): add .github/CODEOWNERS as a templated file Source-Link: https://github.com/googleapis/synthtool/commit/c5026b3217973a8db55db8ee85feee0e9a65e295 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:0e18b9475fbeb12d9ad4302283171edebb6baf2dfca1bd215ee3b34ed79d95d7 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * lint Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- .github/.OwlBot.lock.yaml | 2 +- .github/CODEOWNERS | 9 ++++---- samples/snippets/snippets_findings.py | 26 ++++++------------------ samples/snippets/snippets_list_assets.py | 6 +----- 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 108063d4..7519fa3a 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:4ee57a76a176ede9087c14330c625a71553cf9c72828b2c0ca12f5338171ba60 + digest: sha256:0e18b9475fbeb12d9ad4302283171edebb6baf2dfca1bd215ee3b34ed79d95d7 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 19dd3233..44cc8685 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,9 +3,10 @@ # # For syntax help see: # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax +# Note: This file is autogenerated. To make changes to the codeowner team, please update .repo-metadata.json. -# The @googleapis/yoshi-python is the default owner for changes in this repo -* @googleapis/yoshi-python - +# @googleapis/yoshi-python is the default owner for changes in this repo +* @googleapis/yoshi-python -/samples/ @tdh911 @googleapis/python-samples-owners \ No newline at end of file +# @googleapis/python-samples-owners is the default owner for samples changes +/samples/ @googleapis/python-samples-owners diff --git a/samples/snippets/snippets_findings.py b/samples/snippets/snippets_findings.py index 39aa8f65..20d82ca6 100644 --- a/samples/snippets/snippets_findings.py +++ b/samples/snippets/snippets_findings.py @@ -183,14 +183,10 @@ def create_finding(source_name): ) request = CreateFindingRequest( - parent=source_name, - finding_id=finding_id, - finding=finding, + parent=source_name, finding_id=finding_id, finding=finding, ) # Call The API. - created_finding = client.create_finding( - request=request - ) + created_finding = client.create_finding(request=request) print(created_finding) # [END securitycenter_create_finding] return created_finding @@ -241,11 +237,7 @@ def create_finding_with_source_properties(source_name): ) created_finding = client.create_finding( - request={ - "parent": source_name, - "finding_id": finding_id, - "finding": finding - } + request={"parent": source_name, "finding_id": finding_id, "finding": finding} ) print(created_finding) # [END securitycenter_create_finding_with_source_properties] @@ -283,10 +275,7 @@ def update_finding(source_name): event_time=event_time, ) updated_finding = client.update_finding( - request={ - "finding": finding, - "update_mask": field_mask, - } + request={"finding": finding, "update_mask": field_mask} ) print( @@ -304,6 +293,7 @@ def update_finding_state(source_name): from google.cloud import securitycenter from google.cloud.securitycenter_v1 import Finding + # Create a client. client = securitycenter.SecurityCenterClient() # source_name is the resource path for a source that has been @@ -554,11 +544,7 @@ def group_findings_at_time(source_name): read_time = datetime.utcnow() - timedelta(days=1) group_result_iterator = client.group_findings( - request={ - "parent": source_name, - "group_by": "category", - "read_time": read_time, - } + request={"parent": source_name, "group_by": "category", "read_time": read_time} ) for i, group_result in enumerate(group_result_iterator): print((i + 1), group_result) diff --git a/samples/snippets/snippets_list_assets.py b/samples/snippets/snippets_list_assets.py index 64180acc..7838339e 100644 --- a/samples/snippets/snippets_list_assets.py +++ b/samples/snippets/snippets_list_assets.py @@ -86,11 +86,7 @@ def list_assets_with_filters_and_read_time(organization_id): # Call the API and print results. asset_iterator = client.list_assets( - request={ - "parent": org_name, - "filter": project_filter, - "read_time": read_time, - } + request={"parent": org_name, "filter": project_filter, "read_time": read_time} ) for i, asset_result in enumerate(asset_iterator): print(i, asset_result) From 6f3e1b2503906dd5f9583ac37ebdd1d9e4f11dd2 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 18 Nov 2021 20:51:15 -0500 Subject: [PATCH 10/19] feat: Added mute related APIs, proto messages and fields (#255) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * docs: fix docstring formatting Committer: @parthea PiperOrigin-RevId: 410563372 Source-Link: https://github.com/googleapis/googleapis/commit/23a388deac272effe33962d65ca124130956c1f5 Source-Link: https://github.com/googleapis/googleapis-gen/commit/426ebb90e67733b9e55506d2d9829617c287f998 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDI2ZWJiOTBlNjc3MzNiOWU1NTUwNmQyZDk4Mjk2MTdjMjg3Zjk5OCJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- google/cloud/securitycenter/__init__.py | 36 + google/cloud/securitycenter_v1/__init__.py | 20 + .../securitycenter_v1/gapic_metadata.json | 70 + .../services/security_center/async_client.py | 597 +++ .../services/security_center/client.py | 611 +++ .../services/security_center/pagers.py | 133 + .../security_center/transports/base.py | 89 + .../security_center/transports/grpc.py | 198 + .../transports/grpc_asyncio.py | 203 + .../cloud/securitycenter_v1/types/__init__.py | 20 + .../cloud/securitycenter_v1/types/finding.py | 22 + .../securitycenter_v1/types/mute_config.py | 90 + .../types/securitycenter_service.py | 206 +- .../types/securitycenter_service.py | 1 - scripts/fixup_securitycenter_v1_keywords.py | 7 + .../securitycenter_v1/test_security_center.py | 3881 ++++++++++++----- 16 files changed, 5182 insertions(+), 1002 deletions(-) create mode 100644 google/cloud/securitycenter_v1/types/mute_config.py diff --git a/google/cloud/securitycenter/__init__.py b/google/cloud/securitycenter/__init__.py index 8b715d74..5f2e4ba8 100644 --- a/google/cloud/securitycenter/__init__.py +++ b/google/cloud/securitycenter/__init__.py @@ -25,6 +25,7 @@ from google.cloud.securitycenter_v1.types.finding import Finding from google.cloud.securitycenter_v1.types.folder import Folder from google.cloud.securitycenter_v1.types.indicator import Indicator +from google.cloud.securitycenter_v1.types.mute_config import MuteConfig from google.cloud.securitycenter_v1.types.notification_config import NotificationConfig from google.cloud.securitycenter_v1.types.notification_message import ( NotificationMessage, @@ -37,18 +38,33 @@ RunAssetDiscoveryResponse, ) from google.cloud.securitycenter_v1.types.security_marks import SecurityMarks +from google.cloud.securitycenter_v1.types.securitycenter_service import ( + BulkMuteFindingsRequest, +) +from google.cloud.securitycenter_v1.types.securitycenter_service import ( + BulkMuteFindingsResponse, +) from google.cloud.securitycenter_v1.types.securitycenter_service import ( CreateFindingRequest, ) +from google.cloud.securitycenter_v1.types.securitycenter_service import ( + CreateMuteConfigRequest, +) from google.cloud.securitycenter_v1.types.securitycenter_service import ( CreateNotificationConfigRequest, ) from google.cloud.securitycenter_v1.types.securitycenter_service import ( CreateSourceRequest, ) +from google.cloud.securitycenter_v1.types.securitycenter_service import ( + DeleteMuteConfigRequest, +) from google.cloud.securitycenter_v1.types.securitycenter_service import ( DeleteNotificationConfigRequest, ) +from google.cloud.securitycenter_v1.types.securitycenter_service import ( + GetMuteConfigRequest, +) from google.cloud.securitycenter_v1.types.securitycenter_service import ( GetNotificationConfigRequest, ) @@ -81,6 +97,12 @@ from google.cloud.securitycenter_v1.types.securitycenter_service import ( ListFindingsResponse, ) +from google.cloud.securitycenter_v1.types.securitycenter_service import ( + ListMuteConfigsRequest, +) +from google.cloud.securitycenter_v1.types.securitycenter_service import ( + ListMuteConfigsResponse, +) from google.cloud.securitycenter_v1.types.securitycenter_service import ( ListNotificationConfigsRequest, ) @@ -99,9 +121,13 @@ from google.cloud.securitycenter_v1.types.securitycenter_service import ( SetFindingStateRequest, ) +from google.cloud.securitycenter_v1.types.securitycenter_service import SetMuteRequest from google.cloud.securitycenter_v1.types.securitycenter_service import ( UpdateFindingRequest, ) +from google.cloud.securitycenter_v1.types.securitycenter_service import ( + UpdateMuteConfigRequest, +) from google.cloud.securitycenter_v1.types.securitycenter_service import ( UpdateNotificationConfigRequest, ) @@ -127,16 +153,22 @@ "Finding", "Folder", "Indicator", + "MuteConfig", "NotificationConfig", "NotificationMessage", "OrganizationSettings", "Resource", "RunAssetDiscoveryResponse", "SecurityMarks", + "BulkMuteFindingsRequest", + "BulkMuteFindingsResponse", "CreateFindingRequest", + "CreateMuteConfigRequest", "CreateNotificationConfigRequest", "CreateSourceRequest", + "DeleteMuteConfigRequest", "DeleteNotificationConfigRequest", + "GetMuteConfigRequest", "GetNotificationConfigRequest", "GetOrganizationSettingsRequest", "GetSourceRequest", @@ -149,13 +181,17 @@ "ListAssetsResponse", "ListFindingsRequest", "ListFindingsResponse", + "ListMuteConfigsRequest", + "ListMuteConfigsResponse", "ListNotificationConfigsRequest", "ListNotificationConfigsResponse", "ListSourcesRequest", "ListSourcesResponse", "RunAssetDiscoveryRequest", "SetFindingStateRequest", + "SetMuteRequest", "UpdateFindingRequest", + "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", "UpdateOrganizationSettingsRequest", "UpdateSecurityMarksRequest", diff --git a/google/cloud/securitycenter_v1/__init__.py b/google/cloud/securitycenter_v1/__init__.py index c1e8ab0e..743b5fee 100644 --- a/google/cloud/securitycenter_v1/__init__.py +++ b/google/cloud/securitycenter_v1/__init__.py @@ -21,16 +21,22 @@ from .types.finding import Finding from .types.folder import Folder from .types.indicator import Indicator +from .types.mute_config import MuteConfig from .types.notification_config import NotificationConfig from .types.notification_message import NotificationMessage from .types.organization_settings import OrganizationSettings from .types.resource import Resource from .types.run_asset_discovery_response import RunAssetDiscoveryResponse from .types.security_marks import SecurityMarks +from .types.securitycenter_service import BulkMuteFindingsRequest +from .types.securitycenter_service import BulkMuteFindingsResponse from .types.securitycenter_service import CreateFindingRequest +from .types.securitycenter_service import CreateMuteConfigRequest from .types.securitycenter_service import CreateNotificationConfigRequest from .types.securitycenter_service import CreateSourceRequest +from .types.securitycenter_service import DeleteMuteConfigRequest from .types.securitycenter_service import DeleteNotificationConfigRequest +from .types.securitycenter_service import GetMuteConfigRequest from .types.securitycenter_service import GetNotificationConfigRequest from .types.securitycenter_service import GetOrganizationSettingsRequest from .types.securitycenter_service import GetSourceRequest @@ -43,13 +49,17 @@ from .types.securitycenter_service import ListAssetsResponse from .types.securitycenter_service import ListFindingsRequest from .types.securitycenter_service import ListFindingsResponse +from .types.securitycenter_service import ListMuteConfigsRequest +from .types.securitycenter_service import ListMuteConfigsResponse from .types.securitycenter_service import ListNotificationConfigsRequest from .types.securitycenter_service import ListNotificationConfigsResponse from .types.securitycenter_service import ListSourcesRequest from .types.securitycenter_service import ListSourcesResponse from .types.securitycenter_service import RunAssetDiscoveryRequest from .types.securitycenter_service import SetFindingStateRequest +from .types.securitycenter_service import SetMuteRequest from .types.securitycenter_service import UpdateFindingRequest +from .types.securitycenter_service import UpdateMuteConfigRequest from .types.securitycenter_service import UpdateNotificationConfigRequest from .types.securitycenter_service import UpdateOrganizationSettingsRequest from .types.securitycenter_service import UpdateSecurityMarksRequest @@ -63,14 +73,19 @@ __all__ = ( "SecurityCenterAsyncClient", "Asset", + "BulkMuteFindingsRequest", + "BulkMuteFindingsResponse", "CreateFindingRequest", + "CreateMuteConfigRequest", "CreateNotificationConfigRequest", "CreateSourceRequest", "Cve", "Cvssv3", + "DeleteMuteConfigRequest", "DeleteNotificationConfigRequest", "Finding", "Folder", + "GetMuteConfigRequest", "GetNotificationConfigRequest", "GetOrganizationSettingsRequest", "GetSourceRequest", @@ -84,10 +99,13 @@ "ListAssetsResponse", "ListFindingsRequest", "ListFindingsResponse", + "ListMuteConfigsRequest", + "ListMuteConfigsResponse", "ListNotificationConfigsRequest", "ListNotificationConfigsResponse", "ListSourcesRequest", "ListSourcesResponse", + "MuteConfig", "NotificationConfig", "NotificationMessage", "OrganizationSettings", @@ -98,8 +116,10 @@ "SecurityCenterClient", "SecurityMarks", "SetFindingStateRequest", + "SetMuteRequest", "Source", "UpdateFindingRequest", + "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", "UpdateOrganizationSettingsRequest", "UpdateSecurityMarksRequest", diff --git a/google/cloud/securitycenter_v1/gapic_metadata.json b/google/cloud/securitycenter_v1/gapic_metadata.json index e3afaeec..50c3bcb4 100644 --- a/google/cloud/securitycenter_v1/gapic_metadata.json +++ b/google/cloud/securitycenter_v1/gapic_metadata.json @@ -10,11 +10,21 @@ "grpc": { "libraryClient": "SecurityCenterClient", "rpcs": { + "BulkMuteFindings": { + "methods": [ + "bulk_mute_findings" + ] + }, "CreateFinding": { "methods": [ "create_finding" ] }, + "CreateMuteConfig": { + "methods": [ + "create_mute_config" + ] + }, "CreateNotificationConfig": { "methods": [ "create_notification_config" @@ -25,6 +35,11 @@ "create_source" ] }, + "DeleteMuteConfig": { + "methods": [ + "delete_mute_config" + ] + }, "DeleteNotificationConfig": { "methods": [ "delete_notification_config" @@ -35,6 +50,11 @@ "get_iam_policy" ] }, + "GetMuteConfig": { + "methods": [ + "get_mute_config" + ] + }, "GetNotificationConfig": { "methods": [ "get_notification_config" @@ -70,6 +90,11 @@ "list_findings" ] }, + "ListMuteConfigs": { + "methods": [ + "list_mute_configs" + ] + }, "ListNotificationConfigs": { "methods": [ "list_notification_configs" @@ -95,6 +120,11 @@ "set_iam_policy" ] }, + "SetMute": { + "methods": [ + "set_mute" + ] + }, "TestIamPermissions": { "methods": [ "test_iam_permissions" @@ -105,6 +135,11 @@ "update_finding" ] }, + "UpdateMuteConfig": { + "methods": [ + "update_mute_config" + ] + }, "UpdateNotificationConfig": { "methods": [ "update_notification_config" @@ -130,11 +165,21 @@ "grpc-async": { "libraryClient": "SecurityCenterAsyncClient", "rpcs": { + "BulkMuteFindings": { + "methods": [ + "bulk_mute_findings" + ] + }, "CreateFinding": { "methods": [ "create_finding" ] }, + "CreateMuteConfig": { + "methods": [ + "create_mute_config" + ] + }, "CreateNotificationConfig": { "methods": [ "create_notification_config" @@ -145,6 +190,11 @@ "create_source" ] }, + "DeleteMuteConfig": { + "methods": [ + "delete_mute_config" + ] + }, "DeleteNotificationConfig": { "methods": [ "delete_notification_config" @@ -155,6 +205,11 @@ "get_iam_policy" ] }, + "GetMuteConfig": { + "methods": [ + "get_mute_config" + ] + }, "GetNotificationConfig": { "methods": [ "get_notification_config" @@ -190,6 +245,11 @@ "list_findings" ] }, + "ListMuteConfigs": { + "methods": [ + "list_mute_configs" + ] + }, "ListNotificationConfigs": { "methods": [ "list_notification_configs" @@ -215,6 +275,11 @@ "set_iam_policy" ] }, + "SetMute": { + "methods": [ + "set_mute" + ] + }, "TestIamPermissions": { "methods": [ "test_iam_permissions" @@ -225,6 +290,11 @@ "update_finding" ] }, + "UpdateMuteConfig": { + "methods": [ + "update_mute_config" + ] + }, "UpdateNotificationConfig": { "methods": [ "update_notification_config" diff --git a/google/cloud/securitycenter_v1/services/security_center/async_client.py b/google/cloud/securitycenter_v1/services/security_center/async_client.py index df613923..ff090b80 100644 --- a/google/cloud/securitycenter_v1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1/services/security_center/async_client.py @@ -37,6 +37,8 @@ from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import indicator +from google.cloud.securitycenter_v1.types import mute_config +from google.cloud.securitycenter_v1.types import mute_config as gcs_mute_config from google.cloud.securitycenter_v1.types import notification_config from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -74,6 +76,8 @@ class SecurityCenterAsyncClient: parse_asset_path = staticmethod(SecurityCenterClient.parse_asset_path) finding_path = staticmethod(SecurityCenterClient.finding_path) parse_finding_path = staticmethod(SecurityCenterClient.parse_finding_path) + mute_config_path = staticmethod(SecurityCenterClient.mute_config_path) + parse_mute_config_path = staticmethod(SecurityCenterClient.parse_mute_config_path) notification_config_path = staticmethod( SecurityCenterClient.notification_config_path ) @@ -212,6 +216,100 @@ def __init__( client_info=client_info, ) + async def bulk_mute_findings( + self, + request: Union[securitycenter_service.BulkMuteFindingsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Kicks off an LRO to bulk mute findings for a parent + based on a filter. The parent can be either an + organization, folder or project. The findings matched by + the filter will be muted after the LRO is done. + + Args: + request (Union[google.cloud.securitycenter_v1.types.BulkMuteFindingsRequest, dict]): + The request object. Request message for bulk findings + update. + Note: + 1. If multiple bulk update requests match the same + resource, the order in which they get executed is not + defined. + 2. Once a bulk operation is started, there is no way to + stop it. + parent (:class:`str`): + Required. The parent, at which bulk action needs to be + applied. Its format is + "organizations/[organization_id]", + "folders/[folder_id]", "projects/[project_id]". + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.securitycenter_v1.types.BulkMuteFindingsResponse` + The response to a BulkMute request. Contains the LRO + information. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.BulkMuteFindingsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.bulk_mute_findings, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + securitycenter_service.BulkMuteFindingsResponse, + metadata_type=empty_pb2.Empty, + ) + + # Done; return the response. + return response + async def create_source( self, request: Union[securitycenter_service.CreateSourceRequest, dict] = None, @@ -402,6 +500,103 @@ async def create_finding( # Done; return the response. return response + async def create_mute_config( + self, + request: Union[securitycenter_service.CreateMuteConfigRequest, dict] = None, + *, + parent: str = None, + mute_config: gcs_mute_config.MuteConfig = None, + mute_config_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_mute_config.MuteConfig: + r"""Creates a mute config. + + Args: + request (Union[google.cloud.securitycenter_v1.types.CreateMuteConfigRequest, dict]): + The request object. Request message for creating a mute + config. + parent (:class:`str`): + Required. Resource name of the new mute configs's + parent. Its format is "organizations/[organization_id]", + "folders/[folder_id]", or "projects/[project_id]". + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + mute_config (:class:`google.cloud.securitycenter_v1.types.MuteConfig`): + Required. The mute config being + created. + + This corresponds to the ``mute_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + mute_config_id (:class:`str`): + Required. Unique identifier provided + by the client within the parent scope. + It must consist of lower case letters, + numbers, and hyphen, with the first + character a letter, the last a letter or + a number, and a 63 character maximum. + + This corresponds to the ``mute_config_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.types.MuteConfig: + A mute config is a Cloud SCC resource + that contains the configuration to mute + create/update events of findings. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, mute_config, mute_config_id]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.CreateMuteConfigRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if mute_config is not None: + request.mute_config = mute_config + if mute_config_id is not None: + request.mute_config_id = mute_config_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_mute_config, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + async def create_notification_config( self, request: Union[ @@ -505,6 +700,72 @@ async def create_notification_config( # Done; return the response. return response + async def delete_mute_config( + self, + request: Union[securitycenter_service.DeleteMuteConfigRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes an existing mute config. + + Args: + request (Union[google.cloud.securitycenter_v1.types.DeleteMuteConfigRequest, dict]): + The request object. Request message for deleting a mute + config. + name (:class:`str`): + Required. Name of the mute config to delete. Its format + is organizations/{organization}/muteConfigs/{config_id}, + folders/{folder}/muteConfigs/{config_id}, or + projects/{project}/muteConfigs/{config_id} + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.DeleteMuteConfigRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.delete_mute_config, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, retry=retry, timeout=timeout, metadata=metadata, + ) + async def delete_notification_config( self, request: Union[ @@ -709,6 +970,81 @@ async def get_iam_policy( # Done; return the response. return response + async def get_mute_config( + self, + request: Union[securitycenter_service.GetMuteConfigRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> mute_config.MuteConfig: + r"""Gets a mute config. + + Args: + request (Union[google.cloud.securitycenter_v1.types.GetMuteConfigRequest, dict]): + The request object. Request message for retrieving a + mute config. + name (:class:`str`): + Required. Name of the mute config to retrieve. Its + format is + organizations/{organization}/muteConfigs/{config_id}, + folders/{folder}/muteConfigs/{config_id}, or + projects/{project}/muteConfigs/{config_id} + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.types.MuteConfig: + A mute config is a Cloud SCC resource + that contains the configuration to mute + create/update events of findings. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.GetMuteConfigRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_mute_config, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + async def get_notification_config( self, request: Union[ @@ -1301,6 +1637,89 @@ async def list_findings( # Done; return the response. return response + async def list_mute_configs( + self, + request: Union[securitycenter_service.ListMuteConfigsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListMuteConfigsAsyncPager: + r"""Lists mute configs. + + Args: + request (Union[google.cloud.securitycenter_v1.types.ListMuteConfigsRequest, dict]): + The request object. Request message for listing mute + configs at a given scope e.g. organization, folder or + project. + parent (:class:`str`): + Required. The parent, which owns the collection of mute + configs. Its format is + "organizations/[organization_id]", + "folders/[folder_id]", "projects/[project_id]". + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.services.security_center.pagers.ListMuteConfigsAsyncPager: + Response message for listing mute + configs. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.ListMuteConfigsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_mute_configs, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListMuteConfigsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + async def list_notification_configs( self, request: Union[ @@ -1673,6 +2092,99 @@ async def set_finding_state( # Done; return the response. return response + async def set_mute( + self, + request: Union[securitycenter_service.SetMuteRequest, dict] = None, + *, + name: str = None, + mute: finding.Finding.Mute = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> finding.Finding: + r"""Updates the mute state of a finding. + + Args: + request (Union[google.cloud.securitycenter_v1.types.SetMuteRequest, dict]): + The request object. Request message for updating a + finding's mute status. + name (:class:`str`): + Required. The relative resource name of the finding. + See: + https://cloud.google.com/apis/design/resource_names#relative_resource_name + Example: + "organizations/{organization_id}/sources/{source_id}/finding/{finding_id}", + "folders/{folder_id}/sources/{source_id}/finding/{finding_id}", + "projects/{project_id}/sources/{source_id}/finding/{finding_id}". + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + mute (:class:`google.cloud.securitycenter_v1.types.Finding.Mute`): + Required. The desired state of the + Mute. + + This corresponds to the ``mute`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.types.Finding: + Security Command Center finding. + A finding is a record of assessment data + like security, risk, health, or privacy, + that is ingested into Security Command + Center for presentation, notification, + analysis, policy testing, and + enforcement. For example, a cross-site + scripting (XSS) vulnerability in an App + Engine application is a finding. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name, mute]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.SetMuteRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if mute is not None: + request.mute = mute + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.set_mute, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + async def set_iam_policy( self, request: Union[iam_policy_pb2.SetIamPolicyRequest, dict] = None, @@ -1980,6 +2492,91 @@ async def update_finding( # Done; return the response. return response + async def update_mute_config( + self, + request: Union[securitycenter_service.UpdateMuteConfigRequest, dict] = None, + *, + mute_config: gcs_mute_config.MuteConfig = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_mute_config.MuteConfig: + r"""Updates a mute config. + + Args: + request (Union[google.cloud.securitycenter_v1.types.UpdateMuteConfigRequest, dict]): + The request object. Request message for updating a mute + config. + mute_config (:class:`google.cloud.securitycenter_v1.types.MuteConfig`): + Required. The mute config being + updated. + + This corresponds to the ``mute_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + The list of fields to be updated. + If empty all mutable fields will be + updated. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.types.MuteConfig: + A mute config is a Cloud SCC resource + that contains the configuration to mute + create/update events of findings. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([mute_config, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.UpdateMuteConfigRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if mute_config is not None: + request.mute_config = mute_config + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_mute_config, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("mute_config.name", request.mute_config.name),) + ), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + async def update_notification_config( self, request: Union[ diff --git a/google/cloud/securitycenter_v1/services/security_center/client.py b/google/cloud/securitycenter_v1/services/security_center/client.py index 6722a340..6a6918b2 100644 --- a/google/cloud/securitycenter_v1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1/services/security_center/client.py @@ -40,6 +40,8 @@ from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import indicator +from google.cloud.securitycenter_v1.types import mute_config +from google.cloud.securitycenter_v1.types import mute_config as gcs_mute_config from google.cloud.securitycenter_v1.types import notification_config from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -214,6 +216,22 @@ def parse_finding_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def mute_config_path(organization: str, mute_config: str,) -> str: + """Returns a fully-qualified mute_config string.""" + return "organizations/{organization}/muteConfigs/{mute_config}".format( + organization=organization, mute_config=mute_config, + ) + + @staticmethod + def parse_mute_config_path(path: str) -> Dict[str, str]: + """Parses a mute_config path into its component segments.""" + m = re.match( + r"^organizations/(?P.+?)/muteConfigs/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def notification_config_path(organization: str, notification_config: str,) -> str: """Returns a fully-qualified notification_config string.""" @@ -470,6 +488,100 @@ def __init__( always_use_jwt_access=True, ) + def bulk_mute_findings( + self, + request: Union[securitycenter_service.BulkMuteFindingsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Kicks off an LRO to bulk mute findings for a parent + based on a filter. The parent can be either an + organization, folder or project. The findings matched by + the filter will be muted after the LRO is done. + + Args: + request (Union[google.cloud.securitycenter_v1.types.BulkMuteFindingsRequest, dict]): + The request object. Request message for bulk findings + update. + Note: + 1. If multiple bulk update requests match the same + resource, the order in which they get executed is not + defined. + 2. Once a bulk operation is started, there is no way to + stop it. + parent (str): + Required. The parent, at which bulk action needs to be + applied. Its format is + "organizations/[organization_id]", + "folders/[folder_id]", "projects/[project_id]". + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.securitycenter_v1.types.BulkMuteFindingsResponse` + The response to a BulkMute request. Contains the LRO + information. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a securitycenter_service.BulkMuteFindingsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.BulkMuteFindingsRequest): + request = securitycenter_service.BulkMuteFindingsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.bulk_mute_findings] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + securitycenter_service.BulkMuteFindingsResponse, + metadata_type=empty_pb2.Empty, + ) + + # Done; return the response. + return response + def create_source( self, request: Union[securitycenter_service.CreateSourceRequest, dict] = None, @@ -660,6 +772,103 @@ def create_finding( # Done; return the response. return response + def create_mute_config( + self, + request: Union[securitycenter_service.CreateMuteConfigRequest, dict] = None, + *, + parent: str = None, + mute_config: gcs_mute_config.MuteConfig = None, + mute_config_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_mute_config.MuteConfig: + r"""Creates a mute config. + + Args: + request (Union[google.cloud.securitycenter_v1.types.CreateMuteConfigRequest, dict]): + The request object. Request message for creating a mute + config. + parent (str): + Required. Resource name of the new mute configs's + parent. Its format is "organizations/[organization_id]", + "folders/[folder_id]", or "projects/[project_id]". + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + mute_config (google.cloud.securitycenter_v1.types.MuteConfig): + Required. The mute config being + created. + + This corresponds to the ``mute_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + mute_config_id (str): + Required. Unique identifier provided + by the client within the parent scope. + It must consist of lower case letters, + numbers, and hyphen, with the first + character a letter, the last a letter or + a number, and a 63 character maximum. + + This corresponds to the ``mute_config_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.types.MuteConfig: + A mute config is a Cloud SCC resource + that contains the configuration to mute + create/update events of findings. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, mute_config, mute_config_id]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a securitycenter_service.CreateMuteConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.CreateMuteConfigRequest): + request = securitycenter_service.CreateMuteConfigRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if mute_config is not None: + request.mute_config = mute_config + if mute_config_id is not None: + request.mute_config_id = mute_config_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_mute_config] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + def create_notification_config( self, request: Union[ @@ -767,6 +976,72 @@ def create_notification_config( # Done; return the response. return response + def delete_mute_config( + self, + request: Union[securitycenter_service.DeleteMuteConfigRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes an existing mute config. + + Args: + request (Union[google.cloud.securitycenter_v1.types.DeleteMuteConfigRequest, dict]): + The request object. Request message for deleting a mute + config. + name (str): + Required. Name of the mute config to delete. Its format + is organizations/{organization}/muteConfigs/{config_id}, + folders/{folder}/muteConfigs/{config_id}, or + projects/{project}/muteConfigs/{config_id} + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a securitycenter_service.DeleteMuteConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.DeleteMuteConfigRequest): + request = securitycenter_service.DeleteMuteConfigRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_mute_config] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, retry=retry, timeout=timeout, metadata=metadata, + ) + def delete_notification_config( self, request: Union[ @@ -964,6 +1239,81 @@ def get_iam_policy( # Done; return the response. return response + def get_mute_config( + self, + request: Union[securitycenter_service.GetMuteConfigRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> mute_config.MuteConfig: + r"""Gets a mute config. + + Args: + request (Union[google.cloud.securitycenter_v1.types.GetMuteConfigRequest, dict]): + The request object. Request message for retrieving a + mute config. + name (str): + Required. Name of the mute config to retrieve. Its + format is + organizations/{organization}/muteConfigs/{config_id}, + folders/{folder}/muteConfigs/{config_id}, or + projects/{project}/muteConfigs/{config_id} + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.types.MuteConfig: + A mute config is a Cloud SCC resource + that contains the configuration to mute + create/update events of findings. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a securitycenter_service.GetMuteConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.GetMuteConfigRequest): + request = securitycenter_service.GetMuteConfigRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_mute_config] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + def get_notification_config( self, request: Union[ @@ -1493,6 +1843,89 @@ def list_findings( # Done; return the response. return response + def list_mute_configs( + self, + request: Union[securitycenter_service.ListMuteConfigsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListMuteConfigsPager: + r"""Lists mute configs. + + Args: + request (Union[google.cloud.securitycenter_v1.types.ListMuteConfigsRequest, dict]): + The request object. Request message for listing mute + configs at a given scope e.g. organization, folder or + project. + parent (str): + Required. The parent, which owns the collection of mute + configs. Its format is + "organizations/[organization_id]", + "folders/[folder_id]", "projects/[project_id]". + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.services.security_center.pagers.ListMuteConfigsPager: + Response message for listing mute + configs. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a securitycenter_service.ListMuteConfigsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.ListMuteConfigsRequest): + request = securitycenter_service.ListMuteConfigsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_mute_configs] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListMuteConfigsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + def list_notification_configs( self, request: Union[ @@ -1849,6 +2282,99 @@ def set_finding_state( # Done; return the response. return response + def set_mute( + self, + request: Union[securitycenter_service.SetMuteRequest, dict] = None, + *, + name: str = None, + mute: finding.Finding.Mute = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> finding.Finding: + r"""Updates the mute state of a finding. + + Args: + request (Union[google.cloud.securitycenter_v1.types.SetMuteRequest, dict]): + The request object. Request message for updating a + finding's mute status. + name (str): + Required. The relative resource name of the finding. + See: + https://cloud.google.com/apis/design/resource_names#relative_resource_name + Example: + "organizations/{organization_id}/sources/{source_id}/finding/{finding_id}", + "folders/{folder_id}/sources/{source_id}/finding/{finding_id}", + "projects/{project_id}/sources/{source_id}/finding/{finding_id}". + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + mute (google.cloud.securitycenter_v1.types.Finding.Mute): + Required. The desired state of the + Mute. + + This corresponds to the ``mute`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.types.Finding: + Security Command Center finding. + A finding is a record of assessment data + like security, risk, health, or privacy, + that is ingested into Security Command + Center for presentation, notification, + analysis, policy testing, and + enforcement. For example, a cross-site + scripting (XSS) vulnerability in an App + Engine application is a finding. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name, mute]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a securitycenter_service.SetMuteRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.SetMuteRequest): + request = securitycenter_service.SetMuteRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if mute is not None: + request.mute = mute + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.set_mute] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + def set_iam_policy( self, request: Union[iam_policy_pb2.SetIamPolicyRequest, dict] = None, @@ -2144,6 +2670,91 @@ def update_finding( # Done; return the response. return response + def update_mute_config( + self, + request: Union[securitycenter_service.UpdateMuteConfigRequest, dict] = None, + *, + mute_config: gcs_mute_config.MuteConfig = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_mute_config.MuteConfig: + r"""Updates a mute config. + + Args: + request (Union[google.cloud.securitycenter_v1.types.UpdateMuteConfigRequest, dict]): + The request object. Request message for updating a mute + config. + mute_config (google.cloud.securitycenter_v1.types.MuteConfig): + Required. The mute config being + updated. + + This corresponds to the ``mute_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The list of fields to be updated. + If empty all mutable fields will be + updated. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.types.MuteConfig: + A mute config is a Cloud SCC resource + that contains the configuration to mute + create/update events of findings. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([mute_config, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a securitycenter_service.UpdateMuteConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.UpdateMuteConfigRequest): + request = securitycenter_service.UpdateMuteConfigRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if mute_config is not None: + request.mute_config = mute_config + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_mute_config] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("mute_config.name", request.mute_config.name),) + ), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + def update_notification_config( self, request: Union[ diff --git a/google/cloud/securitycenter_v1/services/security_center/pagers.py b/google/cloud/securitycenter_v1/services/security_center/pagers.py index b04bf9d5..beca9ce6 100644 --- a/google/cloud/securitycenter_v1/services/security_center/pagers.py +++ b/google/cloud/securitycenter_v1/services/security_center/pagers.py @@ -24,6 +24,7 @@ Iterator, ) +from google.cloud.securitycenter_v1.types import mute_config from google.cloud.securitycenter_v1.types import notification_config from google.cloud.securitycenter_v1.types import securitycenter_service from google.cloud.securitycenter_v1.types import source @@ -551,6 +552,138 @@ def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) +class ListMuteConfigsPager: + """A pager for iterating through ``list_mute_configs`` requests. + + This class thinly wraps an initial + :class:`google.cloud.securitycenter_v1.types.ListMuteConfigsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``mute_configs`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListMuteConfigs`` requests and continue to iterate + through the ``mute_configs`` field on the + corresponding responses. + + All the usual :class:`google.cloud.securitycenter_v1.types.ListMuteConfigsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., securitycenter_service.ListMuteConfigsResponse], + request: securitycenter_service.ListMuteConfigsRequest, + response: securitycenter_service.ListMuteConfigsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.securitycenter_v1.types.ListMuteConfigsRequest): + The initial request object. + response (google.cloud.securitycenter_v1.types.ListMuteConfigsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = securitycenter_service.ListMuteConfigsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[securitycenter_service.ListMuteConfigsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[mute_config.MuteConfig]: + for page in self.pages: + yield from page.mute_configs + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListMuteConfigsAsyncPager: + """A pager for iterating through ``list_mute_configs`` requests. + + This class thinly wraps an initial + :class:`google.cloud.securitycenter_v1.types.ListMuteConfigsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``mute_configs`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListMuteConfigs`` requests and continue to iterate + through the ``mute_configs`` field on the + corresponding responses. + + All the usual :class:`google.cloud.securitycenter_v1.types.ListMuteConfigsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., Awaitable[securitycenter_service.ListMuteConfigsResponse] + ], + request: securitycenter_service.ListMuteConfigsRequest, + response: securitycenter_service.ListMuteConfigsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.securitycenter_v1.types.ListMuteConfigsRequest): + The initial request object. + response (google.cloud.securitycenter_v1.types.ListMuteConfigsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = securitycenter_service.ListMuteConfigsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[securitycenter_service.ListMuteConfigsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[mute_config.MuteConfig]: + async def async_generator(): + async for page in self.pages: + for response in page.mute_configs: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + class ListNotificationConfigsPager: """A pager for iterating through ``list_notification_configs`` requests. diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1/services/security_center/transports/base.py index c2d136f9..6ee5d6cf 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/base.py @@ -28,6 +28,8 @@ from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding +from google.cloud.securitycenter_v1.types import mute_config +from google.cloud.securitycenter_v1.types import mute_config as gcs_mute_config from google.cloud.securitycenter_v1.types import notification_config from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -139,17 +141,26 @@ def __init__( def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { + self.bulk_mute_findings: gapic_v1.method.wrap_method( + self.bulk_mute_findings, default_timeout=None, client_info=client_info, + ), self.create_source: gapic_v1.method.wrap_method( self.create_source, default_timeout=60.0, client_info=client_info, ), self.create_finding: gapic_v1.method.wrap_method( self.create_finding, default_timeout=60.0, client_info=client_info, ), + self.create_mute_config: gapic_v1.method.wrap_method( + self.create_mute_config, default_timeout=None, client_info=client_info, + ), self.create_notification_config: gapic_v1.method.wrap_method( self.create_notification_config, default_timeout=60.0, client_info=client_info, ), + self.delete_mute_config: gapic_v1.method.wrap_method( + self.delete_mute_config, default_timeout=None, client_info=client_info, + ), self.delete_notification_config: gapic_v1.method.wrap_method( self.delete_notification_config, default_timeout=60.0, @@ -170,6 +181,9 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.get_mute_config: gapic_v1.method.wrap_method( + self.get_mute_config, default_timeout=None, client_info=client_info, + ), self.get_notification_config: gapic_v1.method.wrap_method( self.get_notification_config, default_retry=retries.Retry( @@ -275,6 +289,9 @@ def _prep_wrapped_messages(self, client_info): default_timeout=480.0, client_info=client_info, ), + self.list_mute_configs: gapic_v1.method.wrap_method( + self.list_mute_configs, default_timeout=None, client_info=client_info, + ), self.list_notification_configs: gapic_v1.method.wrap_method( self.list_notification_configs, default_retry=retries.Retry( @@ -311,6 +328,9 @@ def _prep_wrapped_messages(self, client_info): self.set_finding_state: gapic_v1.method.wrap_method( self.set_finding_state, default_timeout=60.0, client_info=client_info, ), + self.set_mute: gapic_v1.method.wrap_method( + self.set_mute, default_timeout=None, client_info=client_info, + ), self.set_iam_policy: gapic_v1.method.wrap_method( self.set_iam_policy, default_timeout=60.0, client_info=client_info, ), @@ -332,6 +352,9 @@ def _prep_wrapped_messages(self, client_info): self.update_finding: gapic_v1.method.wrap_method( self.update_finding, default_timeout=60.0, client_info=client_info, ), + self.update_mute_config: gapic_v1.method.wrap_method( + self.update_mute_config, default_timeout=None, client_info=client_info, + ), self.update_notification_config: gapic_v1.method.wrap_method( self.update_notification_config, default_timeout=60.0, @@ -366,6 +389,15 @@ def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() + @property + def bulk_mute_findings( + self, + ) -> Callable[ + [securitycenter_service.BulkMuteFindingsRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def create_source( self, @@ -384,6 +416,15 @@ def create_finding( ]: raise NotImplementedError() + @property + def create_mute_config( + self, + ) -> Callable[ + [securitycenter_service.CreateMuteConfigRequest], + Union[gcs_mute_config.MuteConfig, Awaitable[gcs_mute_config.MuteConfig]], + ]: + raise NotImplementedError() + @property def create_notification_config( self, @@ -396,6 +437,15 @@ def create_notification_config( ]: raise NotImplementedError() + @property + def delete_mute_config( + self, + ) -> Callable[ + [securitycenter_service.DeleteMuteConfigRequest], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], + ]: + raise NotImplementedError() + @property def delete_notification_config( self, @@ -414,6 +464,15 @@ def get_iam_policy( ]: raise NotImplementedError() + @property + def get_mute_config( + self, + ) -> Callable[ + [securitycenter_service.GetMuteConfigRequest], + Union[mute_config.MuteConfig, Awaitable[mute_config.MuteConfig]], + ]: + raise NotImplementedError() + @property def get_notification_config( self, @@ -495,6 +554,18 @@ def list_findings( ]: raise NotImplementedError() + @property + def list_mute_configs( + self, + ) -> Callable[ + [securitycenter_service.ListMuteConfigsRequest], + Union[ + securitycenter_service.ListMuteConfigsResponse, + Awaitable[securitycenter_service.ListMuteConfigsResponse], + ], + ]: + raise NotImplementedError() + @property def list_notification_configs( self, @@ -537,6 +608,15 @@ def set_finding_state( ]: raise NotImplementedError() + @property + def set_mute( + self, + ) -> Callable[ + [securitycenter_service.SetMuteRequest], + Union[finding.Finding, Awaitable[finding.Finding]], + ]: + raise NotImplementedError() + @property def set_iam_policy( self, @@ -567,6 +647,15 @@ def update_finding( ]: raise NotImplementedError() + @property + def update_mute_config( + self, + ) -> Callable[ + [securitycenter_service.UpdateMuteConfigRequest], + Union[gcs_mute_config.MuteConfig, Awaitable[gcs_mute_config.MuteConfig]], + ]: + raise NotImplementedError() + @property def update_notification_config( self, diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py index ee3d341b..8b1bae77 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py @@ -27,6 +27,8 @@ from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding +from google.cloud.securitycenter_v1.types import mute_config +from google.cloud.securitycenter_v1.types import mute_config as gcs_mute_config from google.cloud.securitycenter_v1.types import notification_config from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -258,6 +260,37 @@ def operations_client(self) -> operations_v1.OperationsClient: # Return the client from cache. return self._operations_client + @property + def bulk_mute_findings( + self, + ) -> Callable[ + [securitycenter_service.BulkMuteFindingsRequest], operations_pb2.Operation + ]: + r"""Return a callable for the bulk mute findings method over gRPC. + + Kicks off an LRO to bulk mute findings for a parent + based on a filter. The parent can be either an + organization, folder or project. The findings matched by + the filter will be muted after the LRO is done. + + Returns: + Callable[[~.BulkMuteFindingsRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "bulk_mute_findings" not in self._stubs: + self._stubs["bulk_mute_findings"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/BulkMuteFindings", + request_serializer=securitycenter_service.BulkMuteFindingsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["bulk_mute_findings"] + @property def create_source( self, @@ -311,6 +344,34 @@ def create_finding( ) return self._stubs["create_finding"] + @property + def create_mute_config( + self, + ) -> Callable[ + [securitycenter_service.CreateMuteConfigRequest], gcs_mute_config.MuteConfig + ]: + r"""Return a callable for the create mute config method over gRPC. + + Creates a mute config. + + Returns: + Callable[[~.CreateMuteConfigRequest], + ~.MuteConfig]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_mute_config" not in self._stubs: + self._stubs["create_mute_config"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/CreateMuteConfig", + request_serializer=securitycenter_service.CreateMuteConfigRequest.serialize, + response_deserializer=gcs_mute_config.MuteConfig.deserialize, + ) + return self._stubs["create_mute_config"] + @property def create_notification_config( self, @@ -340,6 +401,32 @@ def create_notification_config( ) return self._stubs["create_notification_config"] + @property + def delete_mute_config( + self, + ) -> Callable[[securitycenter_service.DeleteMuteConfigRequest], empty_pb2.Empty]: + r"""Return a callable for the delete mute config method over gRPC. + + Deletes an existing mute config. + + Returns: + Callable[[~.DeleteMuteConfigRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_mute_config" not in self._stubs: + self._stubs["delete_mute_config"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/DeleteMuteConfig", + request_serializer=securitycenter_service.DeleteMuteConfigRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_mute_config"] + @property def delete_notification_config( self, @@ -395,6 +482,34 @@ def get_iam_policy( ) return self._stubs["get_iam_policy"] + @property + def get_mute_config( + self, + ) -> Callable[ + [securitycenter_service.GetMuteConfigRequest], mute_config.MuteConfig + ]: + r"""Return a callable for the get mute config method over gRPC. + + Gets a mute config. + + Returns: + Callable[[~.GetMuteConfigRequest], + ~.MuteConfig]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_mute_config" not in self._stubs: + self._stubs["get_mute_config"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/GetMuteConfig", + request_serializer=securitycenter_service.GetMuteConfigRequest.serialize, + response_deserializer=mute_config.MuteConfig.deserialize, + ) + return self._stubs["get_mute_config"] + @property def get_notification_config( self, @@ -605,6 +720,35 @@ def list_findings( ) return self._stubs["list_findings"] + @property + def list_mute_configs( + self, + ) -> Callable[ + [securitycenter_service.ListMuteConfigsRequest], + securitycenter_service.ListMuteConfigsResponse, + ]: + r"""Return a callable for the list mute configs method over gRPC. + + Lists mute configs. + + Returns: + Callable[[~.ListMuteConfigsRequest], + ~.ListMuteConfigsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_mute_configs" not in self._stubs: + self._stubs["list_mute_configs"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/ListMuteConfigs", + request_serializer=securitycenter_service.ListMuteConfigsRequest.serialize, + response_deserializer=securitycenter_service.ListMuteConfigsResponse.deserialize, + ) + return self._stubs["list_mute_configs"] + @property def list_notification_configs( self, @@ -722,6 +866,32 @@ def set_finding_state( ) return self._stubs["set_finding_state"] + @property + def set_mute( + self, + ) -> Callable[[securitycenter_service.SetMuteRequest], finding.Finding]: + r"""Return a callable for the set mute method over gRPC. + + Updates the mute state of a finding. + + Returns: + Callable[[~.SetMuteRequest], + ~.Finding]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_mute" not in self._stubs: + self._stubs["set_mute"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/SetMute", + request_serializer=securitycenter_service.SetMuteRequest.serialize, + response_deserializer=finding.Finding.deserialize, + ) + return self._stubs["set_mute"] + @property def set_iam_policy( self, @@ -806,6 +976,34 @@ def update_finding( ) return self._stubs["update_finding"] + @property + def update_mute_config( + self, + ) -> Callable[ + [securitycenter_service.UpdateMuteConfigRequest], gcs_mute_config.MuteConfig + ]: + r"""Return a callable for the update mute config method over gRPC. + + Updates a mute config. + + Returns: + Callable[[~.UpdateMuteConfigRequest], + ~.MuteConfig]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_mute_config" not in self._stubs: + self._stubs["update_mute_config"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/UpdateMuteConfig", + request_serializer=securitycenter_service.UpdateMuteConfigRequest.serialize, + response_deserializer=gcs_mute_config.MuteConfig.deserialize, + ) + return self._stubs["update_mute_config"] + @property def update_notification_config( self, diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py index 5d756b54..a173cfa6 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py @@ -27,6 +27,8 @@ from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding +from google.cloud.securitycenter_v1.types import mute_config +from google.cloud.securitycenter_v1.types import mute_config as gcs_mute_config from google.cloud.securitycenter_v1.types import notification_config from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -262,6 +264,38 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: # Return the client from cache. return self._operations_client + @property + def bulk_mute_findings( + self, + ) -> Callable[ + [securitycenter_service.BulkMuteFindingsRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the bulk mute findings method over gRPC. + + Kicks off an LRO to bulk mute findings for a parent + based on a filter. The parent can be either an + organization, folder or project. The findings matched by + the filter will be muted after the LRO is done. + + Returns: + Callable[[~.BulkMuteFindingsRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "bulk_mute_findings" not in self._stubs: + self._stubs["bulk_mute_findings"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/BulkMuteFindings", + request_serializer=securitycenter_service.BulkMuteFindingsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["bulk_mute_findings"] + @property def create_source( self, @@ -319,6 +353,35 @@ def create_finding( ) return self._stubs["create_finding"] + @property + def create_mute_config( + self, + ) -> Callable[ + [securitycenter_service.CreateMuteConfigRequest], + Awaitable[gcs_mute_config.MuteConfig], + ]: + r"""Return a callable for the create mute config method over gRPC. + + Creates a mute config. + + Returns: + Callable[[~.CreateMuteConfigRequest], + Awaitable[~.MuteConfig]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_mute_config" not in self._stubs: + self._stubs["create_mute_config"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/CreateMuteConfig", + request_serializer=securitycenter_service.CreateMuteConfigRequest.serialize, + response_deserializer=gcs_mute_config.MuteConfig.deserialize, + ) + return self._stubs["create_mute_config"] + @property def create_notification_config( self, @@ -348,6 +411,34 @@ def create_notification_config( ) return self._stubs["create_notification_config"] + @property + def delete_mute_config( + self, + ) -> Callable[ + [securitycenter_service.DeleteMuteConfigRequest], Awaitable[empty_pb2.Empty] + ]: + r"""Return a callable for the delete mute config method over gRPC. + + Deletes an existing mute config. + + Returns: + Callable[[~.DeleteMuteConfigRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_mute_config" not in self._stubs: + self._stubs["delete_mute_config"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/DeleteMuteConfig", + request_serializer=securitycenter_service.DeleteMuteConfigRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_mute_config"] + @property def delete_notification_config( self, @@ -404,6 +495,34 @@ def get_iam_policy( ) return self._stubs["get_iam_policy"] + @property + def get_mute_config( + self, + ) -> Callable[ + [securitycenter_service.GetMuteConfigRequest], Awaitable[mute_config.MuteConfig] + ]: + r"""Return a callable for the get mute config method over gRPC. + + Gets a mute config. + + Returns: + Callable[[~.GetMuteConfigRequest], + Awaitable[~.MuteConfig]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_mute_config" not in self._stubs: + self._stubs["get_mute_config"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/GetMuteConfig", + request_serializer=securitycenter_service.GetMuteConfigRequest.serialize, + response_deserializer=mute_config.MuteConfig.deserialize, + ) + return self._stubs["get_mute_config"] + @property def get_notification_config( self, @@ -614,6 +733,35 @@ def list_findings( ) return self._stubs["list_findings"] + @property + def list_mute_configs( + self, + ) -> Callable[ + [securitycenter_service.ListMuteConfigsRequest], + Awaitable[securitycenter_service.ListMuteConfigsResponse], + ]: + r"""Return a callable for the list mute configs method over gRPC. + + Lists mute configs. + + Returns: + Callable[[~.ListMuteConfigsRequest], + Awaitable[~.ListMuteConfigsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_mute_configs" not in self._stubs: + self._stubs["list_mute_configs"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/ListMuteConfigs", + request_serializer=securitycenter_service.ListMuteConfigsRequest.serialize, + response_deserializer=securitycenter_service.ListMuteConfigsResponse.deserialize, + ) + return self._stubs["list_mute_configs"] + @property def list_notification_configs( self, @@ -734,6 +882,32 @@ def set_finding_state( ) return self._stubs["set_finding_state"] + @property + def set_mute( + self, + ) -> Callable[[securitycenter_service.SetMuteRequest], Awaitable[finding.Finding]]: + r"""Return a callable for the set mute method over gRPC. + + Updates the mute state of a finding. + + Returns: + Callable[[~.SetMuteRequest], + Awaitable[~.Finding]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_mute" not in self._stubs: + self._stubs["set_mute"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/SetMute", + request_serializer=securitycenter_service.SetMuteRequest.serialize, + response_deserializer=finding.Finding.deserialize, + ) + return self._stubs["set_mute"] + @property def set_iam_policy( self, @@ -820,6 +994,35 @@ def update_finding( ) return self._stubs["update_finding"] + @property + def update_mute_config( + self, + ) -> Callable[ + [securitycenter_service.UpdateMuteConfigRequest], + Awaitable[gcs_mute_config.MuteConfig], + ]: + r"""Return a callable for the update mute config method over gRPC. + + Updates a mute config. + + Returns: + Callable[[~.UpdateMuteConfigRequest], + Awaitable[~.MuteConfig]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_mute_config" not in self._stubs: + self._stubs["update_mute_config"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/UpdateMuteConfig", + request_serializer=securitycenter_service.UpdateMuteConfigRequest.serialize, + response_deserializer=gcs_mute_config.MuteConfig.deserialize, + ) + return self._stubs["update_mute_config"] + @property def update_notification_config( self, diff --git a/google/cloud/securitycenter_v1/types/__init__.py b/google/cloud/securitycenter_v1/types/__init__.py index d5eba377..aae0aa3d 100644 --- a/google/cloud/securitycenter_v1/types/__init__.py +++ b/google/cloud/securitycenter_v1/types/__init__.py @@ -17,6 +17,7 @@ from .finding import Finding from .folder import Folder from .indicator import Indicator +from .mute_config import MuteConfig from .notification_config import NotificationConfig from .notification_message import NotificationMessage from .organization_settings import OrganizationSettings @@ -24,10 +25,15 @@ from .run_asset_discovery_response import RunAssetDiscoveryResponse from .security_marks import SecurityMarks from .securitycenter_service import ( + BulkMuteFindingsRequest, + BulkMuteFindingsResponse, CreateFindingRequest, + CreateMuteConfigRequest, CreateNotificationConfigRequest, CreateSourceRequest, + DeleteMuteConfigRequest, DeleteNotificationConfigRequest, + GetMuteConfigRequest, GetNotificationConfigRequest, GetOrganizationSettingsRequest, GetSourceRequest, @@ -40,13 +46,17 @@ ListAssetsResponse, ListFindingsRequest, ListFindingsResponse, + ListMuteConfigsRequest, + ListMuteConfigsResponse, ListNotificationConfigsRequest, ListNotificationConfigsResponse, ListSourcesRequest, ListSourcesResponse, RunAssetDiscoveryRequest, SetFindingStateRequest, + SetMuteRequest, UpdateFindingRequest, + UpdateMuteConfigRequest, UpdateNotificationConfigRequest, UpdateOrganizationSettingsRequest, UpdateSecurityMarksRequest, @@ -65,16 +75,22 @@ "Finding", "Folder", "Indicator", + "MuteConfig", "NotificationConfig", "NotificationMessage", "OrganizationSettings", "Resource", "RunAssetDiscoveryResponse", "SecurityMarks", + "BulkMuteFindingsRequest", + "BulkMuteFindingsResponse", "CreateFindingRequest", + "CreateMuteConfigRequest", "CreateNotificationConfigRequest", "CreateSourceRequest", + "DeleteMuteConfigRequest", "DeleteNotificationConfigRequest", + "GetMuteConfigRequest", "GetNotificationConfigRequest", "GetOrganizationSettingsRequest", "GetSourceRequest", @@ -87,13 +103,17 @@ "ListAssetsResponse", "ListFindingsRequest", "ListFindingsResponse", + "ListMuteConfigsRequest", + "ListMuteConfigsResponse", "ListNotificationConfigsRequest", "ListNotificationConfigsResponse", "ListSourcesRequest", "ListSourcesResponse", "RunAssetDiscoveryRequest", "SetFindingStateRequest", + "SetMuteRequest", "UpdateFindingRequest", + "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", "UpdateOrganizationSettingsRequest", "UpdateSecurityMarksRequest", diff --git a/google/cloud/securitycenter_v1/types/finding.py b/google/cloud/securitycenter_v1/types/finding.py index 16a78faf..de6db7be 100644 --- a/google/cloud/securitycenter_v1/types/finding.py +++ b/google/cloud/securitycenter_v1/types/finding.py @@ -102,6 +102,9 @@ class Finding(proto.Message): "projects/{project_number}/sources/{source_id}/findings/{finding_id}", depending on the closest CRM ancestor of the resource associated with the finding. + mute (google.cloud.securitycenter_v1.types.Finding.Mute): + Indicates the mute state of a finding (either + unspecified, muted, unmuted or undefined). finding_class (google.cloud.securitycenter_v1.types.Finding.FindingClass): The class of the finding. indicator (google.cloud.securitycenter_v1.types.Indicator): @@ -115,6 +118,13 @@ class Finding(proto.Message): cve, cvss scores etc. CVE stands for Common Vulnerabilities and Exposures (https://cve.mitre.org/about/) + mute_update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The most recent time this + finding was muted or unmuted. + mute_initiator (str): + First known as mute_annotation. Records additional + information about the mute operation e.g. mute config that + muted the finding, user who muted the finding, etc. """ class State(proto.Enum): @@ -131,6 +141,13 @@ class Severity(proto.Enum): MEDIUM = 3 LOW = 4 + class Mute(proto.Enum): + r"""Mute state a finding can be in.""" + MUTE_UNSPECIFIED = 0 + MUTED = 1 + UNMUTED = 2 + UNDEFINED = 4 + class FindingClass(proto.Enum): r"""Represents what kind of Finding it is.""" FINDING_CLASS_UNSPECIFIED = 0 @@ -157,11 +174,16 @@ class FindingClass(proto.Enum): ) severity = proto.Field(proto.ENUM, number=12, enum=Severity,) canonical_name = proto.Field(proto.STRING, number=14,) + mute = proto.Field(proto.ENUM, number=15, enum=Mute,) finding_class = proto.Field(proto.ENUM, number=17, enum=FindingClass,) indicator = proto.Field(proto.MESSAGE, number=18, message=gcs_indicator.Indicator,) vulnerability = proto.Field( proto.MESSAGE, number=20, message=gcs_vulnerability.Vulnerability, ) + mute_update_time = proto.Field( + proto.MESSAGE, number=21, message=timestamp_pb2.Timestamp, + ) + mute_initiator = proto.Field(proto.STRING, number=28,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/securitycenter_v1/types/mute_config.py b/google/cloud/securitycenter_v1/types/mute_config.py new file mode 100644 index 00000000..83a1483c --- /dev/null +++ b/google/cloud/securitycenter_v1/types/mute_config.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.securitycenter.v1", manifest={"MuteConfig",}, +) + + +class MuteConfig(proto.Message): + r"""A mute config is a Cloud SCC resource that contains the + configuration to mute create/update events of findings. + + Attributes: + name (str): + This field will be ignored if provided on config creation. + Format + "organizations/{organization}/muteConfigs/{mute_config}" + "folders/{folder}/muteConfigs/{mute_config}" + "projects/{project}/muteConfigs/{mute_config}". + display_name (str): + The human readable name to be displayed for + the mute config. + description (str): + A description of the mute config. + filter (str): + Required. An expression that defines the filter to apply + across create/update events of findings. While creating a + filter string, be mindful of the scope in which the mute + configuration is being created. E.g., If a filter contains + project = X but is created under the project = Y scope, it + might not match any findings. + + The following field and operator combinations are supported: + + - severity: ``=``, ``:`` + - category: ``=``, ``:`` + - resource.name: ``=``, ``:`` + - resource.project_name: ``=``, ``:`` + - resource.project_display_name: ``=``, ``:`` + - resource.folders.resource_folder: ``=``, ``:`` + - resource.parent_name: ``=``, ``:`` + - resource.parent_display_name: ``=``, ``:`` + - resource.type: ``=``, ``:`` + - finding_class: ``=``, ``:`` + - indicator.ip_addresses: ``=``, ``:`` + - indicator.domains: ``=``, ``:`` + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time at which the mute + config was created. This field is set by the + server and will be ignored if provided on config + creation. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The most recent time at which + the mute config was updated. This field is set + by the server and will be ignored if provided on + config creation or update. + most_recent_editor (str): + Output only. Email address of the user who + last edited the mute config. This field is set + by the server and will be ignored if provided on + config creation or update. + """ + + name = proto.Field(proto.STRING, number=1,) + display_name = proto.Field(proto.STRING, number=2,) + description = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) + most_recent_editor = proto.Field(proto.STRING, number=7,) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/securitycenter_v1/types/securitycenter_service.py b/google/cloud/securitycenter_v1/types/securitycenter_service.py index 7dbbd37d..6033a41d 100644 --- a/google/cloud/securitycenter_v1/types/securitycenter_service.py +++ b/google/cloud/securitycenter_v1/types/securitycenter_service.py @@ -18,6 +18,7 @@ from google.cloud.securitycenter_v1.types import asset as gcs_asset from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import folder +from google.cloud.securitycenter_v1.types import mute_config as gcs_mute_config from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, ) @@ -35,10 +36,15 @@ __protobuf__ = proto.module( package="google.cloud.securitycenter.v1", manifest={ + "BulkMuteFindingsRequest", + "BulkMuteFindingsResponse", "CreateFindingRequest", + "CreateMuteConfigRequest", "CreateNotificationConfigRequest", "CreateSourceRequest", + "DeleteMuteConfigRequest", "DeleteNotificationConfigRequest", + "GetMuteConfigRequest", "GetNotificationConfigRequest", "GetOrganizationSettingsRequest", "GetSourceRequest", @@ -47,6 +53,8 @@ "GroupFindingsRequest", "GroupFindingsResponse", "GroupResult", + "ListMuteConfigsRequest", + "ListMuteConfigsResponse", "ListNotificationConfigsRequest", "ListNotificationConfigsResponse", "ListSourcesRequest", @@ -56,8 +64,10 @@ "ListFindingsRequest", "ListFindingsResponse", "SetFindingStateRequest", + "SetMuteRequest", "RunAssetDiscoveryRequest", "UpdateFindingRequest", + "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", "UpdateOrganizationSettingsRequest", "UpdateSourceRequest", @@ -66,6 +76,59 @@ ) +class BulkMuteFindingsRequest(proto.Message): + r"""Request message for bulk findings update. + Note: + 1. If multiple bulk update requests match the same resource, the + order in which they get executed is not defined. + 2. Once a bulk operation is started, there is no way to stop it. + + Attributes: + parent (str): + Required. The parent, at which bulk action needs to be + applied. Its format is "organizations/[organization_id]", + "folders/[folder_id]", "projects/[project_id]". + filter (str): + Expression that identifies findings that should be updated. + The expression is a list of zero or more restrictions + combined via logical operators ``AND`` and ``OR``. + Parentheses are supported, and ``OR`` has higher precedence + than ``AND``. + + Restrictions have the form `` `` + and may have a ``-`` character in front of them to indicate + negation. The fields map to those defined in the + corresponding resource. + + The supported operators are: + + - ``=`` for all value types. + - ``>``, ``<``, ``>=``, ``<=`` for integer values. + - ``:``, meaning substring matching, for strings. + + The supported value types are: + + - string literals in quotes. + - integer literals without quotes. + - boolean literals ``true`` and ``false`` without quotes. + mute_annotation (str): + This can be a mute configuration name or any + identifier for mute/unmute of findings based on + the filter. + """ + + parent = proto.Field(proto.STRING, number=1,) + filter = proto.Field(proto.STRING, number=2,) + mute_annotation = proto.Field(proto.STRING, number=3,) + + +class BulkMuteFindingsResponse(proto.Message): + r"""The response to a BulkMute request. Contains the LRO + information. + + """ + + class CreateFindingRequest(proto.Message): r"""Request message for creating a finding. @@ -91,6 +154,31 @@ class CreateFindingRequest(proto.Message): finding = proto.Field(proto.MESSAGE, number=3, message=gcs_finding.Finding,) +class CreateMuteConfigRequest(proto.Message): + r"""Request message for creating a mute config. + + Attributes: + parent (str): + Required. Resource name of the new mute configs's parent. + Its format is "organizations/[organization_id]", + "folders/[folder_id]", or "projects/[project_id]". + mute_config (google.cloud.securitycenter_v1.types.MuteConfig): + Required. The mute config being created. + mute_config_id (str): + Required. Unique identifier provided by the + client within the parent scope. It must consist + of lower case letters, numbers, and hyphen, with + the first character a letter, the last a letter + or a number, and a 63 character maximum. + """ + + parent = proto.Field(proto.STRING, number=1,) + mute_config = proto.Field( + proto.MESSAGE, number=2, message=gcs_mute_config.MuteConfig, + ) + mute_config_id = proto.Field(proto.STRING, number=3,) + + class CreateNotificationConfigRequest(proto.Message): r"""Request message for creating a notification config. @@ -135,6 +223,20 @@ class CreateSourceRequest(proto.Message): source = proto.Field(proto.MESSAGE, number=2, message=gcs_source.Source,) +class DeleteMuteConfigRequest(proto.Message): + r"""Request message for deleting a mute config. + + Attributes: + name (str): + Required. Name of the mute config to delete. Its format is + organizations/{organization}/muteConfigs/{config_id}, + folders/{folder}/muteConfigs/{config_id}, or + projects/{project}/muteConfigs/{config_id} + """ + + name = proto.Field(proto.STRING, number=1,) + + class DeleteNotificationConfigRequest(proto.Message): r"""Request message for deleting a notification config. @@ -148,6 +250,20 @@ class DeleteNotificationConfigRequest(proto.Message): name = proto.Field(proto.STRING, number=1,) +class GetMuteConfigRequest(proto.Message): + r"""Request message for retrieving a mute config. + + Attributes: + name (str): + Required. Name of the mute config to retrieve. Its format is + organizations/{organization}/muteConfigs/{config_id}, + folders/{folder}/muteConfigs/{config_id}, or + projects/{project}/muteConfigs/{config_id} + """ + + name = proto.Field(proto.STRING, number=1,) + + class GetNotificationConfigRequest(proto.Message): r"""Request message for getting a notification config. @@ -612,6 +728,57 @@ class GroupResult(proto.Message): count = proto.Field(proto.INT64, number=2,) +class ListMuteConfigsRequest(proto.Message): + r"""Request message for listing mute configs at a given scope + e.g. organization, folder or project. + + Attributes: + parent (str): + Required. The parent, which owns the collection of mute + configs. Its format is "organizations/[organization_id]", + "folders/[folder_id]", "projects/[project_id]". + page_size (int): + The maximum number of configs to return. The + service may return fewer than this value. + If unspecified, at most 10 configs will be + returned. The maximum value is 1000; values + above 1000 will be coerced to 1000. + page_token (str): + A page token, received from a previous ``ListMuteConfigs`` + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + ``ListMuteConfigs`` must match the call that provided the + page token. + """ + + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + + +class ListMuteConfigsResponse(proto.Message): + r"""Response message for listing mute configs. + + Attributes: + mute_configs (Sequence[google.cloud.securitycenter_v1.types.MuteConfig]): + The mute configs from the specified parent. + next_page_token (str): + A token, which can be sent as ``page_token`` to retrieve the + next page. If this field is omitted, there are no subsequent + pages. + """ + + @property + def raw_page(self): + return self + + mute_configs = proto.RepeatedField( + proto.MESSAGE, number=1, message=gcs_mute_config.MuteConfig, + ) + next_page_token = proto.Field(proto.STRING, number=2,) + + class ListNotificationConfigsRequest(proto.Message): r"""Request message for listing notification configs. @@ -1237,6 +1404,25 @@ class SetFindingStateRequest(proto.Message): start_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) +class SetMuteRequest(proto.Message): + r"""Request message for updating a finding's mute status. + + Attributes: + name (str): + Required. The relative resource name of the finding. See: + https://cloud.google.com/apis/design/resource_names#relative_resource_name + Example: + "organizations/{organization_id}/sources/{source_id}/finding/{finding_id}", + "folders/{folder_id}/sources/{source_id}/finding/{finding_id}", + "projects/{project_id}/sources/{source_id}/finding/{finding_id}". + mute (google.cloud.securitycenter_v1.types.Finding.Mute): + Required. The desired state of the Mute. + """ + + name = proto.Field(proto.STRING, number=1,) + mute = proto.Field(proto.ENUM, number=2, enum=gcs_finding.Finding.Mute,) + + class RunAssetDiscoveryRequest(proto.Message): r"""Request message for running asset discovery for an organization. @@ -1278,6 +1464,25 @@ class UpdateFindingRequest(proto.Message): ) +class UpdateMuteConfigRequest(proto.Message): + r"""Request message for updating a mute config. + + Attributes: + mute_config (google.cloud.securitycenter_v1.types.MuteConfig): + Required. The mute config being updated. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The list of fields to be updated. + If empty all mutable fields will be updated. + """ + + mute_config = proto.Field( + proto.MESSAGE, number=1, message=gcs_mute_config.MuteConfig, + ) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) + + class UpdateNotificationConfigRequest(proto.Message): r"""Request message for updating a notification config. @@ -1308,7 +1513,6 @@ class UpdateOrganizationSettingsRequest(proto.Message): update_mask (google.protobuf.field_mask_pb2.FieldMask): The FieldMask to use when updating the settings resource. - If empty all mutable fields will be updated. """ diff --git a/google/cloud/securitycenter_v1p1beta1/types/securitycenter_service.py b/google/cloud/securitycenter_v1p1beta1/types/securitycenter_service.py index 7fd1f639..e36c8098 100644 --- a/google/cloud/securitycenter_v1p1beta1/types/securitycenter_service.py +++ b/google/cloud/securitycenter_v1p1beta1/types/securitycenter_service.py @@ -1273,7 +1273,6 @@ class UpdateOrganizationSettingsRequest(proto.Message): update_mask (google.protobuf.field_mask_pb2.FieldMask): The FieldMask to use when updating the settings resource. - If empty all mutable fields will be updated. """ diff --git a/scripts/fixup_securitycenter_v1_keywords.py b/scripts/fixup_securitycenter_v1_keywords.py index bb7aec08..5649718b 100644 --- a/scripts/fixup_securitycenter_v1_keywords.py +++ b/scripts/fixup_securitycenter_v1_keywords.py @@ -39,11 +39,15 @@ def partition( class securitycenterCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'bulk_mute_findings': ('parent', 'filter', 'mute_annotation', ), 'create_finding': ('parent', 'finding_id', 'finding', ), + 'create_mute_config': ('parent', 'mute_config', 'mute_config_id', ), 'create_notification_config': ('parent', 'config_id', 'notification_config', ), 'create_source': ('parent', 'source', ), + 'delete_mute_config': ('name', ), 'delete_notification_config': ('name', ), 'get_iam_policy': ('resource', 'options', ), + 'get_mute_config': ('name', ), 'get_notification_config': ('name', ), 'get_organization_settings': ('name', ), 'get_source': ('name', ), @@ -51,13 +55,16 @@ class securitycenterCallTransformer(cst.CSTTransformer): 'group_findings': ('parent', 'group_by', 'filter', 'read_time', 'compare_duration', 'page_token', 'page_size', ), 'list_assets': ('parent', 'filter', 'order_by', 'read_time', 'compare_duration', 'field_mask', 'page_token', 'page_size', ), 'list_findings': ('parent', 'filter', 'order_by', 'read_time', 'compare_duration', 'field_mask', 'page_token', 'page_size', ), + 'list_mute_configs': ('parent', 'page_size', 'page_token', ), 'list_notification_configs': ('parent', 'page_token', 'page_size', ), 'list_sources': ('parent', 'page_token', 'page_size', ), 'run_asset_discovery': ('parent', ), 'set_finding_state': ('name', 'state', 'start_time', ), 'set_iam_policy': ('resource', 'policy', ), + 'set_mute': ('name', 'mute', ), 'test_iam_permissions': ('resource', 'permissions', ), 'update_finding': ('finding', 'update_mask', ), + 'update_mute_config': ('mute_config', 'update_mask', ), 'update_notification_config': ('notification_config', 'update_mask', ), 'update_organization_settings': ('organization_settings', 'update_mask', ), 'update_security_marks': ('security_marks', 'update_mask', 'start_time', ), diff --git a/tests/unit/gapic/securitycenter_v1/test_security_center.py b/tests/unit/gapic/securitycenter_v1/test_security_center.py index 19610e18..447cd0bc 100644 --- a/tests/unit/gapic/securitycenter_v1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1/test_security_center.py @@ -43,6 +43,8 @@ from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import indicator +from google.cloud.securitycenter_v1.types import mute_config +from google.cloud.securitycenter_v1.types import mute_config as gcs_mute_config from google.cloud.securitycenter_v1.types import notification_config from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -508,6 +510,225 @@ def test_security_center_client_client_options_from_dict(): ) +def test_bulk_mute_findings( + transport: str = "grpc", request_type=securitycenter_service.BulkMuteFindingsRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.bulk_mute_findings), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.bulk_mute_findings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.BulkMuteFindingsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_bulk_mute_findings_from_dict(): + test_bulk_mute_findings(request_type=dict) + + +def test_bulk_mute_findings_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.bulk_mute_findings), "__call__" + ) as call: + client.bulk_mute_findings() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.BulkMuteFindingsRequest() + + +@pytest.mark.asyncio +async def test_bulk_mute_findings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.BulkMuteFindingsRequest, +): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.bulk_mute_findings), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.bulk_mute_findings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.BulkMuteFindingsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_bulk_mute_findings_async_from_dict(): + await test_bulk_mute_findings_async(request_type=dict) + + +def test_bulk_mute_findings_field_headers(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.BulkMuteFindingsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.bulk_mute_findings), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.bulk_mute_findings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_bulk_mute_findings_field_headers_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.BulkMuteFindingsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.bulk_mute_findings), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.bulk_mute_findings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +def test_bulk_mute_findings_flattened(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.bulk_mute_findings), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.bulk_mute_findings(parent="parent_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_bulk_mute_findings_flattened_error(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.bulk_mute_findings( + securitycenter_service.BulkMuteFindingsRequest(), parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_bulk_mute_findings_flattened_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.bulk_mute_findings), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.bulk_mute_findings(parent="parent_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_bulk_mute_findings_flattened_error_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.bulk_mute_findings( + securitycenter_service.BulkMuteFindingsRequest(), parent="parent_value", + ) + + def test_create_source( transport: str = "grpc", request_type=securitycenter_service.CreateSourceRequest ): @@ -764,7 +985,9 @@ def test_create_finding( external_uri="external_uri_value", severity=gcs_finding.Finding.Severity.CRITICAL, canonical_name="canonical_name_value", + mute=gcs_finding.Finding.Mute.MUTED, finding_class=gcs_finding.Finding.FindingClass.THREAT, + mute_initiator="mute_initiator_value", ) response = client.create_finding(request) @@ -783,7 +1006,9 @@ def test_create_finding( assert response.external_uri == "external_uri_value" assert response.severity == gcs_finding.Finding.Severity.CRITICAL assert response.canonical_name == "canonical_name_value" + assert response.mute == gcs_finding.Finding.Mute.MUTED assert response.finding_class == gcs_finding.Finding.FindingClass.THREAT + assert response.mute_initiator == "mute_initiator_value" def test_create_finding_from_dict(): @@ -831,7 +1056,9 @@ async def test_create_finding_async( external_uri="external_uri_value", severity=gcs_finding.Finding.Severity.CRITICAL, canonical_name="canonical_name_value", + mute=gcs_finding.Finding.Mute.MUTED, finding_class=gcs_finding.Finding.FindingClass.THREAT, + mute_initiator="mute_initiator_value", ) ) response = await client.create_finding(request) @@ -851,7 +1078,9 @@ async def test_create_finding_async( assert response.external_uri == "external_uri_value" assert response.severity == gcs_finding.Finding.Severity.CRITICAL assert response.canonical_name == "canonical_name_value" + assert response.mute == gcs_finding.Finding.Mute.MUTED assert response.finding_class == gcs_finding.Finding.FindingClass.THREAT + assert response.mute_initiator == "mute_initiator_value" @pytest.mark.asyncio @@ -1006,9 +1235,8 @@ async def test_create_finding_flattened_error_async(): ) -def test_create_notification_config( - transport: str = "grpc", - request_type=securitycenter_service.CreateNotificationConfigRequest, +def test_create_mute_config( + transport: str = "grpc", request_type=securitycenter_service.CreateMuteConfigRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1020,38 +1248,37 @@ def test_create_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_notification_config), "__call__" + type(client.transport.create_mute_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_notification_config.NotificationConfig( + call.return_value = gcs_mute_config.MuteConfig( name="name_value", + display_name="display_name_value", description="description_value", - pubsub_topic="pubsub_topic_value", - service_account="service_account_value", - streaming_config=gcs_notification_config.NotificationConfig.StreamingConfig( - filter="filter_value" - ), + filter="filter_value", + most_recent_editor="most_recent_editor_value", ) - response = client.create_notification_config(request) + response = client.create_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.CreateNotificationConfigRequest() + assert args[0] == securitycenter_service.CreateMuteConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_notification_config.NotificationConfig) + assert isinstance(response, gcs_mute_config.MuteConfig) assert response.name == "name_value" + assert response.display_name == "display_name_value" assert response.description == "description_value" - assert response.pubsub_topic == "pubsub_topic_value" - assert response.service_account == "service_account_value" + assert response.filter == "filter_value" + assert response.most_recent_editor == "most_recent_editor_value" -def test_create_notification_config_from_dict(): - test_create_notification_config(request_type=dict) +def test_create_mute_config_from_dict(): + test_create_mute_config(request_type=dict) -def test_create_notification_config_empty_call(): +def test_create_mute_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SecurityCenterClient( @@ -1060,18 +1287,18 @@ def test_create_notification_config_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_notification_config), "__call__" + type(client.transport.create_mute_config), "__call__" ) as call: - client.create_notification_config() + client.create_mute_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.CreateNotificationConfigRequest() + assert args[0] == securitycenter_service.CreateMuteConfigRequest() @pytest.mark.asyncio -async def test_create_notification_config_async( +async def test_create_mute_config_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.CreateNotificationConfigRequest, + request_type=securitycenter_service.CreateMuteConfigRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1083,52 +1310,54 @@ async def test_create_notification_config_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_notification_config), "__call__" + type(client.transport.create_mute_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_notification_config.NotificationConfig( + gcs_mute_config.MuteConfig( name="name_value", + display_name="display_name_value", description="description_value", - pubsub_topic="pubsub_topic_value", - service_account="service_account_value", + filter="filter_value", + most_recent_editor="most_recent_editor_value", ) ) - response = await client.create_notification_config(request) + response = await client.create_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.CreateNotificationConfigRequest() + assert args[0] == securitycenter_service.CreateMuteConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_notification_config.NotificationConfig) + assert isinstance(response, gcs_mute_config.MuteConfig) assert response.name == "name_value" + assert response.display_name == "display_name_value" assert response.description == "description_value" - assert response.pubsub_topic == "pubsub_topic_value" - assert response.service_account == "service_account_value" + assert response.filter == "filter_value" + assert response.most_recent_editor == "most_recent_editor_value" @pytest.mark.asyncio -async def test_create_notification_config_async_from_dict(): - await test_create_notification_config_async(request_type=dict) +async def test_create_mute_config_async_from_dict(): + await test_create_mute_config_async(request_type=dict) -def test_create_notification_config_field_headers(): +def test_create_mute_config_field_headers(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.CreateNotificationConfigRequest() + request = securitycenter_service.CreateMuteConfigRequest() request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_notification_config), "__call__" + type(client.transport.create_mute_config), "__call__" ) as call: - call.return_value = gcs_notification_config.NotificationConfig() - client.create_notification_config(request) + call.return_value = gcs_mute_config.MuteConfig() + client.create_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -1141,25 +1370,25 @@ def test_create_notification_config_field_headers(): @pytest.mark.asyncio -async def test_create_notification_config_field_headers_async(): +async def test_create_mute_config_field_headers_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.CreateNotificationConfigRequest() + request = securitycenter_service.CreateMuteConfigRequest() request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_notification_config), "__call__" + type(client.transport.create_mute_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_notification_config.NotificationConfig() + gcs_mute_config.MuteConfig() ) - await client.create_notification_config(request) + await client.create_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -1171,23 +1400,21 @@ async def test_create_notification_config_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_create_notification_config_flattened(): +def test_create_mute_config_flattened(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_notification_config), "__call__" + type(client.transport.create_mute_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_notification_config.NotificationConfig() + call.return_value = gcs_mute_config.MuteConfig() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.create_notification_config( + client.create_mute_config( parent="parent_value", - config_id="config_id_value", - notification_config=gcs_notification_config.NotificationConfig( - name="name_value" - ), + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + mute_config_id="mute_config_id_value", ) # Establish that the underlying call was made with the expected @@ -1197,54 +1424,50 @@ def test_create_notification_config_flattened(): arg = args[0].parent mock_val = "parent_value" assert arg == mock_val - arg = args[0].config_id - mock_val = "config_id_value" + arg = args[0].mute_config + mock_val = gcs_mute_config.MuteConfig(name="name_value") assert arg == mock_val - arg = args[0].notification_config - mock_val = gcs_notification_config.NotificationConfig(name="name_value") + arg = args[0].mute_config_id + mock_val = "mute_config_id_value" assert arg == mock_val -def test_create_notification_config_flattened_error(): +def test_create_mute_config_flattened_error(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_notification_config( - securitycenter_service.CreateNotificationConfigRequest(), + client.create_mute_config( + securitycenter_service.CreateMuteConfigRequest(), parent="parent_value", - config_id="config_id_value", - notification_config=gcs_notification_config.NotificationConfig( - name="name_value" - ), + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + mute_config_id="mute_config_id_value", ) @pytest.mark.asyncio -async def test_create_notification_config_flattened_async(): +async def test_create_mute_config_flattened_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_notification_config), "__call__" + type(client.transport.create_mute_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_notification_config.NotificationConfig() + call.return_value = gcs_mute_config.MuteConfig() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_notification_config.NotificationConfig() + gcs_mute_config.MuteConfig() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.create_notification_config( + response = await client.create_mute_config( parent="parent_value", - config_id="config_id_value", - notification_config=gcs_notification_config.NotificationConfig( - name="name_value" - ), + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + mute_config_id="mute_config_id_value", ) # Establish that the underlying call was made with the expected @@ -1254,16 +1477,16 @@ async def test_create_notification_config_flattened_async(): arg = args[0].parent mock_val = "parent_value" assert arg == mock_val - arg = args[0].config_id - mock_val = "config_id_value" + arg = args[0].mute_config + mock_val = gcs_mute_config.MuteConfig(name="name_value") assert arg == mock_val - arg = args[0].notification_config - mock_val = gcs_notification_config.NotificationConfig(name="name_value") + arg = args[0].mute_config_id + mock_val = "mute_config_id_value" assert arg == mock_val @pytest.mark.asyncio -async def test_create_notification_config_flattened_error_async(): +async def test_create_mute_config_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -1271,19 +1494,17 @@ async def test_create_notification_config_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.create_notification_config( - securitycenter_service.CreateNotificationConfigRequest(), + await client.create_mute_config( + securitycenter_service.CreateMuteConfigRequest(), parent="parent_value", - config_id="config_id_value", - notification_config=gcs_notification_config.NotificationConfig( - name="name_value" - ), + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + mute_config_id="mute_config_id_value", ) -def test_delete_notification_config( +def test_create_notification_config( transport: str = "grpc", - request_type=securitycenter_service.DeleteNotificationConfigRequest, + request_type=securitycenter_service.CreateNotificationConfigRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1295,26 +1516,38 @@ def test_delete_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_notification_config(request) + call.return_value = gcs_notification_config.NotificationConfig( + name="name_value", + description="description_value", + pubsub_topic="pubsub_topic_value", + service_account="service_account_value", + streaming_config=gcs_notification_config.NotificationConfig.StreamingConfig( + filter="filter_value" + ), + ) + response = client.create_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.DeleteNotificationConfigRequest() + assert args[0] == securitycenter_service.CreateNotificationConfigRequest() # Establish that the response is the type that we expect. - assert response is None + assert isinstance(response, gcs_notification_config.NotificationConfig) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.pubsub_topic == "pubsub_topic_value" + assert response.service_account == "service_account_value" -def test_delete_notification_config_from_dict(): - test_delete_notification_config(request_type=dict) +def test_create_notification_config_from_dict(): + test_create_notification_config(request_type=dict) -def test_delete_notification_config_empty_call(): +def test_create_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SecurityCenterClient( @@ -1323,18 +1556,18 @@ def test_delete_notification_config_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: - client.delete_notification_config() + client.create_notification_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.DeleteNotificationConfigRequest() + assert args[0] == securitycenter_service.CreateNotificationConfigRequest() @pytest.mark.asyncio -async def test_delete_notification_config_async( +async def test_create_notification_config_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.DeleteNotificationConfigRequest, + request_type=securitycenter_service.CreateNotificationConfigRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1346,41 +1579,52 @@ async def test_delete_notification_config_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_notification_config(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_notification_config.NotificationConfig( + name="name_value", + description="description_value", + pubsub_topic="pubsub_topic_value", + service_account="service_account_value", + ) + ) + response = await client.create_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.DeleteNotificationConfigRequest() + assert args[0] == securitycenter_service.CreateNotificationConfigRequest() # Establish that the response is the type that we expect. - assert response is None + assert isinstance(response, gcs_notification_config.NotificationConfig) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.pubsub_topic == "pubsub_topic_value" + assert response.service_account == "service_account_value" @pytest.mark.asyncio -async def test_delete_notification_config_async_from_dict(): - await test_delete_notification_config_async(request_type=dict) +async def test_create_notification_config_async_from_dict(): + await test_create_notification_config_async(request_type=dict) -def test_delete_notification_config_field_headers(): +def test_create_notification_config_field_headers(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.DeleteNotificationConfigRequest() + request = securitycenter_service.CreateNotificationConfigRequest() - request.name = "name/value" + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: - call.return_value = None - client.delete_notification_config(request) + call.return_value = gcs_notification_config.NotificationConfig() + client.create_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -1389,27 +1633,29 @@ def test_delete_notification_config_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] @pytest.mark.asyncio -async def test_delete_notification_config_field_headers_async(): +async def test_create_notification_config_field_headers_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.DeleteNotificationConfigRequest() + request = securitycenter_service.CreateNotificationConfigRequest() - request.name = "name/value" + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_notification_config(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_notification_config.NotificationConfig() + ) + await client.create_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -1418,71 +1664,102 @@ async def test_delete_notification_config_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_delete_notification_config_flattened(): +def test_create_notification_config_flattened(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = None + call.return_value = gcs_notification_config.NotificationConfig() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_notification_config(name="name_value",) + client.create_notification_config( + parent="parent_value", + config_id="config_id_value", + notification_config=gcs_notification_config.NotificationConfig( + name="name_value" + ), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].config_id + mock_val = "config_id_value" + assert arg == mock_val + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") assert arg == mock_val -def test_delete_notification_config_flattened_error(): +def test_create_notification_config_flattened_error(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_notification_config( - securitycenter_service.DeleteNotificationConfigRequest(), name="name_value", + client.create_notification_config( + securitycenter_service.CreateNotificationConfigRequest(), + parent="parent_value", + config_id="config_id_value", + notification_config=gcs_notification_config.NotificationConfig( + name="name_value" + ), ) @pytest.mark.asyncio -async def test_delete_notification_config_flattened_async(): +async def test_create_notification_config_flattened_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = None + call.return_value = gcs_notification_config.NotificationConfig() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_notification_config.NotificationConfig() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_notification_config(name="name_value",) + response = await client.create_notification_config( + parent="parent_value", + config_id="config_id_value", + notification_config=gcs_notification_config.NotificationConfig( + name="name_value" + ), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].config_id + mock_val = "config_id_value" + assert arg == mock_val + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") assert arg == mock_val @pytest.mark.asyncio -async def test_delete_notification_config_flattened_error_async(): +async def test_create_notification_config_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -1490,13 +1767,18 @@ async def test_delete_notification_config_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.delete_notification_config( - securitycenter_service.DeleteNotificationConfigRequest(), name="name_value", + await client.create_notification_config( + securitycenter_service.CreateNotificationConfigRequest(), + parent="parent_value", + config_id="config_id_value", + notification_config=gcs_notification_config.NotificationConfig( + name="name_value" + ), ) -def test_get_iam_policy( - transport: str = "grpc", request_type=iam_policy_pb2.GetIamPolicyRequest +def test_delete_mute_config( + transport: str = "grpc", request_type=securitycenter_service.DeleteMuteConfigRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1507,27 +1789,27 @@ def test_get_iam_policy( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + with mock.patch.object( + type(client.transport.delete_mute_config), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy(version=774, etag=b"etag_blob",) - response = client.get_iam_policy(request) + call.return_value = None + response = client.delete_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + assert args[0] == securitycenter_service.DeleteMuteConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b"etag_blob" + assert response is None -def test_get_iam_policy_from_dict(): - test_get_iam_policy(request_type=dict) +def test_delete_mute_config_from_dict(): + test_delete_mute_config(request_type=dict) -def test_get_iam_policy_empty_call(): +def test_delete_mute_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SecurityCenterClient( @@ -1535,16 +1817,19 @@ def test_get_iam_policy_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: - client.get_iam_policy() + with mock.patch.object( + type(client.transport.delete_mute_config), "__call__" + ) as call: + client.delete_mute_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + assert args[0] == securitycenter_service.DeleteMuteConfigRequest() @pytest.mark.asyncio -async def test_get_iam_policy_async( - transport: str = "grpc_asyncio", request_type=iam_policy_pb2.GetIamPolicyRequest +async def test_delete_mute_config_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.DeleteMuteConfigRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1555,42 +1840,42 @@ async def test_get_iam_policy_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + with mock.patch.object( + type(client.transport.delete_mute_config), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - policy_pb2.Policy(version=774, etag=b"etag_blob",) - ) - response = await client.get_iam_policy(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + assert args[0] == securitycenter_service.DeleteMuteConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b"etag_blob" + assert response is None @pytest.mark.asyncio -async def test_get_iam_policy_async_from_dict(): - await test_get_iam_policy_async(request_type=dict) +async def test_delete_mute_config_async_from_dict(): + await test_delete_mute_config_async(request_type=dict) -def test_get_iam_policy_field_headers(): +def test_delete_mute_config_field_headers(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = iam_policy_pb2.GetIamPolicyRequest() + request = securitycenter_service.DeleteMuteConfigRequest() - request.resource = "resource/value" + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: - call.return_value = policy_pb2.Policy() - client.get_iam_policy(request) + with mock.patch.object( + type(client.transport.delete_mute_config), "__call__" + ) as call: + call.return_value = None + client.delete_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -1599,25 +1884,27 @@ def test_get_iam_policy_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] @pytest.mark.asyncio -async def test_get_iam_policy_field_headers_async(): +async def test_delete_mute_config_field_headers_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = iam_policy_pb2.GetIamPolicyRequest() + request = securitycenter_service.DeleteMuteConfigRequest() - request.resource = "resource/value" + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - await client.get_iam_policy(request) + with mock.patch.object( + type(client.transport.delete_mute_config), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -1626,82 +1913,71 @@ async def test_get_iam_policy_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_get_iam_policy_from_dict_foreign(): +def test_delete_mute_config_flattened(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + with mock.patch.object( + type(client.transport.delete_mute_config), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - response = client.get_iam_policy( - request={ - "resource": "resource_value", - "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), - } - ) - call.assert_called() - - -def test_get_iam_policy_flattened(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() + call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_iam_policy(resource="resource_value",) + client.delete_mute_config(name="name_value",) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = "resource_value" + arg = args[0].name + mock_val = "name_value" assert arg == mock_val -def test_get_iam_policy_flattened_error(): +def test_delete_mute_config_flattened_error(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), resource="resource_value", + client.delete_mute_config( + securitycenter_service.DeleteMuteConfigRequest(), name="name_value", ) @pytest.mark.asyncio -async def test_get_iam_policy_flattened_async(): +async def test_delete_mute_config_flattened_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + with mock.patch.object( + type(client.transport.delete_mute_config), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() + call.return_value = None - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_iam_policy(resource="resource_value",) + response = await client.delete_mute_config(name="name_value",) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = "resource_value" + arg = args[0].name + mock_val = "name_value" assert arg == mock_val @pytest.mark.asyncio -async def test_get_iam_policy_flattened_error_async(): +async def test_delete_mute_config_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -1709,14 +1985,14 @@ async def test_get_iam_policy_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), resource="resource_value", + await client.delete_mute_config( + securitycenter_service.DeleteMuteConfigRequest(), name="name_value", ) -def test_get_notification_config( +def test_delete_notification_config( transport: str = "grpc", - request_type=securitycenter_service.GetNotificationConfigRequest, + request_type=securitycenter_service.DeleteNotificationConfigRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1728,38 +2004,26 @@ def test_get_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = notification_config.NotificationConfig( - name="name_value", - description="description_value", - pubsub_topic="pubsub_topic_value", - service_account="service_account_value", - streaming_config=notification_config.NotificationConfig.StreamingConfig( - filter="filter_value" - ), - ) - response = client.get_notification_config(request) + call.return_value = None + response = client.delete_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GetNotificationConfigRequest() + assert args[0] == securitycenter_service.DeleteNotificationConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, notification_config.NotificationConfig) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.pubsub_topic == "pubsub_topic_value" - assert response.service_account == "service_account_value" + assert response is None -def test_get_notification_config_from_dict(): - test_get_notification_config(request_type=dict) +def test_delete_notification_config_from_dict(): + test_delete_notification_config(request_type=dict) -def test_get_notification_config_empty_call(): +def test_delete_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SecurityCenterClient( @@ -1768,18 +2032,18 @@ def test_get_notification_config_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: - client.get_notification_config() + client.delete_notification_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GetNotificationConfigRequest() + assert args[0] == securitycenter_service.DeleteNotificationConfigRequest() @pytest.mark.asyncio -async def test_get_notification_config_async( +async def test_delete_notification_config_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.GetNotificationConfigRequest, + request_type=securitycenter_service.DeleteNotificationConfigRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1791,52 +2055,41 @@ async def test_get_notification_config_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - notification_config.NotificationConfig( - name="name_value", - description="description_value", - pubsub_topic="pubsub_topic_value", - service_account="service_account_value", - ) - ) - response = await client.get_notification_config(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GetNotificationConfigRequest() + assert args[0] == securitycenter_service.DeleteNotificationConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, notification_config.NotificationConfig) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.pubsub_topic == "pubsub_topic_value" - assert response.service_account == "service_account_value" + assert response is None @pytest.mark.asyncio -async def test_get_notification_config_async_from_dict(): - await test_get_notification_config_async(request_type=dict) +async def test_delete_notification_config_async_from_dict(): + await test_delete_notification_config_async(request_type=dict) -def test_get_notification_config_field_headers(): +def test_delete_notification_config_field_headers(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.GetNotificationConfigRequest() + request = securitycenter_service.DeleteNotificationConfigRequest() request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: - call.return_value = notification_config.NotificationConfig() - client.get_notification_config(request) + call.return_value = None + client.delete_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -1849,25 +2102,23 @@ def test_get_notification_config_field_headers(): @pytest.mark.asyncio -async def test_get_notification_config_field_headers_async(): +async def test_delete_notification_config_field_headers_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.GetNotificationConfigRequest() + request = securitycenter_service.DeleteNotificationConfigRequest() request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - notification_config.NotificationConfig() - ) - await client.get_notification_config(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -1879,18 +2130,18 @@ async def test_get_notification_config_field_headers_async(): assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_get_notification_config_flattened(): +def test_delete_notification_config_flattened(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = notification_config.NotificationConfig() + call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_notification_config(name="name_value",) + client.delete_notification_config(name="name_value",) # Establish that the underlying call was made with the expected # request object values. @@ -1901,36 +2152,34 @@ def test_get_notification_config_flattened(): assert arg == mock_val -def test_get_notification_config_flattened_error(): +def test_delete_notification_config_flattened_error(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_notification_config( - securitycenter_service.GetNotificationConfigRequest(), name="name_value", + client.delete_notification_config( + securitycenter_service.DeleteNotificationConfigRequest(), name="name_value", ) @pytest.mark.asyncio -async def test_get_notification_config_flattened_async(): +async def test_delete_notification_config_flattened_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = notification_config.NotificationConfig() + call.return_value = None - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - notification_config.NotificationConfig() - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_notification_config(name="name_value",) + response = await client.delete_notification_config(name="name_value",) # Establish that the underlying call was made with the expected # request object values. @@ -1942,7 +2191,7 @@ async def test_get_notification_config_flattened_async(): @pytest.mark.asyncio -async def test_get_notification_config_flattened_error_async(): +async def test_delete_notification_config_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -1950,14 +2199,13 @@ async def test_get_notification_config_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_notification_config( - securitycenter_service.GetNotificationConfigRequest(), name="name_value", + await client.delete_notification_config( + securitycenter_service.DeleteNotificationConfigRequest(), name="name_value", ) -def test_get_organization_settings( - transport: str = "grpc", - request_type=securitycenter_service.GetOrganizationSettingsRequest, +def test_get_iam_policy( + transport: str = "grpc", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1968,31 +2216,27 @@ def test_get_organization_settings( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_organization_settings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = organization_settings.OrganizationSettings( - name="name_value", enable_asset_discovery=True, - ) - response = client.get_organization_settings(request) + call.return_value = policy_pb2.Policy(version=774, etag=b"etag_blob",) + response = client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, organization_settings.OrganizationSettings) - assert response.name == "name_value" - assert response.enable_asset_discovery is True + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b"etag_blob" -def test_get_organization_settings_from_dict(): - test_get_organization_settings(request_type=dict) +def test_get_iam_policy_from_dict(): + test_get_iam_policy(request_type=dict) -def test_get_organization_settings_empty_call(): +def test_get_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SecurityCenterClient( @@ -2000,19 +2244,16 @@ def test_get_organization_settings_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_organization_settings), "__call__" - ) as call: - client.get_organization_settings() + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + client.get_iam_policy() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() @pytest.mark.asyncio -async def test_get_organization_settings_async( - transport: str = "grpc_asyncio", - request_type=securitycenter_service.GetOrganizationSettingsRequest, +async def test_get_iam_policy_async( + transport: str = "grpc_asyncio", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2023,48 +2264,42 @@ async def test_get_organization_settings_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_organization_settings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - organization_settings.OrganizationSettings( - name="name_value", enable_asset_discovery=True, - ) + policy_pb2.Policy(version=774, etag=b"etag_blob",) ) - response = await client.get_organization_settings(request) + response = await client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() # Establish that the response is the type that we expect. - assert isinstance(response, organization_settings.OrganizationSettings) - assert response.name == "name_value" - assert response.enable_asset_discovery is True + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b"etag_blob" @pytest.mark.asyncio -async def test_get_organization_settings_async_from_dict(): - await test_get_organization_settings_async(request_type=dict) +async def test_get_iam_policy_async_from_dict(): + await test_get_iam_policy_async(request_type=dict) -def test_get_organization_settings_field_headers(): +def test_get_iam_policy_field_headers(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.GetOrganizationSettingsRequest() + request = iam_policy_pb2.GetIamPolicyRequest() - request.name = "name/value" + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_organization_settings), "__call__" - ) as call: - call.return_value = organization_settings.OrganizationSettings() - client.get_organization_settings(request) + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2073,29 +2308,25 @@ def test_get_organization_settings_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] @pytest.mark.asyncio -async def test_get_organization_settings_field_headers_async(): +async def test_get_iam_policy_field_headers_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.GetOrganizationSettingsRequest() + request = iam_policy_pb2.GetIamPolicyRequest() - request.name = "name/value" + request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_organization_settings), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - organization_settings.OrganizationSettings() - ) - await client.get_organization_settings(request) + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + await client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2104,73 +2335,82 @@ async def test_get_organization_settings_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_get_organization_settings_flattened(): +def test_get_iam_policy_from_dict_foreign(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_get_iam_policy_flattened(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_organization_settings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = organization_settings.OrganizationSettings() + call.return_value = policy_pb2.Policy() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_organization_settings(name="name_value",) + client.get_iam_policy(resource="resource_value",) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = "name_value" + arg = args[0].resource + mock_val = "resource_value" assert arg == mock_val -def test_get_organization_settings_flattened_error(): +def test_get_iam_policy_flattened_error(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_organization_settings( - securitycenter_service.GetOrganizationSettingsRequest(), name="name_value", + client.get_iam_policy( + iam_policy_pb2.GetIamPolicyRequest(), resource="resource_value", ) @pytest.mark.asyncio -async def test_get_organization_settings_flattened_async(): +async def test_get_iam_policy_flattened_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_organization_settings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = organization_settings.OrganizationSettings() + call.return_value = policy_pb2.Policy() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - organization_settings.OrganizationSettings() - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_organization_settings(name="name_value",) + response = await client.get_iam_policy(resource="resource_value",) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = "name_value" + arg = args[0].resource + mock_val = "resource_value" assert arg == mock_val @pytest.mark.asyncio -async def test_get_organization_settings_flattened_error_async(): +async def test_get_iam_policy_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -2178,13 +2418,13 @@ async def test_get_organization_settings_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_organization_settings( - securitycenter_service.GetOrganizationSettingsRequest(), name="name_value", + await client.get_iam_policy( + iam_policy_pb2.GetIamPolicyRequest(), resource="resource_value", ) -def test_get_source( - transport: str = "grpc", request_type=securitycenter_service.GetSourceRequest +def test_get_mute_config( + transport: str = "grpc", request_type=securitycenter_service.GetMuteConfigRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2195,34 +2435,36 @@ def test_get_source( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_mute_config), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = source.Source( + call.return_value = mute_config.MuteConfig( name="name_value", display_name="display_name_value", description="description_value", - canonical_name="canonical_name_value", + filter="filter_value", + most_recent_editor="most_recent_editor_value", ) - response = client.get_source(request) + response = client.get_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GetSourceRequest() + assert args[0] == securitycenter_service.GetMuteConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, source.Source) + assert isinstance(response, mute_config.MuteConfig) assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.description == "description_value" - assert response.canonical_name == "canonical_name_value" + assert response.filter == "filter_value" + assert response.most_recent_editor == "most_recent_editor_value" -def test_get_source_from_dict(): - test_get_source(request_type=dict) +def test_get_mute_config_from_dict(): + test_get_mute_config(request_type=dict) -def test_get_source_empty_call(): +def test_get_mute_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SecurityCenterClient( @@ -2230,17 +2472,17 @@ def test_get_source_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_source), "__call__") as call: - client.get_source() + with mock.patch.object(type(client.transport.get_mute_config), "__call__") as call: + client.get_mute_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GetSourceRequest() + assert args[0] == securitycenter_service.GetMuteConfigRequest() @pytest.mark.asyncio -async def test_get_source_async( +async def test_get_mute_config_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.GetSourceRequest, + request_type=securitycenter_service.GetMuteConfigRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2251,49 +2493,51 @@ async def test_get_source_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_mute_config), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - source.Source( + mute_config.MuteConfig( name="name_value", display_name="display_name_value", description="description_value", - canonical_name="canonical_name_value", + filter="filter_value", + most_recent_editor="most_recent_editor_value", ) ) - response = await client.get_source(request) + response = await client.get_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GetSourceRequest() + assert args[0] == securitycenter_service.GetMuteConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, source.Source) + assert isinstance(response, mute_config.MuteConfig) assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.description == "description_value" - assert response.canonical_name == "canonical_name_value" + assert response.filter == "filter_value" + assert response.most_recent_editor == "most_recent_editor_value" @pytest.mark.asyncio -async def test_get_source_async_from_dict(): - await test_get_source_async(request_type=dict) +async def test_get_mute_config_async_from_dict(): + await test_get_mute_config_async(request_type=dict) -def test_get_source_field_headers(): +def test_get_mute_config_field_headers(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.GetSourceRequest() + request = securitycenter_service.GetMuteConfigRequest() request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_source), "__call__") as call: - call.return_value = source.Source() - client.get_source(request) + with mock.patch.object(type(client.transport.get_mute_config), "__call__") as call: + call.return_value = mute_config.MuteConfig() + client.get_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2306,21 +2550,23 @@ def test_get_source_field_headers(): @pytest.mark.asyncio -async def test_get_source_field_headers_async(): +async def test_get_mute_config_field_headers_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.GetSourceRequest() + request = securitycenter_service.GetMuteConfigRequest() request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_source), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(source.Source()) - await client.get_source(request) + with mock.patch.object(type(client.transport.get_mute_config), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + mute_config.MuteConfig() + ) + await client.get_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2332,16 +2578,16 @@ async def test_get_source_field_headers_async(): assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_get_source_flattened(): +def test_get_mute_config_flattened(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_mute_config), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = source.Source() + call.return_value = mute_config.MuteConfig() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_source(name="name_value",) + client.get_mute_config(name="name_value",) # Establish that the underlying call was made with the expected # request object values. @@ -2352,32 +2598,34 @@ def test_get_source_flattened(): assert arg == mock_val -def test_get_source_flattened_error(): +def test_get_mute_config_flattened_error(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_source( - securitycenter_service.GetSourceRequest(), name="name_value", + client.get_mute_config( + securitycenter_service.GetMuteConfigRequest(), name="name_value", ) @pytest.mark.asyncio -async def test_get_source_flattened_async(): +async def test_get_mute_config_flattened_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_mute_config), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = source.Source() + call.return_value = mute_config.MuteConfig() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(source.Source()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + mute_config.MuteConfig() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_source(name="name_value",) + response = await client.get_mute_config(name="name_value",) # Establish that the underlying call was made with the expected # request object values. @@ -2389,7 +2637,7 @@ async def test_get_source_flattened_async(): @pytest.mark.asyncio -async def test_get_source_flattened_error_async(): +async def test_get_mute_config_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -2397,13 +2645,14 @@ async def test_get_source_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_source( - securitycenter_service.GetSourceRequest(), name="name_value", + await client.get_mute_config( + securitycenter_service.GetMuteConfigRequest(), name="name_value", ) -def test_group_assets( - transport: str = "grpc", request_type=securitycenter_service.GroupAssetsRequest +def test_get_notification_config( + transport: str = "grpc", + request_type=securitycenter_service.GetNotificationConfigRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2414,29 +2663,39 @@ def test_group_assets( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + with mock.patch.object( + type(client.transport.get_notification_config), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.GroupAssetsResponse( - next_page_token="next_page_token_value", total_size=1086, + call.return_value = notification_config.NotificationConfig( + name="name_value", + description="description_value", + pubsub_topic="pubsub_topic_value", + service_account="service_account_value", + streaming_config=notification_config.NotificationConfig.StreamingConfig( + filter="filter_value" + ), ) - response = client.group_assets(request) + response = client.get_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GroupAssetsRequest() + assert args[0] == securitycenter_service.GetNotificationConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.GroupAssetsPager) - assert response.next_page_token == "next_page_token_value" - assert response.total_size == 1086 + assert isinstance(response, notification_config.NotificationConfig) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.pubsub_topic == "pubsub_topic_value" + assert response.service_account == "service_account_value" -def test_group_assets_from_dict(): - test_group_assets(request_type=dict) +def test_get_notification_config_from_dict(): + test_get_notification_config(request_type=dict) -def test_group_assets_empty_call(): +def test_get_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SecurityCenterClient( @@ -2444,17 +2703,19 @@ def test_group_assets_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_assets), "__call__") as call: - client.group_assets() + with mock.patch.object( + type(client.transport.get_notification_config), "__call__" + ) as call: + client.get_notification_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GroupAssetsRequest() + assert args[0] == securitycenter_service.GetNotificationConfigRequest() @pytest.mark.asyncio -async def test_group_assets_async( +async def test_get_notification_config_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.GroupAssetsRequest, + request_type=securitycenter_service.GetNotificationConfigRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2465,44 +2726,53 @@ async def test_group_assets_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + with mock.patch.object( + type(client.transport.get_notification_config), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.GroupAssetsResponse( - next_page_token="next_page_token_value", total_size=1086, + notification_config.NotificationConfig( + name="name_value", + description="description_value", + pubsub_topic="pubsub_topic_value", + service_account="service_account_value", ) ) - response = await client.group_assets(request) + response = await client.get_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GroupAssetsRequest() + assert args[0] == securitycenter_service.GetNotificationConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.GroupAssetsAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.total_size == 1086 + assert isinstance(response, notification_config.NotificationConfig) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.pubsub_topic == "pubsub_topic_value" + assert response.service_account == "service_account_value" @pytest.mark.asyncio -async def test_group_assets_async_from_dict(): - await test_group_assets_async(request_type=dict) +async def test_get_notification_config_async_from_dict(): + await test_get_notification_config_async(request_type=dict) -def test_group_assets_field_headers(): +def test_get_notification_config_field_headers(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.GroupAssetsRequest() + request = securitycenter_service.GetNotificationConfigRequest() - request.parent = "parent/value" + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_assets), "__call__") as call: - call.return_value = securitycenter_service.GroupAssetsResponse() - client.group_assets(request) + with mock.patch.object( + type(client.transport.get_notification_config), "__call__" + ) as call: + call.return_value = notification_config.NotificationConfig() + client.get_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2511,27 +2781,29 @@ def test_group_assets_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] @pytest.mark.asyncio -async def test_group_assets_field_headers_async(): +async def test_get_notification_config_field_headers_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.GroupAssetsRequest() + request = securitycenter_service.GetNotificationConfigRequest() - request.parent = "parent/value" + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + with mock.patch.object( + type(client.transport.get_notification_config), "__call__" + ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.GroupAssetsResponse() + notification_config.NotificationConfig() ) - await client.group_assets(request) + await client.get_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2540,45 +2812,1098 @@ async def test_group_assets_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] -def test_group_assets_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_get_notification_config_flattened(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_assets), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - securitycenter_service.GroupAssetsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), - ], - next_page_token="abc", - ), - securitycenter_service.GroupAssetsResponse( - group_by_results=[], next_page_token="def", - ), - securitycenter_service.GroupAssetsResponse( - group_by_results=[securitycenter_service.GroupResult(),], - next_page_token="ghi", - ), - securitycenter_service.GroupAssetsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + with mock.patch.object( + type(client.transport.get_notification_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = notification_config.NotificationConfig() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_notification_config(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_notification_config_flattened_error(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_notification_config( + securitycenter_service.GetNotificationConfigRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_notification_config_flattened_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_notification_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = notification_config.NotificationConfig() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + notification_config.NotificationConfig() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_notification_config(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_notification_config_flattened_error_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_notification_config( + securitycenter_service.GetNotificationConfigRequest(), name="name_value", + ) + + +def test_get_organization_settings( + transport: str = "grpc", + request_type=securitycenter_service.GetOrganizationSettingsRequest, +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_organization_settings), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = organization_settings.OrganizationSettings( + name="name_value", enable_asset_discovery=True, + ) + response = client.get_organization_settings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, organization_settings.OrganizationSettings) + assert response.name == "name_value" + assert response.enable_asset_discovery is True + + +def test_get_organization_settings_from_dict(): + test_get_organization_settings(request_type=dict) + + +def test_get_organization_settings_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_organization_settings), "__call__" + ) as call: + client.get_organization_settings() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() + + +@pytest.mark.asyncio +async def test_get_organization_settings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GetOrganizationSettingsRequest, +): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_organization_settings), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + organization_settings.OrganizationSettings( + name="name_value", enable_asset_discovery=True, + ) + ) + response = await client.get_organization_settings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, organization_settings.OrganizationSettings) + assert response.name == "name_value" + assert response.enable_asset_discovery is True + + +@pytest.mark.asyncio +async def test_get_organization_settings_async_from_dict(): + await test_get_organization_settings_async(request_type=dict) + + +def test_get_organization_settings_field_headers(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.GetOrganizationSettingsRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_organization_settings), "__call__" + ) as call: + call.return_value = organization_settings.OrganizationSettings() + client.get_organization_settings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_organization_settings_field_headers_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.GetOrganizationSettingsRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_organization_settings), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + organization_settings.OrganizationSettings() + ) + await client.get_organization_settings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +def test_get_organization_settings_flattened(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_organization_settings), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = organization_settings.OrganizationSettings() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_organization_settings(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_organization_settings_flattened_error(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_organization_settings( + securitycenter_service.GetOrganizationSettingsRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_organization_settings_flattened_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_organization_settings), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = organization_settings.OrganizationSettings() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + organization_settings.OrganizationSettings() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_organization_settings(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_organization_settings_flattened_error_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_organization_settings( + securitycenter_service.GetOrganizationSettingsRequest(), name="name_value", + ) + + +def test_get_source( + transport: str = "grpc", request_type=securitycenter_service.GetSourceRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_source), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = source.Source( + name="name_value", + display_name="display_name_value", + description="description_value", + canonical_name="canonical_name_value", + ) + response = client.get_source(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GetSourceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, source.Source) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.canonical_name == "canonical_name_value" + + +def test_get_source_from_dict(): + test_get_source(request_type=dict) + + +def test_get_source_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_source), "__call__") as call: + client.get_source() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GetSourceRequest() + + +@pytest.mark.asyncio +async def test_get_source_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GetSourceRequest, +): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_source), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + source.Source( + name="name_value", + display_name="display_name_value", + description="description_value", + canonical_name="canonical_name_value", + ) + ) + response = await client.get_source(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GetSourceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, source.Source) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.canonical_name == "canonical_name_value" + + +@pytest.mark.asyncio +async def test_get_source_async_from_dict(): + await test_get_source_async(request_type=dict) + + +def test_get_source_field_headers(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.GetSourceRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_source), "__call__") as call: + call.return_value = source.Source() + client.get_source(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_source_field_headers_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.GetSourceRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_source), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(source.Source()) + await client.get_source(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +def test_get_source_flattened(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_source), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = source.Source() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_source(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_source_flattened_error(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_source( + securitycenter_service.GetSourceRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_source_flattened_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_source), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = source.Source() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(source.Source()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_source(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_source_flattened_error_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_source( + securitycenter_service.GetSourceRequest(), name="name_value", + ) + + +def test_group_assets( + transport: str = "grpc", request_type=securitycenter_service.GroupAssetsRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = securitycenter_service.GroupAssetsResponse( + next_page_token="next_page_token_value", total_size=1086, + ) + response = client.group_assets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GroupAssetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.GroupAssetsPager) + assert response.next_page_token == "next_page_token_value" + assert response.total_size == 1086 + + +def test_group_assets_from_dict(): + test_group_assets(request_type=dict) + + +def test_group_assets_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + client.group_assets() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GroupAssetsRequest() + + +@pytest.mark.asyncio +async def test_group_assets_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GroupAssetsRequest, +): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.GroupAssetsResponse( + next_page_token="next_page_token_value", total_size=1086, + ) + ) + response = await client.group_assets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GroupAssetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.GroupAssetsAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.total_size == 1086 + + +@pytest.mark.asyncio +async def test_group_assets_async_from_dict(): + await test_group_assets_async(request_type=dict) + + +def test_group_assets_field_headers(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.GroupAssetsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + call.return_value = securitycenter_service.GroupAssetsResponse() + client.group_assets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_group_assets_field_headers_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.GroupAssetsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.GroupAssetsResponse() + ) + await client.group_assets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +def test_group_assets_pager(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.GroupAssetsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + ], + next_page_token="abc", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[], next_page_token="def", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[securitycenter_service.GroupResult(),], + next_page_token="ghi", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.group_assets(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) + + +def test_group_assets_pages(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.GroupAssetsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + ], + next_page_token="abc", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[], next_page_token="def", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[securitycenter_service.GroupResult(),], + next_page_token="ghi", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + ], + ), + RuntimeError, + ) + pages = list(client.group_assets(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_group_assets_async_pager(): + client = SecurityCenterAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.group_assets), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.GroupAssetsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + ], + next_page_token="abc", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[], next_page_token="def", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[securitycenter_service.GroupResult(),], + next_page_token="ghi", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + ], + ), + RuntimeError, + ) + async_pager = await client.group_assets(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, securitycenter_service.GroupResult) for i in responses) + + +@pytest.mark.asyncio +async def test_group_assets_async_pages(): + client = SecurityCenterAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.group_assets), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.GroupAssetsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + ], + next_page_token="abc", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[], next_page_token="def", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[securitycenter_service.GroupResult(),], + next_page_token="ghi", + ), + securitycenter_service.GroupAssetsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.group_assets(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_group_findings( + transport: str = "grpc", request_type=securitycenter_service.GroupFindingsRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = securitycenter_service.GroupFindingsResponse( + next_page_token="next_page_token_value", total_size=1086, + ) + response = client.group_findings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GroupFindingsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.GroupFindingsPager) + assert response.next_page_token == "next_page_token_value" + assert response.total_size == 1086 + + +def test_group_findings_from_dict(): + test_group_findings(request_type=dict) + + +def test_group_findings_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + client.group_findings() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GroupFindingsRequest() + + +@pytest.mark.asyncio +async def test_group_findings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GroupFindingsRequest, +): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.GroupFindingsResponse( + next_page_token="next_page_token_value", total_size=1086, + ) + ) + response = await client.group_findings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.GroupFindingsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.GroupFindingsAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.total_size == 1086 + + +@pytest.mark.asyncio +async def test_group_findings_async_from_dict(): + await test_group_findings_async(request_type=dict) + + +def test_group_findings_field_headers(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.GroupFindingsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + call.return_value = securitycenter_service.GroupFindingsResponse() + client.group_findings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_group_findings_field_headers_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.GroupFindingsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.GroupFindingsResponse() + ) + await client.group_findings(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + + +def test_group_findings_flattened(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = securitycenter_service.GroupFindingsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.group_findings( + parent="parent_value", group_by="group_by_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].group_by + mock_val = "group_by_value" + assert arg == mock_val + + +def test_group_findings_flattened_error(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.group_findings( + securitycenter_service.GroupFindingsRequest(), + parent="parent_value", + group_by="group_by_value", + ) + + +@pytest.mark.asyncio +async def test_group_findings_flattened_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = securitycenter_service.GroupFindingsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.GroupFindingsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.group_findings( + parent="parent_value", group_by="group_by_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].group_by + mock_val = "group_by_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_group_findings_flattened_error_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.group_findings( + securitycenter_service.GroupFindingsRequest(), + parent="parent_value", + group_by="group_by_value", + ) + + +def test_group_findings_pager(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + ], + next_page_token="abc", + ), + securitycenter_service.GroupFindingsResponse( + group_by_results=[], next_page_token="def", + ), + securitycenter_service.GroupFindingsResponse( + group_by_results=[securitycenter_service.GroupResult(),], + next_page_token="ghi", + ), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + ], + ), + RuntimeError, ) - pager = client.group_assets(request={}) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.group_findings(request={}) assert pager._metadata == metadata @@ -2587,14 +3912,14 @@ def test_group_assets_pager(): assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) -def test_group_assets_pages(): +def test_group_findings_pages(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -2602,14 +3927,14 @@ def test_group_assets_pages(): ], next_page_token="abc", ), - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[], next_page_token="def", ), - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[securitycenter_service.GroupResult(),], next_page_token="ghi", ), - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -2617,22 +3942,22 @@ def test_group_assets_pages(): ), RuntimeError, ) - pages = list(client.group_assets(request={}).pages) + pages = list(client.group_findings(request={}).pages) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @pytest.mark.asyncio -async def test_group_assets_async_pager(): +async def test_group_findings_async_pager(): client = SecurityCenterAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.group_assets), "__call__", new_callable=mock.AsyncMock + type(client.transport.group_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -2640,14 +3965,14 @@ async def test_group_assets_async_pager(): ], next_page_token="abc", ), - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[], next_page_token="def", ), - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[securitycenter_service.GroupResult(),], next_page_token="ghi", ), - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -2655,7 +3980,7 @@ async def test_group_assets_async_pager(): ), RuntimeError, ) - async_pager = await client.group_assets(request={},) + async_pager = await client.group_findings(request={},) assert async_pager.next_page_token == "abc" responses = [] async for response in async_pager: @@ -2666,16 +3991,16 @@ async def test_group_assets_async_pager(): @pytest.mark.asyncio -async def test_group_assets_async_pages(): +async def test_group_findings_async_pages(): client = SecurityCenterAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.group_assets), "__call__", new_callable=mock.AsyncMock + type(client.transport.group_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -2683,14 +4008,14 @@ async def test_group_assets_async_pages(): ], next_page_token="abc", ), - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[], next_page_token="def", ), - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[securitycenter_service.GroupResult(),], next_page_token="ghi", ), - securitycenter_service.GroupAssetsResponse( + securitycenter_service.GroupFindingsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -2699,14 +4024,14 @@ async def test_group_assets_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.group_assets(request={})).pages: + async for page_ in (await client.group_findings(request={})).pages: pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_group_findings( - transport: str = "grpc", request_type=securitycenter_service.GroupFindingsRequest +def test_list_assets( + transport: str = "grpc", request_type=securitycenter_service.ListAssetsRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2717,29 +4042,29 @@ def test_group_findings( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.GroupFindingsResponse( + call.return_value = securitycenter_service.ListAssetsResponse( next_page_token="next_page_token_value", total_size=1086, ) - response = client.group_findings(request) + response = client.list_assets(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GroupFindingsRequest() + assert args[0] == securitycenter_service.ListAssetsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.GroupFindingsPager) + assert isinstance(response, pagers.ListAssetsPager) assert response.next_page_token == "next_page_token_value" assert response.total_size == 1086 -def test_group_findings_from_dict(): - test_group_findings(request_type=dict) +def test_list_assets_from_dict(): + test_list_assets(request_type=dict) -def test_group_findings_empty_call(): +def test_list_assets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SecurityCenterClient( @@ -2747,17 +4072,17 @@ def test_group_findings_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_findings), "__call__") as call: - client.group_findings() + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: + client.list_assets() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GroupFindingsRequest() + assert args[0] == securitycenter_service.ListAssetsRequest() @pytest.mark.asyncio -async def test_group_findings_async( +async def test_list_assets_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.GroupFindingsRequest, + request_type=securitycenter_service.ListAssetsRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2768,44 +4093,44 @@ async def test_group_findings_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.GroupFindingsResponse( + securitycenter_service.ListAssetsResponse( next_page_token="next_page_token_value", total_size=1086, ) ) - response = await client.group_findings(request) + response = await client.list_assets(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GroupFindingsRequest() + assert args[0] == securitycenter_service.ListAssetsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.GroupFindingsAsyncPager) + assert isinstance(response, pagers.ListAssetsAsyncPager) assert response.next_page_token == "next_page_token_value" assert response.total_size == 1086 @pytest.mark.asyncio -async def test_group_findings_async_from_dict(): - await test_group_findings_async(request_type=dict) +async def test_list_assets_async_from_dict(): + await test_list_assets_async(request_type=dict) -def test_group_findings_field_headers(): +def test_list_assets_field_headers(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.GroupFindingsRequest() + request = securitycenter_service.ListAssetsRequest() request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_findings), "__call__") as call: - call.return_value = securitycenter_service.GroupFindingsResponse() - client.group_findings(request) + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: + call.return_value = securitycenter_service.ListAssetsResponse() + client.list_assets(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2818,23 +4143,23 @@ def test_group_findings_field_headers(): @pytest.mark.asyncio -async def test_group_findings_field_headers_async(): +async def test_list_assets_field_headers_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.GroupFindingsRequest() + request = securitycenter_service.ListAssetsRequest() request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.GroupFindingsResponse() + securitycenter_service.ListAssetsResponse() ) - await client.group_findings(request) + await client.list_assets(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2846,118 +4171,34 @@ async def test_group_findings_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_group_findings_flattened(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_findings), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.GroupFindingsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.group_findings( - parent="parent_value", group_by="group_by_value", - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = "parent_value" - assert arg == mock_val - arg = args[0].group_by - mock_val = "group_by_value" - assert arg == mock_val - - -def test_group_findings_flattened_error(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.group_findings( - securitycenter_service.GroupFindingsRequest(), - parent="parent_value", - group_by="group_by_value", - ) - - -@pytest.mark.asyncio -async def test_group_findings_flattened_async(): - client = SecurityCenterAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_findings), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.GroupFindingsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.GroupFindingsResponse() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.group_findings( - parent="parent_value", group_by="group_by_value", - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = "parent_value" - assert arg == mock_val - arg = args[0].group_by - mock_val = "group_by_value" - assert arg == mock_val - - -@pytest.mark.asyncio -async def test_group_findings_flattened_error_async(): - client = SecurityCenterAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.group_findings( - securitycenter_service.GroupFindingsRequest(), - parent="parent_value", - group_by="group_by_value", - ) - - -def test_group_findings_pager(): +def test_list_assets_pager(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="abc", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[], next_page_token="def", + securitycenter_service.ListAssetsResponse( + list_assets_results=[], next_page_token="def", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[securitycenter_service.GroupResult(),], + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + ], next_page_token="ghi", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], ), RuntimeError, @@ -2967,135 +4208,147 @@ def test_group_findings_pager(): metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) - pager = client.group_findings(request={}) + pager = client.list_assets(request={}) assert pager._metadata == metadata results = [i for i in pager] assert len(results) == 6 - assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) + assert all( + isinstance(i, securitycenter_service.ListAssetsResponse.ListAssetsResult) + for i in results + ) -def test_group_findings_pages(): +def test_list_assets_pages(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="abc", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[], next_page_token="def", + securitycenter_service.ListAssetsResponse( + list_assets_results=[], next_page_token="def", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[securitycenter_service.GroupResult(),], + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + ], next_page_token="ghi", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], ), RuntimeError, ) - pages = list(client.group_findings(request={}).pages) + pages = list(client.list_assets(request={}).pages) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @pytest.mark.asyncio -async def test_group_findings_async_pager(): +async def test_list_assets_async_pager(): client = SecurityCenterAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.group_findings), "__call__", new_callable=mock.AsyncMock + type(client.transport.list_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="abc", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[], next_page_token="def", + securitycenter_service.ListAssetsResponse( + list_assets_results=[], next_page_token="def", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[securitycenter_service.GroupResult(),], + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + ], next_page_token="ghi", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], ), RuntimeError, ) - async_pager = await client.group_findings(request={},) + async_pager = await client.list_assets(request={},) assert async_pager.next_page_token == "abc" responses = [] async for response in async_pager: responses.append(response) assert len(responses) == 6 - assert all(isinstance(i, securitycenter_service.GroupResult) for i in responses) + assert all( + isinstance(i, securitycenter_service.ListAssetsResponse.ListAssetsResult) + for i in responses + ) @pytest.mark.asyncio -async def test_group_findings_async_pages(): +async def test_list_assets_async_pages(): client = SecurityCenterAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.group_findings), "__call__", new_callable=mock.AsyncMock + type(client.transport.list_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="abc", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[], next_page_token="def", + securitycenter_service.ListAssetsResponse( + list_assets_results=[], next_page_token="def", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[securitycenter_service.GroupResult(),], + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + ], next_page_token="ghi", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], ), RuntimeError, ) pages = [] - async for page_ in (await client.group_findings(request={})).pages: + async for page_ in (await client.list_assets(request={})).pages: pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_list_assets( - transport: str = "grpc", request_type=securitycenter_service.ListAssetsRequest +def test_list_findings( + transport: str = "grpc", request_type=securitycenter_service.ListFindingsRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3106,29 +4359,29 @@ def test_list_assets( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListAssetsResponse( + call.return_value = securitycenter_service.ListFindingsResponse( next_page_token="next_page_token_value", total_size=1086, ) - response = client.list_assets(request) + response = client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.ListAssetsRequest() + assert args[0] == securitycenter_service.ListFindingsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListAssetsPager) + assert isinstance(response, pagers.ListFindingsPager) assert response.next_page_token == "next_page_token_value" assert response.total_size == 1086 -def test_list_assets_from_dict(): - test_list_assets(request_type=dict) +def test_list_findings_from_dict(): + test_list_findings(request_type=dict) -def test_list_assets_empty_call(): +def test_list_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SecurityCenterClient( @@ -3136,17 +4389,17 @@ def test_list_assets_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_assets), "__call__") as call: - client.list_assets() + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: + client.list_findings() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.ListAssetsRequest() + assert args[0] == securitycenter_service.ListFindingsRequest() @pytest.mark.asyncio -async def test_list_assets_async( +async def test_list_findings_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.ListAssetsRequest, + request_type=securitycenter_service.ListFindingsRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3157,44 +4410,44 @@ async def test_list_assets_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListAssetsResponse( + securitycenter_service.ListFindingsResponse( next_page_token="next_page_token_value", total_size=1086, ) ) - response = await client.list_assets(request) + response = await client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.ListAssetsRequest() + assert args[0] == securitycenter_service.ListFindingsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListAssetsAsyncPager) + assert isinstance(response, pagers.ListFindingsAsyncPager) assert response.next_page_token == "next_page_token_value" assert response.total_size == 1086 @pytest.mark.asyncio -async def test_list_assets_async_from_dict(): - await test_list_assets_async(request_type=dict) +async def test_list_findings_async_from_dict(): + await test_list_findings_async(request_type=dict) -def test_list_assets_field_headers(): +def test_list_findings_field_headers(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.ListAssetsRequest() + request = securitycenter_service.ListFindingsRequest() request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_assets), "__call__") as call: - call.return_value = securitycenter_service.ListAssetsResponse() - client.list_assets(request) + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: + call.return_value = securitycenter_service.ListFindingsResponse() + client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3207,23 +4460,23 @@ def test_list_assets_field_headers(): @pytest.mark.asyncio -async def test_list_assets_field_headers_async(): +async def test_list_findings_field_headers_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.ListAssetsRequest() + request = securitycenter_service.ListFindingsRequest() request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListAssetsResponse() + securitycenter_service.ListFindingsResponse() ) - await client.list_assets(request) + await client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3235,34 +4488,34 @@ async def test_list_assets_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_assets_pager(): +def test_list_findings_pager(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="abc", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[], next_page_token="def", + securitycenter_service.ListFindingsResponse( + list_findings_results=[], next_page_token="def", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], ), RuntimeError, @@ -3272,91 +4525,93 @@ def test_list_assets_pager(): metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) - pager = client.list_assets(request={}) + pager = client.list_findings(request={}) assert pager._metadata == metadata results = [i for i in pager] assert len(results) == 6 assert all( - isinstance(i, securitycenter_service.ListAssetsResponse.ListAssetsResult) + isinstance( + i, securitycenter_service.ListFindingsResponse.ListFindingsResult + ) for i in results ) -def test_list_assets_pages(): +def test_list_findings_pages(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="abc", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[], next_page_token="def", + securitycenter_service.ListFindingsResponse( + list_findings_results=[], next_page_token="def", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], ), RuntimeError, ) - pages = list(client.list_assets(request={}).pages) + pages = list(client.list_findings(request={}).pages) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @pytest.mark.asyncio -async def test_list_assets_async_pager(): +async def test_list_findings_async_pager(): client = SecurityCenterAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_assets), "__call__", new_callable=mock.AsyncMock + type(client.transport.list_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="abc", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[], next_page_token="def", + securitycenter_service.ListFindingsResponse( + list_findings_results=[], next_page_token="def", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], ), RuntimeError, ) - async_pager = await client.list_assets(request={},) + async_pager = await client.list_findings(request={},) assert async_pager.next_page_token == "abc" responses = [] async for response in async_pager: @@ -3364,55 +4619,57 @@ async def test_list_assets_async_pager(): assert len(responses) == 6 assert all( - isinstance(i, securitycenter_service.ListAssetsResponse.ListAssetsResult) + isinstance( + i, securitycenter_service.ListFindingsResponse.ListFindingsResult + ) for i in responses ) @pytest.mark.asyncio -async def test_list_assets_async_pages(): +async def test_list_findings_async_pages(): client = SecurityCenterAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_assets), "__call__", new_callable=mock.AsyncMock + type(client.transport.list_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="abc", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[], next_page_token="def", + securitycenter_service.ListFindingsResponse( + list_findings_results=[], next_page_token="def", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_assets(request={})).pages: + async for page_ in (await client.list_findings(request={})).pages: pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_list_findings( - transport: str = "grpc", request_type=securitycenter_service.ListFindingsRequest +def test_list_mute_configs( + transport: str = "grpc", request_type=securitycenter_service.ListMuteConfigsRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3423,29 +4680,30 @@ def test_list_findings( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_findings), "__call__") as call: + with mock.patch.object( + type(client.transport.list_mute_configs), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListFindingsResponse( - next_page_token="next_page_token_value", total_size=1086, + call.return_value = securitycenter_service.ListMuteConfigsResponse( + next_page_token="next_page_token_value", ) - response = client.list_findings(request) + response = client.list_mute_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.ListFindingsRequest() + assert args[0] == securitycenter_service.ListMuteConfigsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListFindingsPager) + assert isinstance(response, pagers.ListMuteConfigsPager) assert response.next_page_token == "next_page_token_value" - assert response.total_size == 1086 -def test_list_findings_from_dict(): - test_list_findings(request_type=dict) +def test_list_mute_configs_from_dict(): + test_list_mute_configs(request_type=dict) -def test_list_findings_empty_call(): +def test_list_mute_configs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SecurityCenterClient( @@ -3453,17 +4711,19 @@ def test_list_findings_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_findings), "__call__") as call: - client.list_findings() + with mock.patch.object( + type(client.transport.list_mute_configs), "__call__" + ) as call: + client.list_mute_configs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.ListFindingsRequest() + assert args[0] == securitycenter_service.ListMuteConfigsRequest() @pytest.mark.asyncio -async def test_list_findings_async( +async def test_list_mute_configs_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.ListFindingsRequest, + request_type=securitycenter_service.ListMuteConfigsRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3474,44 +4734,47 @@ async def test_list_findings_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_findings), "__call__") as call: + with mock.patch.object( + type(client.transport.list_mute_configs), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListFindingsResponse( - next_page_token="next_page_token_value", total_size=1086, + securitycenter_service.ListMuteConfigsResponse( + next_page_token="next_page_token_value", ) ) - response = await client.list_findings(request) + response = await client.list_mute_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.ListFindingsRequest() + assert args[0] == securitycenter_service.ListMuteConfigsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListFindingsAsyncPager) + assert isinstance(response, pagers.ListMuteConfigsAsyncPager) assert response.next_page_token == "next_page_token_value" - assert response.total_size == 1086 @pytest.mark.asyncio -async def test_list_findings_async_from_dict(): - await test_list_findings_async(request_type=dict) +async def test_list_mute_configs_async_from_dict(): + await test_list_mute_configs_async(request_type=dict) -def test_list_findings_field_headers(): +def test_list_mute_configs_field_headers(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.ListFindingsRequest() + request = securitycenter_service.ListMuteConfigsRequest() request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_findings), "__call__") as call: - call.return_value = securitycenter_service.ListFindingsResponse() - client.list_findings(request) + with mock.patch.object( + type(client.transport.list_mute_configs), "__call__" + ) as call: + call.return_value = securitycenter_service.ListMuteConfigsResponse() + client.list_mute_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3524,23 +4787,25 @@ def test_list_findings_field_headers(): @pytest.mark.asyncio -async def test_list_findings_field_headers_async(): +async def test_list_mute_configs_field_headers_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = securitycenter_service.ListFindingsRequest() + request = securitycenter_service.ListMuteConfigsRequest() request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_findings), "__call__") as call: + with mock.patch.object( + type(client.transport.list_mute_configs), "__call__" + ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListFindingsResponse() + securitycenter_service.ListMuteConfigsResponse() ) - await client.list_findings(request) + await client.list_mute_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3552,35 +4817,107 @@ async def test_list_findings_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_findings_pager(): +def test_list_mute_configs_flattened(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_mute_configs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = securitycenter_service.ListMuteConfigsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_mute_configs(parent="parent_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_mute_configs_flattened_error(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_mute_configs( + securitycenter_service.ListMuteConfigsRequest(), parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_mute_configs_flattened_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_mute_configs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = securitycenter_service.ListMuteConfigsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListMuteConfigsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_mute_configs(parent="parent_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_mute_configs_flattened_error_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_mute_configs( + securitycenter_service.ListMuteConfigsRequest(), parent="parent_value", + ) + + +def test_list_mute_configs_pager(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_findings), "__call__") as call: + with mock.patch.object( + type(client.transport.list_mute_configs), "__call__" + ) as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], next_page_token="abc", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[], next_page_token="def", + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[], next_page_token="def", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - ], - next_page_token="ghi", + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[mute_config.MuteConfig(),], next_page_token="ghi", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - ], + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[mute_config.MuteConfig(), mute_config.MuteConfig(),], ), RuntimeError, ) @@ -3589,144 +4926,122 @@ def test_list_findings_pager(): metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) - pager = client.list_findings(request={}) + pager = client.list_mute_configs(request={}) assert pager._metadata == metadata results = [i for i in pager] assert len(results) == 6 - assert all( - isinstance( - i, securitycenter_service.ListFindingsResponse.ListFindingsResult - ) - for i in results - ) + assert all(isinstance(i, mute_config.MuteConfig) for i in results) -def test_list_findings_pages(): +def test_list_mute_configs_pages(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_findings), "__call__") as call: + with mock.patch.object( + type(client.transport.list_mute_configs), "__call__" + ) as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], next_page_token="abc", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[], next_page_token="def", + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[], next_page_token="def", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - ], - next_page_token="ghi", + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[mute_config.MuteConfig(),], next_page_token="ghi", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - ], + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[mute_config.MuteConfig(), mute_config.MuteConfig(),], ), RuntimeError, ) - pages = list(client.list_findings(request={}).pages) + pages = list(client.list_mute_configs(request={}).pages) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @pytest.mark.asyncio -async def test_list_findings_async_pager(): +async def test_list_mute_configs_async_pager(): client = SecurityCenterAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_findings), "__call__", new_callable=mock.AsyncMock + type(client.transport.list_mute_configs), + "__call__", + new_callable=mock.AsyncMock, ) as call: # Set the response to a series of pages. call.side_effect = ( - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], next_page_token="abc", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[], next_page_token="def", + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[], next_page_token="def", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - ], - next_page_token="ghi", + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[mute_config.MuteConfig(),], next_page_token="ghi", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - ], + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[mute_config.MuteConfig(), mute_config.MuteConfig(),], ), RuntimeError, ) - async_pager = await client.list_findings(request={},) + async_pager = await client.list_mute_configs(request={},) assert async_pager.next_page_token == "abc" responses = [] async for response in async_pager: responses.append(response) assert len(responses) == 6 - assert all( - isinstance( - i, securitycenter_service.ListFindingsResponse.ListFindingsResult - ) - for i in responses - ) + assert all(isinstance(i, mute_config.MuteConfig) for i in responses) @pytest.mark.asyncio -async def test_list_findings_async_pages(): +async def test_list_mute_configs_async_pages(): client = SecurityCenterAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_findings), "__call__", new_callable=mock.AsyncMock + type(client.transport.list_mute_configs), + "__call__", + new_callable=mock.AsyncMock, ) as call: - # Set the response to a series of pages. - call.side_effect = ( - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], next_page_token="abc", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[], next_page_token="def", + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[], next_page_token="def", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - ], - next_page_token="ghi", + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[mute_config.MuteConfig(),], next_page_token="ghi", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - ], + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[mute_config.MuteConfig(), mute_config.MuteConfig(),], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_findings(request={})).pages: + async for page_ in (await client.list_mute_configs(request={})).pages: pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -4720,7 +6035,9 @@ def test_set_finding_state( external_uri="external_uri_value", severity=finding.Finding.Severity.CRITICAL, canonical_name="canonical_name_value", + mute=finding.Finding.Mute.MUTED, finding_class=finding.Finding.FindingClass.THREAT, + mute_initiator="mute_initiator_value", ) response = client.set_finding_state(request) @@ -4739,7 +6056,9 @@ def test_set_finding_state( assert response.external_uri == "external_uri_value" assert response.severity == finding.Finding.Severity.CRITICAL assert response.canonical_name == "canonical_name_value" + assert response.mute == finding.Finding.Mute.MUTED assert response.finding_class == finding.Finding.FindingClass.THREAT + assert response.mute_initiator == "mute_initiator_value" def test_set_finding_state_from_dict(): @@ -4791,7 +6110,9 @@ async def test_set_finding_state_async( external_uri="external_uri_value", severity=finding.Finding.Severity.CRITICAL, canonical_name="canonical_name_value", + mute=finding.Finding.Mute.MUTED, finding_class=finding.Finding.FindingClass.THREAT, + mute_initiator="mute_initiator_value", ) ) response = await client.set_finding_state(request) @@ -4811,7 +6132,9 @@ async def test_set_finding_state_async( assert response.external_uri == "external_uri_value" assert response.severity == finding.Finding.Severity.CRITICAL assert response.canonical_name == "canonical_name_value" + assert response.mute == finding.Finding.Mute.MUTED assert response.finding_class == finding.Finding.FindingClass.THREAT + assert response.mute_initiator == "mute_initiator_value" @pytest.mark.asyncio @@ -4878,17 +6201,289 @@ def test_set_finding_state_flattened(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_finding_state), "__call__" - ) as call: + with mock.patch.object( + type(client.transport.set_finding_state), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = finding.Finding() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.set_finding_state( + name="name_value", + state=finding.Finding.State.ACTIVE, + start_time=timestamp_pb2.Timestamp(seconds=751), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].state + mock_val = finding.Finding.State.ACTIVE + assert arg == mock_val + assert TimestampRule().to_proto(args[0].start_time) == timestamp_pb2.Timestamp( + seconds=751 + ) + + +def test_set_finding_state_flattened_error(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.set_finding_state( + securitycenter_service.SetFindingStateRequest(), + name="name_value", + state=finding.Finding.State.ACTIVE, + start_time=timestamp_pb2.Timestamp(seconds=751), + ) + + +@pytest.mark.asyncio +async def test_set_finding_state_flattened_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_finding_state), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = finding.Finding() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.set_finding_state( + name="name_value", + state=finding.Finding.State.ACTIVE, + start_time=timestamp_pb2.Timestamp(seconds=751), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].state + mock_val = finding.Finding.State.ACTIVE + assert arg == mock_val + assert TimestampRule().to_proto(args[0].start_time) == timestamp_pb2.Timestamp( + seconds=751 + ) + + +@pytest.mark.asyncio +async def test_set_finding_state_flattened_error_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.set_finding_state( + securitycenter_service.SetFindingStateRequest(), + name="name_value", + state=finding.Finding.State.ACTIVE, + start_time=timestamp_pb2.Timestamp(seconds=751), + ) + + +def test_set_mute( + transport: str = "grpc", request_type=securitycenter_service.SetMuteRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_mute), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = finding.Finding( + name="name_value", + parent="parent_value", + resource_name="resource_name_value", + state=finding.Finding.State.ACTIVE, + category="category_value", + external_uri="external_uri_value", + severity=finding.Finding.Severity.CRITICAL, + canonical_name="canonical_name_value", + mute=finding.Finding.Mute.MUTED, + finding_class=finding.Finding.FindingClass.THREAT, + mute_initiator="mute_initiator_value", + ) + response = client.set_mute(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.SetMuteRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, finding.Finding) + assert response.name == "name_value" + assert response.parent == "parent_value" + assert response.resource_name == "resource_name_value" + assert response.state == finding.Finding.State.ACTIVE + assert response.category == "category_value" + assert response.external_uri == "external_uri_value" + assert response.severity == finding.Finding.Severity.CRITICAL + assert response.canonical_name == "canonical_name_value" + assert response.mute == finding.Finding.Mute.MUTED + assert response.finding_class == finding.Finding.FindingClass.THREAT + assert response.mute_initiator == "mute_initiator_value" + + +def test_set_mute_from_dict(): + test_set_mute(request_type=dict) + + +def test_set_mute_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_mute), "__call__") as call: + client.set_mute() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.SetMuteRequest() + + +@pytest.mark.asyncio +async def test_set_mute_async( + transport: str = "grpc_asyncio", request_type=securitycenter_service.SetMuteRequest +): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_mute), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + finding.Finding( + name="name_value", + parent="parent_value", + resource_name="resource_name_value", + state=finding.Finding.State.ACTIVE, + category="category_value", + external_uri="external_uri_value", + severity=finding.Finding.Severity.CRITICAL, + canonical_name="canonical_name_value", + mute=finding.Finding.Mute.MUTED, + finding_class=finding.Finding.FindingClass.THREAT, + mute_initiator="mute_initiator_value", + ) + ) + response = await client.set_mute(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.SetMuteRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, finding.Finding) + assert response.name == "name_value" + assert response.parent == "parent_value" + assert response.resource_name == "resource_name_value" + assert response.state == finding.Finding.State.ACTIVE + assert response.category == "category_value" + assert response.external_uri == "external_uri_value" + assert response.severity == finding.Finding.Severity.CRITICAL + assert response.canonical_name == "canonical_name_value" + assert response.mute == finding.Finding.Mute.MUTED + assert response.finding_class == finding.Finding.FindingClass.THREAT + assert response.mute_initiator == "mute_initiator_value" + + +@pytest.mark.asyncio +async def test_set_mute_async_from_dict(): + await test_set_mute_async(request_type=dict) + + +def test_set_mute_field_headers(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.SetMuteRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_mute), "__call__") as call: + call.return_value = finding.Finding() + client.set_mute(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_mute_field_headers_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.SetMuteRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_mute), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) + await client.set_mute(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +def test_set_mute_flattened(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_mute), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.set_finding_state( - name="name_value", - state=finding.Finding.State.ACTIVE, - start_time=timestamp_pb2.Timestamp(seconds=751), + client.set_mute( + name="name_value", mute=finding.Finding.Mute.MUTED, ) # Establish that the underlying call was made with the expected @@ -4898,48 +6493,40 @@ def test_set_finding_state_flattened(): arg = args[0].name mock_val = "name_value" assert arg == mock_val - arg = args[0].state - mock_val = finding.Finding.State.ACTIVE + arg = args[0].mute + mock_val = finding.Finding.Mute.MUTED assert arg == mock_val - assert TimestampRule().to_proto(args[0].start_time) == timestamp_pb2.Timestamp( - seconds=751 - ) -def test_set_finding_state_flattened_error(): +def test_set_mute_flattened_error(): client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.set_finding_state( - securitycenter_service.SetFindingStateRequest(), + client.set_mute( + securitycenter_service.SetMuteRequest(), name="name_value", - state=finding.Finding.State.ACTIVE, - start_time=timestamp_pb2.Timestamp(seconds=751), + mute=finding.Finding.Mute.MUTED, ) @pytest.mark.asyncio -async def test_set_finding_state_flattened_async(): +async def test_set_mute_flattened_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_finding_state), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_mute), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.set_finding_state( - name="name_value", - state=finding.Finding.State.ACTIVE, - start_time=timestamp_pb2.Timestamp(seconds=751), + response = await client.set_mute( + name="name_value", mute=finding.Finding.Mute.MUTED, ) # Establish that the underlying call was made with the expected @@ -4949,16 +6536,13 @@ async def test_set_finding_state_flattened_async(): arg = args[0].name mock_val = "name_value" assert arg == mock_val - arg = args[0].state - mock_val = finding.Finding.State.ACTIVE + arg = args[0].mute + mock_val = finding.Finding.Mute.MUTED assert arg == mock_val - assert TimestampRule().to_proto(args[0].start_time) == timestamp_pb2.Timestamp( - seconds=751 - ) @pytest.mark.asyncio -async def test_set_finding_state_flattened_error_async(): +async def test_set_mute_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4966,11 +6550,10 @@ async def test_set_finding_state_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.set_finding_state( - securitycenter_service.SetFindingStateRequest(), + await client.set_mute( + securitycenter_service.SetMuteRequest(), name="name_value", - state=finding.Finding.State.ACTIVE, - start_time=timestamp_pb2.Timestamp(seconds=751), + mute=finding.Finding.Mute.MUTED, ) @@ -5472,7 +7055,9 @@ def test_update_finding( external_uri="external_uri_value", severity=gcs_finding.Finding.Severity.CRITICAL, canonical_name="canonical_name_value", + mute=gcs_finding.Finding.Mute.MUTED, finding_class=gcs_finding.Finding.FindingClass.THREAT, + mute_initiator="mute_initiator_value", ) response = client.update_finding(request) @@ -5491,7 +7076,9 @@ def test_update_finding( assert response.external_uri == "external_uri_value" assert response.severity == gcs_finding.Finding.Severity.CRITICAL assert response.canonical_name == "canonical_name_value" + assert response.mute == gcs_finding.Finding.Mute.MUTED assert response.finding_class == gcs_finding.Finding.FindingClass.THREAT + assert response.mute_initiator == "mute_initiator_value" def test_update_finding_from_dict(): @@ -5539,7 +7126,9 @@ async def test_update_finding_async( external_uri="external_uri_value", severity=gcs_finding.Finding.Severity.CRITICAL, canonical_name="canonical_name_value", + mute=gcs_finding.Finding.Mute.MUTED, finding_class=gcs_finding.Finding.FindingClass.THREAT, + mute_initiator="mute_initiator_value", ) ) response = await client.update_finding(request) @@ -5559,7 +7148,9 @@ async def test_update_finding_async( assert response.external_uri == "external_uri_value" assert response.severity == gcs_finding.Finding.Severity.CRITICAL assert response.canonical_name == "canonical_name_value" + assert response.mute == gcs_finding.Finding.Mute.MUTED assert response.finding_class == gcs_finding.Finding.FindingClass.THREAT + assert response.mute_initiator == "mute_initiator_value" @pytest.mark.asyncio @@ -5696,6 +7287,267 @@ async def test_update_finding_flattened_error_async(): ) +def test_update_mute_config( + transport: str = "grpc", request_type=securitycenter_service.UpdateMuteConfigRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_mute_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gcs_mute_config.MuteConfig( + name="name_value", + display_name="display_name_value", + description="description_value", + filter="filter_value", + most_recent_editor="most_recent_editor_value", + ) + response = client.update_mute_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.UpdateMuteConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gcs_mute_config.MuteConfig) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.filter == "filter_value" + assert response.most_recent_editor == "most_recent_editor_value" + + +def test_update_mute_config_from_dict(): + test_update_mute_config(request_type=dict) + + +def test_update_mute_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_mute_config), "__call__" + ) as call: + client.update_mute_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.UpdateMuteConfigRequest() + + +@pytest.mark.asyncio +async def test_update_mute_config_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateMuteConfigRequest, +): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_mute_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_mute_config.MuteConfig( + name="name_value", + display_name="display_name_value", + description="description_value", + filter="filter_value", + most_recent_editor="most_recent_editor_value", + ) + ) + response = await client.update_mute_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.UpdateMuteConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gcs_mute_config.MuteConfig) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.filter == "filter_value" + assert response.most_recent_editor == "most_recent_editor_value" + + +@pytest.mark.asyncio +async def test_update_mute_config_async_from_dict(): + await test_update_mute_config_async(request_type=dict) + + +def test_update_mute_config_field_headers(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.UpdateMuteConfigRequest() + + request.mute_config.name = "mute_config.name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_mute_config), "__call__" + ) as call: + call.return_value = gcs_mute_config.MuteConfig() + client.update_mute_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "mute_config.name=mute_config.name/value",) in kw[ + "metadata" + ] + + +@pytest.mark.asyncio +async def test_update_mute_config_field_headers_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.UpdateMuteConfigRequest() + + request.mute_config.name = "mute_config.name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_mute_config), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_mute_config.MuteConfig() + ) + await client.update_mute_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "mute_config.name=mute_config.name/value",) in kw[ + "metadata" + ] + + +def test_update_mute_config_flattened(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_mute_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gcs_mute_config.MuteConfig() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_mute_config( + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].mute_config + mock_val = gcs_mute_config.MuteConfig(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_mute_config_flattened_error(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_mute_config( + securitycenter_service.UpdateMuteConfigRequest(), + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_mute_config_flattened_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_mute_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gcs_mute_config.MuteConfig() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_mute_config.MuteConfig() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_mute_config( + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].mute_config + mock_val = gcs_mute_config.MuteConfig(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_mute_config_flattened_error_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_mute_config( + securitycenter_service.UpdateMuteConfigRequest(), + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + def test_update_notification_config( transport: str = "grpc", request_type=securitycenter_service.UpdateNotificationConfigRequest, @@ -6775,11 +8627,15 @@ def test_security_center_base_transport(): # Every method on the transport should just blindly # raise NotImplementedError. methods = ( + "bulk_mute_findings", "create_source", "create_finding", + "create_mute_config", "create_notification_config", + "delete_mute_config", "delete_notification_config", "get_iam_policy", + "get_mute_config", "get_notification_config", "get_organization_settings", "get_source", @@ -6787,13 +8643,16 @@ def test_security_center_base_transport(): "group_findings", "list_assets", "list_findings", + "list_mute_configs", "list_notification_configs", "list_sources", "run_asset_discovery", "set_finding_state", + "set_mute", "set_iam_policy", "test_iam_permissions", "update_finding", + "update_mute_config", "update_notification_config", "update_organization_settings", "update_source", @@ -7171,9 +9030,31 @@ def test_parse_finding_path(): assert expected == actual -def test_notification_config_path(): +def test_mute_config_path(): organization = "scallop" - notification_config = "abalone" + mute_config = "abalone" + expected = "organizations/{organization}/muteConfigs/{mute_config}".format( + organization=organization, mute_config=mute_config, + ) + actual = SecurityCenterClient.mute_config_path(organization, mute_config) + assert expected == actual + + +def test_parse_mute_config_path(): + expected = { + "organization": "squid", + "mute_config": "clam", + } + path = SecurityCenterClient.mute_config_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_mute_config_path(path) + assert expected == actual + + +def test_notification_config_path(): + organization = "whelk" + notification_config = "octopus" expected = "organizations/{organization}/notificationConfigs/{notification_config}".format( organization=organization, notification_config=notification_config, ) @@ -7185,8 +9066,8 @@ def test_notification_config_path(): def test_parse_notification_config_path(): expected = { - "organization": "squid", - "notification_config": "clam", + "organization": "oyster", + "notification_config": "nudibranch", } path = SecurityCenterClient.notification_config_path(**expected) @@ -7196,7 +9077,7 @@ def test_parse_notification_config_path(): def test_organization_settings_path(): - organization = "whelk" + organization = "cuttlefish" expected = "organizations/{organization}/organizationSettings".format( organization=organization, ) @@ -7206,7 +9087,7 @@ def test_organization_settings_path(): def test_parse_organization_settings_path(): expected = { - "organization": "octopus", + "organization": "mussel", } path = SecurityCenterClient.organization_settings_path(**expected) @@ -7216,8 +9097,8 @@ def test_parse_organization_settings_path(): def test_security_marks_path(): - organization = "oyster" - asset = "nudibranch" + organization = "winkle" + asset = "nautilus" expected = "organizations/{organization}/assets/{asset}/securityMarks".format( organization=organization, asset=asset, ) @@ -7227,8 +9108,8 @@ def test_security_marks_path(): def test_parse_security_marks_path(): expected = { - "organization": "cuttlefish", - "asset": "mussel", + "organization": "scallop", + "asset": "abalone", } path = SecurityCenterClient.security_marks_path(**expected) @@ -7238,8 +9119,8 @@ def test_parse_security_marks_path(): def test_source_path(): - organization = "winkle" - source = "nautilus" + organization = "squid" + source = "clam" expected = "organizations/{organization}/sources/{source}".format( organization=organization, source=source, ) @@ -7249,8 +9130,8 @@ def test_source_path(): def test_parse_source_path(): expected = { - "organization": "scallop", - "source": "abalone", + "organization": "whelk", + "source": "octopus", } path = SecurityCenterClient.source_path(**expected) @@ -7260,8 +9141,8 @@ def test_parse_source_path(): def test_topic_path(): - project = "squid" - topic = "clam" + project = "oyster" + topic = "nudibranch" expected = "projects/{project}/topics/{topic}".format(project=project, topic=topic,) actual = SecurityCenterClient.topic_path(project, topic) assert expected == actual @@ -7269,8 +9150,8 @@ def test_topic_path(): def test_parse_topic_path(): expected = { - "project": "whelk", - "topic": "octopus", + "project": "cuttlefish", + "topic": "mussel", } path = SecurityCenterClient.topic_path(**expected) @@ -7280,7 +9161,7 @@ def test_parse_topic_path(): def test_common_billing_account_path(): - billing_account = "oyster" + billing_account = "winkle" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -7290,7 +9171,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nudibranch", + "billing_account": "nautilus", } path = SecurityCenterClient.common_billing_account_path(**expected) @@ -7300,7 +9181,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "cuttlefish" + folder = "scallop" expected = "folders/{folder}".format(folder=folder,) actual = SecurityCenterClient.common_folder_path(folder) assert expected == actual @@ -7308,7 +9189,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "mussel", + "folder": "abalone", } path = SecurityCenterClient.common_folder_path(**expected) @@ -7318,7 +9199,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "winkle" + organization = "squid" expected = "organizations/{organization}".format(organization=organization,) actual = SecurityCenterClient.common_organization_path(organization) assert expected == actual @@ -7326,7 +9207,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nautilus", + "organization": "clam", } path = SecurityCenterClient.common_organization_path(**expected) @@ -7336,7 +9217,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "scallop" + project = "whelk" expected = "projects/{project}".format(project=project,) actual = SecurityCenterClient.common_project_path(project) assert expected == actual @@ -7344,7 +9225,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "abalone", + "project": "octopus", } path = SecurityCenterClient.common_project_path(**expected) @@ -7354,8 +9235,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "squid" - location = "clam" + project = "oyster" + location = "nudibranch" expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -7365,8 +9246,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "whelk", - "location": "octopus", + "project": "cuttlefish", + "location": "mussel", } path = SecurityCenterClient.common_location_path(**expected) From 8c988a6bb1f2d0814386916c51c64fb8c4c15345 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 19 Nov 2021 23:48:39 +0000 Subject: [PATCH 11/19] feat: Added a new API method UpdateExternalSystem (#256) .. which enables updating a finding w/ external system metadata. External systems are a child resource under finding, and are housed on the finding itself, and can also be filtered on in Notifications, the ListFindings and GroupFindings API. - [ ] Regenerate this pull request now. PiperOrigin-RevId: 411093163 Source-Link: https://github.com/googleapis/googleapis/commit/be8f9889c7662043b89f63d475e72eea9a0621af Source-Link: https://github.com/googleapis/googleapis-gen/commit/186665a0ff6acaf9bf6d5ef0cef663dd828b48a7 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMTg2NjY1YTBmZjZhY2FmOWJmNmQ1ZWYwY2VmNjYzZGQ4MjhiNDhhNyJ9 --- google/cloud/securitycenter/__init__.py | 6 + google/cloud/securitycenter_v1/__init__.py | 4 + .../securitycenter_v1/gapic_metadata.json | 10 + .../services/security_center/async_client.py | 90 +++++ .../services/security_center/client.py | 107 +++++ .../security_center/transports/base.py | 18 + .../security_center/transports/grpc.py | 30 ++ .../transports/grpc_asyncio.py | 30 ++ .../cloud/securitycenter_v1/types/__init__.py | 4 + .../types/external_system.py | 59 +++ .../cloud/securitycenter_v1/types/finding.py | 8 + .../types/securitycenter_service.py | 23 ++ scripts/fixup_securitycenter_v1_keywords.py | 1 + .../securitycenter_v1/test_security_center.py | 370 ++++++++++++++++-- 14 files changed, 722 insertions(+), 38 deletions(-) create mode 100644 google/cloud/securitycenter_v1/types/external_system.py diff --git a/google/cloud/securitycenter/__init__.py b/google/cloud/securitycenter/__init__.py index 5f2e4ba8..b940ed8a 100644 --- a/google/cloud/securitycenter/__init__.py +++ b/google/cloud/securitycenter/__init__.py @@ -22,6 +22,7 @@ ) from google.cloud.securitycenter_v1.types.asset import Asset +from google.cloud.securitycenter_v1.types.external_system import ExternalSystem from google.cloud.securitycenter_v1.types.finding import Finding from google.cloud.securitycenter_v1.types.folder import Folder from google.cloud.securitycenter_v1.types.indicator import Indicator @@ -122,6 +123,9 @@ SetFindingStateRequest, ) from google.cloud.securitycenter_v1.types.securitycenter_service import SetMuteRequest +from google.cloud.securitycenter_v1.types.securitycenter_service import ( + UpdateExternalSystemRequest, +) from google.cloud.securitycenter_v1.types.securitycenter_service import ( UpdateFindingRequest, ) @@ -150,6 +154,7 @@ "SecurityCenterClient", "SecurityCenterAsyncClient", "Asset", + "ExternalSystem", "Finding", "Folder", "Indicator", @@ -190,6 +195,7 @@ "RunAssetDiscoveryRequest", "SetFindingStateRequest", "SetMuteRequest", + "UpdateExternalSystemRequest", "UpdateFindingRequest", "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", diff --git a/google/cloud/securitycenter_v1/__init__.py b/google/cloud/securitycenter_v1/__init__.py index 743b5fee..e1cecc33 100644 --- a/google/cloud/securitycenter_v1/__init__.py +++ b/google/cloud/securitycenter_v1/__init__.py @@ -18,6 +18,7 @@ from .services.security_center import SecurityCenterAsyncClient from .types.asset import Asset +from .types.external_system import ExternalSystem from .types.finding import Finding from .types.folder import Folder from .types.indicator import Indicator @@ -58,6 +59,7 @@ from .types.securitycenter_service import RunAssetDiscoveryRequest from .types.securitycenter_service import SetFindingStateRequest from .types.securitycenter_service import SetMuteRequest +from .types.securitycenter_service import UpdateExternalSystemRequest from .types.securitycenter_service import UpdateFindingRequest from .types.securitycenter_service import UpdateMuteConfigRequest from .types.securitycenter_service import UpdateNotificationConfigRequest @@ -83,6 +85,7 @@ "Cvssv3", "DeleteMuteConfigRequest", "DeleteNotificationConfigRequest", + "ExternalSystem", "Finding", "Folder", "GetMuteConfigRequest", @@ -118,6 +121,7 @@ "SetFindingStateRequest", "SetMuteRequest", "Source", + "UpdateExternalSystemRequest", "UpdateFindingRequest", "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", diff --git a/google/cloud/securitycenter_v1/gapic_metadata.json b/google/cloud/securitycenter_v1/gapic_metadata.json index 50c3bcb4..0d42f887 100644 --- a/google/cloud/securitycenter_v1/gapic_metadata.json +++ b/google/cloud/securitycenter_v1/gapic_metadata.json @@ -130,6 +130,11 @@ "test_iam_permissions" ] }, + "UpdateExternalSystem": { + "methods": [ + "update_external_system" + ] + }, "UpdateFinding": { "methods": [ "update_finding" @@ -285,6 +290,11 @@ "test_iam_permissions" ] }, + "UpdateExternalSystem": { + "methods": [ + "update_external_system" + ] + }, "UpdateFinding": { "methods": [ "update_finding" diff --git a/google/cloud/securitycenter_v1/services/security_center/async_client.py b/google/cloud/securitycenter_v1/services/security_center/async_client.py index ff090b80..011a66dc 100644 --- a/google/cloud/securitycenter_v1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1/services/security_center/async_client.py @@ -34,6 +34,7 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.securitycenter_v1.services.security_center import pagers +from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import indicator @@ -74,6 +75,10 @@ class SecurityCenterAsyncClient: asset_path = staticmethod(SecurityCenterClient.asset_path) parse_asset_path = staticmethod(SecurityCenterClient.parse_asset_path) + external_system_path = staticmethod(SecurityCenterClient.external_system_path) + parse_external_system_path = staticmethod( + SecurityCenterClient.parse_external_system_path + ) finding_path = staticmethod(SecurityCenterClient.finding_path) parse_finding_path = staticmethod(SecurityCenterClient.parse_finding_path) mute_config_path = staticmethod(SecurityCenterClient.mute_config_path) @@ -2406,6 +2411,91 @@ async def test_iam_permissions( # Done; return the response. return response + async def update_external_system( + self, + request: Union[securitycenter_service.UpdateExternalSystemRequest, dict] = None, + *, + external_system: gcs_external_system.ExternalSystem = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_external_system.ExternalSystem: + r"""Updates external system. This is for a given finding. + + Args: + request (Union[google.cloud.securitycenter_v1.types.UpdateExternalSystemRequest, dict]): + The request object. Request message for updating a + ExternalSystem resource. + external_system (:class:`google.cloud.securitycenter_v1.types.ExternalSystem`): + Required. The external system + resource to update. + + This corresponds to the ``external_system`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + The FieldMask to use when updating + the external system resource. + If empty all mutable fields will be + updated. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.types.ExternalSystem: + Representation of third party + SIEM/SOAR fields within SCC. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([external_system, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.UpdateExternalSystemRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if external_system is not None: + request.external_system = external_system + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_external_system, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("external_system.name", request.external_system.name),) + ), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + async def update_finding( self, request: Union[securitycenter_service.UpdateFindingRequest, dict] = None, diff --git a/google/cloud/securitycenter_v1/services/security_center/client.py b/google/cloud/securitycenter_v1/services/security_center/client.py index 6a6918b2..f9f7097a 100644 --- a/google/cloud/securitycenter_v1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1/services/security_center/client.py @@ -37,6 +37,7 @@ from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.securitycenter_v1.services.security_center import pagers +from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import indicator @@ -200,6 +201,27 @@ def parse_asset_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def external_system_path( + organization: str, source: str, finding: str, externalsystem: str, + ) -> str: + """Returns a fully-qualified external_system string.""" + return "organizations/{organization}/sources/{source}/findings/{finding}/externalSystems/{externalsystem}".format( + organization=organization, + source=source, + finding=finding, + externalsystem=externalsystem, + ) + + @staticmethod + def parse_external_system_path(path: str) -> Dict[str, str]: + """Parses a external_system path into its component segments.""" + m = re.match( + r"^organizations/(?P.+?)/sources/(?P.+?)/findings/(?P.+?)/externalSystems/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def finding_path(organization: str, source: str, finding: str,) -> str: """Returns a fully-qualified finding string.""" @@ -2584,6 +2606,91 @@ def test_iam_permissions( # Done; return the response. return response + def update_external_system( + self, + request: Union[securitycenter_service.UpdateExternalSystemRequest, dict] = None, + *, + external_system: gcs_external_system.ExternalSystem = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_external_system.ExternalSystem: + r"""Updates external system. This is for a given finding. + + Args: + request (Union[google.cloud.securitycenter_v1.types.UpdateExternalSystemRequest, dict]): + The request object. Request message for updating a + ExternalSystem resource. + external_system (google.cloud.securitycenter_v1.types.ExternalSystem): + Required. The external system + resource to update. + + This corresponds to the ``external_system`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The FieldMask to use when updating + the external system resource. + If empty all mutable fields will be + updated. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.securitycenter_v1.types.ExternalSystem: + Representation of third party + SIEM/SOAR fields within SCC. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([external_system, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a securitycenter_service.UpdateExternalSystemRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.UpdateExternalSystemRequest): + request = securitycenter_service.UpdateExternalSystemRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if external_system is not None: + request.external_system = external_system + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_external_system] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("external_system.name", request.external_system.name),) + ), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + def update_finding( self, request: Union[securitycenter_service.UpdateFindingRequest, dict] = None, diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1/services/security_center/transports/base.py index 6ee5d6cf..51fac89b 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/base.py @@ -26,6 +26,7 @@ from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import mute_config @@ -349,6 +350,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.update_external_system: gapic_v1.method.wrap_method( + self.update_external_system, + default_timeout=None, + client_info=client_info, + ), self.update_finding: gapic_v1.method.wrap_method( self.update_finding, default_timeout=60.0, client_info=client_info, ), @@ -638,6 +644,18 @@ def test_iam_permissions( ]: raise NotImplementedError() + @property + def update_external_system( + self, + ) -> Callable[ + [securitycenter_service.UpdateExternalSystemRequest], + Union[ + gcs_external_system.ExternalSystem, + Awaitable[gcs_external_system.ExternalSystem], + ], + ]: + raise NotImplementedError() + @property def update_finding( self, diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py index 8b1bae77..a67df2d7 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py @@ -25,6 +25,7 @@ import grpc # type: ignore +from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import mute_config @@ -949,6 +950,35 @@ def test_iam_permissions( ) return self._stubs["test_iam_permissions"] + @property + def update_external_system( + self, + ) -> Callable[ + [securitycenter_service.UpdateExternalSystemRequest], + gcs_external_system.ExternalSystem, + ]: + r"""Return a callable for the update external system method over gRPC. + + Updates external system. This is for a given finding. + + Returns: + Callable[[~.UpdateExternalSystemRequest], + ~.ExternalSystem]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_external_system" not in self._stubs: + self._stubs["update_external_system"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/UpdateExternalSystem", + request_serializer=securitycenter_service.UpdateExternalSystemRequest.serialize, + response_deserializer=gcs_external_system.ExternalSystem.deserialize, + ) + return self._stubs["update_external_system"] + @property def update_finding( self, diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py index a173cfa6..ece0ef4b 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py @@ -25,6 +25,7 @@ import grpc # type: ignore from grpc.experimental import aio # type: ignore +from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import mute_config @@ -965,6 +966,35 @@ def test_iam_permissions( ) return self._stubs["test_iam_permissions"] + @property + def update_external_system( + self, + ) -> Callable[ + [securitycenter_service.UpdateExternalSystemRequest], + Awaitable[gcs_external_system.ExternalSystem], + ]: + r"""Return a callable for the update external system method over gRPC. + + Updates external system. This is for a given finding. + + Returns: + Callable[[~.UpdateExternalSystemRequest], + Awaitable[~.ExternalSystem]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_external_system" not in self._stubs: + self._stubs["update_external_system"] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/UpdateExternalSystem", + request_serializer=securitycenter_service.UpdateExternalSystemRequest.serialize, + response_deserializer=gcs_external_system.ExternalSystem.deserialize, + ) + return self._stubs["update_external_system"] + @property def update_finding( self, diff --git a/google/cloud/securitycenter_v1/types/__init__.py b/google/cloud/securitycenter_v1/types/__init__.py index aae0aa3d..6bf0d256 100644 --- a/google/cloud/securitycenter_v1/types/__init__.py +++ b/google/cloud/securitycenter_v1/types/__init__.py @@ -14,6 +14,7 @@ # limitations under the License. # from .asset import Asset +from .external_system import ExternalSystem from .finding import Finding from .folder import Folder from .indicator import Indicator @@ -55,6 +56,7 @@ RunAssetDiscoveryRequest, SetFindingStateRequest, SetMuteRequest, + UpdateExternalSystemRequest, UpdateFindingRequest, UpdateMuteConfigRequest, UpdateNotificationConfigRequest, @@ -72,6 +74,7 @@ __all__ = ( "Asset", + "ExternalSystem", "Finding", "Folder", "Indicator", @@ -112,6 +115,7 @@ "RunAssetDiscoveryRequest", "SetFindingStateRequest", "SetMuteRequest", + "UpdateExternalSystemRequest", "UpdateFindingRequest", "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", diff --git a/google/cloud/securitycenter_v1/types/external_system.py b/google/cloud/securitycenter_v1/types/external_system.py new file mode 100644 index 00000000..d3154435 --- /dev/null +++ b/google/cloud/securitycenter_v1/types/external_system.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.securitycenter.v1", manifest={"ExternalSystem",}, +) + + +class ExternalSystem(proto.Message): + r"""Representation of third party SIEM/SOAR fields within SCC. + + Attributes: + name (str): + External System Name e.g. jira, demisto, etc. e.g.: + ``organizations/1234/sources/5678/findings/123456/externalSystems/jira`` + ``folders/1234/sources/5678/findings/123456/externalSystems/jira`` + ``projects/1234/sources/5678/findings/123456/externalSystems/jira`` + assignees (Sequence[str]): + References primary/secondary etc assignees in + the external system. + external_uid (str): + Identifier that's used to track the given + finding in the external system. + status (str): + Most recent status of the corresponding + finding's ticket/tracker in the external system. + external_system_update_time (google.protobuf.timestamp_pb2.Timestamp): + The most recent time when the corresponding + finding's ticket/tracker was updated in the + external system. + """ + + name = proto.Field(proto.STRING, number=1,) + assignees = proto.RepeatedField(proto.STRING, number=2,) + external_uid = proto.Field(proto.STRING, number=3,) + status = proto.Field(proto.STRING, number=4,) + external_system_update_time = proto.Field( + proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/securitycenter_v1/types/finding.py b/google/cloud/securitycenter_v1/types/finding.py index de6db7be..e12600b5 100644 --- a/google/cloud/securitycenter_v1/types/finding.py +++ b/google/cloud/securitycenter_v1/types/finding.py @@ -15,6 +15,7 @@ # import proto # type: ignore +from google.cloud.securitycenter_v1.types import external_system from google.cloud.securitycenter_v1.types import indicator as gcs_indicator from google.cloud.securitycenter_v1.types import security_marks as gcs_security_marks from google.cloud.securitycenter_v1.types import vulnerability as gcs_vulnerability @@ -121,6 +122,10 @@ class Finding(proto.Message): mute_update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The most recent time this finding was muted or unmuted. + external_systems (Sequence[google.cloud.securitycenter_v1.types.Finding.ExternalSystemsEntry]): + Output only. Third party SIEM/SOAR fields + within SCC, contains external system information + and external system finding fields. mute_initiator (str): First known as mute_annotation. Records additional information about the mute operation e.g. mute config that @@ -183,6 +188,9 @@ class FindingClass(proto.Enum): mute_update_time = proto.Field( proto.MESSAGE, number=21, message=timestamp_pb2.Timestamp, ) + external_systems = proto.MapField( + proto.STRING, proto.MESSAGE, number=22, message=external_system.ExternalSystem, + ) mute_initiator = proto.Field(proto.STRING, number=28,) diff --git a/google/cloud/securitycenter_v1/types/securitycenter_service.py b/google/cloud/securitycenter_v1/types/securitycenter_service.py index 6033a41d..b36295d4 100644 --- a/google/cloud/securitycenter_v1/types/securitycenter_service.py +++ b/google/cloud/securitycenter_v1/types/securitycenter_service.py @@ -16,6 +16,7 @@ import proto # type: ignore from google.cloud.securitycenter_v1.types import asset as gcs_asset +from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import folder from google.cloud.securitycenter_v1.types import mute_config as gcs_mute_config @@ -66,6 +67,7 @@ "SetFindingStateRequest", "SetMuteRequest", "RunAssetDiscoveryRequest", + "UpdateExternalSystemRequest", "UpdateFindingRequest", "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", @@ -1436,6 +1438,27 @@ class RunAssetDiscoveryRequest(proto.Message): parent = proto.Field(proto.STRING, number=1,) +class UpdateExternalSystemRequest(proto.Message): + r"""Request message for updating a ExternalSystem resource. + + Attributes: + external_system (google.cloud.securitycenter_v1.types.ExternalSystem): + Required. The external system resource to + update. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The FieldMask to use when updating the + external system resource. + If empty all mutable fields will be updated. + """ + + external_system = proto.Field( + proto.MESSAGE, number=1, message=gcs_external_system.ExternalSystem, + ) + update_mask = proto.Field( + proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + ) + + class UpdateFindingRequest(proto.Message): r"""Request message for updating or creating a finding. diff --git a/scripts/fixup_securitycenter_v1_keywords.py b/scripts/fixup_securitycenter_v1_keywords.py index 5649718b..ee3fea5b 100644 --- a/scripts/fixup_securitycenter_v1_keywords.py +++ b/scripts/fixup_securitycenter_v1_keywords.py @@ -63,6 +63,7 @@ class securitycenterCallTransformer(cst.CSTTransformer): 'set_iam_policy': ('resource', 'policy', ), 'set_mute': ('name', 'mute', ), 'test_iam_permissions': ('resource', 'permissions', ), + 'update_external_system': ('external_system', 'update_mask', ), 'update_finding': ('finding', 'update_mask', ), 'update_mute_config': ('mute_config', 'update_mask', ), 'update_notification_config': ('notification_config', 'update_mask', ), diff --git a/tests/unit/gapic/securitycenter_v1/test_security_center.py b/tests/unit/gapic/securitycenter_v1/test_security_center.py index 447cd0bc..210e6dbb 100644 --- a/tests/unit/gapic/securitycenter_v1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1/test_security_center.py @@ -40,6 +40,8 @@ from google.cloud.securitycenter_v1.services.security_center import SecurityCenterClient from google.cloud.securitycenter_v1.services.security_center import pagers from google.cloud.securitycenter_v1.services.security_center import transports +from google.cloud.securitycenter_v1.types import external_system +from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import finding from google.cloud.securitycenter_v1.types import finding as gcs_finding from google.cloud.securitycenter_v1.types import indicator @@ -7032,6 +7034,266 @@ async def test_test_iam_permissions_flattened_error_async(): ) +def test_update_external_system( + transport: str = "grpc", + request_type=securitycenter_service.UpdateExternalSystemRequest, +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_external_system), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gcs_external_system.ExternalSystem( + name="name_value", + assignees=["assignees_value"], + external_uid="external_uid_value", + status="status_value", + ) + response = client.update_external_system(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.UpdateExternalSystemRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gcs_external_system.ExternalSystem) + assert response.name == "name_value" + assert response.assignees == ["assignees_value"] + assert response.external_uid == "external_uid_value" + assert response.status == "status_value" + + +def test_update_external_system_from_dict(): + test_update_external_system(request_type=dict) + + +def test_update_external_system_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_external_system), "__call__" + ) as call: + client.update_external_system() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.UpdateExternalSystemRequest() + + +@pytest.mark.asyncio +async def test_update_external_system_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateExternalSystemRequest, +): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_external_system), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_external_system.ExternalSystem( + name="name_value", + assignees=["assignees_value"], + external_uid="external_uid_value", + status="status_value", + ) + ) + response = await client.update_external_system(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.UpdateExternalSystemRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gcs_external_system.ExternalSystem) + assert response.name == "name_value" + assert response.assignees == ["assignees_value"] + assert response.external_uid == "external_uid_value" + assert response.status == "status_value" + + +@pytest.mark.asyncio +async def test_update_external_system_async_from_dict(): + await test_update_external_system_async(request_type=dict) + + +def test_update_external_system_field_headers(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.UpdateExternalSystemRequest() + + request.external_system.name = "external_system.name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_external_system), "__call__" + ) as call: + call.return_value = gcs_external_system.ExternalSystem() + client.update_external_system(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "external_system.name=external_system.name/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_external_system_field_headers_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = securitycenter_service.UpdateExternalSystemRequest() + + request.external_system.name = "external_system.name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_external_system), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_external_system.ExternalSystem() + ) + await client.update_external_system(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "external_system.name=external_system.name/value", + ) in kw["metadata"] + + +def test_update_external_system_flattened(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_external_system), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gcs_external_system.ExternalSystem() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_external_system( + external_system=gcs_external_system.ExternalSystem(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].external_system + mock_val = gcs_external_system.ExternalSystem(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_external_system_flattened_error(): + client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_external_system( + securitycenter_service.UpdateExternalSystemRequest(), + external_system=gcs_external_system.ExternalSystem(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_external_system_flattened_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_external_system), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gcs_external_system.ExternalSystem() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_external_system.ExternalSystem() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_external_system( + external_system=gcs_external_system.ExternalSystem(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].external_system + mock_val = gcs_external_system.ExternalSystem(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_external_system_flattened_error_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_external_system( + securitycenter_service.UpdateExternalSystemRequest(), + external_system=gcs_external_system.ExternalSystem(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + def test_update_finding( transport: str = "grpc", request_type=securitycenter_service.UpdateFindingRequest ): @@ -8651,6 +8913,7 @@ def test_security_center_base_transport(): "set_mute", "set_iam_policy", "test_iam_permissions", + "update_external_system", "update_finding", "update_mute_config", "update_notification_config", @@ -9006,10 +9269,41 @@ def test_parse_asset_path(): assert expected == actual -def test_finding_path(): +def test_external_system_path(): organization = "oyster" source = "nudibranch" finding = "cuttlefish" + externalsystem = "mussel" + expected = "organizations/{organization}/sources/{source}/findings/{finding}/externalSystems/{externalsystem}".format( + organization=organization, + source=source, + finding=finding, + externalsystem=externalsystem, + ) + actual = SecurityCenterClient.external_system_path( + organization, source, finding, externalsystem + ) + assert expected == actual + + +def test_parse_external_system_path(): + expected = { + "organization": "winkle", + "source": "nautilus", + "finding": "scallop", + "externalsystem": "abalone", + } + path = SecurityCenterClient.external_system_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_external_system_path(path) + assert expected == actual + + +def test_finding_path(): + organization = "squid" + source = "clam" + finding = "whelk" expected = "organizations/{organization}/sources/{source}/findings/{finding}".format( organization=organization, source=source, finding=finding, ) @@ -9019,9 +9313,9 @@ def test_finding_path(): def test_parse_finding_path(): expected = { - "organization": "mussel", - "source": "winkle", - "finding": "nautilus", + "organization": "octopus", + "source": "oyster", + "finding": "nudibranch", } path = SecurityCenterClient.finding_path(**expected) @@ -9031,8 +9325,8 @@ def test_parse_finding_path(): def test_mute_config_path(): - organization = "scallop" - mute_config = "abalone" + organization = "cuttlefish" + mute_config = "mussel" expected = "organizations/{organization}/muteConfigs/{mute_config}".format( organization=organization, mute_config=mute_config, ) @@ -9042,8 +9336,8 @@ def test_mute_config_path(): def test_parse_mute_config_path(): expected = { - "organization": "squid", - "mute_config": "clam", + "organization": "winkle", + "mute_config": "nautilus", } path = SecurityCenterClient.mute_config_path(**expected) @@ -9053,8 +9347,8 @@ def test_parse_mute_config_path(): def test_notification_config_path(): - organization = "whelk" - notification_config = "octopus" + organization = "scallop" + notification_config = "abalone" expected = "organizations/{organization}/notificationConfigs/{notification_config}".format( organization=organization, notification_config=notification_config, ) @@ -9066,8 +9360,8 @@ def test_notification_config_path(): def test_parse_notification_config_path(): expected = { - "organization": "oyster", - "notification_config": "nudibranch", + "organization": "squid", + "notification_config": "clam", } path = SecurityCenterClient.notification_config_path(**expected) @@ -9077,7 +9371,7 @@ def test_parse_notification_config_path(): def test_organization_settings_path(): - organization = "cuttlefish" + organization = "whelk" expected = "organizations/{organization}/organizationSettings".format( organization=organization, ) @@ -9087,7 +9381,7 @@ def test_organization_settings_path(): def test_parse_organization_settings_path(): expected = { - "organization": "mussel", + "organization": "octopus", } path = SecurityCenterClient.organization_settings_path(**expected) @@ -9097,8 +9391,8 @@ def test_parse_organization_settings_path(): def test_security_marks_path(): - organization = "winkle" - asset = "nautilus" + organization = "oyster" + asset = "nudibranch" expected = "organizations/{organization}/assets/{asset}/securityMarks".format( organization=organization, asset=asset, ) @@ -9108,8 +9402,8 @@ def test_security_marks_path(): def test_parse_security_marks_path(): expected = { - "organization": "scallop", - "asset": "abalone", + "organization": "cuttlefish", + "asset": "mussel", } path = SecurityCenterClient.security_marks_path(**expected) @@ -9119,8 +9413,8 @@ def test_parse_security_marks_path(): def test_source_path(): - organization = "squid" - source = "clam" + organization = "winkle" + source = "nautilus" expected = "organizations/{organization}/sources/{source}".format( organization=organization, source=source, ) @@ -9130,8 +9424,8 @@ def test_source_path(): def test_parse_source_path(): expected = { - "organization": "whelk", - "source": "octopus", + "organization": "scallop", + "source": "abalone", } path = SecurityCenterClient.source_path(**expected) @@ -9141,8 +9435,8 @@ def test_parse_source_path(): def test_topic_path(): - project = "oyster" - topic = "nudibranch" + project = "squid" + topic = "clam" expected = "projects/{project}/topics/{topic}".format(project=project, topic=topic,) actual = SecurityCenterClient.topic_path(project, topic) assert expected == actual @@ -9150,8 +9444,8 @@ def test_topic_path(): def test_parse_topic_path(): expected = { - "project": "cuttlefish", - "topic": "mussel", + "project": "whelk", + "topic": "octopus", } path = SecurityCenterClient.topic_path(**expected) @@ -9161,7 +9455,7 @@ def test_parse_topic_path(): def test_common_billing_account_path(): - billing_account = "winkle" + billing_account = "oyster" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -9171,7 +9465,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nautilus", + "billing_account": "nudibranch", } path = SecurityCenterClient.common_billing_account_path(**expected) @@ -9181,7 +9475,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "scallop" + folder = "cuttlefish" expected = "folders/{folder}".format(folder=folder,) actual = SecurityCenterClient.common_folder_path(folder) assert expected == actual @@ -9189,7 +9483,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "abalone", + "folder": "mussel", } path = SecurityCenterClient.common_folder_path(**expected) @@ -9199,7 +9493,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "squid" + organization = "winkle" expected = "organizations/{organization}".format(organization=organization,) actual = SecurityCenterClient.common_organization_path(organization) assert expected == actual @@ -9207,7 +9501,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "clam", + "organization": "nautilus", } path = SecurityCenterClient.common_organization_path(**expected) @@ -9217,7 +9511,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "whelk" + project = "scallop" expected = "projects/{project}".format(project=project,) actual = SecurityCenterClient.common_project_path(project) assert expected == actual @@ -9225,7 +9519,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "octopus", + "project": "abalone", } path = SecurityCenterClient.common_project_path(**expected) @@ -9235,8 +9529,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "oyster" - location = "nudibranch" + project = "squid" + location = "clam" expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -9246,8 +9540,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "cuttlefish", - "location": "mussel", + "project": "whelk", + "location": "octopus", } path = SecurityCenterClient.common_location_path(**expected) From 1689fc9ff8ba6799ff3a3c6858fade769e06ca32 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Wed, 29 Dec 2021 19:57:14 -0500 Subject: [PATCH 12/19] chore: add api_shortname to repo-metadata.json (#260) --- .repo-metadata.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.repo-metadata.json b/.repo-metadata.json index 30ea938e..1ae200e4 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -2,9 +2,9 @@ "name": "securitycenter", "name_pretty": "Google Cloud Security Command Center", "product_documentation": "https://cloud.google.com/security-command-center", - "client_documentation": "https://googleapis.dev/python/securitycenter/latest", + "client_documentation": "https://cloud.google.com/python/docs/reference/securitycenter/latest", "issue_tracker": "https://issuetracker.google.com/savedsearches/559748", - "release_level": "ga", + "release_level": "stable", "language": "python", "library_type": "GAPIC_AUTO", "repo": "googleapis/python-securitycenter", @@ -12,5 +12,6 @@ "api_id": "securitycenter.googleapis.com", "requires_billing": true, "default_version": "v1", - "codeowner_team": "" + "codeowner_team": "", + "api_shortname": "securitycenter" } From 3d10b480a4a557d4422dbe8a4797209c7092a98b Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 6 Jan 2022 17:16:59 +0000 Subject: [PATCH 13/19] chore: use python-samples-reviewers (#262) --- .github/.OwlBot.lock.yaml | 2 +- .github/CODEOWNERS | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 7519fa3a..f33299dd 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:0e18b9475fbeb12d9ad4302283171edebb6baf2dfca1bd215ee3b34ed79d95d7 + digest: sha256:899d5d7cc340fa8ef9d8ae1a8cfba362c6898584f779e156f25ee828ba824610 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 44cc8685..e446644f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -8,5 +8,5 @@ # @googleapis/yoshi-python is the default owner for changes in this repo * @googleapis/yoshi-python -# @googleapis/python-samples-owners is the default owner for samples changes -/samples/ @googleapis/python-samples-owners +# @googleapis/python-samples-reviewers is the default owner for samples changes +/samples/ @googleapis/python-samples-reviewers From 38441ec83c99d0182162e7164aa745c0bef362f5 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 11 Jan 2022 10:06:20 -0500 Subject: [PATCH 14/19] chore: use gapic-generator-python 0.58.4 (#261) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: use gapic-generator-python 0.58.4 fix: provide appropriate mock values for message body fields committer: dovs PiperOrigin-RevId: 419025932 Source-Link: https://github.com/googleapis/googleapis/commit/73da6697f598f1ba30618924936a59f8e457ec89 Source-Link: https://github.com/googleapis/googleapis-gen/commit/46df624a54b9ed47c1a7eefb7a49413cf7b82f98 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDZkZjYyNGE1NGI5ZWQ0N2MxYTdlZWZiN2E0OTQxM2NmN2I4MmY5OCJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../security_center/transports/base.py | 1 - .../security_center/transports/base.py | 1 - .../security_center/transports/base.py | 1 - .../securitycenter_v1/test_security_center.py | 443 +++++++----------- .../test_security_center.py | 272 +++++------ .../test_security_center.py | 344 ++++++-------- 6 files changed, 439 insertions(+), 623 deletions(-) diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1/services/security_center/transports/base.py index 51fac89b..ffea33c4 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/base.py @@ -122,7 +122,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py index 38abc3d0..ff1bf24e 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py @@ -116,7 +116,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py index 1913413f..49684808 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py @@ -121,7 +121,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/tests/unit/gapic/securitycenter_v1/test_security_center.py b/tests/unit/gapic/securitycenter_v1/test_security_center.py index 210e6dbb..c823d051 100644 --- a/tests/unit/gapic/securitycenter_v1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1/test_security_center.py @@ -281,20 +281,20 @@ def test_security_center_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -353,7 +353,7 @@ def test_security_center_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -448,7 +448,7 @@ def test_security_center_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -479,7 +479,7 @@ def test_security_center_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -512,9 +512,10 @@ def test_security_center_client_client_options_from_dict(): ) -def test_bulk_mute_findings( - transport: str = "grpc", request_type=securitycenter_service.BulkMuteFindingsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.BulkMuteFindingsRequest, dict,] +) +def test_bulk_mute_findings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -540,10 +541,6 @@ def test_bulk_mute_findings( assert isinstance(response, future.Future) -def test_bulk_mute_findings_from_dict(): - test_bulk_mute_findings(request_type=dict) - - def test_bulk_mute_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -731,9 +728,10 @@ async def test_bulk_mute_findings_flattened_error_async(): ) -def test_create_source( - transport: str = "grpc", request_type=securitycenter_service.CreateSourceRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.CreateSourceRequest, dict,] +) +def test_create_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -766,10 +764,6 @@ def test_create_source( assert response.canonical_name == "canonical_name_value" -def test_create_source_from_dict(): - test_create_source(request_type=dict) - - def test_create_source_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -964,9 +958,10 @@ async def test_create_source_flattened_error_async(): ) -def test_create_finding( - transport: str = "grpc", request_type=securitycenter_service.CreateFindingRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.CreateFindingRequest, dict,] +) +def test_create_finding(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1013,10 +1008,6 @@ def test_create_finding( assert response.mute_initiator == "mute_initiator_value" -def test_create_finding_from_dict(): - test_create_finding(request_type=dict) - - def test_create_finding_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1237,9 +1228,10 @@ async def test_create_finding_flattened_error_async(): ) -def test_create_mute_config( - transport: str = "grpc", request_type=securitycenter_service.CreateMuteConfigRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.CreateMuteConfigRequest, dict,] +) +def test_create_mute_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1276,10 +1268,6 @@ def test_create_mute_config( assert response.most_recent_editor == "most_recent_editor_value" -def test_create_mute_config_from_dict(): - test_create_mute_config(request_type=dict) - - def test_create_mute_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1504,10 +1492,10 @@ async def test_create_mute_config_flattened_error_async(): ) -def test_create_notification_config( - transport: str = "grpc", - request_type=securitycenter_service.CreateNotificationConfigRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.CreateNotificationConfigRequest, dict,] +) +def test_create_notification_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1545,10 +1533,6 @@ def test_create_notification_config( assert response.service_account == "service_account_value" -def test_create_notification_config_from_dict(): - test_create_notification_config(request_type=dict) - - def test_create_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1779,9 +1763,10 @@ async def test_create_notification_config_flattened_error_async(): ) -def test_delete_mute_config( - transport: str = "grpc", request_type=securitycenter_service.DeleteMuteConfigRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.DeleteMuteConfigRequest, dict,] +) +def test_delete_mute_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1807,10 +1792,6 @@ def test_delete_mute_config( assert response is None -def test_delete_mute_config_from_dict(): - test_delete_mute_config(request_type=dict) - - def test_delete_mute_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1992,10 +1973,10 @@ async def test_delete_mute_config_flattened_error_async(): ) -def test_delete_notification_config( - transport: str = "grpc", - request_type=securitycenter_service.DeleteNotificationConfigRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.DeleteNotificationConfigRequest, dict,] +) +def test_delete_notification_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2021,10 +2002,6 @@ def test_delete_notification_config( assert response is None -def test_delete_notification_config_from_dict(): - test_delete_notification_config(request_type=dict) - - def test_delete_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2206,9 +2183,8 @@ async def test_delete_notification_config_flattened_error_async(): ) -def test_get_iam_policy( - transport: str = "grpc", request_type=iam_policy_pb2.GetIamPolicyRequest -): +@pytest.mark.parametrize("request_type", [iam_policy_pb2.GetIamPolicyRequest, dict,]) +def test_get_iam_policy(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2234,10 +2210,6 @@ def test_get_iam_policy( assert response.etag == b"etag_blob" -def test_get_iam_policy_from_dict(): - test_get_iam_policy(request_type=dict) - - def test_get_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2425,9 +2397,10 @@ async def test_get_iam_policy_flattened_error_async(): ) -def test_get_mute_config( - transport: str = "grpc", request_type=securitycenter_service.GetMuteConfigRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GetMuteConfigRequest, dict,] +) +def test_get_mute_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2462,10 +2435,6 @@ def test_get_mute_config( assert response.most_recent_editor == "most_recent_editor_value" -def test_get_mute_config_from_dict(): - test_get_mute_config(request_type=dict) - - def test_get_mute_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2652,10 +2621,10 @@ async def test_get_mute_config_flattened_error_async(): ) -def test_get_notification_config( - transport: str = "grpc", - request_type=securitycenter_service.GetNotificationConfigRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GetNotificationConfigRequest, dict,] +) +def test_get_notification_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2693,10 +2662,6 @@ def test_get_notification_config( assert response.service_account == "service_account_value" -def test_get_notification_config_from_dict(): - test_get_notification_config(request_type=dict) - - def test_get_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2893,10 +2858,10 @@ async def test_get_notification_config_flattened_error_async(): ) -def test_get_organization_settings( - transport: str = "grpc", - request_type=securitycenter_service.GetOrganizationSettingsRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GetOrganizationSettingsRequest, dict,] +) +def test_get_organization_settings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2926,10 +2891,6 @@ def test_get_organization_settings( assert response.enable_asset_discovery is True -def test_get_organization_settings_from_dict(): - test_get_organization_settings(request_type=dict) - - def test_get_organization_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3121,9 +3082,10 @@ async def test_get_organization_settings_flattened_error_async(): ) -def test_get_source( - transport: str = "grpc", request_type=securitycenter_service.GetSourceRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GetSourceRequest, dict,] +) +def test_get_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3156,10 +3118,6 @@ def test_get_source( assert response.canonical_name == "canonical_name_value" -def test_get_source_from_dict(): - test_get_source(request_type=dict) - - def test_get_source_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3340,9 +3298,10 @@ async def test_get_source_flattened_error_async(): ) -def test_group_assets( - transport: str = "grpc", request_type=securitycenter_service.GroupAssetsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GroupAssetsRequest, dict,] +) +def test_group_assets(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3370,10 +3329,6 @@ def test_group_assets( assert response.total_size == 1086 -def test_group_assets_from_dict(): - test_group_assets(request_type=dict) - - def test_group_assets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3481,8 +3436,10 @@ async def test_group_assets_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_group_assets_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_assets_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_assets), "__call__") as call: @@ -3525,8 +3482,10 @@ def test_group_assets_pager(): assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) -def test_group_assets_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_assets_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_assets), "__call__") as call: @@ -3643,9 +3602,10 @@ async def test_group_assets_async_pages(): assert page_.raw_page.next_page_token == token -def test_group_findings( - transport: str = "grpc", request_type=securitycenter_service.GroupFindingsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GroupFindingsRequest, dict,] +) +def test_group_findings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3673,10 +3633,6 @@ def test_group_findings( assert response.total_size == 1086 -def test_group_findings_from_dict(): - test_group_findings(request_type=dict) - - def test_group_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3870,8 +3826,10 @@ async def test_group_findings_flattened_error_async(): ) -def test_group_findings_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_findings_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_findings), "__call__") as call: @@ -3914,8 +3872,10 @@ def test_group_findings_pager(): assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) -def test_group_findings_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_findings_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_findings), "__call__") as call: @@ -4032,9 +3992,10 @@ async def test_group_findings_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_assets( - transport: str = "grpc", request_type=securitycenter_service.ListAssetsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListAssetsRequest, dict,] +) +def test_list_assets(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4062,10 +4023,6 @@ def test_list_assets( assert response.total_size == 1086 -def test_list_assets_from_dict(): - test_list_assets(request_type=dict) - - def test_list_assets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -4173,8 +4130,10 @@ async def test_list_assets_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_assets_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_assets_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_assets), "__call__") as call: @@ -4222,8 +4181,10 @@ def test_list_assets_pager(): ) -def test_list_assets_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_assets_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_assets), "__call__") as call: @@ -4349,9 +4310,10 @@ async def test_list_assets_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_findings( - transport: str = "grpc", request_type=securitycenter_service.ListFindingsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListFindingsRequest, dict,] +) +def test_list_findings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4379,10 +4341,6 @@ def test_list_findings( assert response.total_size == 1086 -def test_list_findings_from_dict(): - test_list_findings(request_type=dict) - - def test_list_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -4490,8 +4448,10 @@ async def test_list_findings_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_findings_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_findings_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -4541,8 +4501,10 @@ def test_list_findings_pager(): ) -def test_list_findings_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_findings_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -4670,9 +4632,10 @@ async def test_list_findings_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_mute_configs( - transport: str = "grpc", request_type=securitycenter_service.ListMuteConfigsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListMuteConfigsRequest, dict,] +) +def test_list_mute_configs(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4701,10 +4664,6 @@ def test_list_mute_configs( assert response.next_page_token == "next_page_token_value" -def test_list_mute_configs_from_dict(): - test_list_mute_configs(request_type=dict) - - def test_list_mute_configs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -4895,8 +4854,10 @@ async def test_list_mute_configs_flattened_error_async(): ) -def test_list_mute_configs_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_mute_configs_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4937,8 +4898,10 @@ def test_list_mute_configs_pager(): assert all(isinstance(i, mute_config.MuteConfig) for i in results) -def test_list_mute_configs_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_mute_configs_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5049,10 +5012,10 @@ async def test_list_mute_configs_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_notification_configs( - transport: str = "grpc", - request_type=securitycenter_service.ListNotificationConfigsRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListNotificationConfigsRequest, dict,] +) +def test_list_notification_configs(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5081,10 +5044,6 @@ def test_list_notification_configs( assert response.next_page_token == "next_page_token_value" -def test_list_notification_configs_from_dict(): - test_list_notification_configs(request_type=dict) - - def test_list_notification_configs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -5277,8 +5236,10 @@ async def test_list_notification_configs_flattened_error_async(): ) -def test_list_notification_configs_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_notification_configs_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5325,8 +5286,10 @@ def test_list_notification_configs_pager(): ) -def test_list_notification_configs_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_notification_configs_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5451,9 +5414,10 @@ async def test_list_notification_configs_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_sources( - transport: str = "grpc", request_type=securitycenter_service.ListSourcesRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListSourcesRequest, dict,] +) +def test_list_sources(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5480,10 +5444,6 @@ def test_list_sources( assert response.next_page_token == "next_page_token_value" -def test_list_sources_from_dict(): - test_list_sources(request_type=dict) - - def test_list_sources_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -5662,8 +5622,10 @@ async def test_list_sources_flattened_error_async(): ) -def test_list_sources_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_sources_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_sources), "__call__") as call: @@ -5698,8 +5660,10 @@ def test_list_sources_pager(): assert all(isinstance(i, source.Source) for i in results) -def test_list_sources_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_sources_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_sources), "__call__") as call: @@ -5792,10 +5756,10 @@ async def test_list_sources_async_pages(): assert page_.raw_page.next_page_token == token -def test_run_asset_discovery( - transport: str = "grpc", - request_type=securitycenter_service.RunAssetDiscoveryRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.RunAssetDiscoveryRequest, dict,] +) +def test_run_asset_discovery(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5821,10 +5785,6 @@ def test_run_asset_discovery( assert isinstance(response, future.Future) -def test_run_asset_discovery_from_dict(): - test_run_asset_discovery(request_type=dict) - - def test_run_asset_discovery_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -6012,9 +5972,10 @@ async def test_run_asset_discovery_flattened_error_async(): ) -def test_set_finding_state( - transport: str = "grpc", request_type=securitycenter_service.SetFindingStateRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.SetFindingStateRequest, dict,] +) +def test_set_finding_state(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -6063,10 +6024,6 @@ def test_set_finding_state( assert response.mute_initiator == "mute_initiator_value" -def test_set_finding_state_from_dict(): - test_set_finding_state(request_type=dict) - - def test_set_finding_state_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -6299,9 +6256,8 @@ async def test_set_finding_state_flattened_error_async(): ) -def test_set_mute( - transport: str = "grpc", request_type=securitycenter_service.SetMuteRequest -): +@pytest.mark.parametrize("request_type", [securitycenter_service.SetMuteRequest, dict,]) +def test_set_mute(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -6348,10 +6304,6 @@ def test_set_mute( assert response.mute_initiator == "mute_initiator_value" -def test_set_mute_from_dict(): - test_set_mute(request_type=dict) - - def test_set_mute_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -6559,9 +6511,8 @@ async def test_set_mute_flattened_error_async(): ) -def test_set_iam_policy( - transport: str = "grpc", request_type=iam_policy_pb2.SetIamPolicyRequest -): +@pytest.mark.parametrize("request_type", [iam_policy_pb2.SetIamPolicyRequest, dict,]) +def test_set_iam_policy(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -6587,10 +6538,6 @@ def test_set_iam_policy( assert response.etag == b"etag_blob" -def test_set_iam_policy_from_dict(): - test_set_iam_policy(request_type=dict) - - def test_set_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -6778,9 +6725,10 @@ async def test_set_iam_policy_flattened_error_async(): ) -def test_test_iam_permissions( - transport: str = "grpc", request_type=iam_policy_pb2.TestIamPermissionsRequest -): +@pytest.mark.parametrize( + "request_type", [iam_policy_pb2.TestIamPermissionsRequest, dict,] +) +def test_test_iam_permissions(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -6809,10 +6757,6 @@ def test_test_iam_permissions( assert response.permissions == ["permissions_value"] -def test_test_iam_permissions_from_dict(): - test_test_iam_permissions(request_type=dict) - - def test_test_iam_permissions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -7034,10 +6978,10 @@ async def test_test_iam_permissions_flattened_error_async(): ) -def test_update_external_system( - transport: str = "grpc", - request_type=securitycenter_service.UpdateExternalSystemRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateExternalSystemRequest, dict,] +) +def test_update_external_system(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -7072,10 +7016,6 @@ def test_update_external_system( assert response.status == "status_value" -def test_update_external_system_from_dict(): - test_update_external_system(request_type=dict) - - def test_update_external_system_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -7294,9 +7234,10 @@ async def test_update_external_system_flattened_error_async(): ) -def test_update_finding( - transport: str = "grpc", request_type=securitycenter_service.UpdateFindingRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateFindingRequest, dict,] +) +def test_update_finding(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -7343,10 +7284,6 @@ def test_update_finding( assert response.mute_initiator == "mute_initiator_value" -def test_update_finding_from_dict(): - test_update_finding(request_type=dict) - - def test_update_finding_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -7549,9 +7486,10 @@ async def test_update_finding_flattened_error_async(): ) -def test_update_mute_config( - transport: str = "grpc", request_type=securitycenter_service.UpdateMuteConfigRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateMuteConfigRequest, dict,] +) +def test_update_mute_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -7588,10 +7526,6 @@ def test_update_mute_config( assert response.most_recent_editor == "most_recent_editor_value" -def test_update_mute_config_from_dict(): - test_update_mute_config(request_type=dict) - - def test_update_mute_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -7810,10 +7744,10 @@ async def test_update_mute_config_flattened_error_async(): ) -def test_update_notification_config( - transport: str = "grpc", - request_type=securitycenter_service.UpdateNotificationConfigRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateNotificationConfigRequest, dict,] +) +def test_update_notification_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -7851,10 +7785,6 @@ def test_update_notification_config( assert response.service_account == "service_account_value" -def test_update_notification_config_from_dict(): - test_update_notification_config(request_type=dict) - - def test_update_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -8081,10 +8011,10 @@ async def test_update_notification_config_flattened_error_async(): ) -def test_update_organization_settings( - transport: str = "grpc", - request_type=securitycenter_service.UpdateOrganizationSettingsRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateOrganizationSettingsRequest, dict,] +) +def test_update_organization_settings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -8114,10 +8044,6 @@ def test_update_organization_settings( assert response.enable_asset_discovery is True -def test_update_organization_settings_from_dict(): - test_update_organization_settings(request_type=dict) - - def test_update_organization_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -8329,9 +8255,10 @@ async def test_update_organization_settings_flattened_error_async(): ) -def test_update_source( - transport: str = "grpc", request_type=securitycenter_service.UpdateSourceRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateSourceRequest, dict,] +) +def test_update_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -8364,10 +8291,6 @@ def test_update_source( assert response.canonical_name == "canonical_name_value" -def test_update_source_from_dict(): - test_update_source(request_type=dict) - - def test_update_source_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -8552,10 +8475,10 @@ async def test_update_source_flattened_error_async(): ) -def test_update_security_marks( - transport: str = "grpc", - request_type=securitycenter_service.UpdateSecurityMarksRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateSecurityMarksRequest, dict,] +) +def test_update_security_marks(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -8585,10 +8508,6 @@ def test_update_security_marks( assert response.canonical_name == "canonical_name_value" -def test_update_security_marks_from_dict(): - test_update_security_marks(request_type=dict) - - def test_update_security_marks_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -9550,7 +9469,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py b/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py index 6924631f..e1b3b967 100644 --- a/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py @@ -274,20 +274,20 @@ def test_security_center_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -346,7 +346,7 @@ def test_security_center_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -441,7 +441,7 @@ def test_security_center_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -472,7 +472,7 @@ def test_security_center_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -505,9 +505,10 @@ def test_security_center_client_client_options_from_dict(): ) -def test_create_source( - transport: str = "grpc", request_type=securitycenter_service.CreateSourceRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.CreateSourceRequest, dict,] +) +def test_create_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -538,10 +539,6 @@ def test_create_source( assert response.description == "description_value" -def test_create_source_from_dict(): - test_create_source(request_type=dict) - - def test_create_source_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -734,9 +731,10 @@ async def test_create_source_flattened_error_async(): ) -def test_create_finding( - transport: str = "grpc", request_type=securitycenter_service.CreateFindingRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.CreateFindingRequest, dict,] +) +def test_create_finding(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -773,10 +771,6 @@ def test_create_finding( assert response.external_uri == "external_uri_value" -def test_create_finding_from_dict(): - test_create_finding(request_type=dict) - - def test_create_finding_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -987,9 +981,8 @@ async def test_create_finding_flattened_error_async(): ) -def test_get_iam_policy( - transport: str = "grpc", request_type=iam_policy_pb2.GetIamPolicyRequest -): +@pytest.mark.parametrize("request_type", [iam_policy_pb2.GetIamPolicyRequest, dict,]) +def test_get_iam_policy(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1015,10 +1008,6 @@ def test_get_iam_policy( assert response.etag == b"etag_blob" -def test_get_iam_policy_from_dict(): - test_get_iam_policy(request_type=dict) - - def test_get_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1206,10 +1195,10 @@ async def test_get_iam_policy_flattened_error_async(): ) -def test_get_organization_settings( - transport: str = "grpc", - request_type=securitycenter_service.GetOrganizationSettingsRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GetOrganizationSettingsRequest, dict,] +) +def test_get_organization_settings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1239,10 +1228,6 @@ def test_get_organization_settings( assert response.enable_asset_discovery is True -def test_get_organization_settings_from_dict(): - test_get_organization_settings(request_type=dict) - - def test_get_organization_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1434,9 +1419,10 @@ async def test_get_organization_settings_flattened_error_async(): ) -def test_get_source( - transport: str = "grpc", request_type=securitycenter_service.GetSourceRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GetSourceRequest, dict,] +) +def test_get_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1467,10 +1453,6 @@ def test_get_source( assert response.description == "description_value" -def test_get_source_from_dict(): - test_get_source(request_type=dict) - - def test_get_source_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1649,9 +1631,10 @@ async def test_get_source_flattened_error_async(): ) -def test_group_assets( - transport: str = "grpc", request_type=securitycenter_service.GroupAssetsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GroupAssetsRequest, dict,] +) +def test_group_assets(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1678,10 +1661,6 @@ def test_group_assets( assert response.next_page_token == "next_page_token_value" -def test_group_assets_from_dict(): - test_group_assets(request_type=dict) - - def test_group_assets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1788,8 +1767,10 @@ async def test_group_assets_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_group_assets_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_assets_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_assets), "__call__") as call: @@ -1832,8 +1813,10 @@ def test_group_assets_pager(): assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) -def test_group_assets_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_assets_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_assets), "__call__") as call: @@ -1950,9 +1933,10 @@ async def test_group_assets_async_pages(): assert page_.raw_page.next_page_token == token -def test_group_findings( - transport: str = "grpc", request_type=securitycenter_service.GroupFindingsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GroupFindingsRequest, dict,] +) +def test_group_findings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1979,10 +1963,6 @@ def test_group_findings( assert response.next_page_token == "next_page_token_value" -def test_group_findings_from_dict(): - test_group_findings(request_type=dict) - - def test_group_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2175,8 +2155,10 @@ async def test_group_findings_flattened_error_async(): ) -def test_group_findings_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_findings_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_findings), "__call__") as call: @@ -2219,8 +2201,10 @@ def test_group_findings_pager(): assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) -def test_group_findings_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_findings_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_findings), "__call__") as call: @@ -2337,9 +2321,10 @@ async def test_group_findings_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_assets( - transport: str = "grpc", request_type=securitycenter_service.ListAssetsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListAssetsRequest, dict,] +) +def test_list_assets(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2367,10 +2352,6 @@ def test_list_assets( assert response.total_size == 1086 -def test_list_assets_from_dict(): - test_list_assets(request_type=dict) - - def test_list_assets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2478,8 +2459,10 @@ async def test_list_assets_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_assets_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_assets_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_assets), "__call__") as call: @@ -2527,8 +2510,10 @@ def test_list_assets_pager(): ) -def test_list_assets_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_assets_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_assets), "__call__") as call: @@ -2654,9 +2639,10 @@ async def test_list_assets_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_findings( - transport: str = "grpc", request_type=securitycenter_service.ListFindingsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListFindingsRequest, dict,] +) +def test_list_findings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2684,10 +2670,6 @@ def test_list_findings( assert response.total_size == 1086 -def test_list_findings_from_dict(): - test_list_findings(request_type=dict) - - def test_list_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2795,8 +2777,10 @@ async def test_list_findings_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_findings_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_findings_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -2831,8 +2815,10 @@ def test_list_findings_pager(): assert all(isinstance(i, finding.Finding) for i in results) -def test_list_findings_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_findings_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -2925,9 +2911,10 @@ async def test_list_findings_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_sources( - transport: str = "grpc", request_type=securitycenter_service.ListSourcesRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListSourcesRequest, dict,] +) +def test_list_sources(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2954,10 +2941,6 @@ def test_list_sources( assert response.next_page_token == "next_page_token_value" -def test_list_sources_from_dict(): - test_list_sources(request_type=dict) - - def test_list_sources_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3136,8 +3119,10 @@ async def test_list_sources_flattened_error_async(): ) -def test_list_sources_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_sources_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_sources), "__call__") as call: @@ -3172,8 +3157,10 @@ def test_list_sources_pager(): assert all(isinstance(i, source.Source) for i in results) -def test_list_sources_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_sources_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_sources), "__call__") as call: @@ -3266,10 +3253,10 @@ async def test_list_sources_async_pages(): assert page_.raw_page.next_page_token == token -def test_run_asset_discovery( - transport: str = "grpc", - request_type=securitycenter_service.RunAssetDiscoveryRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.RunAssetDiscoveryRequest, dict,] +) +def test_run_asset_discovery(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3295,10 +3282,6 @@ def test_run_asset_discovery( assert isinstance(response, future.Future) -def test_run_asset_discovery_from_dict(): - test_run_asset_discovery(request_type=dict) - - def test_run_asset_discovery_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3486,9 +3469,10 @@ async def test_run_asset_discovery_flattened_error_async(): ) -def test_set_finding_state( - transport: str = "grpc", request_type=securitycenter_service.SetFindingStateRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.SetFindingStateRequest, dict,] +) +def test_set_finding_state(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3527,10 +3511,6 @@ def test_set_finding_state( assert response.external_uri == "external_uri_value" -def test_set_finding_state_from_dict(): - test_set_finding_state(request_type=dict) - - def test_set_finding_state_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3753,9 +3733,8 @@ async def test_set_finding_state_flattened_error_async(): ) -def test_set_iam_policy( - transport: str = "grpc", request_type=iam_policy_pb2.SetIamPolicyRequest -): +@pytest.mark.parametrize("request_type", [iam_policy_pb2.SetIamPolicyRequest, dict,]) +def test_set_iam_policy(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3781,10 +3760,6 @@ def test_set_iam_policy( assert response.etag == b"etag_blob" -def test_set_iam_policy_from_dict(): - test_set_iam_policy(request_type=dict) - - def test_set_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3972,9 +3947,10 @@ async def test_set_iam_policy_flattened_error_async(): ) -def test_test_iam_permissions( - transport: str = "grpc", request_type=iam_policy_pb2.TestIamPermissionsRequest -): +@pytest.mark.parametrize( + "request_type", [iam_policy_pb2.TestIamPermissionsRequest, dict,] +) +def test_test_iam_permissions(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4003,10 +3979,6 @@ def test_test_iam_permissions( assert response.permissions == ["permissions_value"] -def test_test_iam_permissions_from_dict(): - test_test_iam_permissions(request_type=dict) - - def test_test_iam_permissions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -4228,9 +4200,10 @@ async def test_test_iam_permissions_flattened_error_async(): ) -def test_update_finding( - transport: str = "grpc", request_type=securitycenter_service.UpdateFindingRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateFindingRequest, dict,] +) +def test_update_finding(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4267,10 +4240,6 @@ def test_update_finding( assert response.external_uri == "external_uri_value" -def test_update_finding_from_dict(): - test_update_finding(request_type=dict) - - def test_update_finding_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -4463,10 +4432,10 @@ async def test_update_finding_flattened_error_async(): ) -def test_update_organization_settings( - transport: str = "grpc", - request_type=securitycenter_service.UpdateOrganizationSettingsRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateOrganizationSettingsRequest, dict,] +) +def test_update_organization_settings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4496,10 +4465,6 @@ def test_update_organization_settings( assert response.enable_asset_discovery is True -def test_update_organization_settings_from_dict(): - test_update_organization_settings(request_type=dict) - - def test_update_organization_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -4711,9 +4676,10 @@ async def test_update_organization_settings_flattened_error_async(): ) -def test_update_source( - transport: str = "grpc", request_type=securitycenter_service.UpdateSourceRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateSourceRequest, dict,] +) +def test_update_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4744,10 +4710,6 @@ def test_update_source( assert response.description == "description_value" -def test_update_source_from_dict(): - test_update_source(request_type=dict) - - def test_update_source_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -4930,10 +4892,10 @@ async def test_update_source_flattened_error_async(): ) -def test_update_security_marks( - transport: str = "grpc", - request_type=securitycenter_service.UpdateSecurityMarksRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateSecurityMarksRequest, dict,] +) +def test_update_security_marks(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4960,10 +4922,6 @@ def test_update_security_marks( assert response.name == "name_value" -def test_update_security_marks_from_dict(): - test_update_security_marks(request_type=dict) - - def test_update_security_marks_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -5812,7 +5770,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py b/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py index 06d66f84..ca093547 100644 --- a/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py @@ -279,20 +279,20 @@ def test_security_center_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -351,7 +351,7 @@ def test_security_center_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -446,7 +446,7 @@ def test_security_center_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -477,7 +477,7 @@ def test_security_center_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -510,9 +510,10 @@ def test_security_center_client_client_options_from_dict(): ) -def test_create_source( - transport: str = "grpc", request_type=securitycenter_service.CreateSourceRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.CreateSourceRequest, dict,] +) +def test_create_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -545,10 +546,6 @@ def test_create_source( assert response.canonical_name == "canonical_name_value" -def test_create_source_from_dict(): - test_create_source(request_type=dict) - - def test_create_source_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -743,9 +740,10 @@ async def test_create_source_flattened_error_async(): ) -def test_create_finding( - transport: str = "grpc", request_type=securitycenter_service.CreateFindingRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.CreateFindingRequest, dict,] +) +def test_create_finding(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -786,10 +784,6 @@ def test_create_finding( assert response.canonical_name == "canonical_name_value" -def test_create_finding_from_dict(): - test_create_finding(request_type=dict) - - def test_create_finding_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1004,10 +998,10 @@ async def test_create_finding_flattened_error_async(): ) -def test_create_notification_config( - transport: str = "grpc", - request_type=securitycenter_service.CreateNotificationConfigRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.CreateNotificationConfigRequest, dict,] +) +def test_create_notification_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1050,10 +1044,6 @@ def test_create_notification_config( assert response.service_account == "service_account_value" -def test_create_notification_config_from_dict(): - test_create_notification_config(request_type=dict) - - def test_create_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1289,10 +1279,10 @@ async def test_create_notification_config_flattened_error_async(): ) -def test_delete_notification_config( - transport: str = "grpc", - request_type=securitycenter_service.DeleteNotificationConfigRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.DeleteNotificationConfigRequest, dict,] +) +def test_delete_notification_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1318,10 +1308,6 @@ def test_delete_notification_config( assert response is None -def test_delete_notification_config_from_dict(): - test_delete_notification_config(request_type=dict) - - def test_delete_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1503,9 +1489,8 @@ async def test_delete_notification_config_flattened_error_async(): ) -def test_get_iam_policy( - transport: str = "grpc", request_type=iam_policy_pb2.GetIamPolicyRequest -): +@pytest.mark.parametrize("request_type", [iam_policy_pb2.GetIamPolicyRequest, dict,]) +def test_get_iam_policy(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1531,10 +1516,6 @@ def test_get_iam_policy( assert response.etag == b"etag_blob" -def test_get_iam_policy_from_dict(): - test_get_iam_policy(request_type=dict) - - def test_get_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1722,10 +1703,10 @@ async def test_get_iam_policy_flattened_error_async(): ) -def test_get_notification_config( - transport: str = "grpc", - request_type=securitycenter_service.GetNotificationConfigRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GetNotificationConfigRequest, dict,] +) +def test_get_notification_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1767,10 +1748,6 @@ def test_get_notification_config( assert response.service_account == "service_account_value" -def test_get_notification_config_from_dict(): - test_get_notification_config(request_type=dict) - - def test_get_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1971,10 +1948,10 @@ async def test_get_notification_config_flattened_error_async(): ) -def test_get_organization_settings( - transport: str = "grpc", - request_type=securitycenter_service.GetOrganizationSettingsRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GetOrganizationSettingsRequest, dict,] +) +def test_get_organization_settings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2004,10 +1981,6 @@ def test_get_organization_settings( assert response.enable_asset_discovery is True -def test_get_organization_settings_from_dict(): - test_get_organization_settings(request_type=dict) - - def test_get_organization_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2199,9 +2172,10 @@ async def test_get_organization_settings_flattened_error_async(): ) -def test_get_source( - transport: str = "grpc", request_type=securitycenter_service.GetSourceRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GetSourceRequest, dict,] +) +def test_get_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2234,10 +2208,6 @@ def test_get_source( assert response.canonical_name == "canonical_name_value" -def test_get_source_from_dict(): - test_get_source(request_type=dict) - - def test_get_source_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2418,9 +2388,10 @@ async def test_get_source_flattened_error_async(): ) -def test_group_assets( - transport: str = "grpc", request_type=securitycenter_service.GroupAssetsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GroupAssetsRequest, dict,] +) +def test_group_assets(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2448,10 +2419,6 @@ def test_group_assets( assert response.total_size == 1086 -def test_group_assets_from_dict(): - test_group_assets(request_type=dict) - - def test_group_assets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2559,8 +2526,10 @@ async def test_group_assets_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_group_assets_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_assets_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_assets), "__call__") as call: @@ -2603,8 +2572,10 @@ def test_group_assets_pager(): assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) -def test_group_assets_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_assets_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_assets), "__call__") as call: @@ -2721,9 +2692,10 @@ async def test_group_assets_async_pages(): assert page_.raw_page.next_page_token == token -def test_group_findings( - transport: str = "grpc", request_type=securitycenter_service.GroupFindingsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.GroupFindingsRequest, dict,] +) +def test_group_findings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2751,10 +2723,6 @@ def test_group_findings( assert response.total_size == 1086 -def test_group_findings_from_dict(): - test_group_findings(request_type=dict) - - def test_group_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2948,8 +2916,10 @@ async def test_group_findings_flattened_error_async(): ) -def test_group_findings_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_findings_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_findings), "__call__") as call: @@ -2992,8 +2962,10 @@ def test_group_findings_pager(): assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) -def test_group_findings_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_group_findings_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.group_findings), "__call__") as call: @@ -3110,9 +3082,10 @@ async def test_group_findings_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_assets( - transport: str = "grpc", request_type=securitycenter_service.ListAssetsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListAssetsRequest, dict,] +) +def test_list_assets(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3140,10 +3113,6 @@ def test_list_assets( assert response.total_size == 1086 -def test_list_assets_from_dict(): - test_list_assets(request_type=dict) - - def test_list_assets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3323,8 +3292,10 @@ async def test_list_assets_flattened_error_async(): ) -def test_list_assets_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_assets_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_assets), "__call__") as call: @@ -3372,8 +3343,10 @@ def test_list_assets_pager(): ) -def test_list_assets_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_assets_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_assets), "__call__") as call: @@ -3499,9 +3472,10 @@ async def test_list_assets_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_findings( - transport: str = "grpc", request_type=securitycenter_service.ListFindingsRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListFindingsRequest, dict,] +) +def test_list_findings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3529,10 +3503,6 @@ def test_list_findings( assert response.total_size == 1086 -def test_list_findings_from_dict(): - test_list_findings(request_type=dict) - - def test_list_findings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3712,8 +3682,10 @@ async def test_list_findings_flattened_error_async(): ) -def test_list_findings_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_findings_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -3763,8 +3735,10 @@ def test_list_findings_pager(): ) -def test_list_findings_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_findings_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_findings), "__call__") as call: @@ -3892,10 +3866,10 @@ async def test_list_findings_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_notification_configs( - transport: str = "grpc", - request_type=securitycenter_service.ListNotificationConfigsRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListNotificationConfigsRequest, dict,] +) +def test_list_notification_configs(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3924,10 +3898,6 @@ def test_list_notification_configs( assert response.next_page_token == "next_page_token_value" -def test_list_notification_configs_from_dict(): - test_list_notification_configs(request_type=dict) - - def test_list_notification_configs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -4120,8 +4090,10 @@ async def test_list_notification_configs_flattened_error_async(): ) -def test_list_notification_configs_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_notification_configs_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4168,8 +4140,10 @@ def test_list_notification_configs_pager(): ) -def test_list_notification_configs_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_notification_configs_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4294,9 +4268,10 @@ async def test_list_notification_configs_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_sources( - transport: str = "grpc", request_type=securitycenter_service.ListSourcesRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.ListSourcesRequest, dict,] +) +def test_list_sources(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4323,10 +4298,6 @@ def test_list_sources( assert response.next_page_token == "next_page_token_value" -def test_list_sources_from_dict(): - test_list_sources(request_type=dict) - - def test_list_sources_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -4505,8 +4476,10 @@ async def test_list_sources_flattened_error_async(): ) -def test_list_sources_pager(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_sources_pager(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_sources), "__call__") as call: @@ -4541,8 +4514,10 @@ def test_list_sources_pager(): assert all(isinstance(i, source.Source) for i in results) -def test_list_sources_pages(): - client = SecurityCenterClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_sources_pages(transport_name: str = "grpc"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_sources), "__call__") as call: @@ -4635,10 +4610,10 @@ async def test_list_sources_async_pages(): assert page_.raw_page.next_page_token == token -def test_run_asset_discovery( - transport: str = "grpc", - request_type=securitycenter_service.RunAssetDiscoveryRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.RunAssetDiscoveryRequest, dict,] +) +def test_run_asset_discovery(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4664,10 +4639,6 @@ def test_run_asset_discovery( assert isinstance(response, future.Future) -def test_run_asset_discovery_from_dict(): - test_run_asset_discovery(request_type=dict) - - def test_run_asset_discovery_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -4855,9 +4826,10 @@ async def test_run_asset_discovery_flattened_error_async(): ) -def test_set_finding_state( - transport: str = "grpc", request_type=securitycenter_service.SetFindingStateRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.SetFindingStateRequest, dict,] +) +def test_set_finding_state(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4900,10 +4872,6 @@ def test_set_finding_state( assert response.canonical_name == "canonical_name_value" -def test_set_finding_state_from_dict(): - test_set_finding_state(request_type=dict) - - def test_set_finding_state_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -5130,9 +5098,8 @@ async def test_set_finding_state_flattened_error_async(): ) -def test_set_iam_policy( - transport: str = "grpc", request_type=iam_policy_pb2.SetIamPolicyRequest -): +@pytest.mark.parametrize("request_type", [iam_policy_pb2.SetIamPolicyRequest, dict,]) +def test_set_iam_policy(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5158,10 +5125,6 @@ def test_set_iam_policy( assert response.etag == b"etag_blob" -def test_set_iam_policy_from_dict(): - test_set_iam_policy(request_type=dict) - - def test_set_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -5349,9 +5312,10 @@ async def test_set_iam_policy_flattened_error_async(): ) -def test_test_iam_permissions( - transport: str = "grpc", request_type=iam_policy_pb2.TestIamPermissionsRequest -): +@pytest.mark.parametrize( + "request_type", [iam_policy_pb2.TestIamPermissionsRequest, dict,] +) +def test_test_iam_permissions(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5380,10 +5344,6 @@ def test_test_iam_permissions( assert response.permissions == ["permissions_value"] -def test_test_iam_permissions_from_dict(): - test_test_iam_permissions(request_type=dict) - - def test_test_iam_permissions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -5605,9 +5565,10 @@ async def test_test_iam_permissions_flattened_error_async(): ) -def test_update_finding( - transport: str = "grpc", request_type=securitycenter_service.UpdateFindingRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateFindingRequest, dict,] +) +def test_update_finding(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5648,10 +5609,6 @@ def test_update_finding( assert response.canonical_name == "canonical_name_value" -def test_update_finding_from_dict(): - test_update_finding(request_type=dict) - - def test_update_finding_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -5860,10 +5817,10 @@ async def test_update_finding_flattened_error_async(): ) -def test_update_notification_config( - transport: str = "grpc", - request_type=securitycenter_service.UpdateNotificationConfigRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateNotificationConfigRequest, dict,] +) +def test_update_notification_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5906,10 +5863,6 @@ def test_update_notification_config( assert response.service_account == "service_account_value" -def test_update_notification_config_from_dict(): - test_update_notification_config(request_type=dict) - - def test_update_notification_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -6141,10 +6094,10 @@ async def test_update_notification_config_flattened_error_async(): ) -def test_update_organization_settings( - transport: str = "grpc", - request_type=securitycenter_service.UpdateOrganizationSettingsRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateOrganizationSettingsRequest, dict,] +) +def test_update_organization_settings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -6174,10 +6127,6 @@ def test_update_organization_settings( assert response.enable_asset_discovery is True -def test_update_organization_settings_from_dict(): - test_update_organization_settings(request_type=dict) - - def test_update_organization_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -6389,9 +6338,10 @@ async def test_update_organization_settings_flattened_error_async(): ) -def test_update_source( - transport: str = "grpc", request_type=securitycenter_service.UpdateSourceRequest -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateSourceRequest, dict,] +) +def test_update_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -6424,10 +6374,6 @@ def test_update_source( assert response.canonical_name == "canonical_name_value" -def test_update_source_from_dict(): - test_update_source(request_type=dict) - - def test_update_source_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -6624,10 +6570,10 @@ async def test_update_source_flattened_error_async(): ) -def test_update_security_marks( - transport: str = "grpc", - request_type=securitycenter_service.UpdateSecurityMarksRequest, -): +@pytest.mark.parametrize( + "request_type", [securitycenter_service.UpdateSecurityMarksRequest, dict,] +) +def test_update_security_marks(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -6657,10 +6603,6 @@ def test_update_security_marks( assert response.canonical_name == "canonical_name_value" -def test_update_security_marks_from_dict(): - test_update_security_marks(request_type=dict) - - def test_update_security_marks_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -7571,7 +7513,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( From 96db761b0864445b1d9e6ac5ce1b318e33b2e151 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 11 Jan 2022 10:59:57 -0500 Subject: [PATCH 15/19] chore(samples): Add check for tests in directory (#264) Source-Link: https://github.com/googleapis/synthtool/commit/52aef91f8d25223d9dbdb4aebd94ba8eea2101f3 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:36a95b8f494e4674dc9eee9af98961293b51b86b3649942aac800ae6c1f796d4 Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- .github/.OwlBot.lock.yaml | 2 +- samples/snippets/noxfile.py | 70 +++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index f33299dd..6b8a73b3 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:899d5d7cc340fa8ef9d8ae1a8cfba362c6898584f779e156f25ee828ba824610 + digest: sha256:36a95b8f494e4674dc9eee9af98961293b51b86b3649942aac800ae6c1f796d4 diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index 93a9122c..3bbef5d5 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,44 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) From 9dc2bb2577bb5bfc5040f2b5e15de3334e4f8ab7 Mon Sep 17 00:00:00 2001 From: Dan Lee <71398022+dandhlee@users.noreply.github.com> Date: Thu, 13 Jan 2022 16:32:53 -0500 Subject: [PATCH 16/19] chore: update doc links from googleapis.dev to cloud.google.com (#254) Co-authored-by: Anthonios Partheniou --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 063d2f10..dd24a966 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,7 @@ Python Client for Cloud Security Command Center API :target: https://pypi.org/project/google-cloud-securitycenter/ .. _Alpha: https://github.com/googleapis/google-cloud-python/blob/main/README.rst .. _Cloud Security Command Center API: https://cloud.google.com/security-command-center -.. _Client Library Documentation: https://googleapis.dev/python/securitycenter/latest +.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/securitycenter/latest .. _Product Documentation: https://cloud.google.com/security-command-center From beea256811726ef91ec45557b27845bb8f8bf2d4 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 14 Jan 2022 11:07:52 -0500 Subject: [PATCH 17/19] build: switch to release-please for tagging (#266) Source-Link: https://github.com/googleapis/synthtool/commit/f8077d237e0df2cb0066dfc6e09fc41e1c59646a Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:dfa9b663b32de8b5b327e32c1da665a80de48876558dd58091d8160c60ad7355 Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- .github/.OwlBot.lock.yaml | 2 +- .github/release-please.yml | 1 + .github/release-trigger.yml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .github/release-trigger.yml diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 6b8a73b3..ff5126c1 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:36a95b8f494e4674dc9eee9af98961293b51b86b3649942aac800ae6c1f796d4 + digest: sha256:dfa9b663b32de8b5b327e32c1da665a80de48876558dd58091d8160c60ad7355 diff --git a/.github/release-please.yml b/.github/release-please.yml index 4507ad05..466597e5 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1 +1,2 @@ releaseType: python +handleGHRelease: true diff --git a/.github/release-trigger.yml b/.github/release-trigger.yml new file mode 100644 index 00000000..d4ca9418 --- /dev/null +++ b/.github/release-trigger.yml @@ -0,0 +1 @@ +enabled: true From 5fd8e19147198ee1fd18347b2c65a4da5137f05c Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 14 Jan 2022 11:56:14 -0500 Subject: [PATCH 18/19] chore(python): update release.sh to use keystore (#267) Source-Link: https://github.com/googleapis/synthtool/commit/69fda12e2994f0b595a397e8bb6e3e9f380524eb Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:ae600f36b6bc972b368367b6f83a1d91ec2c82a4a116b383d67d547c56fe6de3 Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- .github/.OwlBot.lock.yaml | 2 +- .kokoro/release.sh | 2 +- .kokoro/release/common.cfg | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index ff5126c1..eecb84c2 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:dfa9b663b32de8b5b327e32c1da665a80de48876558dd58091d8160c60ad7355 + digest: sha256:ae600f36b6bc972b368367b6f83a1d91ec2c82a4a116b383d67d547c56fe6de3 diff --git a/.kokoro/release.sh b/.kokoro/release.sh index 5ed166d4..9b9511f7 100755 --- a/.kokoro/release.sh +++ b/.kokoro/release.sh @@ -26,7 +26,7 @@ python3 -m pip install --upgrade twine wheel setuptools export PYTHONUNBUFFERED=1 # Move into the package, build the distribution and upload. -TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token") +TWINE_PASSWORD=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google-cloud-pypi-token-keystore-1") cd github/python-securitycenter python3 setup.py sdist bdist_wheel twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/* diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index c9c29a46..635515fb 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,8 +23,18 @@ env_vars: { value: "github/python-securitycenter/.kokoro/release.sh" } +# Fetch PyPI password +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "google-cloud-pypi-token-keystore-1" + } + } +} + # Tokens needed to report release status back to GitHub env_vars: { key: "SECRET_MANAGER_KEYS" - value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,google-cloud-pypi-token" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" } From 2619d51a0c152c21429fdcdfc00df37e44cf8adc Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 18 Jan 2022 09:03:25 -0700 Subject: [PATCH 19/19] chore(main): release 1.8.0 (#265) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou --- CHANGELOG.md | 18 ++++++++++++++++++ setup.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42ad4e1d..d999ddd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,24 @@ [1]: https://pypi.org/project/google-cloud-securitycenter/#history +## [1.8.0](https://github.com/googleapis/python-securitycenter/compare/v1.7.0...v1.8.0) (2022-01-14) + + +### Features + +* add display_name to the resource which is surfaced in NotificationMessage ([f28a8fe](https://github.com/googleapis/python-securitycenter/commit/f28a8fe8a3732e327543255475cef997ffbfaba9)) +* add support for python 3.10 ([#238](https://github.com/googleapis/python-securitycenter/issues/238)) ([7186526](https://github.com/googleapis/python-securitycenter/commit/718652639dafd4121391c642d55d9347c66bf5cb)) +* Added a new API method UpdateExternalSystem ([#256](https://github.com/googleapis/python-securitycenter/issues/256)) ([8c988a6](https://github.com/googleapis/python-securitycenter/commit/8c988a6bb1f2d0814386916c51c64fb8c4c15345)) +* Added mute related APIs, proto messages and fields ([#255](https://github.com/googleapis/python-securitycenter/issues/255)) ([6f3e1b2](https://github.com/googleapis/python-securitycenter/commit/6f3e1b2503906dd5f9583ac37ebdd1d9e4f11dd2)) +* Added resource type and display_name field to the FindingResult ([#248](https://github.com/googleapis/python-securitycenter/issues/248)) ([f28a8fe](https://github.com/googleapis/python-securitycenter/commit/f28a8fe8a3732e327543255475cef997ffbfaba9)) + + +### Bug Fixes + +* **deps:** drop packaging dependency ([f28a8fe](https://github.com/googleapis/python-securitycenter/commit/f28a8fe8a3732e327543255475cef997ffbfaba9)) +* **deps:** require google-api-core >= 1.28.0 ([f28a8fe](https://github.com/googleapis/python-securitycenter/commit/f28a8fe8a3732e327543255475cef997ffbfaba9)) +* fix extras_require typo in setup.py ([#242](https://github.com/googleapis/python-securitycenter/issues/242)) ([d477b96](https://github.com/googleapis/python-securitycenter/commit/d477b96c4de26adc282b41c16240fe0e38689320)) + ## [1.7.0](https://www.github.com/googleapis/python-securitycenter/compare/v1.6.0...v1.7.0) (2021-10-08) diff --git a/setup.py b/setup.py index 20cdbe83..12558eba 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ name = "google-cloud-securitycenter" description = "Cloud Security Command Center API client library" -version = "1.7.0" +version = "1.8.0" release_status = "Development Status :: 5 - Production/Stable" dependencies = [ # NOTE: Maintainers, please do not require google-api-core>=2.x.x