From a1e7847cfdf78c87b1bd2865341bb2b4d2ab312d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 12 Apr 2023 06:13:23 -0400 Subject: [PATCH] feat: Add Security Health Analytics (SHA) custom modules with Create, Get, List, Update, Delete (#447) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: released securitycenter/v1 SHA custom modules cloud libraries: Create, Get, List, Update, Delete The Security Health Analytics (SHA) custom modules API is now released for general availability track. Create, Get, GetEffective, List, ListEffective, ListDescendant, Update, and Delete are available in the cloud client library. PiperOrigin-RevId: 523462834 Source-Link: https://github.com/googleapis/googleapis/commit/b7b3dfd5a4f83a22b91b1954d44fef17b2eff8a6 Source-Link: https://github.com/googleapis/googleapis-gen/commit/9b679ec02a7e16df9f0e7f66e077e379efd25ad4 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiOWI2NzllYzAyYTdlMTZkZjlmMGU3ZjY2ZTA3N2UzNzllZmQyNWFkNCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- .../google/cloud/securitycenter/__init__.py | 34 + .../cloud/securitycenter_v1/__init__.py | 32 + .../securitycenter_v1/gapic_metadata.json | 120 + .../services/security_center/async_client.py | 1361 +- .../services/security_center/client.py | 1351 +- .../services/security_center/pagers.py | 473 + .../security_center/transports/base.py | 210 +- .../security_center/transports/grpc.py | 297 +- .../transports/grpc_asyncio.py | 311 +- .../security_center/transports/rest.py | 1500 +- .../cloud/securitycenter_v1/types/__init__.py | 30 + .../types/bigquery_export.py | 14 +- .../types/contact_details.py | 4 +- .../cloud/securitycenter_v1/types/database.py | 2 +- ...security_health_analytics_custom_module.py | 104 + .../securitycenter_v1/types/exfiltration.py | 2 +- .../cloud/securitycenter_v1/types/finding.py | 10 +- .../securitycenter_v1/types/indicator.py | 15 +- .../securitycenter_v1/types/kernel_rootkit.py | 27 +- .../securitycenter_v1/types/kubernetes.py | 7 +- ...security_health_analytics_custom_config.py | 174 + ...security_health_analytics_custom_module.py | 137 + .../types/securitycenter_service.py | 328 +- ...ty_health_analytics_custom_module_async.py | 52 + ...ity_health_analytics_custom_module_sync.py | 52 + ...ty_health_analytics_custom_module_async.py | 50 + ...ity_health_analytics_custom_module_sync.py | 50 + ...ty_health_analytics_custom_module_async.py | 52 + ...ity_health_analytics_custom_module_sync.py | 52 + ...ty_health_analytics_custom_module_async.py | 52 + ...ity_health_analytics_custom_module_sync.py | 52 + ...y_health_analytics_custom_modules_async.py | 53 + ...ty_health_analytics_custom_modules_sync.py | 53 + ...y_health_analytics_custom_modules_async.py | 53 + ...ty_health_analytics_custom_modules_sync.py | 53 + ...y_health_analytics_custom_modules_async.py | 53 + ...ty_health_analytics_custom_modules_sync.py | 53 + ...ty_health_analytics_custom_module_async.py | 51 + ...ity_health_analytics_custom_module_sync.py | 51 + ...tadata_google.cloud.securitycenter.v1.json | 2016 +- ...a_google.cloud.securitycenter.v1beta1.json | 2 +- ...google.cloud.securitycenter.v1p1beta1.json | 2 +- .../fixup_securitycenter_v1_keywords.py | 8 + .../securitycenter_v1/test_security_center.py | 17557 +++++++++++----- 44 files changed, 20429 insertions(+), 6531 deletions(-) create mode 100644 packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/effective_security_health_analytics_custom_module.py create mode 100644 packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/security_health_analytics_custom_config.py create mode 100644 packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/security_health_analytics_custom_module.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_async.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_sync.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_async.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_sync.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_async.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_sync.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_async.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_sync.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_async.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_sync.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_async.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_sync.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_async.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_sync.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_async.py create mode 100644 packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_sync.py diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter/__init__.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter/__init__.py index 0605464d7fbc..b51a30f15ad8 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter/__init__.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter/__init__.py @@ -36,6 +36,9 @@ from google.cloud.securitycenter_v1.types.contact_details import Contact, ContactDetails from google.cloud.securitycenter_v1.types.container import Container from google.cloud.securitycenter_v1.types.database import Database +from google.cloud.securitycenter_v1.types.effective_security_health_analytics_custom_module import ( + EffectiveSecurityHealthAnalyticsCustomModule, +) from google.cloud.securitycenter_v1.types.exfiltration import ( ExfilResource, Exfiltration, @@ -63,6 +66,12 @@ from google.cloud.securitycenter_v1.types.run_asset_discovery_response import ( RunAssetDiscoveryResponse, ) +from google.cloud.securitycenter_v1.types.security_health_analytics_custom_config import ( + CustomConfig, +) +from google.cloud.securitycenter_v1.types.security_health_analytics_custom_module import ( + SecurityHealthAnalyticsCustomModule, +) from google.cloud.securitycenter_v1.types.security_marks import SecurityMarks from google.cloud.securitycenter_v1.types.securitycenter_service import ( BulkMuteFindingsRequest, @@ -71,14 +80,18 @@ CreateFindingRequest, CreateMuteConfigRequest, CreateNotificationConfigRequest, + CreateSecurityHealthAnalyticsCustomModuleRequest, CreateSourceRequest, DeleteBigQueryExportRequest, DeleteMuteConfigRequest, DeleteNotificationConfigRequest, + DeleteSecurityHealthAnalyticsCustomModuleRequest, GetBigQueryExportRequest, + GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, GetMuteConfigRequest, GetNotificationConfigRequest, GetOrganizationSettingsRequest, + GetSecurityHealthAnalyticsCustomModuleRequest, GetSourceRequest, GroupAssetsRequest, GroupAssetsResponse, @@ -89,12 +102,18 @@ ListAssetsResponse, ListBigQueryExportsRequest, ListBigQueryExportsResponse, + ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + ListDescendantSecurityHealthAnalyticsCustomModulesResponse, + ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + ListEffectiveSecurityHealthAnalyticsCustomModulesResponse, ListFindingsRequest, ListFindingsResponse, ListMuteConfigsRequest, ListMuteConfigsResponse, ListNotificationConfigsRequest, ListNotificationConfigsResponse, + ListSecurityHealthAnalyticsCustomModulesRequest, + ListSecurityHealthAnalyticsCustomModulesResponse, ListSourcesRequest, ListSourcesResponse, RunAssetDiscoveryRequest, @@ -106,6 +125,7 @@ UpdateMuteConfigRequest, UpdateNotificationConfigRequest, UpdateOrganizationSettingsRequest, + UpdateSecurityHealthAnalyticsCustomModuleRequest, UpdateSecurityMarksRequest, UpdateSourceRequest, ) @@ -131,6 +151,7 @@ "ContactDetails", "Container", "Database", + "EffectiveSecurityHealthAnalyticsCustomModule", "ExfilResource", "Exfiltration", "ExternalSystem", @@ -151,6 +172,8 @@ "Process", "Resource", "RunAssetDiscoveryResponse", + "CustomConfig", + "SecurityHealthAnalyticsCustomModule", "SecurityMarks", "BulkMuteFindingsRequest", "BulkMuteFindingsResponse", @@ -158,14 +181,18 @@ "CreateFindingRequest", "CreateMuteConfigRequest", "CreateNotificationConfigRequest", + "CreateSecurityHealthAnalyticsCustomModuleRequest", "CreateSourceRequest", "DeleteBigQueryExportRequest", "DeleteMuteConfigRequest", "DeleteNotificationConfigRequest", + "DeleteSecurityHealthAnalyticsCustomModuleRequest", "GetBigQueryExportRequest", + "GetEffectiveSecurityHealthAnalyticsCustomModuleRequest", "GetMuteConfigRequest", "GetNotificationConfigRequest", "GetOrganizationSettingsRequest", + "GetSecurityHealthAnalyticsCustomModuleRequest", "GetSourceRequest", "GroupAssetsRequest", "GroupAssetsResponse", @@ -176,12 +203,18 @@ "ListAssetsResponse", "ListBigQueryExportsRequest", "ListBigQueryExportsResponse", + "ListDescendantSecurityHealthAnalyticsCustomModulesRequest", + "ListDescendantSecurityHealthAnalyticsCustomModulesResponse", + "ListEffectiveSecurityHealthAnalyticsCustomModulesRequest", + "ListEffectiveSecurityHealthAnalyticsCustomModulesResponse", "ListFindingsRequest", "ListFindingsResponse", "ListMuteConfigsRequest", "ListMuteConfigsResponse", "ListNotificationConfigsRequest", "ListNotificationConfigsResponse", + "ListSecurityHealthAnalyticsCustomModulesRequest", + "ListSecurityHealthAnalyticsCustomModulesResponse", "ListSourcesRequest", "ListSourcesResponse", "RunAssetDiscoveryRequest", @@ -193,6 +226,7 @@ "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", "UpdateOrganizationSettingsRequest", + "UpdateSecurityHealthAnalyticsCustomModuleRequest", "UpdateSecurityMarksRequest", "UpdateSourceRequest", "Source", diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/__init__.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/__init__.py index 82e69b65940a..7b1268e05db6 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/__init__.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/__init__.py @@ -27,6 +27,9 @@ from .types.contact_details import Contact, ContactDetails from .types.container import Container from .types.database import Database +from .types.effective_security_health_analytics_custom_module import ( + EffectiveSecurityHealthAnalyticsCustomModule, +) from .types.exfiltration import ExfilResource, Exfiltration from .types.external_system import ExternalSystem from .types.file import File @@ -45,6 +48,10 @@ from .types.process import EnvironmentVariable, Process from .types.resource import Resource from .types.run_asset_discovery_response import RunAssetDiscoveryResponse +from .types.security_health_analytics_custom_config import CustomConfig +from .types.security_health_analytics_custom_module import ( + SecurityHealthAnalyticsCustomModule, +) from .types.security_marks import SecurityMarks from .types.securitycenter_service import ( BulkMuteFindingsRequest, @@ -53,14 +60,18 @@ CreateFindingRequest, CreateMuteConfigRequest, CreateNotificationConfigRequest, + CreateSecurityHealthAnalyticsCustomModuleRequest, CreateSourceRequest, DeleteBigQueryExportRequest, DeleteMuteConfigRequest, DeleteNotificationConfigRequest, + DeleteSecurityHealthAnalyticsCustomModuleRequest, GetBigQueryExportRequest, + GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, GetMuteConfigRequest, GetNotificationConfigRequest, GetOrganizationSettingsRequest, + GetSecurityHealthAnalyticsCustomModuleRequest, GetSourceRequest, GroupAssetsRequest, GroupAssetsResponse, @@ -71,12 +82,18 @@ ListAssetsResponse, ListBigQueryExportsRequest, ListBigQueryExportsResponse, + ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + ListDescendantSecurityHealthAnalyticsCustomModulesResponse, + ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + ListEffectiveSecurityHealthAnalyticsCustomModulesResponse, ListFindingsRequest, ListFindingsResponse, ListMuteConfigsRequest, ListMuteConfigsResponse, ListNotificationConfigsRequest, ListNotificationConfigsResponse, + ListSecurityHealthAnalyticsCustomModulesRequest, + ListSecurityHealthAnalyticsCustomModulesResponse, ListSourcesRequest, ListSourcesResponse, RunAssetDiscoveryRequest, @@ -88,6 +105,7 @@ UpdateMuteConfigRequest, UpdateNotificationConfigRequest, UpdateOrganizationSettingsRequest, + UpdateSecurityHealthAnalyticsCustomModuleRequest, UpdateSecurityMarksRequest, UpdateSourceRequest, ) @@ -110,13 +128,17 @@ "CreateFindingRequest", "CreateMuteConfigRequest", "CreateNotificationConfigRequest", + "CreateSecurityHealthAnalyticsCustomModuleRequest", "CreateSourceRequest", + "CustomConfig", "Cve", "Cvssv3", "Database", "DeleteBigQueryExportRequest", "DeleteMuteConfigRequest", "DeleteNotificationConfigRequest", + "DeleteSecurityHealthAnalyticsCustomModuleRequest", + "EffectiveSecurityHealthAnalyticsCustomModule", "EnvironmentVariable", "ExfilResource", "Exfiltration", @@ -126,9 +148,11 @@ "Folder", "Geolocation", "GetBigQueryExportRequest", + "GetEffectiveSecurityHealthAnalyticsCustomModuleRequest", "GetMuteConfigRequest", "GetNotificationConfigRequest", "GetOrganizationSettingsRequest", + "GetSecurityHealthAnalyticsCustomModuleRequest", "GetSourceRequest", "GroupAssetsRequest", "GroupAssetsResponse", @@ -144,12 +168,18 @@ "ListAssetsResponse", "ListBigQueryExportsRequest", "ListBigQueryExportsResponse", + "ListDescendantSecurityHealthAnalyticsCustomModulesRequest", + "ListDescendantSecurityHealthAnalyticsCustomModulesResponse", + "ListEffectiveSecurityHealthAnalyticsCustomModulesRequest", + "ListEffectiveSecurityHealthAnalyticsCustomModulesResponse", "ListFindingsRequest", "ListFindingsResponse", "ListMuteConfigsRequest", "ListMuteConfigsResponse", "ListNotificationConfigsRequest", "ListNotificationConfigsResponse", + "ListSecurityHealthAnalyticsCustomModulesRequest", + "ListSecurityHealthAnalyticsCustomModulesResponse", "ListSourcesRequest", "ListSourcesResponse", "MitreAttack", @@ -163,6 +193,7 @@ "RunAssetDiscoveryRequest", "RunAssetDiscoveryResponse", "SecurityCenterClient", + "SecurityHealthAnalyticsCustomModule", "SecurityMarks", "ServiceAccountDelegationInfo", "SetFindingStateRequest", @@ -174,6 +205,7 @@ "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", "UpdateOrganizationSettingsRequest", + "UpdateSecurityHealthAnalyticsCustomModuleRequest", "UpdateSecurityMarksRequest", "UpdateSourceRequest", "Vulnerability", diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/gapic_metadata.json b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/gapic_metadata.json index 17110f05eba3..5c23812a9d9e 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/gapic_metadata.json +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/gapic_metadata.json @@ -35,6 +35,11 @@ "create_notification_config" ] }, + "CreateSecurityHealthAnalyticsCustomModule": { + "methods": [ + "create_security_health_analytics_custom_module" + ] + }, "CreateSource": { "methods": [ "create_source" @@ -55,11 +60,21 @@ "delete_notification_config" ] }, + "DeleteSecurityHealthAnalyticsCustomModule": { + "methods": [ + "delete_security_health_analytics_custom_module" + ] + }, "GetBigQueryExport": { "methods": [ "get_big_query_export" ] }, + "GetEffectiveSecurityHealthAnalyticsCustomModule": { + "methods": [ + "get_effective_security_health_analytics_custom_module" + ] + }, "GetIamPolicy": { "methods": [ "get_iam_policy" @@ -80,6 +95,11 @@ "get_organization_settings" ] }, + "GetSecurityHealthAnalyticsCustomModule": { + "methods": [ + "get_security_health_analytics_custom_module" + ] + }, "GetSource": { "methods": [ "get_source" @@ -105,6 +125,16 @@ "list_big_query_exports" ] }, + "ListDescendantSecurityHealthAnalyticsCustomModules": { + "methods": [ + "list_descendant_security_health_analytics_custom_modules" + ] + }, + "ListEffectiveSecurityHealthAnalyticsCustomModules": { + "methods": [ + "list_effective_security_health_analytics_custom_modules" + ] + }, "ListFindings": { "methods": [ "list_findings" @@ -120,6 +150,11 @@ "list_notification_configs" ] }, + "ListSecurityHealthAnalyticsCustomModules": { + "methods": [ + "list_security_health_analytics_custom_modules" + ] + }, "ListSources": { "methods": [ "list_sources" @@ -180,6 +215,11 @@ "update_organization_settings" ] }, + "UpdateSecurityHealthAnalyticsCustomModule": { + "methods": [ + "update_security_health_analytics_custom_module" + ] + }, "UpdateSecurityMarks": { "methods": [ "update_security_marks" @@ -220,6 +260,11 @@ "create_notification_config" ] }, + "CreateSecurityHealthAnalyticsCustomModule": { + "methods": [ + "create_security_health_analytics_custom_module" + ] + }, "CreateSource": { "methods": [ "create_source" @@ -240,11 +285,21 @@ "delete_notification_config" ] }, + "DeleteSecurityHealthAnalyticsCustomModule": { + "methods": [ + "delete_security_health_analytics_custom_module" + ] + }, "GetBigQueryExport": { "methods": [ "get_big_query_export" ] }, + "GetEffectiveSecurityHealthAnalyticsCustomModule": { + "methods": [ + "get_effective_security_health_analytics_custom_module" + ] + }, "GetIamPolicy": { "methods": [ "get_iam_policy" @@ -265,6 +320,11 @@ "get_organization_settings" ] }, + "GetSecurityHealthAnalyticsCustomModule": { + "methods": [ + "get_security_health_analytics_custom_module" + ] + }, "GetSource": { "methods": [ "get_source" @@ -290,6 +350,16 @@ "list_big_query_exports" ] }, + "ListDescendantSecurityHealthAnalyticsCustomModules": { + "methods": [ + "list_descendant_security_health_analytics_custom_modules" + ] + }, + "ListEffectiveSecurityHealthAnalyticsCustomModules": { + "methods": [ + "list_effective_security_health_analytics_custom_modules" + ] + }, "ListFindings": { "methods": [ "list_findings" @@ -305,6 +375,11 @@ "list_notification_configs" ] }, + "ListSecurityHealthAnalyticsCustomModules": { + "methods": [ + "list_security_health_analytics_custom_modules" + ] + }, "ListSources": { "methods": [ "list_sources" @@ -365,6 +440,11 @@ "update_organization_settings" ] }, + "UpdateSecurityHealthAnalyticsCustomModule": { + "methods": [ + "update_security_health_analytics_custom_module" + ] + }, "UpdateSecurityMarks": { "methods": [ "update_security_marks" @@ -405,6 +485,11 @@ "create_notification_config" ] }, + "CreateSecurityHealthAnalyticsCustomModule": { + "methods": [ + "create_security_health_analytics_custom_module" + ] + }, "CreateSource": { "methods": [ "create_source" @@ -425,11 +510,21 @@ "delete_notification_config" ] }, + "DeleteSecurityHealthAnalyticsCustomModule": { + "methods": [ + "delete_security_health_analytics_custom_module" + ] + }, "GetBigQueryExport": { "methods": [ "get_big_query_export" ] }, + "GetEffectiveSecurityHealthAnalyticsCustomModule": { + "methods": [ + "get_effective_security_health_analytics_custom_module" + ] + }, "GetIamPolicy": { "methods": [ "get_iam_policy" @@ -450,6 +545,11 @@ "get_organization_settings" ] }, + "GetSecurityHealthAnalyticsCustomModule": { + "methods": [ + "get_security_health_analytics_custom_module" + ] + }, "GetSource": { "methods": [ "get_source" @@ -475,6 +575,16 @@ "list_big_query_exports" ] }, + "ListDescendantSecurityHealthAnalyticsCustomModules": { + "methods": [ + "list_descendant_security_health_analytics_custom_modules" + ] + }, + "ListEffectiveSecurityHealthAnalyticsCustomModules": { + "methods": [ + "list_effective_security_health_analytics_custom_modules" + ] + }, "ListFindings": { "methods": [ "list_findings" @@ -490,6 +600,11 @@ "list_notification_configs" ] }, + "ListSecurityHealthAnalyticsCustomModules": { + "methods": [ + "list_security_health_analytics_custom_modules" + ] + }, "ListSources": { "methods": [ "list_sources" @@ -550,6 +665,11 @@ "update_organization_settings" ] }, + "UpdateSecurityHealthAnalyticsCustomModule": { + "methods": [ + "update_security_health_analytics_custom_module" + ] + }, "UpdateSecurityMarks": { "methods": [ "update_security_marks" diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/async_client.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/async_client.py index b7d5022359eb..1a7a539967d6 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/async_client.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/async_client.py @@ -59,8 +59,14 @@ connection, container, database, + effective_security_health_analytics_custom_module, exfiltration, ) +from google.cloud.securitycenter_v1.types import ( + process, + run_asset_discovery_response, + security_health_analytics_custom_config, +) from google.cloud.securitycenter_v1.types import ( iam_binding, indicator, @@ -68,7 +74,6 @@ kubernetes, mitre_attack, ) -from google.cloud.securitycenter_v1.types import process, run_asset_discovery_response from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -76,6 +81,10 @@ from google.cloud.securitycenter_v1.types import ( organization_settings as gcs_organization_settings, ) +from google.cloud.securitycenter_v1.types import security_health_analytics_custom_module +from google.cloud.securitycenter_v1.types import ( + security_health_analytics_custom_module as gcs_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import security_marks as gcs_security_marks from google.cloud.securitycenter_v1.types import file from google.cloud.securitycenter_v1.types import finding @@ -109,6 +118,12 @@ class SecurityCenterAsyncClient: parse_big_query_export_path = staticmethod( SecurityCenterClient.parse_big_query_export_path ) + effective_security_health_analytics_custom_module_path = staticmethod( + SecurityCenterClient.effective_security_health_analytics_custom_module_path + ) + parse_effective_security_health_analytics_custom_module_path = staticmethod( + SecurityCenterClient.parse_effective_security_health_analytics_custom_module_path + ) external_system_path = staticmethod(SecurityCenterClient.external_system_path) parse_external_system_path = staticmethod( SecurityCenterClient.parse_external_system_path @@ -129,6 +144,12 @@ class SecurityCenterAsyncClient: parse_organization_settings_path = staticmethod( SecurityCenterClient.parse_organization_settings_path ) + security_health_analytics_custom_module_path = staticmethod( + SecurityCenterClient.security_health_analytics_custom_module_path + ) + parse_security_health_analytics_custom_module_path = staticmethod( + SecurityCenterClient.parse_security_health_analytics_custom_module_path + ) security_marks_path = staticmethod(SecurityCenterClient.security_marks_path) parse_security_marks_path = staticmethod( SecurityCenterClient.parse_security_marks_path @@ -422,6 +443,151 @@ async def sample_bulk_mute_findings(): # Done; return the response. return response + async def create_security_health_analytics_custom_module( + self, + request: Optional[ + Union[ + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] + ] = None, + *, + parent: Optional[str] = None, + security_health_analytics_custom_module: Optional[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + r"""Creates a resident + SecurityHealthAnalyticsCustomModule at the scope of the + given CRM parent, and also creates inherited + SecurityHealthAnalyticsCustomModules for all CRM + descendants of the given parent. These modules are + enabled by default. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + async def sample_create_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.CreateSecurityHealthAnalyticsCustomModuleRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.securitycenter_v1.types.CreateSecurityHealthAnalyticsCustomModuleRequest, dict]]): + The request object. Request message for creating security + health analytics custom modules. + parent (:class:`str`): + Required. Resource name of the new + custom module's parent. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings" + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + security_health_analytics_custom_module (:class:`google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule`): + Required. SecurityHealthAnalytics + custom module to create. The provided + name is ignored and reset with provided + parent information and server-generated + ID. + + This corresponds to the ``security_health_analytics_custom_module`` 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.SecurityHealthAnalyticsCustomModule: + Represents an instance of a Security + Health Analytics custom module, + including its full module name, display + name, enablement state, and last updated + time. You can create a custom module at + the organization, folder, or project + level. Custom modules that you create at + the organization or folder level are + inherited by the child folders and + projects. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, security_health_analytics_custom_module]) + 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.CreateSecurityHealthAnalyticsCustomModuleRequest( + request + ) + ) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if security_health_analytics_custom_module is not None: + request.security_health_analytics_custom_module = ( + security_health_analytics_custom_module + ) + + # 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_security_health_analytics_custom_module, + default_timeout=60.0, + 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_source( self, request: Optional[ @@ -1142,6 +1308,112 @@ async def sample_delete_notification_config(): metadata=metadata, ) + async def delete_security_health_analytics_custom_module( + self, + request: Optional[ + Union[ + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes the specified + SecurityHealthAnalyticsCustomModule and all of its + descendants in the CRM hierarchy. This method is only + supported for resident custom modules. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + async def sample_delete_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.DeleteSecurityHealthAnalyticsCustomModuleRequest( + name="name_value", + ) + + # Make the request + await client.delete_security_health_analytics_custom_module(request=request) + + Args: + request (Optional[Union[google.cloud.securitycenter_v1.types.DeleteSecurityHealthAnalyticsCustomModuleRequest, dict]]): + The request object. Request message for deleting security + health analytics custom modules. + name (:class:`str`): + Required. Name of the custom module + to delete. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/customModules/{customModule}", + "folders/{folder}/securityHealthAnalyticsSettings/customModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/customModules/{customModule}" + + 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. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = ( + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest( + 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_security_health_analytics_custom_module, + default_timeout=60.0, + 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 get_big_query_export( self, request: Optional[ @@ -1771,16 +2043,22 @@ async def sample_get_organization_settings(): # Done; return the response. return response - async def get_source( + async def get_effective_security_health_analytics_custom_module( self, - request: Optional[Union[securitycenter_service.GetSourceRequest, dict]] = None, + request: Optional[ + Union[ + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] + ] = None, *, name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), - ) -> source.Source: - r"""Gets a source. + ) -> effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule: + r"""Retrieves an + EffectiveSecurityHealthAnalyticsCustomModule. .. code-block:: python @@ -1793,28 +2071,33 @@ async def get_source( # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import securitycenter_v1 - async def sample_get_source(): + async def sample_get_effective_security_health_analytics_custom_module(): # Create a client client = securitycenter_v1.SecurityCenterAsyncClient() # Initialize request argument(s) - request = securitycenter_v1.GetSourceRequest( + request = securitycenter_v1.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest( name="name_value", ) # Make the request - response = await client.get_source(request=request) + response = await client.get_effective_security_health_analytics_custom_module(request=request) # Handle the response print(response) Args: - request (Optional[Union[google.cloud.securitycenter_v1.types.GetSourceRequest, dict]]): - The request object. Request message for getting a source. + request (Optional[Union[google.cloud.securitycenter_v1.types.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, dict]]): + The request object. Request message for getting effective + security health analytics custom + modules. name (:class:`str`): - Required. Relative resource name of the source. Its - format is - "organizations/[organization_id]/source/[source_id]". + Required. Name of the effective + custom module to get. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}", + "folders/{folder}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}" This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1826,13 +2109,21 @@ async def sample_get_source(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.types.Source: - Security Command Center finding - source. A finding source is an entity or - a mechanism that can produce a finding. - A source is like a container of findings - that come from the same scanner, logger, - monitor, and other tools. + google.cloud.securitycenter_v1.types.EffectiveSecurityHealthAnalyticsCustomModule: + An EffectiveSecurityHealthAnalyticsCustomModule is the representation of + a Security Health Analytics custom module at a + specified level of the resource hierarchy: + organization, folder, or project. If a custom module + is inherited from a parent organization or folder, + the value of the enablementState property in + EffectiveSecurityHealthAnalyticsCustomModule is set + to the value that is effective in the parent, instead + of INHERITED. For example, if the module is enabled + in a parent organization or folder, the effective + enablement_state for the module in all child folders + or projects is also enabled. + EffectiveSecurityHealthAnalyticsCustomModule is + read-only. """ # Create or coerce a protobuf request object. @@ -1845,7 +2136,9 @@ async def sample_get_source(): "the individual field arguments should be set." ) - request = securitycenter_service.GetSourceRequest(request) + request = securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest( + request + ) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1855,7 +2148,7 @@ async def sample_get_source(): # 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_source, + self._client._transport.get_effective_security_health_analytics_custom_module, default_retry=retries.Retry( initial=0.1, maximum=60.0, @@ -1887,18 +2180,21 @@ async def sample_get_source(): # Done; return the response. return response - async def group_assets( + async def get_security_health_analytics_custom_module( self, request: Optional[ - Union[securitycenter_service.GroupAssetsRequest, dict] + Union[ + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] ] = None, *, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.GroupAssetsAsyncPager: - r"""Filters an organization's assets and groups them by - their specified properties. + ) -> security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + r"""Retrieves a SecurityHealthAnalyticsCustomModule. .. code-block:: python @@ -1911,27 +2207,36 @@ async def group_assets( # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import securitycenter_v1 - async def sample_group_assets(): + async def sample_get_security_health_analytics_custom_module(): # Create a client client = securitycenter_v1.SecurityCenterAsyncClient() # Initialize request argument(s) - request = securitycenter_v1.GroupAssetsRequest( - parent="parent_value", - group_by="group_by_value", + request = securitycenter_v1.GetSecurityHealthAnalyticsCustomModuleRequest( + name="name_value", ) # Make the request - page_result = client.group_assets(request=request) + response = await client.get_security_health_analytics_custom_module(request=request) # Handle the response - async for response in page_result: - print(response) + print(response) Args: - request (Optional[Union[google.cloud.securitycenter_v1.types.GroupAssetsRequest, dict]]): - The request object. Request message for grouping by - assets. + request (Optional[Union[google.cloud.securitycenter_v1.types.GetSecurityHealthAnalyticsCustomModuleRequest, dict]]): + The request object. Request message for getting security + health analytics custom modules. + name (:class:`str`): + Required. Name of the custom module + to get. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/customModules/{customModule}", + "folders/{folder}/securityHealthAnalyticsSettings/customModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/customModules/{customModule}" + + 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. @@ -1939,21 +2244,42 @@ async def sample_group_assets(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.services.security_center.pagers.GroupAssetsAsyncPager: - Response message for grouping by - assets. - Iterating over this object will yield - results and resolve additional pages - automatically. + google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule: + Represents an instance of a Security + Health Analytics custom module, + including its full module name, display + name, enablement state, and last updated + time. You can create a custom module at + the organization, folder, or project + level. Custom modules that you create at + the organization or folder level are + inherited by the child folders and + projects. """ # Create or coerce a protobuf request object. - request = securitycenter_service.GroupAssetsRequest(request) + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest( + 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.group_assets, + self._client._transport.get_security_health_analytics_custom_module, default_retry=retries.Retry( initial=0.1, maximum=60.0, @@ -1962,7 +2288,221 @@ async def sample_group_assets(): core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), - deadline=480.0, + deadline=60.0, + ), + default_timeout=60.0, + 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_source( + self, + request: Optional[Union[securitycenter_service.GetSourceRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> source.Source: + r"""Gets a source. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + async def sample_get_source(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.GetSourceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_source(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.securitycenter_v1.types.GetSourceRequest, dict]]): + The request object. Request message for getting a source. + name (:class:`str`): + Required. Relative resource name of the source. Its + format is + "organizations/[organization_id]/source/[source_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.Source: + Security Command Center finding + source. A finding source is an entity or + a mechanism that can produce a finding. + A source is like a container of findings + that come from the same scanner, logger, + monitor, and other tools. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.GetSourceRequest(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_source, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # 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 group_assets( + self, + request: Optional[ + Union[securitycenter_service.GroupAssetsRequest, dict] + ] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.GroupAssetsAsyncPager: + r"""Filters an organization's assets and groups them by + their specified properties. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + async def sample_group_assets(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.GroupAssetsRequest( + parent="parent_value", + group_by="group_by_value", + ) + + # Make the request + page_result = client.group_assets(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[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, + 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.GroupAssetsAsyncPager: + Response message for grouping by + assets. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + request = securitycenter_service.GroupAssetsRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.group_assets, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=480.0, ), default_timeout=480.0, client_info=DEFAULT_CLIENT_INFO, @@ -2196,9 +2736,371 @@ async def sample_list_assets(): async for response in page_result: print(response) - Args: - request (Optional[Union[google.cloud.securitycenter_v1.types.ListAssetsRequest, dict]]): - The request object. Request message for listing assets. + Args: + request (Optional[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. + 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.ListAssetsAsyncPager: + Response message for listing assets. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + request = securitycenter_service.ListAssetsRequest(request) + + # 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_assets, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=480.0, + ), + default_timeout=480.0, + 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.ListAssetsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_descendant_security_health_analytics_custom_modules( + self, + request: Optional[ + Union[ + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + dict, + ] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListDescendantSecurityHealthAnalyticsCustomModulesAsyncPager: + r"""Returns a list of all resident + SecurityHealthAnalyticsCustomModules under the given CRM + parent and all of the parent’s CRM descendants. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + async def sample_list_descendant_security_health_analytics_custom_modules(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListDescendantSecurityHealthAnalyticsCustomModulesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_descendant_security_health_analytics_custom_modules(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.securitycenter_v1.types.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, dict]]): + The request object. Request message for listing + descendant security health analytics + custom modules. + parent (:class:`str`): + Required. Name of parent to list + descendant custom modules. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings" + + 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.ListDescendantSecurityHealthAnalyticsCustomModulesAsyncPager: + Response message for listing + descendant security health analytics + custom modules. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest( + 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_descendant_security_health_analytics_custom_modules, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # 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.ListDescendantSecurityHealthAnalyticsCustomModulesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_findings( + self, + request: Optional[ + Union[securitycenter_service.ListFindingsRequest, dict] + ] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListFindingsAsyncPager: + r"""Lists an organization or source's findings. + + To list across all sources provide a ``-`` as the source id. + Example: /v1/organizations/{organization_id}/sources/-/findings + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + async def sample_list_findings(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListFindingsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_findings(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[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, + 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.ListFindingsAsyncPager: + Response message for listing + findings. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + request = securitycenter_service.ListFindingsRequest(request) + + # 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_findings, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=480.0, + ), + default_timeout=480.0, + 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.ListFindingsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_mute_configs( + self, + request: Optional[ + Union[securitycenter_service.ListMuteConfigsRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListMuteConfigsAsyncPager: + r"""Lists mute configs. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + async def sample_list_mute_configs(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListMuteConfigsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_mute_configs(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[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. @@ -2206,31 +3108,36 @@ async def sample_list_assets(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.services.security_center.pagers.ListAssetsAsyncPager: - Response message for listing assets. + 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. - request = securitycenter_service.ListAssetsRequest(request) + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + 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_assets, - default_retry=retries.Retry( - initial=0.1, - maximum=60.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=480.0, - ), - default_timeout=480.0, + self._client._transport.list_mute_configs, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -2250,7 +3157,7 @@ async def sample_list_assets(): # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. - response = pagers.ListAssetsAsyncPager( + response = pagers.ListMuteConfigsAsyncPager( method=rpc, request=request, response=response, @@ -2260,20 +3167,18 @@ async def sample_list_assets(): # Done; return the response. return response - async def list_findings( + async def list_notification_configs( self, request: Optional[ - Union[securitycenter_service.ListFindingsRequest, dict] + Union[securitycenter_service.ListNotificationConfigsRequest, dict] ] = None, *, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListFindingsAsyncPager: - r"""Lists an organization or source's findings. - - To list across all sources provide a ``-`` as the source id. - Example: /v1/organizations/{organization_id}/sources/-/findings + ) -> pagers.ListNotificationConfigsAsyncPager: + r"""Lists notification configs. .. code-block:: python @@ -2286,25 +3191,35 @@ async def list_findings( # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import securitycenter_v1 - async def sample_list_findings(): + async def sample_list_notification_configs(): # Create a client client = securitycenter_v1.SecurityCenterAsyncClient() # Initialize request argument(s) - request = securitycenter_v1.ListFindingsRequest( + request = securitycenter_v1.ListNotificationConfigsRequest( parent="parent_value", ) # Make the request - page_result = client.list_findings(request=request) + page_result = client.list_notification_configs(request=request) # Handle the response async for response in page_result: print(response) Args: - request (Optional[Union[google.cloud.securitycenter_v1.types.ListFindingsRequest, dict]]): - The request object. Request message for listing findings. + request (Optional[Union[google.cloud.securitycenter_v1.types.ListNotificationConfigsRequest, dict]]): + The request object. Request message for listing + notification configs. + parent (:class:`str`): + Required. The name of the parent in which to list the + notification configurations. 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. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2312,21 +3227,35 @@ async def sample_list_findings(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.services.security_center.pagers.ListFindingsAsyncPager: + google.cloud.securitycenter_v1.services.security_center.pagers.ListNotificationConfigsAsyncPager: Response message for listing - findings. + notification configs. Iterating over this object will yield results and resolve additional pages automatically. """ # Create or coerce a protobuf request object. - request = securitycenter_service.ListFindingsRequest(request) + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = securitycenter_service.ListNotificationConfigsRequest(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_findings, + self._client._transport.list_notification_configs, default_retry=retries.Retry( initial=0.1, maximum=60.0, @@ -2335,9 +3264,9 @@ async def sample_list_findings(): core_exceptions.DeadlineExceeded, core_exceptions.ServiceUnavailable, ), - deadline=480.0, + deadline=60.0, ), - default_timeout=480.0, + default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -2357,7 +3286,7 @@ async def sample_list_findings(): # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. - response = pagers.ListFindingsAsyncPager( + response = pagers.ListNotificationConfigsAsyncPager( method=rpc, request=request, response=response, @@ -2367,18 +3296,25 @@ async def sample_list_findings(): # Done; return the response. return response - async def list_mute_configs( + async def list_effective_security_health_analytics_custom_modules( self, request: Optional[ - Union[securitycenter_service.ListMuteConfigsRequest, dict] + Union[ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + dict, + ] ] = None, *, parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListMuteConfigsAsyncPager: - r"""Lists mute configs. + ) -> pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesAsyncPager: + r"""Returns a list of all + EffectiveSecurityHealthAnalyticsCustomModules for the + given parent. This includes resident modules defined at + the scope of the parent, and inherited modules, + inherited from CRM ancestors. .. code-block:: python @@ -2391,32 +3327,34 @@ async def list_mute_configs( # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import securitycenter_v1 - async def sample_list_mute_configs(): + async def sample_list_effective_security_health_analytics_custom_modules(): # Create a client client = securitycenter_v1.SecurityCenterAsyncClient() # Initialize request argument(s) - request = securitycenter_v1.ListMuteConfigsRequest( + request = securitycenter_v1.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest( parent="parent_value", ) # Make the request - page_result = client.list_mute_configs(request=request) + page_result = client.list_effective_security_health_analytics_custom_modules(request=request) # Handle the response async for response in page_result: print(response) Args: - request (Optional[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. + request (Optional[Union[google.cloud.securitycenter_v1.types.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, dict]]): + The request object. Request message for listing effective + security health analytics custom + modules. 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]". + Required. Name of parent to list + effective custom modules. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings" This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -2428,9 +3366,10 @@ async def sample_list_mute_configs(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.services.security_center.pagers.ListMuteConfigsAsyncPager: - Response message for listing mute - configs. + google.cloud.securitycenter_v1.services.security_center.pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesAsyncPager: + Response message for listing + effective security health analytics + custom modules. Iterating over this object will yield results and resolve additional pages automatically. @@ -2446,7 +3385,9 @@ async def sample_list_mute_configs(): "the individual field arguments should be set." ) - request = securitycenter_service.ListMuteConfigsRequest(request) + request = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest( + request + ) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2456,8 +3397,18 @@ async def sample_list_mute_configs(): # 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, + self._client._transport.list_effective_security_health_analytics_custom_modules, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -2477,7 +3428,7 @@ async def sample_list_mute_configs(): # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. - response = pagers.ListMuteConfigsAsyncPager( + response = pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesAsyncPager( method=rpc, request=request, response=response, @@ -2487,18 +3438,25 @@ async def sample_list_mute_configs(): # Done; return the response. return response - async def list_notification_configs( + async def list_security_health_analytics_custom_modules( self, request: Optional[ - Union[securitycenter_service.ListNotificationConfigsRequest, dict] + Union[ + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, + dict, + ] ] = None, *, parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListNotificationConfigsAsyncPager: - r"""Lists notification configs. + ) -> pagers.ListSecurityHealthAnalyticsCustomModulesAsyncPager: + r"""Returns a list of all + SecurityHealthAnalyticsCustomModules for the given + parent. This includes resident modules defined at the + scope of the parent, and inherited modules, inherited + from CRM ancestors. .. code-block:: python @@ -2511,31 +3469,33 @@ async def list_notification_configs( # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import securitycenter_v1 - async def sample_list_notification_configs(): + async def sample_list_security_health_analytics_custom_modules(): # Create a client client = securitycenter_v1.SecurityCenterAsyncClient() # Initialize request argument(s) - request = securitycenter_v1.ListNotificationConfigsRequest( + request = securitycenter_v1.ListSecurityHealthAnalyticsCustomModulesRequest( parent="parent_value", ) # Make the request - page_result = client.list_notification_configs(request=request) + page_result = client.list_security_health_analytics_custom_modules(request=request) # Handle the response async for response in page_result: print(response) Args: - request (Optional[Union[google.cloud.securitycenter_v1.types.ListNotificationConfigsRequest, dict]]): - The request object. Request message for listing - notification configs. + request (Optional[Union[google.cloud.securitycenter_v1.types.ListSecurityHealthAnalyticsCustomModulesRequest, dict]]): + The request object. Request message for listing security + health analytics custom modules. parent (:class:`str`): - Required. The name of the parent in which to list the - notification configurations. Its format is - "organizations/[organization_id]", - "folders/[folder_id]", or "projects/[project_id]". + Required. Name of parent to list + custom modules. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings" This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -2547,9 +3507,9 @@ async def sample_list_notification_configs(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.services.security_center.pagers.ListNotificationConfigsAsyncPager: - Response message for listing - notification configs. + google.cloud.securitycenter_v1.services.security_center.pagers.ListSecurityHealthAnalyticsCustomModulesAsyncPager: + Response message for listing security + health analytics custom modules. Iterating over this object will yield results and resolve additional pages automatically. @@ -2565,7 +3525,11 @@ async def sample_list_notification_configs(): "the individual field arguments should be set." ) - request = securitycenter_service.ListNotificationConfigsRequest(request) + request = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest( + request + ) + ) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2575,7 +3539,7 @@ async def sample_list_notification_configs(): # 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_notification_configs, + self._client._transport.list_security_health_analytics_custom_modules, default_retry=retries.Retry( initial=0.1, maximum=60.0, @@ -2606,7 +3570,7 @@ async def sample_list_notification_configs(): # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. - response = pagers.ListNotificationConfigsAsyncPager( + response = pagers.ListSecurityHealthAnalyticsCustomModulesAsyncPager( method=rpc, request=request, response=response, @@ -4009,6 +4973,151 @@ async def sample_update_organization_settings(): # Done; return the response. return response + async def update_security_health_analytics_custom_module( + self, + request: Optional[ + Union[ + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] + ] = None, + *, + security_health_analytics_custom_module: Optional[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + r"""Updates the SecurityHealthAnalyticsCustomModule under + the given name based on the given update mask. Updating + the enablement state is supported on both resident and + inherited modules (though resident modules cannot have + an enablement state of “inherited”). Updating the + display name and custom config of a module is supported + on resident modules only. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + async def sample_update_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.UpdateSecurityHealthAnalyticsCustomModuleRequest( + ) + + # Make the request + response = await client.update_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.securitycenter_v1.types.UpdateSecurityHealthAnalyticsCustomModuleRequest, dict]]): + The request object. Request message for updating security + health analytics custom modules. + security_health_analytics_custom_module (:class:`google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule`): + Required. The SecurityHealthAnalytics + custom module to update. + + This corresponds to the ``security_health_analytics_custom_module`` 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 update. + 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.SecurityHealthAnalyticsCustomModule: + Represents an instance of a Security + Health Analytics custom module, + including its full module name, display + name, enablement state, and last updated + time. You can create a custom module at + the organization, folder, or project + level. Custom modules that you create at + the organization or folder level are + inherited by the child folders and + projects. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any( + [security_health_analytics_custom_module, 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.UpdateSecurityHealthAnalyticsCustomModuleRequest( + request + ) + ) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if security_health_analytics_custom_module is not None: + request.security_health_analytics_custom_module = ( + security_health_analytics_custom_module + ) + 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_security_health_analytics_custom_module, + default_timeout=60.0, + 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( + ( + ( + "security_health_analytics_custom_module.name", + request.security_health_analytics_custom_module.name, + ), + ) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + async def update_source( self, request: Optional[ diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/client.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/client.py index 9175c80cc66e..a5124395a641 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/client.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/client.py @@ -63,8 +63,14 @@ connection, container, database, + effective_security_health_analytics_custom_module, exfiltration, ) +from google.cloud.securitycenter_v1.types import ( + process, + run_asset_discovery_response, + security_health_analytics_custom_config, +) from google.cloud.securitycenter_v1.types import ( iam_binding, indicator, @@ -72,7 +78,6 @@ kubernetes, mitre_attack, ) -from google.cloud.securitycenter_v1.types import process, run_asset_discovery_response from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -80,6 +85,10 @@ from google.cloud.securitycenter_v1.types import ( organization_settings as gcs_organization_settings, ) +from google.cloud.securitycenter_v1.types import security_health_analytics_custom_module +from google.cloud.securitycenter_v1.types import ( + security_health_analytics_custom_module as gcs_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import security_marks as gcs_security_marks from google.cloud.securitycenter_v1.types import file from google.cloud.securitycenter_v1.types import finding @@ -261,6 +270,28 @@ def parse_big_query_export_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def effective_security_health_analytics_custom_module_path( + organization: str, + effective_custom_module: str, + ) -> str: + """Returns a fully-qualified effective_security_health_analytics_custom_module string.""" + return "organizations/{organization}/securityHealthAnalyticsSettings/effectiveCustomModules/{effective_custom_module}".format( + organization=organization, + effective_custom_module=effective_custom_module, + ) + + @staticmethod + def parse_effective_security_health_analytics_custom_module_path( + path: str, + ) -> Dict[str, str]: + """Parses a effective_security_health_analytics_custom_module path into its component segments.""" + m = re.match( + r"^organizations/(?P.+?)/securityHealthAnalyticsSettings/effectiveCustomModules/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def external_system_path( organization: str, @@ -366,6 +397,26 @@ def parse_organization_settings_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def security_health_analytics_custom_module_path( + organization: str, + custom_module: str, + ) -> str: + """Returns a fully-qualified security_health_analytics_custom_module string.""" + return "organizations/{organization}/securityHealthAnalyticsSettings/customModules/{custom_module}".format( + organization=organization, + custom_module=custom_module, + ) + + @staticmethod + def parse_security_health_analytics_custom_module_path(path: str) -> Dict[str, str]: + """Parses a security_health_analytics_custom_module path into its component segments.""" + m = re.match( + r"^organizations/(?P.+?)/securityHealthAnalyticsSettings/customModules/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def security_marks_path( organization: str, @@ -797,6 +848,156 @@ def sample_bulk_mute_findings(): # Done; return the response. return response + def create_security_health_analytics_custom_module( + self, + request: Optional[ + Union[ + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] + ] = None, + *, + parent: Optional[str] = None, + security_health_analytics_custom_module: Optional[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + r"""Creates a resident + SecurityHealthAnalyticsCustomModule at the scope of the + given CRM parent, and also creates inherited + SecurityHealthAnalyticsCustomModules for all CRM + descendants of the given parent. These modules are + enabled by default. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + def sample_create_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.CreateSecurityHealthAnalyticsCustomModuleRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.securitycenter_v1.types.CreateSecurityHealthAnalyticsCustomModuleRequest, dict]): + The request object. Request message for creating security + health analytics custom modules. + parent (str): + Required. Resource name of the new + custom module's parent. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings" + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + security_health_analytics_custom_module (google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule): + Required. SecurityHealthAnalytics + custom module to create. The provided + name is ignored and reset with provided + parent information and server-generated + ID. + + This corresponds to the ``security_health_analytics_custom_module`` 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.SecurityHealthAnalyticsCustomModule: + Represents an instance of a Security + Health Analytics custom module, + including its full module name, display + name, enablement state, and last updated + time. You can create a custom module at + the organization, folder, or project + level. Custom modules that you create at + the organization or folder level are + inherited by the child folders and + projects. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, security_health_analytics_custom_module]) + 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.CreateSecurityHealthAnalyticsCustomModuleRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, + ): + request = ( + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest( + request + ) + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if security_health_analytics_custom_module is not None: + request.security_health_analytics_custom_module = ( + security_health_analytics_custom_module + ) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.create_security_health_analytics_custom_module + ] + + # 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_source( self, request: Optional[ @@ -1525,6 +1726,117 @@ def sample_delete_notification_config(): metadata=metadata, ) + def delete_security_health_analytics_custom_module( + self, + request: Optional[ + Union[ + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes the specified + SecurityHealthAnalyticsCustomModule and all of its + descendants in the CRM hierarchy. This method is only + supported for resident custom modules. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + def sample_delete_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.DeleteSecurityHealthAnalyticsCustomModuleRequest( + name="name_value", + ) + + # Make the request + client.delete_security_health_analytics_custom_module(request=request) + + Args: + request (Union[google.cloud.securitycenter_v1.types.DeleteSecurityHealthAnalyticsCustomModuleRequest, dict]): + The request object. Request message for deleting security + health analytics custom modules. + name (str): + Required. Name of the custom module + to delete. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/customModules/{customModule}", + "folders/{folder}/securityHealthAnalyticsSettings/customModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/customModules/{customModule}" + + 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. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + 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.DeleteSecurityHealthAnalyticsCustomModuleRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, + ): + request = ( + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest( + 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_security_health_analytics_custom_module + ] + + # 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 get_big_query_export( self, request: Optional[ @@ -2125,16 +2437,22 @@ def sample_get_organization_settings(): # Done; return the response. return response - def get_source( + def get_effective_security_health_analytics_custom_module( self, - request: Optional[Union[securitycenter_service.GetSourceRequest, dict]] = None, + request: Optional[ + Union[ + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] + ] = None, *, name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), - ) -> source.Source: - r"""Gets a source. + ) -> effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule: + r"""Retrieves an + EffectiveSecurityHealthAnalyticsCustomModule. .. code-block:: python @@ -2147,28 +2465,33 @@ def get_source( # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import securitycenter_v1 - def sample_get_source(): + def sample_get_effective_security_health_analytics_custom_module(): # Create a client client = securitycenter_v1.SecurityCenterClient() # Initialize request argument(s) - request = securitycenter_v1.GetSourceRequest( + request = securitycenter_v1.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest( name="name_value", ) # Make the request - response = client.get_source(request=request) + response = client.get_effective_security_health_analytics_custom_module(request=request) # Handle the response print(response) Args: - request (Union[google.cloud.securitycenter_v1.types.GetSourceRequest, dict]): - The request object. Request message for getting a source. + request (Union[google.cloud.securitycenter_v1.types.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, dict]): + The request object. Request message for getting effective + security health analytics custom + modules. name (str): - Required. Relative resource name of the source. Its - format is - "organizations/[organization_id]/source/[source_id]". + Required. Name of the effective + custom module to get. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}", + "folders/{folder}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}" This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -2180,13 +2503,21 @@ def sample_get_source(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.types.Source: - Security Command Center finding - source. A finding source is an entity or - a mechanism that can produce a finding. - A source is like a container of findings - that come from the same scanner, logger, - monitor, and other tools. + google.cloud.securitycenter_v1.types.EffectiveSecurityHealthAnalyticsCustomModule: + An EffectiveSecurityHealthAnalyticsCustomModule is the representation of + a Security Health Analytics custom module at a + specified level of the resource hierarchy: + organization, folder, or project. If a custom module + is inherited from a parent organization or folder, + the value of the enablementState property in + EffectiveSecurityHealthAnalyticsCustomModule is set + to the value that is effective in the parent, instead + of INHERITED. For example, if the module is enabled + in a parent organization or folder, the effective + enablement_state for the module in all child folders + or projects is also enabled. + EffectiveSecurityHealthAnalyticsCustomModule is + read-only. """ # Create or coerce a protobuf request object. @@ -2200,11 +2531,16 @@ def sample_get_source(): ) # Minor optimization to avoid making a copy if the user passes - # in a securitycenter_service.GetSourceRequest. + # in a securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, securitycenter_service.GetSourceRequest): - request = securitycenter_service.GetSourceRequest(request) + if not isinstance( + request, + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, + ): + request = securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest( + request + ) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: @@ -2212,7 +2548,9 @@ def sample_get_source(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_source] + rpc = self._transport._wrapped_methods[ + self._transport.get_effective_security_health_analytics_custom_module + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2231,18 +2569,21 @@ def sample_get_source(): # Done; return the response. return response - def group_assets( + def get_security_health_analytics_custom_module( self, request: Optional[ - Union[securitycenter_service.GroupAssetsRequest, dict] + Union[ + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] ] = None, *, + name: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.GroupAssetsPager: - r"""Filters an organization's assets and groups them by - their specified properties. + ) -> security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + r"""Retrieves a SecurityHealthAnalyticsCustomModule. .. code-block:: python @@ -2255,22 +2596,253 @@ def group_assets( # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import securitycenter_v1 - def sample_group_assets(): + def sample_get_security_health_analytics_custom_module(): # Create a client client = securitycenter_v1.SecurityCenterClient() # Initialize request argument(s) - request = securitycenter_v1.GroupAssetsRequest( - parent="parent_value", - group_by="group_by_value", + request = securitycenter_v1.GetSecurityHealthAnalyticsCustomModuleRequest( + name="name_value", ) # Make the request - page_result = client.group_assets(request=request) + response = client.get_security_health_analytics_custom_module(request=request) # Handle the response - for response in page_result: - print(response) + print(response) + + Args: + request (Union[google.cloud.securitycenter_v1.types.GetSecurityHealthAnalyticsCustomModuleRequest, dict]): + The request object. Request message for getting security + health analytics custom modules. + name (str): + Required. Name of the custom module + to get. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/customModules/{customModule}", + "folders/{folder}/securityHealthAnalyticsSettings/customModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/customModules/{customModule}" + + 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.SecurityHealthAnalyticsCustomModule: + Represents an instance of a Security + Health Analytics custom module, + including its full module name, display + name, enablement state, and last updated + time. You can create a custom module at + the organization, folder, or project + level. Custom modules that you create at + the organization or folder level are + inherited by the child folders and + projects. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + 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.GetSecurityHealthAnalyticsCustomModuleRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, + ): + request = ( + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest( + 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_security_health_analytics_custom_module + ] + + # 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_source( + self, + request: Optional[Union[securitycenter_service.GetSourceRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> source.Source: + r"""Gets a source. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + def sample_get_source(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.GetSourceRequest( + name="name_value", + ) + + # Make the request + response = client.get_source(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.securitycenter_v1.types.GetSourceRequest, dict]): + The request object. Request message for getting a source. + name (str): + Required. Relative resource name of the source. Its + format is + "organizations/[organization_id]/source/[source_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.Source: + Security Command Center finding + source. A finding source is an entity or + a mechanism that can produce a finding. + A source is like a container of findings + that come from the same scanner, logger, + monitor, and other tools. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + 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.GetSourceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.GetSourceRequest): + request = securitycenter_service.GetSourceRequest(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_source] + + # 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 group_assets( + self, + request: Optional[ + Union[securitycenter_service.GroupAssetsRequest, dict] + ] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.GroupAssetsPager: + r"""Filters an organization's assets and groups them by + their specified properties. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + def sample_group_assets(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.GroupAssetsRequest( + parent="parent_value", + group_by="group_by_value", + ) + + # Make the request + page_result = client.group_assets(request=request) + + # Handle the response + for response in page_result: + print(response) Args: request (Union[google.cloud.securitycenter_v1.types.GroupAssetsRequest, dict]): @@ -2521,9 +3093,348 @@ def sample_list_assets(): for response in page_result: print(response) - Args: - request (Union[google.cloud.securitycenter_v1.types.ListAssetsRequest, dict]): - The request object. Request message for listing assets. + Args: + 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. + 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.ListAssetsPager: + Response message for listing assets. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a securitycenter_service.ListAssetsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.ListAssetsRequest): + request = securitycenter_service.ListAssetsRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_assets] + + # 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.ListAssetsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_descendant_security_health_analytics_custom_modules( + self, + request: Optional[ + Union[ + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + dict, + ] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListDescendantSecurityHealthAnalyticsCustomModulesPager: + r"""Returns a list of all resident + SecurityHealthAnalyticsCustomModules under the given CRM + parent and all of the parent’s CRM descendants. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + def sample_list_descendant_security_health_analytics_custom_modules(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListDescendantSecurityHealthAnalyticsCustomModulesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_descendant_security_health_analytics_custom_modules(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.securitycenter_v1.types.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, dict]): + The request object. Request message for listing + descendant security health analytics + custom modules. + parent (str): + Required. Name of parent to list + descendant custom modules. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings" + + 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.ListDescendantSecurityHealthAnalyticsCustomModulesPager: + Response message for listing + descendant security health analytics + custom modules. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + 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.ListDescendantSecurityHealthAnalyticsCustomModulesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + ): + request = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest( + 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_descendant_security_health_analytics_custom_modules + ] + + # 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.ListDescendantSecurityHealthAnalyticsCustomModulesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_findings( + self, + request: Optional[ + Union[securitycenter_service.ListFindingsRequest, dict] + ] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListFindingsPager: + r"""Lists an organization or source's findings. + + To list across all sources provide a ``-`` as the source id. + Example: /v1/organizations/{organization_id}/sources/-/findings + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + def sample_list_findings(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListFindingsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_findings(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + 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, + 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.ListFindingsPager: + Response message for listing + findings. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a securitycenter_service.ListFindingsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, securitycenter_service.ListFindingsRequest): + request = securitycenter_service.ListFindingsRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListFindingsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_mute_configs( + self, + request: Optional[ + Union[securitycenter_service.ListMuteConfigsRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListMuteConfigsPager: + r"""Lists mute configs. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + def sample_list_mute_configs(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListMuteConfigsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_mute_configs(request=request) + + # Handle the response + for response in page_result: + print(response) + + 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. @@ -2531,24 +3442,38 @@ def sample_list_assets(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.services.security_center.pagers.ListAssetsPager: - Response message for listing assets. + 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. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + 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.ListAssetsRequest. + # 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.ListAssetsRequest): - request = securitycenter_service.ListAssetsRequest(request) + 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_assets] + rpc = self._transport._wrapped_methods[self._transport.list_mute_configs] # Certain fields should be provided within the metadata header; # add these here. @@ -2566,7 +3491,7 @@ def sample_list_assets(): # This method is paged; wrap the response in a pager, which provides # an `__iter__` convenience method. - response = pagers.ListAssetsPager( + response = pagers.ListMuteConfigsPager( method=rpc, request=request, response=response, @@ -2576,20 +3501,18 @@ def sample_list_assets(): # Done; return the response. return response - def list_findings( + def list_notification_configs( self, request: Optional[ - Union[securitycenter_service.ListFindingsRequest, dict] + Union[securitycenter_service.ListNotificationConfigsRequest, dict] ] = None, *, + parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListFindingsPager: - r"""Lists an organization or source's findings. - - To list across all sources provide a ``-`` as the source id. - Example: /v1/organizations/{organization_id}/sources/-/findings + ) -> pagers.ListNotificationConfigsPager: + r"""Lists notification configs. .. code-block:: python @@ -2602,25 +3525,35 @@ def list_findings( # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import securitycenter_v1 - def sample_list_findings(): + def sample_list_notification_configs(): # Create a client client = securitycenter_v1.SecurityCenterClient() # Initialize request argument(s) - request = securitycenter_v1.ListFindingsRequest( + request = securitycenter_v1.ListNotificationConfigsRequest( parent="parent_value", ) # Make the request - page_result = client.list_findings(request=request) + page_result = client.list_notification_configs(request=request) # Handle the response for response in page_result: print(response) Args: - request (Union[google.cloud.securitycenter_v1.types.ListFindingsRequest, dict]): - The request object. Request message for listing findings. + request (Union[google.cloud.securitycenter_v1.types.ListNotificationConfigsRequest, dict]): + The request object. Request message for listing + notification configs. + parent (str): + Required. The name of the parent in which to list the + notification configurations. 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. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2628,25 +3561,42 @@ def sample_list_findings(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.services.security_center.pagers.ListFindingsPager: + google.cloud.securitycenter_v1.services.security_center.pagers.ListNotificationConfigsPager: Response message for listing - findings. + notification configs. Iterating over this object will yield results and resolve additional pages automatically. """ # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + 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.ListFindingsRequest. + # in a securitycenter_service.ListNotificationConfigsRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, securitycenter_service.ListFindingsRequest): - request = securitycenter_service.ListFindingsRequest(request) + if not isinstance( + request, securitycenter_service.ListNotificationConfigsRequest + ): + request = securitycenter_service.ListNotificationConfigsRequest(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_findings] + rpc = self._transport._wrapped_methods[ + self._transport.list_notification_configs + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2664,7 +3614,7 @@ def sample_list_findings(): # This method is paged; wrap the response in a pager, which provides # an `__iter__` convenience method. - response = pagers.ListFindingsPager( + response = pagers.ListNotificationConfigsPager( method=rpc, request=request, response=response, @@ -2674,18 +3624,25 @@ def sample_list_findings(): # Done; return the response. return response - def list_mute_configs( + def list_effective_security_health_analytics_custom_modules( self, request: Optional[ - Union[securitycenter_service.ListMuteConfigsRequest, dict] + Union[ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + dict, + ] ] = None, *, parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListMuteConfigsPager: - r"""Lists mute configs. + ) -> pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesPager: + r"""Returns a list of all + EffectiveSecurityHealthAnalyticsCustomModules for the + given parent. This includes resident modules defined at + the scope of the parent, and inherited modules, + inherited from CRM ancestors. .. code-block:: python @@ -2698,32 +3655,34 @@ def list_mute_configs( # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import securitycenter_v1 - def sample_list_mute_configs(): + def sample_list_effective_security_health_analytics_custom_modules(): # Create a client client = securitycenter_v1.SecurityCenterClient() # Initialize request argument(s) - request = securitycenter_v1.ListMuteConfigsRequest( + request = securitycenter_v1.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest( parent="parent_value", ) # Make the request - page_result = client.list_mute_configs(request=request) + page_result = client.list_effective_security_health_analytics_custom_modules(request=request) # Handle the response for response in page_result: print(response) 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. + request (Union[google.cloud.securitycenter_v1.types.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, dict]): + The request object. Request message for listing effective + security health analytics custom + modules. parent (str): - Required. The parent, which owns the collection of mute - configs. Its format is - "organizations/[organization_id]", - "folders/[folder_id]", "projects/[project_id]". + Required. Name of parent to list + effective custom modules. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings" This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -2735,9 +3694,10 @@ def sample_list_mute_configs(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.services.security_center.pagers.ListMuteConfigsPager: - Response message for listing mute - configs. + google.cloud.securitycenter_v1.services.security_center.pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesPager: + Response message for listing + effective security health analytics + custom modules. Iterating over this object will yield results and resolve additional pages automatically. @@ -2754,11 +3714,16 @@ def sample_list_mute_configs(): ) # Minor optimization to avoid making a copy if the user passes - # in a securitycenter_service.ListMuteConfigsRequest. + # in a securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest. # 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 not isinstance( + request, + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + ): + request = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest( + request + ) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: @@ -2766,7 +3731,9 @@ def sample_list_mute_configs(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_mute_configs] + rpc = self._transport._wrapped_methods[ + self._transport.list_effective_security_health_analytics_custom_modules + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2784,7 +3751,7 @@ def sample_list_mute_configs(): # This method is paged; wrap the response in a pager, which provides # an `__iter__` convenience method. - response = pagers.ListMuteConfigsPager( + response = pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesPager( method=rpc, request=request, response=response, @@ -2794,18 +3761,25 @@ def sample_list_mute_configs(): # Done; return the response. return response - def list_notification_configs( + def list_security_health_analytics_custom_modules( self, request: Optional[ - Union[securitycenter_service.ListNotificationConfigsRequest, dict] + Union[ + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, + dict, + ] ] = None, *, parent: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListNotificationConfigsPager: - r"""Lists notification configs. + ) -> pagers.ListSecurityHealthAnalyticsCustomModulesPager: + r"""Returns a list of all + SecurityHealthAnalyticsCustomModules for the given + parent. This includes resident modules defined at the + scope of the parent, and inherited modules, inherited + from CRM ancestors. .. code-block:: python @@ -2818,31 +3792,33 @@ def list_notification_configs( # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import securitycenter_v1 - def sample_list_notification_configs(): + def sample_list_security_health_analytics_custom_modules(): # Create a client client = securitycenter_v1.SecurityCenterClient() # Initialize request argument(s) - request = securitycenter_v1.ListNotificationConfigsRequest( + request = securitycenter_v1.ListSecurityHealthAnalyticsCustomModulesRequest( parent="parent_value", ) # Make the request - page_result = client.list_notification_configs(request=request) + page_result = client.list_security_health_analytics_custom_modules(request=request) # Handle the response for response in page_result: print(response) Args: - request (Union[google.cloud.securitycenter_v1.types.ListNotificationConfigsRequest, dict]): - The request object. Request message for listing - notification configs. + request (Union[google.cloud.securitycenter_v1.types.ListSecurityHealthAnalyticsCustomModulesRequest, dict]): + The request object. Request message for listing security + health analytics custom modules. parent (str): - Required. The name of the parent in which to list the - notification configurations. Its format is - "organizations/[organization_id]", - "folders/[folder_id]", or "projects/[project_id]". + Required. Name of parent to list + custom modules. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings" This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -2854,9 +3830,9 @@ def sample_list_notification_configs(): sent along with the request as metadata. Returns: - google.cloud.securitycenter_v1.services.security_center.pagers.ListNotificationConfigsPager: - Response message for listing - notification configs. + google.cloud.securitycenter_v1.services.security_center.pagers.ListSecurityHealthAnalyticsCustomModulesPager: + Response message for listing security + health analytics custom modules. Iterating over this object will yield results and resolve additional pages automatically. @@ -2873,13 +3849,18 @@ def sample_list_notification_configs(): ) # Minor optimization to avoid making a copy if the user passes - # in a securitycenter_service.ListNotificationConfigsRequest. + # in a securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance( - request, securitycenter_service.ListNotificationConfigsRequest + request, + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, ): - request = securitycenter_service.ListNotificationConfigsRequest(request) + request = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest( + request + ) + ) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: @@ -2888,7 +3869,7 @@ def sample_list_notification_configs(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[ - self._transport.list_notification_configs + self._transport.list_security_health_analytics_custom_modules ] # Certain fields should be provided within the metadata header; @@ -2907,7 +3888,7 @@ def sample_list_notification_configs(): # This method is paged; wrap the response in a pager, which provides # an `__iter__` convenience method. - response = pagers.ListNotificationConfigsPager( + response = pagers.ListSecurityHealthAnalyticsCustomModulesPager( method=rpc, request=request, response=response, @@ -4293,6 +5274,156 @@ def sample_update_organization_settings(): # Done; return the response. return response + def update_security_health_analytics_custom_module( + self, + request: Optional[ + Union[ + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] + ] = None, + *, + security_health_analytics_custom_module: Optional[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + r"""Updates the SecurityHealthAnalyticsCustomModule under + the given name based on the given update mask. Updating + the enablement state is supported on both resident and + inherited modules (though resident modules cannot have + an enablement state of “inherited”). Updating the + display name and custom config of a module is supported + on resident modules only. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import securitycenter_v1 + + def sample_update_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.UpdateSecurityHealthAnalyticsCustomModuleRequest( + ) + + # Make the request + response = client.update_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.securitycenter_v1.types.UpdateSecurityHealthAnalyticsCustomModuleRequest, dict]): + The request object. Request message for updating security + health analytics custom modules. + security_health_analytics_custom_module (google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule): + Required. The SecurityHealthAnalytics + custom module to update. + + This corresponds to the ``security_health_analytics_custom_module`` 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 update. + 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.SecurityHealthAnalyticsCustomModule: + Represents an instance of a Security + Health Analytics custom module, + including its full module name, display + name, enablement state, and last updated + time. You can create a custom module at + the organization, folder, or project + level. Custom modules that you create at + the organization or folder level are + inherited by the child folders and + projects. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any( + [security_health_analytics_custom_module, 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.UpdateSecurityHealthAnalyticsCustomModuleRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, + ): + request = ( + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest( + request + ) + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if security_health_analytics_custom_module is not None: + request.security_health_analytics_custom_module = ( + security_health_analytics_custom_module + ) + 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_security_health_analytics_custom_module + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ( + "security_health_analytics_custom_module.name", + request.security_health_analytics_custom_module.name, + ), + ) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + def update_source( self, request: Optional[ diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/pagers.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/pagers.py index cae5c834b4fd..b06f11acbb63 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/pagers.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/pagers.py @@ -26,8 +26,10 @@ from google.cloud.securitycenter_v1.types import ( bigquery_export, + effective_security_health_analytics_custom_module, mute_config, notification_config, + security_health_analytics_custom_module, securitycenter_service, source, ) @@ -423,6 +425,162 @@ def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) +class ListDescendantSecurityHealthAnalyticsCustomModulesPager: + """A pager for iterating through ``list_descendant_security_health_analytics_custom_modules`` requests. + + This class thinly wraps an initial + :class:`google.cloud.securitycenter_v1.types.ListDescendantSecurityHealthAnalyticsCustomModulesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``security_health_analytics_custom_modules`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListDescendantSecurityHealthAnalyticsCustomModules`` requests and continue to iterate + through the ``security_health_analytics_custom_modules`` field on the + corresponding responses. + + All the usual :class:`google.cloud.securitycenter_v1.types.ListDescendantSecurityHealthAnalyticsCustomModulesResponse` + 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.ListDescendantSecurityHealthAnalyticsCustomModulesResponse, + ], + request: securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + response: securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse, + *, + 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.ListDescendantSecurityHealthAnalyticsCustomModulesRequest): + The initial request object. + response (google.cloud.securitycenter_v1.types.ListDescendantSecurityHealthAnalyticsCustomModulesResponse): + 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.ListDescendantSecurityHealthAnalyticsCustomModulesRequest( + 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.ListDescendantSecurityHealthAnalyticsCustomModulesResponse + ]: + 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[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ]: + for page in self.pages: + yield from page.security_health_analytics_custom_modules + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListDescendantSecurityHealthAnalyticsCustomModulesAsyncPager: + """A pager for iterating through ``list_descendant_security_health_analytics_custom_modules`` requests. + + This class thinly wraps an initial + :class:`google.cloud.securitycenter_v1.types.ListDescendantSecurityHealthAnalyticsCustomModulesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``security_health_analytics_custom_modules`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListDescendantSecurityHealthAnalyticsCustomModules`` requests and continue to iterate + through the ``security_health_analytics_custom_modules`` field on the + corresponding responses. + + All the usual :class:`google.cloud.securitycenter_v1.types.ListDescendantSecurityHealthAnalyticsCustomModulesResponse` + 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.ListDescendantSecurityHealthAnalyticsCustomModulesResponse + ], + ], + request: securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + response: securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse, + *, + 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.ListDescendantSecurityHealthAnalyticsCustomModulesRequest): + The initial request object. + response (google.cloud.securitycenter_v1.types.ListDescendantSecurityHealthAnalyticsCustomModulesResponse): + 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.ListDescendantSecurityHealthAnalyticsCustomModulesRequest( + 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.ListDescendantSecurityHealthAnalyticsCustomModulesResponse + ]: + 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[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ]: + async def async_generator(): + async for page in self.pages: + for response in page.security_health_analytics_custom_modules: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + class ListFindingsPager: """A pager for iterating through ``list_findings`` requests. @@ -819,6 +977,321 @@ def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) +class ListEffectiveSecurityHealthAnalyticsCustomModulesPager: + """A pager for iterating through ``list_effective_security_health_analytics_custom_modules`` requests. + + This class thinly wraps an initial + :class:`google.cloud.securitycenter_v1.types.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``effective_security_health_analytics_custom_modules`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListEffectiveSecurityHealthAnalyticsCustomModules`` requests and continue to iterate + through the ``effective_security_health_analytics_custom_modules`` field on the + corresponding responses. + + All the usual :class:`google.cloud.securitycenter_v1.types.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse` + 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.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse, + ], + request: securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + response: securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse, + *, + 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.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest): + The initial request object. + response (google.cloud.securitycenter_v1.types.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse): + 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.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest( + 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.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse + ]: + 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[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule + ]: + for page in self.pages: + yield from page.effective_security_health_analytics_custom_modules + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListEffectiveSecurityHealthAnalyticsCustomModulesAsyncPager: + """A pager for iterating through ``list_effective_security_health_analytics_custom_modules`` requests. + + This class thinly wraps an initial + :class:`google.cloud.securitycenter_v1.types.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``effective_security_health_analytics_custom_modules`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListEffectiveSecurityHealthAnalyticsCustomModules`` requests and continue to iterate + through the ``effective_security_health_analytics_custom_modules`` field on the + corresponding responses. + + All the usual :class:`google.cloud.securitycenter_v1.types.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse` + 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.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse + ], + ], + request: securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + response: securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse, + *, + 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.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest): + The initial request object. + response (google.cloud.securitycenter_v1.types.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse): + 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.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest( + 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.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse + ]: + 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[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule + ]: + async def async_generator(): + async for page in self.pages: + for response in page.effective_security_health_analytics_custom_modules: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListSecurityHealthAnalyticsCustomModulesPager: + """A pager for iterating through ``list_security_health_analytics_custom_modules`` requests. + + This class thinly wraps an initial + :class:`google.cloud.securitycenter_v1.types.ListSecurityHealthAnalyticsCustomModulesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``security_health_analytics_custom_modules`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListSecurityHealthAnalyticsCustomModules`` requests and continue to iterate + through the ``security_health_analytics_custom_modules`` field on the + corresponding responses. + + All the usual :class:`google.cloud.securitycenter_v1.types.ListSecurityHealthAnalyticsCustomModulesResponse` + 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.ListSecurityHealthAnalyticsCustomModulesResponse + ], + request: securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, + response: securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse, + *, + 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.ListSecurityHealthAnalyticsCustomModulesRequest): + The initial request object. + response (google.cloud.securitycenter_v1.types.ListSecurityHealthAnalyticsCustomModulesResponse): + 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.ListSecurityHealthAnalyticsCustomModulesRequest( + 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.ListSecurityHealthAnalyticsCustomModulesResponse + ]: + 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[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ]: + for page in self.pages: + yield from page.security_health_analytics_custom_modules + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListSecurityHealthAnalyticsCustomModulesAsyncPager: + """A pager for iterating through ``list_security_health_analytics_custom_modules`` requests. + + This class thinly wraps an initial + :class:`google.cloud.securitycenter_v1.types.ListSecurityHealthAnalyticsCustomModulesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``security_health_analytics_custom_modules`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListSecurityHealthAnalyticsCustomModules`` requests and continue to iterate + through the ``security_health_analytics_custom_modules`` field on the + corresponding responses. + + All the usual :class:`google.cloud.securitycenter_v1.types.ListSecurityHealthAnalyticsCustomModulesResponse` + 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.ListSecurityHealthAnalyticsCustomModulesResponse + ], + ], + request: securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, + response: securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse, + *, + 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.ListSecurityHealthAnalyticsCustomModulesRequest): + The initial request object. + response (google.cloud.securitycenter_v1.types.ListSecurityHealthAnalyticsCustomModulesResponse): + 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.ListSecurityHealthAnalyticsCustomModulesRequest( + 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.ListSecurityHealthAnalyticsCustomModulesResponse + ]: + 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[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ]: + async def async_generator(): + async for page in self.pages: + for response in page.security_health_analytics_custom_modules: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + class ListSourcesPager: """A pager for iterating through ``list_sources`` requests. diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/base.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/base.py index d38838e36967..33860dca8453 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/base.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/base.py @@ -29,6 +29,10 @@ from google.protobuf import empty_pb2 # type: ignore from google.cloud.securitycenter_v1 import gapic_version as package_version +from google.cloud.securitycenter_v1.types import ( + bigquery_export, + effective_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -36,8 +40,11 @@ from google.cloud.securitycenter_v1.types import ( organization_settings as gcs_organization_settings, ) +from google.cloud.securitycenter_v1.types import security_health_analytics_custom_module +from google.cloud.securitycenter_v1.types import ( + security_health_analytics_custom_module as gcs_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import security_marks as gcs_security_marks -from google.cloud.securitycenter_v1.types import bigquery_export 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 @@ -148,6 +155,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.create_security_health_analytics_custom_module: gapic_v1.method.wrap_method( + self.create_security_health_analytics_custom_module, + default_timeout=60.0, + client_info=client_info, + ), self.create_source: gapic_v1.method.wrap_method( self.create_source, default_timeout=60.0, @@ -178,6 +190,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.delete_security_health_analytics_custom_module: gapic_v1.method.wrap_method( + self.delete_security_health_analytics_custom_module, + default_timeout=60.0, + client_info=client_info, + ), self.get_big_query_export: gapic_v1.method.wrap_method( self.get_big_query_export, default_timeout=None, @@ -233,6 +250,36 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.get_effective_security_health_analytics_custom_module: gapic_v1.method.wrap_method( + self.get_effective_security_health_analytics_custom_module, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.get_security_health_analytics_custom_module: gapic_v1.method.wrap_method( + self.get_security_health_analytics_custom_module, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), self.get_source: gapic_v1.method.wrap_method( self.get_source, default_retry=retries.Retry( @@ -293,6 +340,21 @@ def _prep_wrapped_messages(self, client_info): default_timeout=480.0, client_info=client_info, ), + self.list_descendant_security_health_analytics_custom_modules: gapic_v1.method.wrap_method( + self.list_descendant_security_health_analytics_custom_modules, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), self.list_findings: gapic_v1.method.wrap_method( self.list_findings, default_retry=retries.Retry( @@ -328,6 +390,36 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.list_effective_security_health_analytics_custom_modules: gapic_v1.method.wrap_method( + self.list_effective_security_health_analytics_custom_modules, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.list_security_health_analytics_custom_modules: gapic_v1.method.wrap_method( + self.list_security_health_analytics_custom_modules, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), self.list_sources: gapic_v1.method.wrap_method( self.list_sources, default_retry=retries.Retry( @@ -403,6 +495,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.update_security_health_analytics_custom_module: gapic_v1.method.wrap_method( + self.update_security_health_analytics_custom_module, + default_timeout=60.0, + client_info=client_info, + ), self.update_source: gapic_v1.method.wrap_method( self.update_source, default_timeout=60.0, @@ -458,6 +555,20 @@ def bulk_mute_findings( ]: raise NotImplementedError() + @property + def create_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest], + Union[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + Awaitable[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ], + ], + ]: + raise NotImplementedError() + @property def create_source( self, @@ -515,6 +626,15 @@ def delete_notification_config( ]: raise NotImplementedError() + @property + def delete_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], + ]: + raise NotImplementedError() + @property def get_big_query_export( self, @@ -568,6 +688,34 @@ def get_organization_settings( ]: raise NotImplementedError() + @property + def get_effective_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest], + Union[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, + Awaitable[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule + ], + ], + ]: + raise NotImplementedError() + + @property + def get_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest], + Union[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + Awaitable[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ], + ], + ]: + raise NotImplementedError() + @property def get_source( self, @@ -613,6 +761,22 @@ def list_assets( ]: raise NotImplementedError() + @property + def list_descendant_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [ + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest + ], + Union[ + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse, + Awaitable[ + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse + ], + ], + ]: + raise NotImplementedError() + @property def list_findings( self, @@ -649,6 +813,36 @@ def list_notification_configs( ]: raise NotImplementedError() + @property + def list_effective_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest + ], + Union[ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse, + Awaitable[ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse + ], + ], + ]: + raise NotImplementedError() + + @property + def list_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest], + Union[ + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse, + Awaitable[ + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse + ], + ], + ]: + raise NotImplementedError() + @property def list_sources( self, @@ -763,6 +957,20 @@ def update_organization_settings( ]: raise NotImplementedError() + @property + def update_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest], + Union[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + Awaitable[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ], + ], + ]: + raise NotImplementedError() + @property def update_source( self, diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py index 45cd7a02d3eb..dd20ebcf25a3 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py @@ -26,6 +26,10 @@ from google.protobuf import empty_pb2 # type: ignore import grpc # type: ignore +from google.cloud.securitycenter_v1.types import ( + bigquery_export, + effective_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -33,8 +37,11 @@ from google.cloud.securitycenter_v1.types import ( organization_settings as gcs_organization_settings, ) +from google.cloud.securitycenter_v1.types import security_health_analytics_custom_module +from google.cloud.securitycenter_v1.types import ( + security_health_analytics_custom_module as gcs_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import security_marks as gcs_security_marks -from google.cloud.securitycenter_v1.types import bigquery_export 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 @@ -295,6 +302,43 @@ def bulk_mute_findings( ) return self._stubs["bulk_mute_findings"] + @property + def create_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest], + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ]: + r"""Return a callable for the create security health + analytics custom module method over gRPC. + + Creates a resident + SecurityHealthAnalyticsCustomModule at the scope of the + given CRM parent, and also creates inherited + SecurityHealthAnalyticsCustomModules for all CRM + descendants of the given parent. These modules are + enabled by default. + + Returns: + Callable[[~.CreateSecurityHealthAnalyticsCustomModuleRequest], + ~.SecurityHealthAnalyticsCustomModule]: + 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_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "create_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/CreateSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.deserialize, + ) + return self._stubs["create_security_health_analytics_custom_module"] + @property def create_source( self, @@ -459,6 +503,41 @@ def delete_notification_config( ) return self._stubs["delete_notification_config"] + @property + def delete_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest], + empty_pb2.Empty, + ]: + r"""Return a callable for the delete security health + analytics custom module method over gRPC. + + Deletes the specified + SecurityHealthAnalyticsCustomModule and all of its + descendants in the CRM hierarchy. This method is only + supported for resident custom modules. + + Returns: + Callable[[~.DeleteSecurityHealthAnalyticsCustomModuleRequest], + ~.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_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "delete_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/DeleteSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_security_health_analytics_custom_module"] + @property def get_big_query_export( self, @@ -601,6 +680,71 @@ def get_organization_settings( ) return self._stubs["get_organization_settings"] + @property + def get_effective_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest], + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, + ]: + r"""Return a callable for the get effective security health + analytics custom module method over gRPC. + + Retrieves an + EffectiveSecurityHealthAnalyticsCustomModule. + + Returns: + Callable[[~.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest], + ~.EffectiveSecurityHealthAnalyticsCustomModule]: + 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_effective_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "get_effective_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/GetEffectiveSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.deserialize, + ) + return self._stubs["get_effective_security_health_analytics_custom_module"] + + @property + def get_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest], + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ]: + r"""Return a callable for the get security health analytics + custom module method over gRPC. + + Retrieves a SecurityHealthAnalyticsCustomModule. + + Returns: + Callable[[~.GetSecurityHealthAnalyticsCustomModuleRequest], + ~.SecurityHealthAnalyticsCustomModule]: + 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_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "get_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/GetSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.deserialize, + ) + return self._stubs["get_security_health_analytics_custom_module"] + @property def get_source( self, @@ -721,6 +865,45 @@ def list_assets( ) return self._stubs["list_assets"] + @property + def list_descendant_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [ + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest + ], + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse, + ]: + r"""Return a callable for the list descendant security + health analytics custom modules method over gRPC. + + Returns a list of all resident + SecurityHealthAnalyticsCustomModules under the given CRM + parent and all of the parent’s CRM descendants. + + Returns: + Callable[[~.ListDescendantSecurityHealthAnalyticsCustomModulesRequest], + ~.ListDescendantSecurityHealthAnalyticsCustomModulesResponse]: + 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_descendant_security_health_analytics_custom_modules" + not in self._stubs + ): + self._stubs[ + "list_descendant_security_health_analytics_custom_modules" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/ListDescendantSecurityHealthAnalyticsCustomModules", + request_serializer=securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest.serialize, + response_deserializer=securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse.deserialize, + ) + return self._stubs["list_descendant_security_health_analytics_custom_modules"] + @property def list_findings( self, @@ -811,6 +994,80 @@ def list_notification_configs( ) return self._stubs["list_notification_configs"] + @property + def list_effective_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest + ], + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse, + ]: + r"""Return a callable for the list effective security health + analytics custom modules method over gRPC. + + Returns a list of all + EffectiveSecurityHealthAnalyticsCustomModules for the + given parent. This includes resident modules defined at + the scope of the parent, and inherited modules, + inherited from CRM ancestors. + + Returns: + Callable[[~.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest], + ~.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse]: + 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_effective_security_health_analytics_custom_modules" not in self._stubs: + self._stubs[ + "list_effective_security_health_analytics_custom_modules" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/ListEffectiveSecurityHealthAnalyticsCustomModules", + request_serializer=securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest.serialize, + response_deserializer=securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse.deserialize, + ) + return self._stubs["list_effective_security_health_analytics_custom_modules"] + + @property + def list_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest], + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse, + ]: + r"""Return a callable for the list security health analytics + custom modules method over gRPC. + + Returns a list of all + SecurityHealthAnalyticsCustomModules for the given + parent. This includes resident modules defined at the + scope of the parent, and inherited modules, inherited + from CRM ancestors. + + Returns: + Callable[[~.ListSecurityHealthAnalyticsCustomModulesRequest], + ~.ListSecurityHealthAnalyticsCustomModulesResponse]: + 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_security_health_analytics_custom_modules" not in self._stubs: + self._stubs[ + "list_security_health_analytics_custom_modules" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/ListSecurityHealthAnalyticsCustomModules", + request_serializer=securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest.serialize, + response_deserializer=securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse.deserialize, + ) + return self._stubs["list_security_health_analytics_custom_modules"] + @property def list_sources( self, @@ -1125,6 +1382,44 @@ def update_organization_settings( ) return self._stubs["update_organization_settings"] + @property + def update_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest], + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ]: + r"""Return a callable for the update security health + analytics custom module method over gRPC. + + Updates the SecurityHealthAnalyticsCustomModule under + the given name based on the given update mask. Updating + the enablement state is supported on both resident and + inherited modules (though resident modules cannot have + an enablement state of “inherited”). Updating the + display name and custom config of a module is supported + on resident modules only. + + Returns: + Callable[[~.UpdateSecurityHealthAnalyticsCustomModuleRequest], + ~.SecurityHealthAnalyticsCustomModule]: + 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_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "update_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/UpdateSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.deserialize, + ) + return self._stubs["update_security_health_analytics_custom_module"] + @property def update_source( self, diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py index 720a77dfc5d3..410c1c984be4 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py @@ -26,6 +26,10 @@ import grpc # type: ignore from grpc.experimental import aio # type: ignore +from google.cloud.securitycenter_v1.types import ( + bigquery_export, + effective_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -33,8 +37,11 @@ from google.cloud.securitycenter_v1.types import ( organization_settings as gcs_organization_settings, ) +from google.cloud.securitycenter_v1.types import security_health_analytics_custom_module +from google.cloud.securitycenter_v1.types import ( + security_health_analytics_custom_module as gcs_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import security_marks as gcs_security_marks -from google.cloud.securitycenter_v1.types import bigquery_export 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 @@ -301,6 +308,45 @@ def bulk_mute_findings( ) return self._stubs["bulk_mute_findings"] + @property + def create_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ], + ]: + r"""Return a callable for the create security health + analytics custom module method over gRPC. + + Creates a resident + SecurityHealthAnalyticsCustomModule at the scope of the + given CRM parent, and also creates inherited + SecurityHealthAnalyticsCustomModules for all CRM + descendants of the given parent. These modules are + enabled by default. + + Returns: + Callable[[~.CreateSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[~.SecurityHealthAnalyticsCustomModule]]: + 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_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "create_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/CreateSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.deserialize, + ) + return self._stubs["create_security_health_analytics_custom_module"] + @property def create_source( self, @@ -473,6 +519,41 @@ def delete_notification_config( ) return self._stubs["delete_notification_config"] + @property + def delete_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[empty_pb2.Empty], + ]: + r"""Return a callable for the delete security health + analytics custom module method over gRPC. + + Deletes the specified + SecurityHealthAnalyticsCustomModule and all of its + descendants in the CRM hierarchy. This method is only + supported for resident custom modules. + + Returns: + Callable[[~.DeleteSecurityHealthAnalyticsCustomModuleRequest], + 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_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "delete_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/DeleteSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_security_health_analytics_custom_module"] + @property def get_big_query_export( self, @@ -615,6 +696,75 @@ def get_organization_settings( ) return self._stubs["get_organization_settings"] + @property + def get_effective_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule + ], + ]: + r"""Return a callable for the get effective security health + analytics custom module method over gRPC. + + Retrieves an + EffectiveSecurityHealthAnalyticsCustomModule. + + Returns: + Callable[[~.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[~.EffectiveSecurityHealthAnalyticsCustomModule]]: + 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_effective_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "get_effective_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/GetEffectiveSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.deserialize, + ) + return self._stubs["get_effective_security_health_analytics_custom_module"] + + @property + def get_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ], + ]: + r"""Return a callable for the get security health analytics + custom module method over gRPC. + + Retrieves a SecurityHealthAnalyticsCustomModule. + + Returns: + Callable[[~.GetSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[~.SecurityHealthAnalyticsCustomModule]]: + 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_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "get_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/GetSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.deserialize, + ) + return self._stubs["get_security_health_analytics_custom_module"] + @property def get_source( self, @@ -735,6 +885,47 @@ def list_assets( ) return self._stubs["list_assets"] + @property + def list_descendant_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [ + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest + ], + Awaitable[ + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse + ], + ]: + r"""Return a callable for the list descendant security + health analytics custom modules method over gRPC. + + Returns a list of all resident + SecurityHealthAnalyticsCustomModules under the given CRM + parent and all of the parent’s CRM descendants. + + Returns: + Callable[[~.ListDescendantSecurityHealthAnalyticsCustomModulesRequest], + Awaitable[~.ListDescendantSecurityHealthAnalyticsCustomModulesResponse]]: + 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_descendant_security_health_analytics_custom_modules" + not in self._stubs + ): + self._stubs[ + "list_descendant_security_health_analytics_custom_modules" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/ListDescendantSecurityHealthAnalyticsCustomModules", + request_serializer=securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest.serialize, + response_deserializer=securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse.deserialize, + ) + return self._stubs["list_descendant_security_health_analytics_custom_modules"] + @property def list_findings( self, @@ -825,6 +1016,84 @@ def list_notification_configs( ) return self._stubs["list_notification_configs"] + @property + def list_effective_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest + ], + Awaitable[ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse + ], + ]: + r"""Return a callable for the list effective security health + analytics custom modules method over gRPC. + + Returns a list of all + EffectiveSecurityHealthAnalyticsCustomModules for the + given parent. This includes resident modules defined at + the scope of the parent, and inherited modules, + inherited from CRM ancestors. + + Returns: + Callable[[~.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest], + Awaitable[~.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse]]: + 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_effective_security_health_analytics_custom_modules" not in self._stubs: + self._stubs[ + "list_effective_security_health_analytics_custom_modules" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/ListEffectiveSecurityHealthAnalyticsCustomModules", + request_serializer=securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest.serialize, + response_deserializer=securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse.deserialize, + ) + return self._stubs["list_effective_security_health_analytics_custom_modules"] + + @property + def list_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest], + Awaitable[ + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse + ], + ]: + r"""Return a callable for the list security health analytics + custom modules method over gRPC. + + Returns a list of all + SecurityHealthAnalyticsCustomModules for the given + parent. This includes resident modules defined at the + scope of the parent, and inherited modules, inherited + from CRM ancestors. + + Returns: + Callable[[~.ListSecurityHealthAnalyticsCustomModulesRequest], + Awaitable[~.ListSecurityHealthAnalyticsCustomModulesResponse]]: + 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_security_health_analytics_custom_modules" not in self._stubs: + self._stubs[ + "list_security_health_analytics_custom_modules" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/ListSecurityHealthAnalyticsCustomModules", + request_serializer=securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest.serialize, + response_deserializer=securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse.deserialize, + ) + return self._stubs["list_security_health_analytics_custom_modules"] + @property def list_sources( self, @@ -1145,6 +1414,46 @@ def update_organization_settings( ) return self._stubs["update_organization_settings"] + @property + def update_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ], + ]: + r"""Return a callable for the update security health + analytics custom module method over gRPC. + + Updates the SecurityHealthAnalyticsCustomModule under + the given name based on the given update mask. Updating + the enablement state is supported on both resident and + inherited modules (though resident modules cannot have + an enablement state of “inherited”). Updating the + display name and custom config of a module is supported + on resident modules only. + + Returns: + Callable[[~.UpdateSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[~.SecurityHealthAnalyticsCustomModule]]: + 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_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "update_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/UpdateSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.deserialize, + ) + return self._stubs["update_security_health_analytics_custom_module"] + @property def update_source( self, diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/rest.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/rest.py index cb199735b7c5..5a1ed8f030f9 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/rest.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/services/security_center/transports/rest.py @@ -48,6 +48,10 @@ from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.cloud.securitycenter_v1.types import ( + bigquery_export, + effective_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -55,8 +59,11 @@ from google.cloud.securitycenter_v1.types import ( organization_settings as gcs_organization_settings, ) +from google.cloud.securitycenter_v1.types import security_health_analytics_custom_module +from google.cloud.securitycenter_v1.types import ( + security_health_analytics_custom_module as gcs_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import security_marks as gcs_security_marks -from google.cloud.securitycenter_v1.types import bigquery_export 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 @@ -132,6 +139,14 @@ def post_create_notification_config(self, response): logging.log(f"Received response: {response}") return response + def pre_create_security_health_analytics_custom_module(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_security_health_analytics_custom_module(self, response): + logging.log(f"Received response: {response}") + return response + def pre_create_source(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -152,6 +167,10 @@ def pre_delete_notification_config(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata + def pre_delete_security_health_analytics_custom_module(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + def pre_get_big_query_export(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -160,6 +179,14 @@ def post_get_big_query_export(self, response): logging.log(f"Received response: {response}") return response + def pre_get_effective_security_health_analytics_custom_module(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_effective_security_health_analytics_custom_module(self, response): + logging.log(f"Received response: {response}") + return response + def pre_get_iam_policy(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -192,6 +219,14 @@ def post_get_organization_settings(self, response): logging.log(f"Received response: {response}") return response + def pre_get_security_health_analytics_custom_module(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_security_health_analytics_custom_module(self, response): + logging.log(f"Received response: {response}") + return response + def pre_get_source(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -232,6 +267,22 @@ def post_list_big_query_exports(self, response): logging.log(f"Received response: {response}") return response + def pre_list_descendant_security_health_analytics_custom_modules(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_descendant_security_health_analytics_custom_modules(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_effective_security_health_analytics_custom_modules(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_effective_security_health_analytics_custom_modules(self, response): + logging.log(f"Received response: {response}") + return response + def pre_list_findings(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -256,6 +307,14 @@ def post_list_notification_configs(self, response): logging.log(f"Received response: {response}") return response + def pre_list_security_health_analytics_custom_modules(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_security_health_analytics_custom_modules(self, response): + logging.log(f"Received response: {response}") + return response + def pre_list_sources(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -352,6 +411,14 @@ def post_update_organization_settings(self, response): logging.log(f"Received response: {response}") return response + def pre_update_security_health_analytics_custom_module(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_security_health_analytics_custom_module(self, response): + logging.log(f"Received response: {response}") + return response + def pre_update_security_marks(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -496,6 +563,33 @@ def post_create_notification_config( """ return response + def pre_create_security_health_analytics_custom_module( + self, + request: securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, + Sequence[Tuple[str, str]], + ]: + """Pre-rpc interceptor for create_security_health_analytics_custom_module + + Override in a subclass to manipulate the request or metadata + before they are sent to the SecurityCenter server. + """ + return request, metadata + + def post_create_security_health_analytics_custom_module( + self, + response: gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) -> gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + """Post-rpc interceptor for create_security_health_analytics_custom_module + + Override in a subclass to manipulate the response + after it is returned by the SecurityCenter server but before + it is returned to user code. + """ + return response + def pre_create_source( self, request: securitycenter_service.CreateSourceRequest, @@ -560,6 +654,21 @@ def pre_delete_notification_config( """ return request, metadata + def pre_delete_security_health_analytics_custom_module( + self, + request: securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, + Sequence[Tuple[str, str]], + ]: + """Pre-rpc interceptor for delete_security_health_analytics_custom_module + + Override in a subclass to manipulate the request or metadata + before they are sent to the SecurityCenter server. + """ + return request, metadata + def pre_get_big_query_export( self, request: securitycenter_service.GetBigQueryExportRequest, @@ -585,6 +694,33 @@ def post_get_big_query_export( """ return response + def pre_get_effective_security_health_analytics_custom_module( + self, + request: securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, + Sequence[Tuple[str, str]], + ]: + """Pre-rpc interceptor for get_effective_security_health_analytics_custom_module + + Override in a subclass to manipulate the request or metadata + before they are sent to the SecurityCenter server. + """ + return request, metadata + + def post_get_effective_security_health_analytics_custom_module( + self, + response: effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, + ) -> effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule: + """Post-rpc interceptor for get_effective_security_health_analytics_custom_module + + Override in a subclass to manipulate the response + after it is returned by the SecurityCenter server but before + it is returned to user code. + """ + return response + def pre_get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest, @@ -679,6 +815,33 @@ def post_get_organization_settings( """ return response + def pre_get_security_health_analytics_custom_module( + self, + request: securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, + Sequence[Tuple[str, str]], + ]: + """Pre-rpc interceptor for get_security_health_analytics_custom_module + + Override in a subclass to manipulate the request or metadata + before they are sent to the SecurityCenter server. + """ + return request, metadata + + def post_get_security_health_analytics_custom_module( + self, + response: security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) -> security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + """Post-rpc interceptor for get_security_health_analytics_custom_module + + Override in a subclass to manipulate the response + after it is returned by the SecurityCenter server but before + it is returned to user code. + """ + return response + def pre_get_source( self, request: securitycenter_service.GetSourceRequest, @@ -794,6 +957,60 @@ def post_list_big_query_exports( """ return response + def pre_list_descendant_security_health_analytics_custom_modules( + self, + request: securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + Sequence[Tuple[str, str]], + ]: + """Pre-rpc interceptor for list_descendant_security_health_analytics_custom_modules + + Override in a subclass to manipulate the request or metadata + before they are sent to the SecurityCenter server. + """ + return request, metadata + + def post_list_descendant_security_health_analytics_custom_modules( + self, + response: securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse, + ) -> securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse: + """Post-rpc interceptor for list_descendant_security_health_analytics_custom_modules + + Override in a subclass to manipulate the response + after it is returned by the SecurityCenter server but before + it is returned to user code. + """ + return response + + def pre_list_effective_security_health_analytics_custom_modules( + self, + request: securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + Sequence[Tuple[str, str]], + ]: + """Pre-rpc interceptor for list_effective_security_health_analytics_custom_modules + + Override in a subclass to manipulate the request or metadata + before they are sent to the SecurityCenter server. + """ + return request, metadata + + def post_list_effective_security_health_analytics_custom_modules( + self, + response: securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse, + ) -> securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse: + """Post-rpc interceptor for list_effective_security_health_analytics_custom_modules + + Override in a subclass to manipulate the response + after it is returned by the SecurityCenter server but before + it is returned to user code. + """ + return response + def pre_list_findings( self, request: securitycenter_service.ListFindingsRequest, @@ -867,6 +1084,33 @@ def post_list_notification_configs( """ return response + def pre_list_security_health_analytics_custom_modules( + self, + request: securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, + Sequence[Tuple[str, str]], + ]: + """Pre-rpc interceptor for list_security_health_analytics_custom_modules + + Override in a subclass to manipulate the request or metadata + before they are sent to the SecurityCenter server. + """ + return request, metadata + + def post_list_security_health_analytics_custom_modules( + self, + response: securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse, + ) -> securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse: + """Post-rpc interceptor for list_security_health_analytics_custom_modules + + Override in a subclass to manipulate the response + after it is returned by the SecurityCenter server but before + it is returned to user code. + """ + return response + def pre_list_sources( self, request: securitycenter_service.ListSourcesRequest, @@ -1151,6 +1395,33 @@ def post_update_organization_settings( """ return response + def pre_update_security_health_analytics_custom_module( + self, + request: securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, + Sequence[Tuple[str, str]], + ]: + """Pre-rpc interceptor for update_security_health_analytics_custom_module + + Override in a subclass to manipulate the request or metadata + before they are sent to the SecurityCenter server. + """ + return request, metadata + + def post_update_security_health_analytics_custom_module( + self, + response: gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) -> gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + """Post-rpc interceptor for update_security_health_analytics_custom_module + + Override in a subclass to manipulate the response + after it is returned by the SecurityCenter server but before + it is returned to user code. + """ + return response + def pre_update_security_marks( self, request: securitycenter_service.UpdateSecurityMarksRequest, @@ -2001,9 +2272,9 @@ def __call__( resp = self._interceptor.post_create_notification_config(resp) return resp - class _CreateSource(SecurityCenterRestStub): + class _CreateSecurityHealthAnalyticsCustomModule(SecurityCenterRestStub): def __hash__(self): - return hash("CreateSource") + return hash("CreateSecurityHealthAnalyticsCustomModule") __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} @@ -2017,44 +2288,66 @@ def _get_unset_required_fields(cls, message_dict): def __call__( self, - request: securitycenter_service.CreateSourceRequest, + request: securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> gcs_source.Source: - r"""Call the create source method over HTTP. + ) -> gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + r"""Call the create security health + analytics custom module method over HTTP. - Args: - request (~.securitycenter_service.CreateSourceRequest): - The request object. Request message for creating a - source. - 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. + Args: + request (~.securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest): + The request object. Request message for creating security + health analytics custom modules. + 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: - ~.gcs_source.Source: - Security Command Center finding - source. A finding source is an entity or - a mechanism that can produce a finding. - A source is like a container of findings - that come from the same scanner, logger, - monitor, and other tools. + Returns: + ~.gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + Represents an instance of a Security + Health Analytics custom module, + including its full module name, display + name, enablement state, and last updated + time. You can create a custom module at + the organization, folder, or project + level. Custom modules that you create at + the organization or folder level are + inherited by the child folders and + projects. """ http_options: List[Dict[str, str]] = [ { "method": "post", - "uri": "/v1/{parent=organizations/*}/sources", - "body": "source", + "uri": "/v1/{parent=organizations/*/securityHealthAnalyticsSettings}/customModules", + "body": "security_health_analytics_custom_module", + }, + { + "method": "post", + "uri": "/v1/{parent=folders/*/securityHealthAnalyticsSettings}/customModules", + "body": "security_health_analytics_custom_module", + }, + { + "method": "post", + "uri": "/v1/{parent=projects/*/securityHealthAnalyticsSettings}/customModules", + "body": "security_health_analytics_custom_module", }, ] - request, metadata = self._interceptor.pre_create_source(request, metadata) - pb_request = securitycenter_service.CreateSourceRequest.pb(request) + ( + request, + metadata, + ) = self._interceptor.pre_create_security_health_analytics_custom_module( + request, metadata + ) + pb_request = securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest.pb( + request + ) transcoded_request = path_template.transcode(http_options, pb_request) # Jsonify the request body @@ -2096,16 +2389,24 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = gcs_source.Source() - pb_resp = gcs_source.Source.pb(resp) + resp = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + pb_resp = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( + resp + ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_source(resp) + resp = ( + self._interceptor.post_create_security_health_analytics_custom_module( + resp + ) + ) return resp - class _DeleteBigQueryExport(SecurityCenterRestStub): + class _CreateSource(SecurityCenterRestStub): def __hash__(self): - return hash("DeleteBigQueryExport") + return hash("CreateSource") __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} @@ -2119,18 +2420,120 @@ def _get_unset_required_fields(cls, message_dict): def __call__( self, - request: securitycenter_service.DeleteBigQueryExportRequest, + request: securitycenter_service.CreateSourceRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), - ): - r"""Call the delete big query export method over HTTP. + ) -> gcs_source.Source: + r"""Call the create source method over HTTP. Args: - request (~.securitycenter_service.DeleteBigQueryExportRequest): - The request object. Request message for deleting a - BigQuery export. + request (~.securitycenter_service.CreateSourceRequest): + The request object. Request message for creating a + source. + 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: + ~.gcs_source.Source: + Security Command Center finding + source. A finding source is an entity or + a mechanism that can produce a finding. + A source is like a container of findings + that come from the same scanner, logger, + monitor, and other tools. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{parent=organizations/*}/sources", + "body": "source", + }, + ] + request, metadata = self._interceptor.pre_create_source(request, metadata) + pb_request = securitycenter_service.CreateSourceRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = gcs_source.Source() + pb_resp = gcs_source.Source.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_source(resp) + return resp + + class _DeleteBigQueryExport(SecurityCenterRestStub): + def __hash__(self): + return hash("DeleteBigQueryExport") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: securitycenter_service.DeleteBigQueryExportRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ): + r"""Call the delete big query export method over HTTP. + + Args: + request (~.securitycenter_service.DeleteBigQueryExportRequest): + The request object. Request message for deleting a + BigQuery export. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2361,6 +2764,97 @@ def __call__( if response.status_code >= 400: raise core_exceptions.from_http_response(response) + class _DeleteSecurityHealthAnalyticsCustomModule(SecurityCenterRestStub): + def __hash__(self): + return hash("DeleteSecurityHealthAnalyticsCustomModule") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ): + r"""Call the delete security health + analytics custom module method over HTTP. + + Args: + request (~.securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest): + The request object. Request message for deleting security + health analytics custom modules. + 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. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "delete", + "uri": "/v1/{name=organizations/*/securityHealthAnalyticsSettings/customModules/*}", + }, + { + "method": "delete", + "uri": "/v1/{name=folders/*/securityHealthAnalyticsSettings/customModules/*}", + }, + { + "method": "delete", + "uri": "/v1/{name=projects/*/securityHealthAnalyticsSettings/customModules/*}", + }, + ] + ( + request, + metadata, + ) = self._interceptor.pre_delete_security_health_analytics_custom_module( + request, metadata + ) + pb_request = securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest.pb( + request + ) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + class _GetBigQueryExport(SecurityCenterRestStub): def __hash__(self): return hash("GetBigQueryExport") @@ -2460,6 +2954,130 @@ def __call__( resp = self._interceptor.post_get_big_query_export(resp) return resp + class _GetEffectiveSecurityHealthAnalyticsCustomModule(SecurityCenterRestStub): + def __hash__(self): + return hash("GetEffectiveSecurityHealthAnalyticsCustomModule") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule: + r"""Call the get effective security + health analytics custom module method over HTTP. + + Args: + request (~.securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest): + The request object. Request message for getting effective + security health analytics custom + modules. + 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: + ~.effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule: + An EffectiveSecurityHealthAnalyticsCustomModule is the + representation of a Security Health Analytics custom + module at a specified level of the resource hierarchy: + organization, folder, or project. If a custom module is + inherited from a parent organization or folder, the + value of the ``enablementState`` property in + EffectiveSecurityHealthAnalyticsCustomModule is set to + the value that is effective in the parent, instead of + ``INHERITED``. For example, if the module is enabled in + a parent organization or folder, the effective + enablement_state for the module in all child folders or + projects is also ``enabled``. + EffectiveSecurityHealthAnalyticsCustomModule is + read-only. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=organizations/*/securityHealthAnalyticsSettings/effectiveCustomModules/*}", + }, + { + "method": "get", + "uri": "/v1/{name=folders/*/securityHealthAnalyticsSettings/effectiveCustomModules/*}", + }, + { + "method": "get", + "uri": "/v1/{name=projects/*/securityHealthAnalyticsSettings/effectiveCustomModules/*}", + }, + ] + ( + request, + metadata, + ) = self._interceptor.pre_get_effective_security_health_analytics_custom_module( + request, metadata + ) + pb_request = securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest.pb( + request + ) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = ( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule() + ) + pb_resp = effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.pb( + resp + ) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_effective_security_health_analytics_custom_module( + resp + ) + return resp + class _GetIamPolicy(SecurityCenterRestStub): def __hash__(self): return hash("GetIamPolicy") @@ -2753,9 +3371,112 @@ def __call__( r"""Call the get notification config method over HTTP. Args: - request (~.securitycenter_service.GetNotificationConfigRequest): - The request object. Request message for getting a - notification config. + request (~.securitycenter_service.GetNotificationConfigRequest): + The request object. Request message for getting a + notification config. + 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: + ~.notification_config.NotificationConfig: + Cloud Security Command Center (Cloud + SCC) notification configs. + A notification config is a Cloud SCC + resource that contains the configuration + to send notifications for create/update + events of findings, assets and etc. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=organizations/*/notificationConfigs/*}", + }, + { + "method": "get", + "uri": "/v1/{name=folders/*/notificationConfigs/*}", + }, + { + "method": "get", + "uri": "/v1/{name=projects/*/notificationConfigs/*}", + }, + ] + request, metadata = self._interceptor.pre_get_notification_config( + request, metadata + ) + pb_request = securitycenter_service.GetNotificationConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = notification_config.NotificationConfig() + pb_resp = notification_config.NotificationConfig.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_notification_config(resp) + return resp + + class _GetOrganizationSettings(SecurityCenterRestStub): + def __hash__(self): + return hash("GetOrganizationSettings") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: securitycenter_service.GetOrganizationSettingsRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> organization_settings.OrganizationSettings: + r"""Call the get organization settings method over HTTP. + + Args: + request (~.securitycenter_service.GetOrganizationSettingsRequest): + The request object. Request message for getting + organization settings. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -2763,34 +3484,25 @@ def __call__( sent along with the request as metadata. Returns: - ~.notification_config.NotificationConfig: - Cloud Security Command Center (Cloud - SCC) notification configs. - A notification config is a Cloud SCC - resource that contains the configuration - to send notifications for create/update - events of findings, assets and etc. + ~.organization_settings.OrganizationSettings: + User specified settings that are + attached to the Security Command Center + organization. """ http_options: List[Dict[str, str]] = [ { "method": "get", - "uri": "/v1/{name=organizations/*/notificationConfigs/*}", - }, - { - "method": "get", - "uri": "/v1/{name=folders/*/notificationConfigs/*}", - }, - { - "method": "get", - "uri": "/v1/{name=projects/*/notificationConfigs/*}", + "uri": "/v1/{name=organizations/*/organizationSettings}", }, ] - request, metadata = self._interceptor.pre_get_notification_config( + request, metadata = self._interceptor.pre_get_organization_settings( request, metadata ) - pb_request = securitycenter_service.GetNotificationConfigRequest.pb(request) + pb_request = securitycenter_service.GetOrganizationSettingsRequest.pb( + request + ) transcoded_request = path_template.transcode(http_options, pb_request) uri = transcoded_request["uri"] @@ -2824,16 +3536,16 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = notification_config.NotificationConfig() - pb_resp = notification_config.NotificationConfig.pb(resp) + resp = organization_settings.OrganizationSettings() + pb_resp = organization_settings.OrganizationSettings.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_notification_config(resp) + resp = self._interceptor.post_get_organization_settings(resp) return resp - class _GetOrganizationSettings(SecurityCenterRestStub): + class _GetSecurityHealthAnalyticsCustomModule(SecurityCenterRestStub): def __hash__(self): - return hash("GetOrganizationSettings") + return hash("GetSecurityHealthAnalyticsCustomModule") __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} @@ -2847,43 +3559,64 @@ def _get_unset_required_fields(cls, message_dict): def __call__( self, - request: securitycenter_service.GetOrganizationSettingsRequest, + request: securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> organization_settings.OrganizationSettings: - r"""Call the get organization settings method over HTTP. + ) -> security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + r"""Call the get security health + analytics custom module method over HTTP. - Args: - request (~.securitycenter_service.GetOrganizationSettingsRequest): - The request object. Request message for getting - organization settings. - 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. + Args: + request (~.securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest): + The request object. Request message for getting security + health analytics custom modules. + 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: - ~.organization_settings.OrganizationSettings: - User specified settings that are - attached to the Security Command Center - organization. + Returns: + ~.security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + Represents an instance of a Security + Health Analytics custom module, + including its full module name, display + name, enablement state, and last updated + time. You can create a custom module at + the organization, folder, or project + level. Custom modules that you create at + the organization or folder level are + inherited by the child folders and + projects. """ http_options: List[Dict[str, str]] = [ { "method": "get", - "uri": "/v1/{name=organizations/*/organizationSettings}", + "uri": "/v1/{name=organizations/*/securityHealthAnalyticsSettings/customModules/*}", + }, + { + "method": "get", + "uri": "/v1/{name=folders/*/securityHealthAnalyticsSettings/customModules/*}", + }, + { + "method": "get", + "uri": "/v1/{name=projects/*/securityHealthAnalyticsSettings/customModules/*}", }, ] - request, metadata = self._interceptor.pre_get_organization_settings( + ( + request, + metadata, + ) = self._interceptor.pre_get_security_health_analytics_custom_module( request, metadata ) - pb_request = securitycenter_service.GetOrganizationSettingsRequest.pb( - request + pb_request = ( + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest.pb( + request + ) ) transcoded_request = path_template.transcode(http_options, pb_request) @@ -2918,11 +3651,17 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = organization_settings.OrganizationSettings() - pb_resp = organization_settings.OrganizationSettings.pb(resp) + resp = ( + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + pb_resp = security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( + resp + ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_organization_settings(resp) + resp = self._interceptor.post_get_security_health_analytics_custom_module( + resp + ) return resp class _GetSource(SecurityCenterRestStub): @@ -3362,31 +4101,251 @@ def __call__( metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. - Returns: - ~.securitycenter_service.ListBigQueryExportsResponse: - Response message for listing BigQuery - exports. + Returns: + ~.securitycenter_service.ListBigQueryExportsResponse: + Response message for listing BigQuery + exports. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=organizations/*}/bigQueryExports", + }, + { + "method": "get", + "uri": "/v1/{parent=folders/*}/bigQueryExports", + }, + { + "method": "get", + "uri": "/v1/{parent=projects/*}/bigQueryExports", + }, + ] + request, metadata = self._interceptor.pre_list_big_query_exports( + request, metadata + ) + pb_request = securitycenter_service.ListBigQueryExportsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = securitycenter_service.ListBigQueryExportsResponse() + pb_resp = securitycenter_service.ListBigQueryExportsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_big_query_exports(resp) + return resp + + class _ListDescendantSecurityHealthAnalyticsCustomModules(SecurityCenterRestStub): + def __hash__(self): + return hash("ListDescendantSecurityHealthAnalyticsCustomModules") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse: + r"""Call the list descendant security + health analytics custom modules method over HTTP. + + Args: + request (~.securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest): + The request object. Request message for listing + descendant security health analytics + custom modules. + 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: + ~.securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse: + Response message for listing + descendant security health analytics + custom modules. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=organizations/*/securityHealthAnalyticsSettings}/customModules:listDescendant", + }, + { + "method": "get", + "uri": "/v1/{parent=folders/*/securityHealthAnalyticsSettings}/customModules:listDescendant", + }, + { + "method": "get", + "uri": "/v1/{parent=projects/*/securityHealthAnalyticsSettings}/customModules:listDescendant", + }, + ] + ( + request, + metadata, + ) = self._interceptor.pre_list_descendant_security_health_analytics_custom_modules( + request, metadata + ) + pb_request = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest.pb( + request + ) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse() + ) + pb_resp = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse.pb( + resp + ) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_descendant_security_health_analytics_custom_modules( + resp + ) + return resp + + class _ListEffectiveSecurityHealthAnalyticsCustomModules(SecurityCenterRestStub): + def __hash__(self): + return hash("ListEffectiveSecurityHealthAnalyticsCustomModules") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse: + r"""Call the list effective security + health analytics custom modules method over HTTP. + + Args: + request (~.securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest): + The request object. Request message for listing effective + security health analytics custom + modules. + 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: + ~.securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse: + Response message for listing + effective security health analytics + custom modules. """ http_options: List[Dict[str, str]] = [ { "method": "get", - "uri": "/v1/{parent=organizations/*}/bigQueryExports", + "uri": "/v1/{parent=organizations/*/securityHealthAnalyticsSettings}/effectiveCustomModules", }, { "method": "get", - "uri": "/v1/{parent=folders/*}/bigQueryExports", + "uri": "/v1/{parent=folders/*/securityHealthAnalyticsSettings}/effectiveCustomModules", }, { "method": "get", - "uri": "/v1/{parent=projects/*}/bigQueryExports", + "uri": "/v1/{parent=projects/*/securityHealthAnalyticsSettings}/effectiveCustomModules", }, ] - request, metadata = self._interceptor.pre_list_big_query_exports( + ( + request, + metadata, + ) = self._interceptor.pre_list_effective_security_health_analytics_custom_modules( request, metadata ) - pb_request = securitycenter_service.ListBigQueryExportsRequest.pb(request) + pb_request = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest.pb( + request + ) transcoded_request = path_template.transcode(http_options, pb_request) uri = transcoded_request["uri"] @@ -3420,11 +4379,17 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = securitycenter_service.ListBigQueryExportsResponse() - pb_resp = securitycenter_service.ListBigQueryExportsResponse.pb(resp) + resp = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse() + ) + pb_resp = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse.pb( + resp + ) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_big_query_exports(resp) + resp = self._interceptor.post_list_effective_security_health_analytics_custom_modules( + resp + ) return resp class _ListFindings(SecurityCenterRestStub): @@ -3724,6 +4689,117 @@ def __call__( resp = self._interceptor.post_list_notification_configs(resp) return resp + class _ListSecurityHealthAnalyticsCustomModules(SecurityCenterRestStub): + def __hash__(self): + return hash("ListSecurityHealthAnalyticsCustomModules") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse: + r"""Call the list security health + analytics custom modules method over HTTP. + + Args: + request (~.securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest): + The request object. Request message for listing security + health analytics custom modules. + 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: + ~.securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse: + Response message for listing security + health analytics custom modules. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=organizations/*/securityHealthAnalyticsSettings}/customModules", + }, + { + "method": "get", + "uri": "/v1/{parent=folders/*/securityHealthAnalyticsSettings}/customModules", + }, + { + "method": "get", + "uri": "/v1/{parent=projects/*/securityHealthAnalyticsSettings}/customModules", + }, + ] + ( + request, + metadata, + ) = self._interceptor.pre_list_security_health_analytics_custom_modules( + request, metadata + ) + pb_request = securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest.pb( + request + ) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse() + ) + pb_resp = securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse.pb( + resp + ) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_security_health_analytics_custom_modules( + resp + ) + return resp + class _ListSources(SecurityCenterRestStub): def __hash__(self): return hash("ListSources") @@ -5083,6 +6159,138 @@ def __call__( resp = self._interceptor.post_update_organization_settings(resp) return resp + class _UpdateSecurityHealthAnalyticsCustomModule(SecurityCenterRestStub): + def __hash__(self): + return hash("UpdateSecurityHealthAnalyticsCustomModule") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + r"""Call the update security health + analytics custom module method over HTTP. + + Args: + request (~.securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest): + The request object. Request message for updating security + health analytics custom modules. + 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: + ~.gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule: + Represents an instance of a Security + Health Analytics custom module, + including its full module name, display + name, enablement state, and last updated + time. You can create a custom module at + the organization, folder, or project + level. Custom modules that you create at + the organization or folder level are + inherited by the child folders and + projects. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "patch", + "uri": "/v1/{security_health_analytics_custom_module.name=organizations/*/securityHealthAnalyticsSettings/customModules/*}", + "body": "security_health_analytics_custom_module", + }, + { + "method": "patch", + "uri": "/v1/{security_health_analytics_custom_module.name=folders/*/securityHealthAnalyticsSettings/customModules/*}", + "body": "security_health_analytics_custom_module", + }, + { + "method": "patch", + "uri": "/v1/{security_health_analytics_custom_module.name=projects/*/securityHealthAnalyticsSettings/customModules/*}", + "body": "security_health_analytics_custom_module", + }, + ] + ( + request, + metadata, + ) = self._interceptor.pre_update_security_health_analytics_custom_module( + request, metadata + ) + pb_request = securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest.pb( + request + ) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + pb_resp = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( + resp + ) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = ( + self._interceptor.post_update_security_health_analytics_custom_module( + resp + ) + ) + return resp + class _UpdateSecurityMarks(SecurityCenterRestStub): def __hash__(self): return hash("UpdateSecurityMarks") @@ -5366,6 +6574,17 @@ def create_notification_config( # In C++ this would require a dynamic_cast return self._CreateNotificationConfig(self._session, self._host, self._interceptor) # type: ignore + @property + def create_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest], + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateSecurityHealthAnalyticsCustomModule(self._session, self._host, self._interceptor) # type: ignore + @property def create_source( self, @@ -5402,6 +6621,17 @@ def delete_notification_config( # In C++ this would require a dynamic_cast return self._DeleteNotificationConfig(self._session, self._host, self._interceptor) # type: ignore + @property + def delete_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest], + empty_pb2.Empty, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteSecurityHealthAnalyticsCustomModule(self._session, self._host, self._interceptor) # type: ignore + @property def get_big_query_export( self, @@ -5413,6 +6643,17 @@ def get_big_query_export( # In C++ this would require a dynamic_cast return self._GetBigQueryExport(self._session, self._host, self._interceptor) # type: ignore + @property + def get_effective_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest], + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetEffectiveSecurityHealthAnalyticsCustomModule(self._session, self._host, self._interceptor) # type: ignore + @property def get_iam_policy( self, @@ -5453,6 +6694,17 @@ def get_organization_settings( # In C++ this would require a dynamic_cast return self._GetOrganizationSettings(self._session, self._host, self._interceptor) # type: ignore + @property + def get_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest], + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetSecurityHealthAnalyticsCustomModule(self._session, self._host, self._interceptor) # type: ignore + @property def get_source( self, @@ -5505,6 +6757,32 @@ def list_big_query_exports( # In C++ this would require a dynamic_cast return self._ListBigQueryExports(self._session, self._host, self._interceptor) # type: ignore + @property + def list_descendant_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [ + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest + ], + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListDescendantSecurityHealthAnalyticsCustomModules(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_effective_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest + ], + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListEffectiveSecurityHealthAnalyticsCustomModules(self._session, self._host, self._interceptor) # type: ignore + @property def list_findings( self, @@ -5538,6 +6816,17 @@ def list_notification_configs( # In C++ this would require a dynamic_cast return self._ListNotificationConfigs(self._session, self._host, self._interceptor) # type: ignore + @property + def list_security_health_analytics_custom_modules( + self, + ) -> Callable[ + [securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest], + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListSecurityHealthAnalyticsCustomModules(self._session, self._host, self._interceptor) # type: ignore + @property def list_sources( self, @@ -5656,6 +6945,17 @@ def update_organization_settings( # In C++ this would require a dynamic_cast return self._UpdateOrganizationSettings(self._session, self._host, self._interceptor) # type: ignore + @property + def update_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest], + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateSecurityHealthAnalyticsCustomModule(self._session, self._host, self._interceptor) # type: ignore + @property def update_security_marks( self, diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/__init__.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/__init__.py index 5d902c0fe5ae..f73d61aebc43 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/__init__.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/__init__.py @@ -21,6 +21,9 @@ from .contact_details import Contact, ContactDetails from .container import Container from .database import Database +from .effective_security_health_analytics_custom_module import ( + EffectiveSecurityHealthAnalyticsCustomModule, +) from .exfiltration import ExfilResource, Exfiltration from .external_system import ExternalSystem from .file import File @@ -39,6 +42,8 @@ from .process import EnvironmentVariable, Process from .resource import Resource from .run_asset_discovery_response import RunAssetDiscoveryResponse +from .security_health_analytics_custom_config import CustomConfig +from .security_health_analytics_custom_module import SecurityHealthAnalyticsCustomModule from .security_marks import SecurityMarks from .securitycenter_service import ( BulkMuteFindingsRequest, @@ -47,14 +52,18 @@ CreateFindingRequest, CreateMuteConfigRequest, CreateNotificationConfigRequest, + CreateSecurityHealthAnalyticsCustomModuleRequest, CreateSourceRequest, DeleteBigQueryExportRequest, DeleteMuteConfigRequest, DeleteNotificationConfigRequest, + DeleteSecurityHealthAnalyticsCustomModuleRequest, GetBigQueryExportRequest, + GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, GetMuteConfigRequest, GetNotificationConfigRequest, GetOrganizationSettingsRequest, + GetSecurityHealthAnalyticsCustomModuleRequest, GetSourceRequest, GroupAssetsRequest, GroupAssetsResponse, @@ -65,12 +74,18 @@ ListAssetsResponse, ListBigQueryExportsRequest, ListBigQueryExportsResponse, + ListDescendantSecurityHealthAnalyticsCustomModulesRequest, + ListDescendantSecurityHealthAnalyticsCustomModulesResponse, + ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + ListEffectiveSecurityHealthAnalyticsCustomModulesResponse, ListFindingsRequest, ListFindingsResponse, ListMuteConfigsRequest, ListMuteConfigsResponse, ListNotificationConfigsRequest, ListNotificationConfigsResponse, + ListSecurityHealthAnalyticsCustomModulesRequest, + ListSecurityHealthAnalyticsCustomModulesResponse, ListSourcesRequest, ListSourcesResponse, RunAssetDiscoveryRequest, @@ -82,6 +97,7 @@ UpdateMuteConfigRequest, UpdateNotificationConfigRequest, UpdateOrganizationSettingsRequest, + UpdateSecurityHealthAnalyticsCustomModuleRequest, UpdateSecurityMarksRequest, UpdateSourceRequest, ) @@ -100,6 +116,7 @@ "ContactDetails", "Container", "Database", + "EffectiveSecurityHealthAnalyticsCustomModule", "ExfilResource", "Exfiltration", "ExternalSystem", @@ -120,6 +137,8 @@ "Process", "Resource", "RunAssetDiscoveryResponse", + "CustomConfig", + "SecurityHealthAnalyticsCustomModule", "SecurityMarks", "BulkMuteFindingsRequest", "BulkMuteFindingsResponse", @@ -127,14 +146,18 @@ "CreateFindingRequest", "CreateMuteConfigRequest", "CreateNotificationConfigRequest", + "CreateSecurityHealthAnalyticsCustomModuleRequest", "CreateSourceRequest", "DeleteBigQueryExportRequest", "DeleteMuteConfigRequest", "DeleteNotificationConfigRequest", + "DeleteSecurityHealthAnalyticsCustomModuleRequest", "GetBigQueryExportRequest", + "GetEffectiveSecurityHealthAnalyticsCustomModuleRequest", "GetMuteConfigRequest", "GetNotificationConfigRequest", "GetOrganizationSettingsRequest", + "GetSecurityHealthAnalyticsCustomModuleRequest", "GetSourceRequest", "GroupAssetsRequest", "GroupAssetsResponse", @@ -145,12 +168,18 @@ "ListAssetsResponse", "ListBigQueryExportsRequest", "ListBigQueryExportsResponse", + "ListDescendantSecurityHealthAnalyticsCustomModulesRequest", + "ListDescendantSecurityHealthAnalyticsCustomModulesResponse", + "ListEffectiveSecurityHealthAnalyticsCustomModulesRequest", + "ListEffectiveSecurityHealthAnalyticsCustomModulesResponse", "ListFindingsRequest", "ListFindingsResponse", "ListMuteConfigsRequest", "ListMuteConfigsResponse", "ListNotificationConfigsRequest", "ListNotificationConfigsResponse", + "ListSecurityHealthAnalyticsCustomModulesRequest", + "ListSecurityHealthAnalyticsCustomModulesResponse", "ListSourcesRequest", "ListSourcesResponse", "RunAssetDiscoveryRequest", @@ -162,6 +191,7 @@ "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", "UpdateOrganizationSettingsRequest", + "UpdateSecurityHealthAnalyticsCustomModuleRequest", "UpdateSecurityMarksRequest", "UpdateSourceRequest", "Source", diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/bigquery_export.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/bigquery_export.py index 563309bccf23..044f7b7ed02c 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/bigquery_export.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/bigquery_export.py @@ -74,24 +74,24 @@ class BigQueryExport(proto.Message): BigQuery Dataset unique ID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_). create_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The time at which the big query + Output only. The time at which the BigQuery export was created. This field is set by the server and will be ignored if provided on export on creation. update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The most recent time at which - the big export was updated. This field is set by - the server and will be ignored if provided on - export creation or update. + the BigQuery export was updated. This field is + set by the server and will be ignored if + provided on export creation or update. most_recent_editor (str): Output only. Email address of the user who - last edited the big query export. This field is + last edited the BigQuery export. This field is set by the server and will be ignored if provided on export creation or update. principal (str): Output only. The service account that needs - permission to create table, upload data to the - big query dataset. + permission to create table and upload data to + the BigQuery dataset. """ name: str = proto.Field( diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/contact_details.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/contact_details.py index a7cee6e20c0b..b0f600da4e89 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/contact_details.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/contact_details.py @@ -44,11 +44,11 @@ class ContactDetails(proto.Message): class Contact(proto.Message): - r"""Representa a single contact's email address + r"""The email address of a contact. Attributes: email (str): - An email address e.g. "person123@company.com". + An email address. For example, "``person123@company.com``". """ email: str = proto.Field( diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/database.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/database.py index bad0e30d94f3..78efc65cac04 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/database.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/database.py @@ -34,7 +34,7 @@ class Database(proto.Message): database instance itself. Some database resources may not have the full resource name populated because these resource types are not yet supported by Cloud Asset Inventory (e.g. CloudSQL - databases). In these cases only the display name will be + databases). In these cases only the display name will be provided. Attributes: diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/effective_security_health_analytics_custom_module.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/effective_security_health_analytics_custom_module.py new file mode 100644 index 000000000000..d82d75b4e571 --- /dev/null +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/effective_security_health_analytics_custom_module.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.cloud.securitycenter_v1.types import security_health_analytics_custom_config + +__protobuf__ = proto.module( + package="google.cloud.securitycenter.v1", + manifest={ + "EffectiveSecurityHealthAnalyticsCustomModule", + }, +) + + +class EffectiveSecurityHealthAnalyticsCustomModule(proto.Message): + r"""An EffectiveSecurityHealthAnalyticsCustomModule is the + representation of a Security Health Analytics custom module at a + specified level of the resource hierarchy: organization, folder, or + project. If a custom module is inherited from a parent organization + or folder, the value of the ``enablementState`` property in + EffectiveSecurityHealthAnalyticsCustomModule is set to the value + that is effective in the parent, instead of ``INHERITED``. For + example, if the module is enabled in a parent organization or + folder, the effective enablement_state for the module in all child + folders or projects is also ``enabled``. + EffectiveSecurityHealthAnalyticsCustomModule is read-only. + + Attributes: + name (str): + Output only. The resource name of the custom + module. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}", + or + "folders/{folder}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}". + custom_config (google.cloud.securitycenter_v1.types.CustomConfig): + Output only. The user-specified configuration + for the module. + enablement_state (google.cloud.securitycenter_v1.types.EffectiveSecurityHealthAnalyticsCustomModule.EnablementState): + Output only. The effective state of + enablement for the module at the given level of + the hierarchy. + display_name (str): + Output only. The display name for the custom + module. The name must be between 1 and 128 + characters, start with a lowercase letter, and + contain alphanumeric characters or underscores + only. + """ + + class EnablementState(proto.Enum): + r"""The enablement state of the module. + + Values: + ENABLEMENT_STATE_UNSPECIFIED (0): + Unspecified enablement state. + ENABLED (1): + The module is enabled at the given level. + DISABLED (2): + The module is disabled at the given level. + """ + ENABLEMENT_STATE_UNSPECIFIED = 0 + ENABLED = 1 + DISABLED = 2 + + name: str = proto.Field( + proto.STRING, + number=1, + ) + custom_config: security_health_analytics_custom_config.CustomConfig = proto.Field( + proto.MESSAGE, + number=2, + message=security_health_analytics_custom_config.CustomConfig, + ) + enablement_state: EnablementState = proto.Field( + proto.ENUM, + number=3, + enum=EnablementState, + ) + display_name: str = proto.Field( + proto.STRING, + number=4, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/exfiltration.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/exfiltration.py index d00225d7775b..8f035aeef6bc 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/exfiltration.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/exfiltration.py @@ -30,7 +30,7 @@ class Exfiltration(proto.Message): r"""Exfiltration represents a data exfiltration attempt of one or - more sources to one or more targets. Sources represent the + more sources to one or more targets. Sources represent the source of data that is exfiltrated, and Targets represents the destination the data was copied to. diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/finding.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/finding.py index 0868d24df066..4fa963756915 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/finding.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/finding.py @@ -137,7 +137,7 @@ class Finding(proto.Message): https://en.wikipedia.org/wiki/Indicator_of_compromise vulnerability (google.cloud.securitycenter_v1.types.Vulnerability): Represents vulnerability-specific fields like - CVE and CVS scores. CVE stands for Common + CVE and CVSS scores. CVE stands for Common Vulnerabilities and Exposures (https://cve.mitre.org/about/) mute_update_time (google.protobuf.timestamp_pb2.Timestamp): @@ -204,6 +204,10 @@ class Finding(proto.Message): Finding. next_steps (str): Next steps associate to the finding. + module_name (str): + Unique identifier of the module which + generated the finding. Example: + folders/598186756061/securityHealthAnalyticsSettings/customModules/56799441161885 containers (MutableSequence[google.cloud.securitycenter_v1.types.Container]): Containers associated with the finding. containers provides information for both @@ -506,6 +510,10 @@ class FindingClass(proto.Enum): proto.STRING, number=40, ) + module_name: str = proto.Field( + proto.STRING, + number=41, + ) containers: MutableSequence[container.Container] = proto.RepeatedField( proto.MESSAGE, number=42, diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/indicator.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/indicator.py index 6048ab240ac2..00995e4a7e45 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/indicator.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/indicator.py @@ -28,16 +28,17 @@ class Indicator(proto.Message): - r"""Represents what's commonly known as an Indicator of compromise (IoC) - in computer forensics. This is an artifact observed on a network or - in an operating system that, with high confidence, indicates a - computer intrusion. Reference: - https://en.wikipedia.org/wiki/Indicator_of_compromise + r"""Represents what's commonly known as an *indicator of compromise* + (IoC) in computer forensics. This is an artifact observed on a + network or in an operating system that, with high confidence, + indicates a computer intrusion. For more information, see `Indicator + of + compromise `__. Attributes: ip_addresses (MutableSequence[str]): - List of ip addresses associated to the - Finding. + The list of IP addresses that are associated + with the finding. domains (MutableSequence[str]): List of domains associated to the Finding. signatures (MutableSequence[google.cloud.securitycenter_v1.types.Indicator.ProcessSignature]): diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/kernel_rootkit.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/kernel_rootkit.py index 62980f75e17d..42c029488a1b 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/kernel_rootkit.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/kernel_rootkit.py @@ -34,35 +34,36 @@ class KernelRootkit(proto.Message): name (str): Rootkit name when available. unexpected_code_modification (bool): - True if unexpected modifications of kernel + True when unexpected modifications of kernel code memory are present. unexpected_read_only_data_modification (bool): - True if unexpected modifications of kernel + True when unexpected modifications of kernel read-only data memory are present. unexpected_ftrace_handler (bool): - True if ``ftrace`` points are present with callbacks + True when ``ftrace`` points are present with callbacks pointing to regions that are not in the expected kernel or module code range. unexpected_kprobe_handler (bool): - True if ``kprobe`` points are present with callbacks + True when ``kprobe`` points are present with callbacks pointing to regions that are not in the expected kernel or module code range. unexpected_kernel_code_pages (bool): - True if kernel code pages that are not in the - expected kernel or module code regions are + True when kernel code pages that are not in + the expected kernel or module code regions are present. unexpected_system_call_handler (bool): - True if system call handlers that are are not - in the expected kernel or module code regions - are present. + True when system call handlers that are are + not in the expected kernel or module code + regions are present. unexpected_interrupt_handler (bool): - True if interrupt handlers that are are not + True when interrupt handlers that are are not in the expected kernel or module code regions are present. unexpected_processes_in_runqueue (bool): - True if unexpected processes in the scheduler - run queue are present. Such processes are in the - run queue, but not in the process task list. + True when unexpected processes in the + scheduler run queue are present. Such processes + are in the run queue, but not in the process + task list. """ name: str = proto.Field( diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/kubernetes.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/kubernetes.py index e0406a6b289f..ac0b4bec6d9c 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/kubernetes.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/kubernetes.py @@ -30,7 +30,7 @@ class Kubernetes(proto.Message): - r"""Kubernetes related attributes. + r"""Kubernetes-related attributes. Attributes: pods (MutableSequence[google.cloud.securitycenter_v1.types.Kubernetes.Pod]): @@ -178,8 +178,9 @@ class Binding(proto.Message): The Role or ClusterRole referenced by the binding. subjects (MutableSequence[google.cloud.securitycenter_v1.types.Kubernetes.Subject]): - Represents the subjects(s) bound to the role. - Not always available for PATCH requests. + Represents one or more subjects that are + bound to the role. Not always available for + PATCH requests. """ ns: str = proto.Field( diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/security_health_analytics_custom_config.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/security_health_analytics_custom_config.py new file mode 100644 index 000000000000..8cbe610c692b --- /dev/null +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/security_health_analytics_custom_config.py @@ -0,0 +1,174 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +from google.type import expr_pb2 # type: ignore +import proto # type: ignore + +__protobuf__ = proto.module( + package="google.cloud.securitycenter.v1", + manifest={ + "CustomConfig", + }, +) + + +class CustomConfig(proto.Message): + r"""Defines the properties in a custom module configuration for + Security Health Analytics. Use the custom module configuration + to create custom detectors that generate custom findings for + resources that you specify. + + Attributes: + predicate (google.type.expr_pb2.Expr): + The CEL expression to evaluate to produce + findings. When the expression evaluates to true + against a resource, a finding is generated. + custom_output (google.cloud.securitycenter_v1.types.CustomConfig.CustomOutputSpec): + Custom output properties. + resource_selector (google.cloud.securitycenter_v1.types.CustomConfig.ResourceSelector): + The resource types that the custom module + operates on. Each custom module can specify up + to 5 resource types. + severity (google.cloud.securitycenter_v1.types.CustomConfig.Severity): + The severity to assign to findings generated + by the module. + description (str): + Text that describes the vulnerability or + misconfiguration that the custom module detects. + This explanation is returned with each finding + instance to help investigators understand the + detected issue. The text must be enclosed in + quotation marks. + recommendation (str): + An explanation of the recommended steps that security teams + can take to resolve the detected issue. This explanation is + returned with each finding generated by this module in the + ``nextSteps`` property of the finding JSON. + """ + + class Severity(proto.Enum): + r"""Defines the valid value options for the severity of a + finding. + + Values: + SEVERITY_UNSPECIFIED (0): + Unspecified severity. + CRITICAL (1): + Critical severity. + HIGH (2): + High severity. + MEDIUM (3): + Medium severity. + LOW (4): + Low severity. + """ + SEVERITY_UNSPECIFIED = 0 + CRITICAL = 1 + HIGH = 2 + MEDIUM = 3 + LOW = 4 + + class CustomOutputSpec(proto.Message): + r"""A set of optional name-value pairs that define custom source + properties to return with each finding that is generated by the + custom module. The custom source properties that are defined here + are included in the finding JSON under ``sourceProperties``. + + Attributes: + properties (MutableSequence[google.cloud.securitycenter_v1.types.CustomConfig.CustomOutputSpec.Property]): + A list of custom output properties to add to + the finding. + """ + + class Property(proto.Message): + r"""An individual name-value pair that defines a custom source + property. + + Attributes: + name (str): + Name of the property for the custom output. + value_expression (google.type.expr_pb2.Expr): + The CEL expression for the custom output. A + resource property can be specified to return the + value of the property or a text string enclosed + in quotation marks. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + value_expression: expr_pb2.Expr = proto.Field( + proto.MESSAGE, + number=2, + message=expr_pb2.Expr, + ) + + properties: MutableSequence[ + "CustomConfig.CustomOutputSpec.Property" + ] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="CustomConfig.CustomOutputSpec.Property", + ) + + class ResourceSelector(proto.Message): + r"""Resource for selecting resource type. + + Attributes: + resource_types (MutableSequence[str]): + The resource types to run the detector on. + """ + + resource_types: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=1, + ) + + predicate: expr_pb2.Expr = proto.Field( + proto.MESSAGE, + number=1, + message=expr_pb2.Expr, + ) + custom_output: CustomOutputSpec = proto.Field( + proto.MESSAGE, + number=2, + message=CustomOutputSpec, + ) + resource_selector: ResourceSelector = proto.Field( + proto.MESSAGE, + number=3, + message=ResourceSelector, + ) + severity: Severity = proto.Field( + proto.ENUM, + number=4, + enum=Severity, + ) + description: str = proto.Field( + proto.STRING, + number=5, + ) + recommendation: str = proto.Field( + proto.STRING, + number=6, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/security_health_analytics_custom_module.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/security_health_analytics_custom_module.py new file mode 100644 index 000000000000..1a40c286ebd6 --- /dev/null +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/security_health_analytics_custom_module.py @@ -0,0 +1,137 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +from google.protobuf import timestamp_pb2 # type: ignore +import proto # type: ignore + +from google.cloud.securitycenter_v1.types import security_health_analytics_custom_config + +__protobuf__ = proto.module( + package="google.cloud.securitycenter.v1", + manifest={ + "SecurityHealthAnalyticsCustomModule", + }, +) + + +class SecurityHealthAnalyticsCustomModule(proto.Message): + r"""Represents an instance of a Security Health Analytics custom + module, including its full module name, display name, enablement + state, and last updated time. You can create a custom module at + the organization, folder, or project level. Custom modules that + you create at the organization or folder level are inherited by + the child folders and projects. + + Attributes: + name (str): + Immutable. The resource name of the custom + module. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/customModules/{customModule}", + or + "folders/{folder}/securityHealthAnalyticsSettings/customModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/customModules/{customModule}" + The id {customModule} is server-generated and is + not user settable. It will be a numeric id + containing 1-20 digits. + display_name (str): + The display name of the Security Health + Analytics custom module. This display name + becomes the finding category for all findings + that are returned by this custom module. The + display name must be between 1 and 128 + characters, start with a lowercase letter, and + contain alphanumeric characters or underscores + only. + enablement_state (google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule.EnablementState): + The enablement state of the custom module. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time at which the custom + module was last updated. + last_editor (str): + Output only. The editor that last updated the + custom module. + ancestor_module (str): + Output only. If empty, indicates that the custom module was + created in the organization, folder, or project in which you + are viewing the custom module. Otherwise, + ``ancestor_module`` specifies the organization or folder + from which the custom module is inherited. + custom_config (google.cloud.securitycenter_v1.types.CustomConfig): + The user specified custom configuration for + the module. + """ + + class EnablementState(proto.Enum): + r"""Possible enablement states of a custom module. + + Values: + ENABLEMENT_STATE_UNSPECIFIED (0): + Unspecified enablement state. + ENABLED (1): + The module is enabled at the given CRM + resource. + DISABLED (2): + The module is disabled at the given CRM + resource. + INHERITED (3): + State is inherited from an ancestor module. + The module will either be effectively ENABLED or + DISABLED based on its closest non-inherited + ancestor module in the CRM hierarchy. + """ + ENABLEMENT_STATE_UNSPECIFIED = 0 + ENABLED = 1 + DISABLED = 2 + INHERITED = 3 + + name: str = proto.Field( + proto.STRING, + number=1, + ) + display_name: str = proto.Field( + proto.STRING, + number=2, + ) + enablement_state: EnablementState = proto.Field( + proto.ENUM, + number=4, + enum=EnablementState, + ) + update_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + last_editor: str = proto.Field( + proto.STRING, + number=6, + ) + ancestor_module: str = proto.Field( + proto.STRING, + number=7, + ) + custom_config: security_health_analytics_custom_config.CustomConfig = proto.Field( + proto.MESSAGE, + number=8, + message=security_health_analytics_custom_config.CustomConfig, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/securitycenter_service.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/securitycenter_service.py index 048561624586..7fc55cffb17d 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/securitycenter_service.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/types/securitycenter_service.py @@ -23,6 +23,10 @@ from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore +from google.cloud.securitycenter_v1.types import ( + bigquery_export, + effective_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -30,9 +34,11 @@ from google.cloud.securitycenter_v1.types import ( organization_settings as gcs_organization_settings, ) +from google.cloud.securitycenter_v1.types import ( + security_health_analytics_custom_module as gcs_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import security_marks as gcs_security_marks from google.cloud.securitycenter_v1.types import asset as gcs_asset -from google.cloud.securitycenter_v1.types import bigquery_export 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 @@ -46,23 +52,33 @@ "CreateFindingRequest", "CreateMuteConfigRequest", "CreateNotificationConfigRequest", + "CreateSecurityHealthAnalyticsCustomModuleRequest", "CreateSourceRequest", "DeleteMuteConfigRequest", "DeleteNotificationConfigRequest", + "DeleteSecurityHealthAnalyticsCustomModuleRequest", "GetBigQueryExportRequest", "GetMuteConfigRequest", "GetNotificationConfigRequest", "GetOrganizationSettingsRequest", + "GetEffectiveSecurityHealthAnalyticsCustomModuleRequest", + "GetSecurityHealthAnalyticsCustomModuleRequest", "GetSourceRequest", "GroupAssetsRequest", "GroupAssetsResponse", "GroupFindingsRequest", "GroupFindingsResponse", "GroupResult", + "ListDescendantSecurityHealthAnalyticsCustomModulesRequest", + "ListDescendantSecurityHealthAnalyticsCustomModulesResponse", "ListMuteConfigsRequest", "ListMuteConfigsResponse", "ListNotificationConfigsRequest", "ListNotificationConfigsResponse", + "ListEffectiveSecurityHealthAnalyticsCustomModulesRequest", + "ListEffectiveSecurityHealthAnalyticsCustomModulesResponse", + "ListSecurityHealthAnalyticsCustomModulesRequest", + "ListSecurityHealthAnalyticsCustomModulesResponse", "ListSourcesRequest", "ListSourcesResponse", "ListAssetsRequest", @@ -77,6 +93,7 @@ "UpdateMuteConfigRequest", "UpdateNotificationConfigRequest", "UpdateOrganizationSettingsRequest", + "UpdateSecurityHealthAnalyticsCustomModuleRequest", "UpdateSourceRequest", "UpdateSecurityMarksRequest", "CreateBigQueryExportRequest", @@ -254,6 +271,36 @@ class CreateNotificationConfigRequest(proto.Message): ) +class CreateSecurityHealthAnalyticsCustomModuleRequest(proto.Message): + r"""Request message for creating security health analytics custom + modules. + + Attributes: + parent (str): + Required. Resource name of the new custom + module's parent. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings". + security_health_analytics_custom_module (google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule): + Required. SecurityHealthAnalytics custom + module to create. The provided name is ignored + and reset with provided parent information and + server-generated ID. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + security_health_analytics_custom_module: gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule = proto.Field( + proto.MESSAGE, + number=2, + message=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + + class CreateSourceRequest(proto.Message): r"""Request message for creating a source. @@ -313,6 +360,26 @@ class DeleteNotificationConfigRequest(proto.Message): ) +class DeleteSecurityHealthAnalyticsCustomModuleRequest(proto.Message): + r"""Request message for deleting security health analytics custom + modules. + + Attributes: + name (str): + Required. Name of the custom module to + delete. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/customModules/{customModule}", + "folders/{folder}/securityHealthAnalyticsSettings/customModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/customModules/{customModule}". + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + class GetBigQueryExportRequest(proto.Message): r"""Request message for retrieving a BigQuery export. @@ -382,6 +449,46 @@ class GetOrganizationSettingsRequest(proto.Message): ) +class GetEffectiveSecurityHealthAnalyticsCustomModuleRequest(proto.Message): + r"""Request message for getting effective security health + analytics custom modules. + + Attributes: + name (str): + Required. Name of the effective custom module + to get. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}", + "folders/{folder}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/effectiveCustomModules/{customModule}". + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class GetSecurityHealthAnalyticsCustomModuleRequest(proto.Message): + r"""Request message for getting security health analytics custom + modules. + + Attributes: + name (str): + Required. Name of the custom module to get. + Its format is + "organizations/{organization}/securityHealthAnalyticsSettings/customModules/{customModule}", + "folders/{folder}/securityHealthAnalyticsSettings/customModules/{customModule}", + or + "projects/{project}/securityHealthAnalyticsSettings/customModules/{customModule}". + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + class GetSourceRequest(proto.Message): r"""Request message for getting a source. @@ -895,6 +1002,71 @@ class GroupResult(proto.Message): ) +class ListDescendantSecurityHealthAnalyticsCustomModulesRequest(proto.Message): + r"""Request message for listing descendant security health + analytics custom modules. + + Attributes: + parent (str): + Required. Name of parent to list descendant + custom modules. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings". + page_size (int): + The maximum number of results to return in a + single response. Default is 10, minimum is 1, + maximum is 1000. + page_token (str): + The value returned by the last call + indicating a continuation + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ListDescendantSecurityHealthAnalyticsCustomModulesResponse(proto.Message): + r"""Response message for listing descendant security health + analytics custom modules. + + Attributes: + security_health_analytics_custom_modules (MutableSequence[google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule]): + Custom modules belonging to the requested + parent and its descendants. + next_page_token (str): + If not empty, indicates that there may be + more custom modules to be returned. + """ + + @property + def raw_page(self): + return self + + security_health_analytics_custom_modules: MutableSequence[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + class ListMuteConfigsRequest(proto.Message): r"""Request message for listing mute configs at a given scope e.g. organization, folder or project. @@ -1023,6 +1195,136 @@ def raw_page(self): ) +class ListEffectiveSecurityHealthAnalyticsCustomModulesRequest(proto.Message): + r"""Request message for listing effective security health + analytics custom modules. + + Attributes: + parent (str): + Required. Name of parent to list effective + custom modules. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings". + page_size (int): + The maximum number of results to return in a + single response. Default is 10, minimum is 1, + maximum is 1000. + page_token (str): + The value returned by the last call + indicating a continuation + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ListEffectiveSecurityHealthAnalyticsCustomModulesResponse(proto.Message): + r"""Response message for listing effective security health + analytics custom modules. + + Attributes: + effective_security_health_analytics_custom_modules (MutableSequence[google.cloud.securitycenter_v1.types.EffectiveSecurityHealthAnalyticsCustomModule]): + Effective custom modules belonging to the + requested parent. + next_page_token (str): + If not empty, indicates that there may be + more effective custom modules to be returned. + """ + + @property + def raw_page(self): + return self + + effective_security_health_analytics_custom_modules: MutableSequence[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule + ] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +class ListSecurityHealthAnalyticsCustomModulesRequest(proto.Message): + r"""Request message for listing security health analytics custom + modules. + + Attributes: + parent (str): + Required. Name of parent to list custom + modules. Its format is + "organizations/{organization}/securityHealthAnalyticsSettings", + "folders/{folder}/securityHealthAnalyticsSettings", + or + "projects/{project}/securityHealthAnalyticsSettings". + page_size (int): + The maximum number of results to return in a + single response. Default is 10, minimum is 1, + maximum is 1000. + page_token (str): + The value returned by the last call + indicating a continuation + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ListSecurityHealthAnalyticsCustomModulesResponse(proto.Message): + r"""Response message for listing security health analytics custom + modules. + + Attributes: + security_health_analytics_custom_modules (MutableSequence[google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule]): + Custom modules belonging to the requested + parent. + next_page_token (str): + If not empty, indicates that there may be + more custom modules to be returned. + """ + + @property + def raw_page(self): + return self + + security_health_analytics_custom_modules: MutableSequence[ + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule + ] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + class ListSourcesRequest(proto.Message): r"""Request message for listing sources. @@ -1942,6 +2244,30 @@ class UpdateOrganizationSettingsRequest(proto.Message): ) +class UpdateSecurityHealthAnalyticsCustomModuleRequest(proto.Message): + r"""Request message for updating security health analytics custom + modules. + + Attributes: + security_health_analytics_custom_module (google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule): + Required. The SecurityHealthAnalytics custom + module to update. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The list of fields to update. + """ + + security_health_analytics_custom_module: gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule = proto.Field( + proto.MESSAGE, + number=1, + message=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + class UpdateSourceRequest(proto.Message): r"""Request message for updating a source. diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_async.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_async.py new file mode 100644 index 000000000000..f35b78c053fc --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSecurityHealthAnalyticsCustomModule +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_CreateSecurityHealthAnalyticsCustomModule_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +async def sample_create_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.CreateSecurityHealthAnalyticsCustomModuleRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_CreateSecurityHealthAnalyticsCustomModule_async] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_sync.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_sync.py new file mode 100644 index 000000000000..016c1c409301 --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSecurityHealthAnalyticsCustomModule +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_CreateSecurityHealthAnalyticsCustomModule_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +def sample_create_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.CreateSecurityHealthAnalyticsCustomModuleRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_CreateSecurityHealthAnalyticsCustomModule_sync] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_async.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_async.py new file mode 100644 index 000000000000..82a795d9dc3e --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSecurityHealthAnalyticsCustomModule +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_DeleteSecurityHealthAnalyticsCustomModule_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +async def sample_delete_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.DeleteSecurityHealthAnalyticsCustomModuleRequest( + name="name_value", + ) + + # Make the request + await client.delete_security_health_analytics_custom_module(request=request) + + +# [END securitycenter_v1_generated_SecurityCenter_DeleteSecurityHealthAnalyticsCustomModule_async] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_sync.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_sync.py new file mode 100644 index 000000000000..69bb5311e950 --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSecurityHealthAnalyticsCustomModule +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_DeleteSecurityHealthAnalyticsCustomModule_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +def sample_delete_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.DeleteSecurityHealthAnalyticsCustomModuleRequest( + name="name_value", + ) + + # Make the request + client.delete_security_health_analytics_custom_module(request=request) + + +# [END securitycenter_v1_generated_SecurityCenter_DeleteSecurityHealthAnalyticsCustomModule_sync] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_async.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_async.py new file mode 100644 index 000000000000..7c17fef33857 --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEffectiveSecurityHealthAnalyticsCustomModule +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_GetEffectiveSecurityHealthAnalyticsCustomModule_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +async def sample_get_effective_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest( + name="name_value", + ) + + # Make the request + response = await client.get_effective_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_GetEffectiveSecurityHealthAnalyticsCustomModule_async] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_sync.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_sync.py new file mode 100644 index 000000000000..81240c52afde --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEffectiveSecurityHealthAnalyticsCustomModule +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_GetEffectiveSecurityHealthAnalyticsCustomModule_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +def sample_get_effective_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest( + name="name_value", + ) + + # Make the request + response = client.get_effective_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_GetEffectiveSecurityHealthAnalyticsCustomModule_sync] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_async.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_async.py new file mode 100644 index 000000000000..a19f6dec41dd --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSecurityHealthAnalyticsCustomModule +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_GetSecurityHealthAnalyticsCustomModule_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +async def sample_get_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.GetSecurityHealthAnalyticsCustomModuleRequest( + name="name_value", + ) + + # Make the request + response = await client.get_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_GetSecurityHealthAnalyticsCustomModule_async] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_sync.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_sync.py new file mode 100644 index 000000000000..0cbba110f9f8 --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSecurityHealthAnalyticsCustomModule +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_GetSecurityHealthAnalyticsCustomModule_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +def sample_get_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.GetSecurityHealthAnalyticsCustomModuleRequest( + name="name_value", + ) + + # Make the request + response = client.get_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_GetSecurityHealthAnalyticsCustomModule_sync] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_async.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_async.py new file mode 100644 index 000000000000..a5f8dacaad6c --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDescendantSecurityHealthAnalyticsCustomModules +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_ListDescendantSecurityHealthAnalyticsCustomModules_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +async def sample_list_descendant_security_health_analytics_custom_modules(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListDescendantSecurityHealthAnalyticsCustomModulesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_descendant_security_health_analytics_custom_modules(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_ListDescendantSecurityHealthAnalyticsCustomModules_async] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_sync.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_sync.py new file mode 100644 index 000000000000..0d3dfa296682 --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDescendantSecurityHealthAnalyticsCustomModules +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_ListDescendantSecurityHealthAnalyticsCustomModules_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +def sample_list_descendant_security_health_analytics_custom_modules(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListDescendantSecurityHealthAnalyticsCustomModulesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_descendant_security_health_analytics_custom_modules(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_ListDescendantSecurityHealthAnalyticsCustomModules_sync] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_async.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_async.py new file mode 100644 index 000000000000..585382cab775 --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEffectiveSecurityHealthAnalyticsCustomModules +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_ListEffectiveSecurityHealthAnalyticsCustomModules_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +async def sample_list_effective_security_health_analytics_custom_modules(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_effective_security_health_analytics_custom_modules(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_ListEffectiveSecurityHealthAnalyticsCustomModules_async] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_sync.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_sync.py new file mode 100644 index 000000000000..0162f609e787 --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEffectiveSecurityHealthAnalyticsCustomModules +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_ListEffectiveSecurityHealthAnalyticsCustomModules_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +def sample_list_effective_security_health_analytics_custom_modules(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_effective_security_health_analytics_custom_modules(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_ListEffectiveSecurityHealthAnalyticsCustomModules_sync] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_async.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_async.py new file mode 100644 index 000000000000..d3b7b4a7728a --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSecurityHealthAnalyticsCustomModules +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_ListSecurityHealthAnalyticsCustomModules_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +async def sample_list_security_health_analytics_custom_modules(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListSecurityHealthAnalyticsCustomModulesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_security_health_analytics_custom_modules(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_ListSecurityHealthAnalyticsCustomModules_async] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_sync.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_sync.py new file mode 100644 index 000000000000..b8aaf90edf4c --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSecurityHealthAnalyticsCustomModules +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_ListSecurityHealthAnalyticsCustomModules_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +def sample_list_security_health_analytics_custom_modules(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.ListSecurityHealthAnalyticsCustomModulesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_security_health_analytics_custom_modules(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_ListSecurityHealthAnalyticsCustomModules_sync] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_async.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_async.py new file mode 100644 index 000000000000..3ae5c6bad61d --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateSecurityHealthAnalyticsCustomModule +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_UpdateSecurityHealthAnalyticsCustomModule_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +async def sample_update_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + request = securitycenter_v1.UpdateSecurityHealthAnalyticsCustomModuleRequest( + ) + + # Make the request + response = await client.update_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_UpdateSecurityHealthAnalyticsCustomModule_async] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_sync.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_sync.py new file mode 100644 index 000000000000..538d1b1e7891 --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateSecurityHealthAnalyticsCustomModule +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-securitycenter + + +# [START securitycenter_v1_generated_SecurityCenter_UpdateSecurityHealthAnalyticsCustomModule_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import securitycenter_v1 + + +def sample_update_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + request = securitycenter_v1.UpdateSecurityHealthAnalyticsCustomModuleRequest( + ) + + # Make the request + response = client.update_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_UpdateSecurityHealthAnalyticsCustomModule_sync] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1.json b/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1.json index 38463d21574c..ec678e1a8024 100644 --- a/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1.json +++ b/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-securitycenter", - "version": "1.19.1" + "version": "0.1.0" }, "snippets": [ { @@ -880,6 +880,175 @@ ], "title": "securitycenter_v1_generated_security_center_create_notification_config_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", + "shortName": "SecurityCenterAsyncClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.create_security_health_analytics_custom_module", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.CreateSecurityHealthAnalyticsCustomModule", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "CreateSecurityHealthAnalyticsCustomModule" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.CreateSecurityHealthAnalyticsCustomModuleRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "security_health_analytics_custom_module", + "type": "google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule", + "shortName": "create_security_health_analytics_custom_module" + }, + "description": "Sample for CreateSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_CreateSecurityHealthAnalyticsCustomModule_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", + "shortName": "SecurityCenterClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.create_security_health_analytics_custom_module", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.CreateSecurityHealthAnalyticsCustomModule", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "CreateSecurityHealthAnalyticsCustomModule" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.CreateSecurityHealthAnalyticsCustomModuleRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "security_health_analytics_custom_module", + "type": "google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule", + "shortName": "create_security_health_analytics_custom_module" + }, + "description": "Sample for CreateSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_CreateSecurityHealthAnalyticsCustomModule_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_create_security_health_analytics_custom_module_sync.py" + }, { "canonical": true, "clientMethod": { @@ -1522,19 +1691,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_big_query_export", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.delete_security_health_analytics_custom_module", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetBigQueryExport", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.DeleteSecurityHealthAnalyticsCustomModule", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetBigQueryExport" + "shortName": "DeleteSecurityHealthAnalyticsCustomModule" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GetBigQueryExportRequest" + "type": "google.cloud.securitycenter_v1.types.DeleteSecurityHealthAnalyticsCustomModuleRequest" }, { "name": "name", @@ -1553,22 +1722,21 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.types.BigQueryExport", - "shortName": "get_big_query_export" + "shortName": "delete_security_health_analytics_custom_module" }, - "description": "Sample for GetBigQueryExport", - "file": "securitycenter_v1_generated_security_center_get_big_query_export_async.py", + "description": "Sample for DeleteSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetBigQueryExport_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_DeleteSecurityHealthAnalyticsCustomModule_async", "segments": [ { - "end": 51, + "end": 49, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 49, "start": 27, "type": "SHORT" }, @@ -1583,17 +1751,15 @@ "type": "REQUEST_INITIALIZATION" }, { - "end": 48, "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 52, - "start": 49, + "end": 50, "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_big_query_export_async.py" + "title": "securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_async.py" }, { "canonical": true, @@ -1602,19 +1768,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_big_query_export", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.delete_security_health_analytics_custom_module", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetBigQueryExport", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.DeleteSecurityHealthAnalyticsCustomModule", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetBigQueryExport" + "shortName": "DeleteSecurityHealthAnalyticsCustomModule" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GetBigQueryExportRequest" + "type": "google.cloud.securitycenter_v1.types.DeleteSecurityHealthAnalyticsCustomModuleRequest" }, { "name": "name", @@ -1633,22 +1799,21 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.types.BigQueryExport", - "shortName": "get_big_query_export" + "shortName": "delete_security_health_analytics_custom_module" }, - "description": "Sample for GetBigQueryExport", - "file": "securitycenter_v1_generated_security_center_get_big_query_export_sync.py", + "description": "Sample for DeleteSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetBigQueryExport_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_DeleteSecurityHealthAnalyticsCustomModule_sync", "segments": [ { - "end": 51, + "end": 49, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 49, "start": 27, "type": "SHORT" }, @@ -1663,17 +1828,15 @@ "type": "REQUEST_INITIALIZATION" }, { - "end": 48, "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 52, - "start": 49, + "end": 50, "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_big_query_export_sync.py" + "title": "securitycenter_v1_generated_security_center_delete_security_health_analytics_custom_module_sync.py" }, { "canonical": true, @@ -1683,22 +1846,22 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_iam_policy", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_big_query_export", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetIamPolicy", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetBigQueryExport", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetIamPolicy" + "shortName": "GetBigQueryExport" }, "parameters": [ { "name": "request", - "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + "type": "google.cloud.securitycenter_v1.types.GetBigQueryExportRequest" }, { - "name": "resource", + "name": "name", "type": "str" }, { @@ -1714,47 +1877,47 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "get_iam_policy" + "resultType": "google.cloud.securitycenter_v1.types.BigQueryExport", + "shortName": "get_big_query_export" }, - "description": "Sample for GetIamPolicy", - "file": "securitycenter_v1_generated_security_center_get_iam_policy_async.py", + "description": "Sample for GetBigQueryExport", + "file": "securitycenter_v1_generated_security_center_get_big_query_export_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetIamPolicy_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetBigQueryExport_async", "segments": [ { - "end": 52, + "end": 51, "start": 27, "type": "FULL" }, { - "end": 52, + "end": 51, "start": 27, "type": "SHORT" }, { - "end": 41, - "start": 39, + "end": 40, + "start": 38, "type": "CLIENT_INITIALIZATION" }, { - "end": 46, - "start": 42, + "end": 45, + "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 49, - "start": 47, + "end": 48, + "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 53, - "start": 50, + "end": 52, + "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_iam_policy_async.py" + "title": "securitycenter_v1_generated_security_center_get_big_query_export_async.py" }, { "canonical": true, @@ -1763,22 +1926,22 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_iam_policy", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_big_query_export", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetIamPolicy", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetBigQueryExport", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetIamPolicy" + "shortName": "GetBigQueryExport" }, "parameters": [ { "name": "request", - "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + "type": "google.cloud.securitycenter_v1.types.GetBigQueryExportRequest" }, { - "name": "resource", + "name": "name", "type": "str" }, { @@ -1794,47 +1957,47 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "get_iam_policy" + "resultType": "google.cloud.securitycenter_v1.types.BigQueryExport", + "shortName": "get_big_query_export" }, - "description": "Sample for GetIamPolicy", - "file": "securitycenter_v1_generated_security_center_get_iam_policy_sync.py", + "description": "Sample for GetBigQueryExport", + "file": "securitycenter_v1_generated_security_center_get_big_query_export_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetIamPolicy_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetBigQueryExport_sync", "segments": [ { - "end": 52, + "end": 51, "start": 27, "type": "FULL" }, { - "end": 52, + "end": 51, "start": 27, "type": "SHORT" }, { - "end": 41, - "start": 39, + "end": 40, + "start": 38, "type": "CLIENT_INITIALIZATION" }, { - "end": 46, - "start": 42, + "end": 45, + "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 49, - "start": 47, + "end": 48, + "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 53, - "start": 50, + "end": 52, + "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_iam_policy_sync.py" + "title": "securitycenter_v1_generated_security_center_get_big_query_export_sync.py" }, { "canonical": true, @@ -1844,19 +2007,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_mute_config", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_effective_security_health_analytics_custom_module", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetMuteConfig", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetEffectiveSecurityHealthAnalyticsCustomModule", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetMuteConfig" + "shortName": "GetEffectiveSecurityHealthAnalyticsCustomModule" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GetMuteConfigRequest" + "type": "google.cloud.securitycenter_v1.types.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest" }, { "name": "name", @@ -1875,14 +2038,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.types.MuteConfig", - "shortName": "get_mute_config" + "resultType": "google.cloud.securitycenter_v1.types.EffectiveSecurityHealthAnalyticsCustomModule", + "shortName": "get_effective_security_health_analytics_custom_module" }, - "description": "Sample for GetMuteConfig", - "file": "securitycenter_v1_generated_security_center_get_mute_config_async.py", + "description": "Sample for GetEffectiveSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetMuteConfig_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetEffectiveSecurityHealthAnalyticsCustomModule_async", "segments": [ { "end": 51, @@ -1915,7 +2078,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_mute_config_async.py" + "title": "securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_async.py" }, { "canonical": true, @@ -1924,19 +2087,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_mute_config", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_effective_security_health_analytics_custom_module", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetMuteConfig", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetEffectiveSecurityHealthAnalyticsCustomModule", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetMuteConfig" + "shortName": "GetEffectiveSecurityHealthAnalyticsCustomModule" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GetMuteConfigRequest" + "type": "google.cloud.securitycenter_v1.types.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest" }, { "name": "name", @@ -1955,14 +2118,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.types.MuteConfig", - "shortName": "get_mute_config" + "resultType": "google.cloud.securitycenter_v1.types.EffectiveSecurityHealthAnalyticsCustomModule", + "shortName": "get_effective_security_health_analytics_custom_module" }, - "description": "Sample for GetMuteConfig", - "file": "securitycenter_v1_generated_security_center_get_mute_config_sync.py", + "description": "Sample for GetEffectiveSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetMuteConfig_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetEffectiveSecurityHealthAnalyticsCustomModule_sync", "segments": [ { "end": 51, @@ -1995,7 +2158,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_mute_config_sync.py" + "title": "securitycenter_v1_generated_security_center_get_effective_security_health_analytics_custom_module_sync.py" }, { "canonical": true, @@ -2005,22 +2168,22 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_notification_config", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_iam_policy", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetNotificationConfig", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetIamPolicy", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetNotificationConfig" + "shortName": "GetIamPolicy" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GetNotificationConfigRequest" + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" }, { - "name": "name", + "name": "resource", "type": "str" }, { @@ -2036,47 +2199,47 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.types.NotificationConfig", - "shortName": "get_notification_config" + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" }, - "description": "Sample for GetNotificationConfig", - "file": "securitycenter_v1_generated_security_center_get_notification_config_async.py", + "description": "Sample for GetIamPolicy", + "file": "securitycenter_v1_generated_security_center_get_iam_policy_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetNotificationConfig_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetIamPolicy_async", "segments": [ { - "end": 51, + "end": 52, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 52, "start": 27, "type": "SHORT" }, { - "end": 40, - "start": 38, + "end": 41, + "start": 39, "type": "CLIENT_INITIALIZATION" }, { - "end": 45, - "start": 41, + "end": 46, + "start": 42, "type": "REQUEST_INITIALIZATION" }, { - "end": 48, - "start": 46, + "end": 49, + "start": 47, "type": "REQUEST_EXECUTION" }, { - "end": 52, - "start": 49, + "end": 53, + "start": 50, "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_notification_config_async.py" + "title": "securitycenter_v1_generated_security_center_get_iam_policy_async.py" }, { "canonical": true, @@ -2085,22 +2248,22 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_notification_config", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_iam_policy", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetNotificationConfig", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetIamPolicy", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetNotificationConfig" + "shortName": "GetIamPolicy" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GetNotificationConfigRequest" + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" }, { - "name": "name", + "name": "resource", "type": "str" }, { @@ -2116,47 +2279,47 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.types.NotificationConfig", - "shortName": "get_notification_config" + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" }, - "description": "Sample for GetNotificationConfig", - "file": "securitycenter_v1_generated_security_center_get_notification_config_sync.py", + "description": "Sample for GetIamPolicy", + "file": "securitycenter_v1_generated_security_center_get_iam_policy_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetNotificationConfig_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetIamPolicy_sync", "segments": [ { - "end": 51, + "end": 52, "start": 27, "type": "FULL" }, { - "end": 51, + "end": 52, "start": 27, "type": "SHORT" }, { - "end": 40, - "start": 38, + "end": 41, + "start": 39, "type": "CLIENT_INITIALIZATION" }, { - "end": 45, - "start": 41, + "end": 46, + "start": 42, "type": "REQUEST_INITIALIZATION" }, { - "end": 48, - "start": 46, + "end": 49, + "start": 47, "type": "REQUEST_EXECUTION" }, { - "end": 52, - "start": 49, + "end": 53, + "start": 50, "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_notification_config_sync.py" + "title": "securitycenter_v1_generated_security_center_get_iam_policy_sync.py" }, { "canonical": true, @@ -2166,19 +2329,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_organization_settings", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_mute_config", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetOrganizationSettings", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetMuteConfig", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetOrganizationSettings" + "shortName": "GetMuteConfig" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GetOrganizationSettingsRequest" + "type": "google.cloud.securitycenter_v1.types.GetMuteConfigRequest" }, { "name": "name", @@ -2197,14 +2360,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.types.OrganizationSettings", - "shortName": "get_organization_settings" + "resultType": "google.cloud.securitycenter_v1.types.MuteConfig", + "shortName": "get_mute_config" }, - "description": "Sample for GetOrganizationSettings", - "file": "securitycenter_v1_generated_security_center_get_organization_settings_async.py", + "description": "Sample for GetMuteConfig", + "file": "securitycenter_v1_generated_security_center_get_mute_config_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetOrganizationSettings_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetMuteConfig_async", "segments": [ { "end": 51, @@ -2237,7 +2400,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_organization_settings_async.py" + "title": "securitycenter_v1_generated_security_center_get_mute_config_async.py" }, { "canonical": true, @@ -2246,19 +2409,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_organization_settings", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_mute_config", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetOrganizationSettings", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetMuteConfig", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetOrganizationSettings" + "shortName": "GetMuteConfig" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GetOrganizationSettingsRequest" + "type": "google.cloud.securitycenter_v1.types.GetMuteConfigRequest" }, { "name": "name", @@ -2277,14 +2440,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.types.OrganizationSettings", - "shortName": "get_organization_settings" + "resultType": "google.cloud.securitycenter_v1.types.MuteConfig", + "shortName": "get_mute_config" }, - "description": "Sample for GetOrganizationSettings", - "file": "securitycenter_v1_generated_security_center_get_organization_settings_sync.py", + "description": "Sample for GetMuteConfig", + "file": "securitycenter_v1_generated_security_center_get_mute_config_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetOrganizationSettings_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetMuteConfig_sync", "segments": [ { "end": 51, @@ -2317,7 +2480,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_organization_settings_sync.py" + "title": "securitycenter_v1_generated_security_center_get_mute_config_sync.py" }, { "canonical": true, @@ -2327,19 +2490,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_source", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_notification_config", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetSource", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetNotificationConfig", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetSource" + "shortName": "GetNotificationConfig" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GetSourceRequest" + "type": "google.cloud.securitycenter_v1.types.GetNotificationConfigRequest" }, { "name": "name", @@ -2358,14 +2521,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.types.Source", - "shortName": "get_source" + "resultType": "google.cloud.securitycenter_v1.types.NotificationConfig", + "shortName": "get_notification_config" }, - "description": "Sample for GetSource", - "file": "securitycenter_v1_generated_security_center_get_source_async.py", + "description": "Sample for GetNotificationConfig", + "file": "securitycenter_v1_generated_security_center_get_notification_config_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetSource_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetNotificationConfig_async", "segments": [ { "end": 51, @@ -2398,7 +2561,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_source_async.py" + "title": "securitycenter_v1_generated_security_center_get_notification_config_async.py" }, { "canonical": true, @@ -2407,19 +2570,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_source", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_notification_config", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetSource", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetNotificationConfig", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GetSource" + "shortName": "GetNotificationConfig" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GetSourceRequest" + "type": "google.cloud.securitycenter_v1.types.GetNotificationConfigRequest" }, { "name": "name", @@ -2438,14 +2601,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.types.Source", - "shortName": "get_source" + "resultType": "google.cloud.securitycenter_v1.types.NotificationConfig", + "shortName": "get_notification_config" }, - "description": "Sample for GetSource", - "file": "securitycenter_v1_generated_security_center_get_source_sync.py", + "description": "Sample for GetNotificationConfig", + "file": "securitycenter_v1_generated_security_center_get_notification_config_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GetSource_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetNotificationConfig_sync", "segments": [ { "end": 51, @@ -2478,7 +2641,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_get_source_sync.py" + "title": "securitycenter_v1_generated_security_center_get_notification_config_sync.py" }, { "canonical": true, @@ -2488,19 +2651,23 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.group_assets", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_organization_settings", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GroupAssets", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetOrganizationSettings", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GroupAssets" + "shortName": "GetOrganizationSettings" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GroupAssetsRequest" + "type": "google.cloud.securitycenter_v1.types.GetOrganizationSettingsRequest" + }, + { + "name": "name", + "type": "str" }, { "name": "retry", @@ -2515,22 +2682,22 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.GroupAssetsAsyncPager", - "shortName": "group_assets" + "resultType": "google.cloud.securitycenter_v1.types.OrganizationSettings", + "shortName": "get_organization_settings" }, - "description": "Sample for GroupAssets", - "file": "securitycenter_v1_generated_security_center_group_assets_async.py", + "description": "Sample for GetOrganizationSettings", + "file": "securitycenter_v1_generated_security_center_get_organization_settings_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GroupAssets_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetOrganizationSettings_async", "segments": [ { - "end": 53, + "end": 51, "start": 27, "type": "FULL" }, { - "end": 53, + "end": 51, "start": 27, "type": "SHORT" }, @@ -2540,22 +2707,22 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 46, + "end": 45, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 49, - "start": 47, + "end": 48, + "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 54, - "start": 50, + "end": 52, + "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_group_assets_async.py" + "title": "securitycenter_v1_generated_security_center_get_organization_settings_async.py" }, { "canonical": true, @@ -2564,19 +2731,23 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.group_assets", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_organization_settings", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GroupAssets", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetOrganizationSettings", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GroupAssets" + "shortName": "GetOrganizationSettings" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GroupAssetsRequest" + "type": "google.cloud.securitycenter_v1.types.GetOrganizationSettingsRequest" + }, + { + "name": "name", + "type": "str" }, { "name": "retry", @@ -2591,22 +2762,900 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.GroupAssetsPager", - "shortName": "group_assets" + "resultType": "google.cloud.securitycenter_v1.types.OrganizationSettings", + "shortName": "get_organization_settings" }, - "description": "Sample for GroupAssets", - "file": "securitycenter_v1_generated_security_center_group_assets_sync.py", + "description": "Sample for GetOrganizationSettings", + "file": "securitycenter_v1_generated_security_center_get_organization_settings_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GroupAssets_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetOrganizationSettings_sync", "segments": [ { - "end": 53, + "end": 51, "start": 27, "type": "FULL" }, { - "end": 53, + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_get_organization_settings_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", + "shortName": "SecurityCenterAsyncClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_security_health_analytics_custom_module", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetSecurityHealthAnalyticsCustomModule", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "GetSecurityHealthAnalyticsCustomModule" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.GetSecurityHealthAnalyticsCustomModuleRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule", + "shortName": "get_security_health_analytics_custom_module" + }, + "description": "Sample for GetSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetSecurityHealthAnalyticsCustomModule_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", + "shortName": "SecurityCenterClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_security_health_analytics_custom_module", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetSecurityHealthAnalyticsCustomModule", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "GetSecurityHealthAnalyticsCustomModule" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.GetSecurityHealthAnalyticsCustomModuleRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule", + "shortName": "get_security_health_analytics_custom_module" + }, + "description": "Sample for GetSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetSecurityHealthAnalyticsCustomModule_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_get_security_health_analytics_custom_module_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", + "shortName": "SecurityCenterAsyncClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.get_source", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetSource", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "GetSource" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.GetSourceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.types.Source", + "shortName": "get_source" + }, + "description": "Sample for GetSource", + "file": "securitycenter_v1_generated_security_center_get_source_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetSource_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_get_source_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", + "shortName": "SecurityCenterClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.get_source", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GetSource", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "GetSource" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.GetSourceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.types.Source", + "shortName": "get_source" + }, + "description": "Sample for GetSource", + "file": "securitycenter_v1_generated_security_center_get_source_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GetSource_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_get_source_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", + "shortName": "SecurityCenterAsyncClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.group_assets", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GroupAssets", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "GroupAssets" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.GroupAssetsRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.GroupAssetsAsyncPager", + "shortName": "group_assets" + }, + "description": "Sample for GroupAssets", + "file": "securitycenter_v1_generated_security_center_group_assets_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GroupAssets_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_group_assets_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", + "shortName": "SecurityCenterClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.group_assets", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GroupAssets", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "GroupAssets" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.GroupAssetsRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.GroupAssetsPager", + "shortName": "group_assets" + }, + "description": "Sample for GroupAssets", + "file": "securitycenter_v1_generated_security_center_group_assets_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GroupAssets_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_group_assets_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", + "shortName": "SecurityCenterAsyncClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.group_findings", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GroupFindings", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "GroupFindings" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.GroupFindingsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "group_by", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.GroupFindingsAsyncPager", + "shortName": "group_findings" + }, + "description": "Sample for GroupFindings", + "file": "securitycenter_v1_generated_security_center_group_findings_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GroupFindings_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_group_findings_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", + "shortName": "SecurityCenterClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.group_findings", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GroupFindings", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "GroupFindings" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.GroupFindingsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "group_by", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.GroupFindingsPager", + "shortName": "group_findings" + }, + "description": "Sample for GroupFindings", + "file": "securitycenter_v1_generated_security_center_group_findings_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_GroupFindings_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_group_findings_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", + "shortName": "SecurityCenterAsyncClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_assets", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListAssets", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "ListAssets" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.ListAssetsRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListAssetsAsyncPager", + "shortName": "list_assets" + }, + "description": "Sample for ListAssets", + "file": "securitycenter_v1_generated_security_center_list_assets_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListAssets_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_list_assets_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", + "shortName": "SecurityCenterClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_assets", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListAssets", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "ListAssets" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.ListAssetsRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListAssetsPager", + "shortName": "list_assets" + }, + "description": "Sample for ListAssets", + "file": "securitycenter_v1_generated_security_center_list_assets_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListAssets_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_list_assets_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", + "shortName": "SecurityCenterAsyncClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_big_query_exports", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListBigQueryExports", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "ListBigQueryExports" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.ListBigQueryExportsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListBigQueryExportsAsyncPager", + "shortName": "list_big_query_exports" + }, + "description": "Sample for ListBigQueryExports", + "file": "securitycenter_v1_generated_security_center_list_big_query_exports_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListBigQueryExports_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, "start": 27, "type": "SHORT" }, @@ -2616,51 +3665,127 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 46, + "end": 45, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 49, - "start": 47, + "end": 48, + "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 54, - "start": 50, + "end": 53, + "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_group_assets_sync.py" + "title": "securitycenter_v1_generated_security_center_list_big_query_exports_async.py" }, { "canonical": true, "clientMethod": { - "async": true, "client": { - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", - "shortName": "SecurityCenterAsyncClient" + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", + "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.group_findings", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_big_query_exports", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GroupFindings", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListBigQueryExports", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GroupFindings" + "shortName": "ListBigQueryExports" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GroupFindingsRequest" + "type": "google.cloud.securitycenter_v1.types.ListBigQueryExportsRequest" }, { "name": "parent", "type": "str" }, { - "name": "group_by", + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListBigQueryExportsPager", + "shortName": "list_big_query_exports" + }, + "description": "Sample for ListBigQueryExports", + "file": "securitycenter_v1_generated_security_center_list_big_query_exports_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListBigQueryExports_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_list_big_query_exports_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", + "shortName": "SecurityCenterAsyncClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_descendant_security_health_analytics_custom_modules", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListDescendantSecurityHealthAnalyticsCustomModules", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "ListDescendantSecurityHealthAnalyticsCustomModules" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.ListDescendantSecurityHealthAnalyticsCustomModulesRequest" + }, + { + "name": "parent", "type": "str" }, { @@ -2676,22 +3801,22 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.GroupFindingsAsyncPager", - "shortName": "group_findings" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListDescendantSecurityHealthAnalyticsCustomModulesAsyncPager", + "shortName": "list_descendant_security_health_analytics_custom_modules" }, - "description": "Sample for GroupFindings", - "file": "securitycenter_v1_generated_security_center_group_findings_async.py", + "description": "Sample for ListDescendantSecurityHealthAnalyticsCustomModules", + "file": "securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GroupFindings_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListDescendantSecurityHealthAnalyticsCustomModules_async", "segments": [ { - "end": 53, + "end": 52, "start": 27, "type": "FULL" }, { - "end": 53, + "end": 52, "start": 27, "type": "SHORT" }, @@ -2701,22 +3826,22 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 46, + "end": 45, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 49, - "start": 47, + "end": 48, + "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 54, - "start": 50, + "end": 53, + "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_group_findings_async.py" + "title": "securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_async.py" }, { "canonical": true, @@ -2725,28 +3850,24 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.group_findings", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_descendant_security_health_analytics_custom_modules", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.GroupFindings", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListDescendantSecurityHealthAnalyticsCustomModules", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "GroupFindings" + "shortName": "ListDescendantSecurityHealthAnalyticsCustomModules" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.GroupFindingsRequest" + "type": "google.cloud.securitycenter_v1.types.ListDescendantSecurityHealthAnalyticsCustomModulesRequest" }, { "name": "parent", "type": "str" }, - { - "name": "group_by", - "type": "str" - }, { "name": "retry", "type": "google.api_core.retry.Retry" @@ -2760,22 +3881,22 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.GroupFindingsPager", - "shortName": "group_findings" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListDescendantSecurityHealthAnalyticsCustomModulesPager", + "shortName": "list_descendant_security_health_analytics_custom_modules" }, - "description": "Sample for GroupFindings", - "file": "securitycenter_v1_generated_security_center_group_findings_sync.py", + "description": "Sample for ListDescendantSecurityHealthAnalyticsCustomModules", + "file": "securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_GroupFindings_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListDescendantSecurityHealthAnalyticsCustomModules_sync", "segments": [ { - "end": 53, + "end": 52, "start": 27, "type": "FULL" }, { - "end": 53, + "end": 52, "start": 27, "type": "SHORT" }, @@ -2785,22 +3906,22 @@ "type": "CLIENT_INITIALIZATION" }, { - "end": 46, + "end": 45, "start": 41, "type": "REQUEST_INITIALIZATION" }, { - "end": 49, - "start": 47, + "end": 48, + "start": 46, "type": "REQUEST_EXECUTION" }, { - "end": 54, - "start": 50, + "end": 53, + "start": 49, "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_group_findings_sync.py" + "title": "securitycenter_v1_generated_security_center_list_descendant_security_health_analytics_custom_modules_sync.py" }, { "canonical": true, @@ -2810,19 +3931,23 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_assets", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_effective_security_health_analytics_custom_modules", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListAssets", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListEffectiveSecurityHealthAnalyticsCustomModules", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "ListAssets" + "shortName": "ListEffectiveSecurityHealthAnalyticsCustomModules" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.ListAssetsRequest" + "type": "google.cloud.securitycenter_v1.types.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest" + }, + { + "name": "parent", + "type": "str" }, { "name": "retry", @@ -2837,14 +3962,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListAssetsAsyncPager", - "shortName": "list_assets" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesAsyncPager", + "shortName": "list_effective_security_health_analytics_custom_modules" }, - "description": "Sample for ListAssets", - "file": "securitycenter_v1_generated_security_center_list_assets_async.py", + "description": "Sample for ListEffectiveSecurityHealthAnalyticsCustomModules", + "file": "securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_ListAssets_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListEffectiveSecurityHealthAnalyticsCustomModules_async", "segments": [ { "end": 52, @@ -2877,7 +4002,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_list_assets_async.py" + "title": "securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_async.py" }, { "canonical": true, @@ -2886,19 +4011,23 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_assets", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_effective_security_health_analytics_custom_modules", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListAssets", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListEffectiveSecurityHealthAnalyticsCustomModules", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "ListAssets" + "shortName": "ListEffectiveSecurityHealthAnalyticsCustomModules" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.ListAssetsRequest" + "type": "google.cloud.securitycenter_v1.types.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest" + }, + { + "name": "parent", + "type": "str" }, { "name": "retry", @@ -2913,14 +4042,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListAssetsPager", - "shortName": "list_assets" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesPager", + "shortName": "list_effective_security_health_analytics_custom_modules" }, - "description": "Sample for ListAssets", - "file": "securitycenter_v1_generated_security_center_list_assets_sync.py", + "description": "Sample for ListEffectiveSecurityHealthAnalyticsCustomModules", + "file": "securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_ListAssets_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListEffectiveSecurityHealthAnalyticsCustomModules_sync", "segments": [ { "end": 52, @@ -2953,7 +4082,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_list_assets_sync.py" + "title": "securitycenter_v1_generated_security_center_list_effective_security_health_analytics_custom_modules_sync.py" }, { "canonical": true, @@ -2963,23 +4092,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_big_query_exports", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_findings", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListBigQueryExports", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListFindings", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "ListBigQueryExports" + "shortName": "ListFindings" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.ListBigQueryExportsRequest" - }, - { - "name": "parent", - "type": "str" + "type": "google.cloud.securitycenter_v1.types.ListFindingsRequest" }, { "name": "retry", @@ -2994,14 +4119,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListBigQueryExportsAsyncPager", - "shortName": "list_big_query_exports" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListFindingsAsyncPager", + "shortName": "list_findings" }, - "description": "Sample for ListBigQueryExports", - "file": "securitycenter_v1_generated_security_center_list_big_query_exports_async.py", + "description": "Sample for ListFindings", + "file": "securitycenter_v1_generated_security_center_list_findings_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_ListBigQueryExports_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListFindings_async", "segments": [ { "end": 52, @@ -3034,7 +4159,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_list_big_query_exports_async.py" + "title": "securitycenter_v1_generated_security_center_list_findings_async.py" }, { "canonical": true, @@ -3043,23 +4168,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_big_query_exports", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_findings", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListBigQueryExports", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListFindings", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "ListBigQueryExports" + "shortName": "ListFindings" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.ListBigQueryExportsRequest" - }, - { - "name": "parent", - "type": "str" + "type": "google.cloud.securitycenter_v1.types.ListFindingsRequest" }, { "name": "retry", @@ -3074,14 +4195,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListBigQueryExportsPager", - "shortName": "list_big_query_exports" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListFindingsPager", + "shortName": "list_findings" }, - "description": "Sample for ListBigQueryExports", - "file": "securitycenter_v1_generated_security_center_list_big_query_exports_sync.py", + "description": "Sample for ListFindings", + "file": "securitycenter_v1_generated_security_center_list_findings_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_ListBigQueryExports_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListFindings_sync", "segments": [ { "end": 52, @@ -3114,7 +4235,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_list_big_query_exports_sync.py" + "title": "securitycenter_v1_generated_security_center_list_findings_sync.py" }, { "canonical": true, @@ -3124,19 +4245,23 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_findings", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_mute_configs", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListFindings", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListMuteConfigs", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "ListFindings" + "shortName": "ListMuteConfigs" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.ListFindingsRequest" + "type": "google.cloud.securitycenter_v1.types.ListMuteConfigsRequest" + }, + { + "name": "parent", + "type": "str" }, { "name": "retry", @@ -3151,14 +4276,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListFindingsAsyncPager", - "shortName": "list_findings" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListMuteConfigsAsyncPager", + "shortName": "list_mute_configs" }, - "description": "Sample for ListFindings", - "file": "securitycenter_v1_generated_security_center_list_findings_async.py", + "description": "Sample for ListMuteConfigs", + "file": "securitycenter_v1_generated_security_center_list_mute_configs_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_ListFindings_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListMuteConfigs_async", "segments": [ { "end": 52, @@ -3191,7 +4316,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_list_findings_async.py" + "title": "securitycenter_v1_generated_security_center_list_mute_configs_async.py" }, { "canonical": true, @@ -3200,19 +4325,23 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_findings", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_mute_configs", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListFindings", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListMuteConfigs", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "ListFindings" + "shortName": "ListMuteConfigs" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.ListFindingsRequest" + "type": "google.cloud.securitycenter_v1.types.ListMuteConfigsRequest" + }, + { + "name": "parent", + "type": "str" }, { "name": "retry", @@ -3227,14 +4356,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListFindingsPager", - "shortName": "list_findings" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListMuteConfigsPager", + "shortName": "list_mute_configs" }, - "description": "Sample for ListFindings", - "file": "securitycenter_v1_generated_security_center_list_findings_sync.py", + "description": "Sample for ListMuteConfigs", + "file": "securitycenter_v1_generated_security_center_list_mute_configs_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_ListFindings_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListMuteConfigs_sync", "segments": [ { "end": 52, @@ -3267,7 +4396,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_list_findings_sync.py" + "title": "securitycenter_v1_generated_security_center_list_mute_configs_sync.py" }, { "canonical": true, @@ -3277,19 +4406,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_mute_configs", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_notification_configs", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListMuteConfigs", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListNotificationConfigs", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "ListMuteConfigs" + "shortName": "ListNotificationConfigs" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.ListMuteConfigsRequest" + "type": "google.cloud.securitycenter_v1.types.ListNotificationConfigsRequest" }, { "name": "parent", @@ -3308,14 +4437,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListMuteConfigsAsyncPager", - "shortName": "list_mute_configs" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListNotificationConfigsAsyncPager", + "shortName": "list_notification_configs" }, - "description": "Sample for ListMuteConfigs", - "file": "securitycenter_v1_generated_security_center_list_mute_configs_async.py", + "description": "Sample for ListNotificationConfigs", + "file": "securitycenter_v1_generated_security_center_list_notification_configs_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_ListMuteConfigs_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListNotificationConfigs_async", "segments": [ { "end": 52, @@ -3348,7 +4477,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_list_mute_configs_async.py" + "title": "securitycenter_v1_generated_security_center_list_notification_configs_async.py" }, { "canonical": true, @@ -3357,19 +4486,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_mute_configs", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_notification_configs", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListMuteConfigs", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListNotificationConfigs", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "ListMuteConfigs" + "shortName": "ListNotificationConfigs" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.ListMuteConfigsRequest" + "type": "google.cloud.securitycenter_v1.types.ListNotificationConfigsRequest" }, { "name": "parent", @@ -3388,14 +4517,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListMuteConfigsPager", - "shortName": "list_mute_configs" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListNotificationConfigsPager", + "shortName": "list_notification_configs" }, - "description": "Sample for ListMuteConfigs", - "file": "securitycenter_v1_generated_security_center_list_mute_configs_sync.py", + "description": "Sample for ListNotificationConfigs", + "file": "securitycenter_v1_generated_security_center_list_notification_configs_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_ListMuteConfigs_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListNotificationConfigs_sync", "segments": [ { "end": 52, @@ -3428,7 +4557,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_list_mute_configs_sync.py" + "title": "securitycenter_v1_generated_security_center_list_notification_configs_sync.py" }, { "canonical": true, @@ -3438,19 +4567,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", "shortName": "SecurityCenterAsyncClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_notification_configs", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.list_security_health_analytics_custom_modules", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListNotificationConfigs", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListSecurityHealthAnalyticsCustomModules", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "ListNotificationConfigs" + "shortName": "ListSecurityHealthAnalyticsCustomModules" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.ListNotificationConfigsRequest" + "type": "google.cloud.securitycenter_v1.types.ListSecurityHealthAnalyticsCustomModulesRequest" }, { "name": "parent", @@ -3469,14 +4598,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListNotificationConfigsAsyncPager", - "shortName": "list_notification_configs" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListSecurityHealthAnalyticsCustomModulesAsyncPager", + "shortName": "list_security_health_analytics_custom_modules" }, - "description": "Sample for ListNotificationConfigs", - "file": "securitycenter_v1_generated_security_center_list_notification_configs_async.py", + "description": "Sample for ListSecurityHealthAnalyticsCustomModules", + "file": "securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_async.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_ListNotificationConfigs_async", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListSecurityHealthAnalyticsCustomModules_async", "segments": [ { "end": 52, @@ -3509,7 +4638,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_list_notification_configs_async.py" + "title": "securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_async.py" }, { "canonical": true, @@ -3518,19 +4647,19 @@ "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", "shortName": "SecurityCenterClient" }, - "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_notification_configs", + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.list_security_health_analytics_custom_modules", "method": { - "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListNotificationConfigs", + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.ListSecurityHealthAnalyticsCustomModules", "service": { "fullName": "google.cloud.securitycenter.v1.SecurityCenter", "shortName": "SecurityCenter" }, - "shortName": "ListNotificationConfigs" + "shortName": "ListSecurityHealthAnalyticsCustomModules" }, "parameters": [ { "name": "request", - "type": "google.cloud.securitycenter_v1.types.ListNotificationConfigsRequest" + "type": "google.cloud.securitycenter_v1.types.ListSecurityHealthAnalyticsCustomModulesRequest" }, { "name": "parent", @@ -3549,14 +4678,14 @@ "type": "Sequence[Tuple[str, str]" } ], - "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListNotificationConfigsPager", - "shortName": "list_notification_configs" + "resultType": "google.cloud.securitycenter_v1.services.security_center.pagers.ListSecurityHealthAnalyticsCustomModulesPager", + "shortName": "list_security_health_analytics_custom_modules" }, - "description": "Sample for ListNotificationConfigs", - "file": "securitycenter_v1_generated_security_center_list_notification_configs_sync.py", + "description": "Sample for ListSecurityHealthAnalyticsCustomModules", + "file": "securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_sync.py", "language": "PYTHON", "origin": "API_DEFINITION", - "regionTag": "securitycenter_v1_generated_SecurityCenter_ListNotificationConfigs_sync", + "regionTag": "securitycenter_v1_generated_SecurityCenter_ListSecurityHealthAnalyticsCustomModules_sync", "segments": [ { "end": 52, @@ -3589,7 +4718,7 @@ "type": "RESPONSE_HANDLING" } ], - "title": "securitycenter_v1_generated_security_center_list_notification_configs_sync.py" + "title": "securitycenter_v1_generated_security_center_list_security_health_analytics_custom_modules_sync.py" }, { "canonical": true, @@ -5587,6 +6716,175 @@ ], "title": "securitycenter_v1_generated_security_center_update_organization_settings_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", + "shortName": "SecurityCenterAsyncClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.update_security_health_analytics_custom_module", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.UpdateSecurityHealthAnalyticsCustomModule", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "UpdateSecurityHealthAnalyticsCustomModule" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.UpdateSecurityHealthAnalyticsCustomModuleRequest" + }, + { + "name": "security_health_analytics_custom_module", + "type": "google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule", + "shortName": "update_security_health_analytics_custom_module" + }, + "description": "Sample for UpdateSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_UpdateSecurityHealthAnalyticsCustomModule_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient", + "shortName": "SecurityCenterClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterClient.update_security_health_analytics_custom_module", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.UpdateSecurityHealthAnalyticsCustomModule", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "UpdateSecurityHealthAnalyticsCustomModule" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.UpdateSecurityHealthAnalyticsCustomModuleRequest" + }, + { + "name": "security_health_analytics_custom_module", + "type": "google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.securitycenter_v1.types.SecurityHealthAnalyticsCustomModule", + "shortName": "update_security_health_analytics_custom_module" + }, + "description": "Sample for UpdateSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_UpdateSecurityHealthAnalyticsCustomModule_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_update_security_health_analytics_custom_module_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1beta1.json b/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1beta1.json index 40bca2cbb354..a4c1295eaf99 100644 --- a/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1beta1.json +++ b/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-securitycenter", - "version": "1.19.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1p1beta1.json b/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1p1beta1.json index 6114500d5321..774592ce11f7 100644 --- a/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1p1beta1.json +++ b/packages/google-cloud-securitycenter/samples/generated_samples/snippet_metadata_google.cloud.securitycenter.v1p1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-securitycenter", - "version": "1.19.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-securitycenter/scripts/fixup_securitycenter_v1_keywords.py b/packages/google-cloud-securitycenter/scripts/fixup_securitycenter_v1_keywords.py index 3181353e0a84..af2d084dae19 100644 --- a/packages/google-cloud-securitycenter/scripts/fixup_securitycenter_v1_keywords.py +++ b/packages/google-cloud-securitycenter/scripts/fixup_securitycenter_v1_keywords.py @@ -44,23 +44,30 @@ class securitycenterCallTransformer(cst.CSTTransformer): 'create_finding': ('parent', 'finding_id', 'finding', ), 'create_mute_config': ('parent', 'mute_config', 'mute_config_id', ), 'create_notification_config': ('parent', 'config_id', 'notification_config', ), + 'create_security_health_analytics_custom_module': ('parent', 'security_health_analytics_custom_module', ), 'create_source': ('parent', 'source', ), 'delete_big_query_export': ('name', ), 'delete_mute_config': ('name', ), 'delete_notification_config': ('name', ), + 'delete_security_health_analytics_custom_module': ('name', ), 'get_big_query_export': ('name', ), + 'get_effective_security_health_analytics_custom_module': ('name', ), 'get_iam_policy': ('resource', 'options', ), 'get_mute_config': ('name', ), 'get_notification_config': ('name', ), 'get_organization_settings': ('name', ), + 'get_security_health_analytics_custom_module': ('name', ), 'get_source': ('name', ), 'group_assets': ('parent', 'group_by', 'filter', 'compare_duration', 'read_time', 'page_token', 'page_size', ), '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_big_query_exports': ('parent', 'page_size', 'page_token', ), + 'list_descendant_security_health_analytics_custom_modules': ('parent', 'page_size', 'page_token', ), + 'list_effective_security_health_analytics_custom_modules': ('parent', 'page_size', 'page_token', ), '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_security_health_analytics_custom_modules': ('parent', 'page_size', 'page_token', ), 'list_sources': ('parent', 'page_token', 'page_size', ), 'run_asset_discovery': ('parent', ), 'set_finding_state': ('name', 'state', 'start_time', ), @@ -73,6 +80,7 @@ class securitycenterCallTransformer(cst.CSTTransformer): 'update_mute_config': ('mute_config', 'update_mask', ), 'update_notification_config': ('notification_config', 'update_mask', ), 'update_organization_settings': ('organization_settings', 'update_mask', ), + 'update_security_health_analytics_custom_module': ('security_health_analytics_custom_module', 'update_mask', ), 'update_security_marks': ('security_marks', 'update_mask', 'start_time', ), 'update_source': ('source', 'update_mask', ), } diff --git a/packages/google-cloud-securitycenter/tests/unit/gapic/securitycenter_v1/test_security_center.py b/packages/google-cloud-securitycenter/tests/unit/gapic/securitycenter_v1/test_security_center.py index 0e9185a448f2..3e9413029d83 100644 --- a/packages/google-cloud-securitycenter/tests/unit/gapic/securitycenter_v1/test_security_center.py +++ b/packages/google-cloud-securitycenter/tests/unit/gapic/securitycenter_v1/test_security_center.py @@ -75,8 +75,14 @@ contact_details, container, database, + effective_security_health_analytics_custom_module, exfiltration, ) +from google.cloud.securitycenter_v1.types import ( + process, + run_asset_discovery_response, + security_health_analytics_custom_config, +) from google.cloud.securitycenter_v1.types import ( iam_binding, indicator, @@ -85,7 +91,6 @@ label, mitre_attack, ) -from google.cloud.securitycenter_v1.types import process, run_asset_discovery_response from google.cloud.securitycenter_v1.types import external_system as gcs_external_system from google.cloud.securitycenter_v1.types import ( notification_config as gcs_notification_config, @@ -93,6 +98,10 @@ from google.cloud.securitycenter_v1.types import ( organization_settings as gcs_organization_settings, ) +from google.cloud.securitycenter_v1.types import security_health_analytics_custom_module +from google.cloud.securitycenter_v1.types import ( + security_health_analytics_custom_module as gcs_security_health_analytics_custom_module, +) from google.cloud.securitycenter_v1.types import security_marks as gcs_security_marks from google.cloud.securitycenter_v1.types import external_system from google.cloud.securitycenter_v1.types import file @@ -1001,6 +1010,327 @@ async def test_bulk_mute_findings_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, + dict, + ], +) +def test_create_security_health_analytics_custom_module( + request_type, transport: str = "grpc" +): + 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.create_security_health_analytics_custom_module), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value", + display_name="display_name_value", + enablement_state=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, + last_editor="last_editor_value", + ancestor_module="ancestor_module_value", + ) + response = client.create_security_health_analytics_custom_module(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.CreateSecurityHealthAnalyticsCustomModuleRequest() + ) + + # Establish that the response is the type that we expect. + assert isinstance( + response, + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert ( + response.enablement_state + == gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) + assert response.last_editor == "last_editor_value" + assert response.ancestor_module == "ancestor_module_value" + + +def test_create_security_health_analytics_custom_module_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.create_security_health_analytics_custom_module), + "__call__", + ) as call: + client.create_security_health_analytics_custom_module() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert ( + args[0] + == securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest() + ) + + +@pytest.mark.asyncio +async def test_create_security_health_analytics_custom_module_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, +): + 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.create_security_health_analytics_custom_module), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value", + display_name="display_name_value", + enablement_state=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, + last_editor="last_editor_value", + ancestor_module="ancestor_module_value", + ) + ) + response = await client.create_security_health_analytics_custom_module(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.CreateSecurityHealthAnalyticsCustomModuleRequest() + ) + + # Establish that the response is the type that we expect. + assert isinstance( + response, + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert ( + response.enablement_state + == gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) + assert response.last_editor == "last_editor_value" + assert response.ancestor_module == "ancestor_module_value" + + +@pytest.mark.asyncio +async def test_create_security_health_analytics_custom_module_async_from_dict(): + await test_create_security_health_analytics_custom_module_async(request_type=dict) + + +def test_create_security_health_analytics_custom_module_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.CreateSecurityHealthAnalyticsCustomModuleRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_security_health_analytics_custom_module), + "__call__", + ) as call: + call.return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + client.create_security_health_analytics_custom_module(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_create_security_health_analytics_custom_module_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.CreateSecurityHealthAnalyticsCustomModuleRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_security_health_analytics_custom_module), + "__call__", + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + await client.create_security_health_analytics_custom_module(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_create_security_health_analytics_custom_module_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_security_health_analytics_custom_module), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_security_health_analytics_custom_module( + parent="parent_value", + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + 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].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].security_health_analytics_custom_module + mock_val = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ) + assert arg == mock_val + + +def test_create_security_health_analytics_custom_module_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_security_health_analytics_custom_module( + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest(), + parent="parent_value", + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ), + ) + + +@pytest.mark.asyncio +async def test_create_security_health_analytics_custom_module_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_security_health_analytics_custom_module), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_security_health_analytics_custom_module( + parent="parent_value", + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + 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].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].security_health_analytics_custom_module + mock_val = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_security_health_analytics_custom_module_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.create_security_health_analytics_custom_module( + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest(), + parent="parent_value", + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ), + ) + + @pytest.mark.parametrize( "request_type", [ @@ -1287,6 +1617,7 @@ def test_create_finding(request_type, transport: str = "grpc"): parent_display_name="parent_display_name_value", description="description_value", next_steps="next_steps_value", + module_name="module_name_value", ) response = client.create_finding(request) @@ -1311,6 +1642,7 @@ def test_create_finding(request_type, transport: str = "grpc"): assert response.parent_display_name == "parent_display_name_value" assert response.description == "description_value" assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" def test_create_finding_empty_call(): @@ -1362,6 +1694,7 @@ async def test_create_finding_async( parent_display_name="parent_display_name_value", description="description_value", next_steps="next_steps_value", + module_name="module_name_value", ) ) response = await client.create_finding(request) @@ -1387,6 +1720,7 @@ async def test_create_finding_async( assert response.parent_display_name == "parent_display_name_value" assert response.description == "description_value" assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" @pytest.mark.asyncio @@ -2599,11 +2933,13 @@ async def test_delete_notification_config_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GetBigQueryExportRequest, + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, dict, ], ) -def test_get_big_query_export(request_type, transport: str = "grpc"): +def test_delete_security_health_analytics_custom_module( + request_type, transport: str = "grpc" +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2615,16 +2951,267 @@ def test_get_big_query_export(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_big_query_export), "__call__" + type(client.transport.delete_security_health_analytics_custom_module), + "__call__", ) as call: # Designate an appropriate return value for the call. - call.return_value = bigquery_export.BigQueryExport( - name="name_value", - description="description_value", - filter="filter_value", - dataset="dataset_value", - most_recent_editor="most_recent_editor_value", - principal="principal_value", + call.return_value = None + response = client.delete_security_health_analytics_custom_module(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.DeleteSecurityHealthAnalyticsCustomModuleRequest() + ) + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_security_health_analytics_custom_module_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.delete_security_health_analytics_custom_module), + "__call__", + ) as call: + client.delete_security_health_analytics_custom_module() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert ( + args[0] + == securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest() + ) + + +@pytest.mark.asyncio +async def test_delete_security_health_analytics_custom_module_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, +): + 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.delete_security_health_analytics_custom_module), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_security_health_analytics_custom_module(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.DeleteSecurityHealthAnalyticsCustomModuleRequest() + ) + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_security_health_analytics_custom_module_async_from_dict(): + await test_delete_security_health_analytics_custom_module_async(request_type=dict) + + +def test_delete_security_health_analytics_custom_module_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.DeleteSecurityHealthAnalyticsCustomModuleRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_security_health_analytics_custom_module), + "__call__", + ) as call: + call.return_value = None + client.delete_security_health_analytics_custom_module(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_delete_security_health_analytics_custom_module_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.DeleteSecurityHealthAnalyticsCustomModuleRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_security_health_analytics_custom_module), + "__call__", + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_security_health_analytics_custom_module(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_delete_security_health_analytics_custom_module_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_security_health_analytics_custom_module), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_security_health_analytics_custom_module( + 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_delete_security_health_analytics_custom_module_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_security_health_analytics_custom_module( + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_security_health_analytics_custom_module_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_security_health_analytics_custom_module), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + + 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.delete_security_health_analytics_custom_module( + 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_delete_security_health_analytics_custom_module_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.delete_security_health_analytics_custom_module( + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.GetBigQueryExportRequest, + dict, + ], +) +def test_get_big_query_export(request_type, transport: str = "grpc"): + 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_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = bigquery_export.BigQueryExport( + name="name_value", + description="description_value", + filter="filter_value", + dataset="dataset_value", + most_recent_editor="most_recent_editor_value", + principal="principal_value", ) response = client.get_big_query_export(request) @@ -3877,11 +4464,13 @@ async def test_get_organization_settings_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GetSourceRequest, + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, dict, ], ) -def test_get_source(request_type, transport: str = "grpc"): +def test_get_effective_security_health_analytics_custom_module( + request_type, transport: str = "grpc" +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -3892,30 +4481,40 @@ def test_get_source(request_type, transport: str = "grpc"): 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_effective_security_health_analytics_custom_module), + "__call__", + ) as call: # Designate an appropriate return value for the call. - call.return_value = source.Source( + call.return_value = effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule( name="name_value", + enablement_state=effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, display_name="display_name_value", - description="description_value", - canonical_name="canonical_name_value", ) - response = client.get_source(request) + response = client.get_effective_security_health_analytics_custom_module(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.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest() + ) # Establish that the response is the type that we expect. - assert isinstance(response, source.Source) + assert isinstance( + response, + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, + ) assert response.name == "name_value" + assert ( + response.enablement_state + == effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.canonical_name == "canonical_name_value" -def test_get_source_empty_call(): +def test_get_effective_security_health_analytics_custom_module_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( @@ -3924,17 +4523,23 @@ 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_effective_security_health_analytics_custom_module), + "__call__", + ) as call: + client.get_effective_security_health_analytics_custom_module() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GetSourceRequest() + assert ( + args[0] + == securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest() + ) @pytest.mark.asyncio -async def test_get_source_async( +async def test_get_effective_security_health_analytics_custom_module_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.GetSourceRequest, + request_type=securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3946,51 +4551,72 @@ 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_effective_security_health_analytics_custom_module), + "__call__", + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - source.Source( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule( name="name_value", + enablement_state=effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, display_name="display_name_value", - description="description_value", - canonical_name="canonical_name_value", ) ) - response = await client.get_source(request) + response = await client.get_effective_security_health_analytics_custom_module( + 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.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest() + ) # Establish that the response is the type that we expect. - assert isinstance(response, source.Source) + assert isinstance( + response, + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, + ) assert response.name == "name_value" + assert ( + response.enablement_state + == effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) 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) +async def test_get_effective_security_health_analytics_custom_module_async_from_dict(): + await test_get_effective_security_health_analytics_custom_module_async( + request_type=dict + ) -def test_get_source_field_headers(): +def test_get_effective_security_health_analytics_custom_module_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.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest() + ) 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_effective_security_health_analytics_custom_module), + "__call__", + ) as call: + call.return_value = ( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule() + ) + client.get_effective_security_health_analytics_custom_module(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -4006,21 +4632,28 @@ def test_get_source_field_headers(): @pytest.mark.asyncio -async def test_get_source_field_headers_async(): +async def test_get_effective_security_health_analytics_custom_module_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.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest() + ) 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_effective_security_health_analytics_custom_module), + "__call__", + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule() + ) + await client.get_effective_security_health_analytics_custom_module(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -4035,18 +4668,23 @@ async def test_get_source_field_headers_async(): ) in kw["metadata"] -def test_get_source_flattened(): +def test_get_effective_security_health_analytics_custom_module_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_effective_security_health_analytics_custom_module), + "__call__", + ) as call: # Designate an appropriate return value for the call. - call.return_value = source.Source() + call.return_value = ( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_source( + client.get_effective_security_health_analytics_custom_module( name="name_value", ) @@ -4059,7 +4697,7 @@ def test_get_source_flattened(): assert arg == mock_val -def test_get_source_flattened_error(): +def test_get_effective_security_health_analytics_custom_module_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4067,27 +4705,34 @@ def test_get_source_flattened_error(): # 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(), + client.get_effective_security_health_analytics_custom_module( + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest(), name="name_value", ) @pytest.mark.asyncio -async def test_get_source_flattened_async(): +async def test_get_effective_security_health_analytics_custom_module_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_effective_security_health_analytics_custom_module), + "__call__", + ) as call: # Designate an appropriate return value for the call. - call.return_value = source.Source() + call.return_value = ( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule() + ) - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(source.Source()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_source( + response = await client.get_effective_security_health_analytics_custom_module( name="name_value", ) @@ -4101,7 +4746,7 @@ async def test_get_source_flattened_async(): @pytest.mark.asyncio -async def test_get_source_flattened_error_async(): +async def test_get_effective_security_health_analytics_custom_module_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4109,8 +4754,8 @@ 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(), + await client.get_effective_security_health_analytics_custom_module( + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest(), name="name_value", ) @@ -4118,11 +4763,13 @@ async def test_get_source_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GroupAssetsRequest, + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, dict, ], ) -def test_group_assets(request_type, transport: str = "grpc"): +def test_get_security_health_analytics_custom_module( + request_type, transport: str = "grpc" +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -4133,26 +4780,43 @@ def test_group_assets(request_type, transport: str = "grpc"): 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_security_health_analytics_custom_module), "__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 = security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value", + display_name="display_name_value", + enablement_state=security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, + last_editor="last_editor_value", + ancestor_module="ancestor_module_value", ) - response = client.group_assets(request) + response = client.get_security_health_analytics_custom_module(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.GetSecurityHealthAnalyticsCustomModuleRequest() + ) # 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, + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert ( + response.enablement_state + == security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) + assert response.last_editor == "last_editor_value" + assert response.ancestor_module == "ancestor_module_value" -def test_group_assets_empty_call(): +def test_get_security_health_analytics_custom_module_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( @@ -4161,17 +4825,22 @@ 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_security_health_analytics_custom_module), "__call__" + ) as call: + client.get_security_health_analytics_custom_module() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GroupAssetsRequest() + assert ( + args[0] + == securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest() + ) @pytest.mark.asyncio -async def test_group_assets_async( +async def test_get_security_health_analytics_custom_module_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.GroupAssetsRequest, + request_type=securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4183,47 +4852,68 @@ 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_security_health_analytics_custom_module), "__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, + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value", + display_name="display_name_value", + enablement_state=security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, + last_editor="last_editor_value", + ancestor_module="ancestor_module_value", ) ) - response = await client.group_assets(request) + response = await client.get_security_health_analytics_custom_module(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.GetSecurityHealthAnalyticsCustomModuleRequest() + ) # 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, + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert ( + response.enablement_state + == security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) + assert response.last_editor == "last_editor_value" + assert response.ancestor_module == "ancestor_module_value" @pytest.mark.asyncio -async def test_group_assets_async_from_dict(): - await test_group_assets_async(request_type=dict) +async def test_get_security_health_analytics_custom_module_async_from_dict(): + await test_get_security_health_analytics_custom_module_async(request_type=dict) -def test_group_assets_field_headers(): +def test_get_security_health_analytics_custom_module_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.GetSecurityHealthAnalyticsCustomModuleRequest() - 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_security_health_analytics_custom_module), "__call__" + ) as call: + call.return_value = ( + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + client.get_security_health_analytics_custom_module(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -4234,28 +4924,30 @@ def test_group_assets_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_group_assets_field_headers_async(): +async def test_get_security_health_analytics_custom_module_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.GetSecurityHealthAnalyticsCustomModuleRequest() - 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_security_health_analytics_custom_module), "__call__" + ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.GroupAssetsResponse() + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() ) - await client.group_assets(request) + await client.get_security_health_analytics_custom_module(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -4266,206 +4958,108 @@ async def test_group_assets_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] -def test_group_assets_pager(transport_name: str = "grpc"): +def test_get_security_health_analytics_custom_module_flattened(): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, + 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, + with mock.patch.object( + type(client.transport.get_security_health_analytics_custom_module), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_security_health_analytics_custom_module( + name="name_value", ) - pager = client.group_assets(request={}) - - assert pager._metadata == metadata - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) + # 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_group_assets_pages(transport_name: str = "grpc"): +def test_get_security_health_analytics_custom_module_flattened_error(): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, + 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, + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_security_health_analytics_custom_module( + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest(), + name="name_value", ) - 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(): +async def test_get_security_health_analytics_custom_module_flattened_async(): client = SecurityCenterAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + 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.get_security_health_analytics_custom_module), "__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, + # Designate an appropriate return value for the call. + call.return_value = ( + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() ) - async_pager = await client.group_assets( - request={}, + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_security_health_analytics_custom_module( + name="name_value", ) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - assert len(responses) == 6 - assert all(isinstance(i, securitycenter_service.GroupResult) for i in responses) + # 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_group_assets_async_pages(): +async def test_get_security_health_analytics_custom_module_flattened_error_async(): client = SecurityCenterAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + 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, + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_security_health_analytics_custom_module( + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest(), + name="name_value", ) - pages = [] - async for page_ in ( - await client.group_assets(request={}) - ).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GroupFindingsRequest, + securitycenter_service.GetSourceRequest, dict, ], ) -def test_group_findings(request_type, transport: str = "grpc"): +def test_get_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -4476,26 +5070,30 @@ def test_group_findings(request_type, transport: str = "grpc"): 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.get_source), "__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, + call.return_value = source.Source( + name="name_value", + display_name="display_name_value", + description="description_value", + canonical_name="canonical_name_value", ) - response = client.group_findings(request) + 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.GroupFindingsRequest() + assert args[0] == securitycenter_service.GetSourceRequest() # 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 + 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_group_findings_empty_call(): +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( @@ -4504,17 +5102,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.get_source), "__call__") as call: + client.get_source() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.GroupFindingsRequest() + assert args[0] == securitycenter_service.GetSourceRequest() @pytest.mark.asyncio -async def test_group_findings_async( +async def test_get_source_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.GroupFindingsRequest, + request_type=securitycenter_service.GetSourceRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4526,47 +5124,51 @@ 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.get_source), "__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, + source.Source( + name="name_value", + display_name="display_name_value", + description="description_value", + canonical_name="canonical_name_value", ) ) - response = await client.group_findings(request) + 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.GroupFindingsRequest() + assert args[0] == securitycenter_service.GetSourceRequest() # 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 + 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_group_findings_async_from_dict(): - await test_group_findings_async(request_type=dict) +async def test_get_source_async_from_dict(): + await test_get_source_async(request_type=dict) -def test_group_findings_field_headers(): +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.GroupFindingsRequest() + request = securitycenter_service.GetSourceRequest() - 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_findings), "__call__") as call: - call.return_value = securitycenter_service.GroupFindingsResponse() - client.group_findings(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 @@ -4577,28 +5179,26 @@ def test_group_findings_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_group_findings_field_headers_async(): +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.GroupFindingsRequest() + request = securitycenter_service.GetSourceRequest() - 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_findings), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.GroupFindingsResponse() - ) - await client.group_findings(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) @@ -4609,39 +5209,35 @@ async def test_group_findings_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "name=name_value", ) in kw["metadata"] -def test_group_findings_flattened(): +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.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.GroupFindingsResponse() + call.return_value = source.Source() # 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", + 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].parent - mock_val = "parent_value" - assert arg == mock_val - arg = args[0].group_by - mock_val = "group_by_value" + arg = args[0].name + mock_val = "name_value" assert arg == mock_val -def test_group_findings_flattened_error(): +def test_get_source_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4649,48 +5245,41 @@ def test_group_findings_flattened_error(): # 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", + client.get_source( + securitycenter_service.GetSourceRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_group_findings_flattened_async(): +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.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.GroupFindingsResponse() + call.return_value = source.Source() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.GroupFindingsResponse() - ) + 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.group_findings( - parent="parent_value", - group_by="group_by_value", + 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].parent - mock_val = "parent_value" - assert arg == mock_val - arg = args[0].group_by - mock_val = "group_by_value" + arg = args[0].name + mock_val = "name_value" assert arg == mock_val @pytest.mark.asyncio -async def test_group_findings_flattened_error_async(): +async def test_get_source_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4698,42 +5287,196 @@ async def test_group_findings_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.group_findings( - securitycenter_service.GroupFindingsRequest(), - parent="parent_value", - group_by="group_by_value", + await client.get_source( + securitycenter_service.GetSourceRequest(), + name="name_value", ) -def test_group_findings_pager(transport_name: str = "grpc"): +@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_name, + 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: - # 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", + 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_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(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: + # 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.GroupFindingsResponse( + 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.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -4746,7 +5489,7 @@ def test_group_findings_pager(transport_name: str = "grpc"): metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) - pager = client.group_findings(request={}) + pager = client.group_assets(request={}) assert pager._metadata == metadata @@ -4755,17 +5498,17 @@ def test_group_findings_pager(transport_name: str = "grpc"): assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) -def test_group_findings_pages(transport_name: str = "grpc"): +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_findings), "__call__") as call: + 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.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -4773,17 +5516,17 @@ def test_group_findings_pages(transport_name: str = "grpc"): ], next_page_token="abc", ), - securitycenter_service.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[], next_page_token="def", ), - securitycenter_service.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[ securitycenter_service.GroupResult(), ], next_page_token="ghi", ), - securitycenter_service.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -4791,24 +5534,24 @@ def test_group_findings_pages(transport_name: str = "grpc"): ), RuntimeError, ) - pages = list(client.group_findings(request={}).pages) + 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_findings_async_pager(): +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_findings), "__call__", new_callable=mock.AsyncMock + 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.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -4816,17 +5559,17 @@ async def test_group_findings_async_pager(): ], next_page_token="abc", ), - securitycenter_service.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[], next_page_token="def", ), - securitycenter_service.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[ securitycenter_service.GroupResult(), ], next_page_token="ghi", ), - securitycenter_service.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -4834,7 +5577,7 @@ async def test_group_findings_async_pager(): ), RuntimeError, ) - async_pager = await client.group_findings( + async_pager = await client.group_assets( request={}, ) assert async_pager.next_page_token == "abc" @@ -4847,18 +5590,18 @@ async def test_group_findings_async_pager(): @pytest.mark.asyncio -async def test_group_findings_async_pages(): +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_findings), "__call__", new_callable=mock.AsyncMock + 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.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -4866,17 +5609,17 @@ async def test_group_findings_async_pages(): ], next_page_token="abc", ), - securitycenter_service.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[], next_page_token="def", ), - securitycenter_service.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[ securitycenter_service.GroupResult(), ], next_page_token="ghi", ), - securitycenter_service.GroupFindingsResponse( + securitycenter_service.GroupAssetsResponse( group_by_results=[ securitycenter_service.GroupResult(), securitycenter_service.GroupResult(), @@ -4886,7 +5629,7 @@ async def test_group_findings_async_pages(): ) pages = [] async for page_ in ( - await client.group_findings(request={}) + await client.group_assets(request={}) ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): @@ -4896,11 +5639,11 @@ async def test_group_findings_async_pages(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListAssetsRequest, + securitycenter_service.GroupFindingsRequest, dict, ], ) -def test_list_assets(request_type, transport: str = "grpc"): +def test_group_findings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -4911,26 +5654,26 @@ def test_list_assets(request_type, transport: str = "grpc"): 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.group_findings), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListAssetsResponse( + call.return_value = securitycenter_service.GroupFindingsResponse( next_page_token="next_page_token_value", total_size=1086, ) - response = client.list_assets(request) + 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.ListAssetsRequest() + assert args[0] == securitycenter_service.GroupFindingsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListAssetsPager) + assert isinstance(response, pagers.GroupFindingsPager) assert response.next_page_token == "next_page_token_value" assert response.total_size == 1086 -def test_list_assets_empty_call(): +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( @@ -4939,17 +5682,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.group_findings), "__call__") as call: + client.group_findings() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.ListAssetsRequest() + assert args[0] == securitycenter_service.GroupFindingsRequest() @pytest.mark.asyncio -async def test_list_assets_async( +async def test_group_findings_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.ListAssetsRequest, + request_type=securitycenter_service.GroupFindingsRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4961,47 +5704,47 @@ 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.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListAssetsResponse( + securitycenter_service.GroupFindingsResponse( next_page_token="next_page_token_value", total_size=1086, ) ) - response = await client.list_assets(request) + 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.ListAssetsRequest() + assert args[0] == securitycenter_service.GroupFindingsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListAssetsAsyncPager) + 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_list_assets_async_from_dict(): - await test_list_assets_async(request_type=dict) +async def test_group_findings_async_from_dict(): + await test_group_findings_async(request_type=dict) -def test_list_assets_field_headers(): +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.ListAssetsRequest() + 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.list_assets), "__call__") as call: - call.return_value = securitycenter_service.ListAssetsResponse() - client.list_assets(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 @@ -5017,23 +5760,23 @@ def test_list_assets_field_headers(): @pytest.mark.asyncio -async def test_list_assets_field_headers_async(): +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.ListAssetsRequest() + 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.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListAssetsResponse() + securitycenter_service.GroupFindingsResponse() ) - await client.list_assets(request) + await client.group_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -5048,38 +5791,130 @@ async def test_list_assets_field_headers_async(): ) in kw["metadata"] -def test_list_assets_pager(transport_name: str = "grpc"): +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(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: + 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.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), ], next_page_token="abc", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[], + securitycenter_service.GroupFindingsResponse( + group_by_results=[], next_page_token="def", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), ], next_page_token="ghi", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), ], ), RuntimeError, @@ -5089,98 +5924,95 @@ def test_list_assets_pager(transport_name: str = "grpc"): metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) - pager = client.list_assets(request={}) + pager = client.group_findings(request={}) assert pager._metadata == metadata results = list(pager) assert len(results) == 6 - assert all( - isinstance(i, securitycenter_service.ListAssetsResponse.ListAssetsResult) - for i in results - ) + assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) -def test_list_assets_pages(transport_name: str = "grpc"): +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.list_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.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), ], next_page_token="abc", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[], + securitycenter_service.GroupFindingsResponse( + group_by_results=[], next_page_token="def", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), ], next_page_token="ghi", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), ], ), RuntimeError, ) - pages = list(client.list_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_list_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.list_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.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), ], next_page_token="abc", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[], + securitycenter_service.GroupFindingsResponse( + group_by_results=[], next_page_token="def", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), ], next_page_token="ghi", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), ], ), RuntimeError, ) - async_pager = await client.list_assets( + async_pager = await client.group_findings( request={}, ) assert async_pager.next_page_token == "abc" @@ -5189,53 +6021,50 @@ async def test_list_assets_async_pager(): responses.append(response) assert len(responses) == 6 - assert all( - isinstance(i, securitycenter_service.ListAssetsResponse.ListAssetsResult) - for i in responses - ) + assert all(isinstance(i, securitycenter_service.GroupResult) for i in responses) @pytest.mark.asyncio -async def test_list_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.list_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.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), ], next_page_token="abc", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[], + securitycenter_service.GroupFindingsResponse( + group_by_results=[], next_page_token="def", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), ], next_page_token="ghi", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.GroupFindingsResponse( + group_by_results=[ + securitycenter_service.GroupResult(), + securitycenter_service.GroupResult(), ], ), RuntimeError, ) pages = [] async for page_ in ( - await client.list_assets(request={}) + await client.group_findings(request={}) ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): @@ -5245,11 +6074,11 @@ async def test_list_assets_async_pages(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListFindingsRequest, + securitycenter_service.ListAssetsRequest, dict, ], ) -def test_list_findings(request_type, transport: str = "grpc"): +def test_list_assets(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -5260,26 +6089,26 @@ def test_list_findings(request_type, transport: str = "grpc"): 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_assets), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListFindingsResponse( + call.return_value = securitycenter_service.ListAssetsResponse( next_page_token="next_page_token_value", total_size=1086, ) - response = client.list_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.ListFindingsRequest() + assert args[0] == securitycenter_service.ListAssetsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListFindingsPager) + assert isinstance(response, pagers.ListAssetsPager) assert response.next_page_token == "next_page_token_value" assert response.total_size == 1086 -def test_list_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( @@ -5288,17 +6117,17 @@ 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_assets), "__call__") as call: + client.list_assets() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.ListFindingsRequest() + assert args[0] == securitycenter_service.ListAssetsRequest() @pytest.mark.asyncio -async def test_list_findings_async( +async def test_list_assets_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.ListFindingsRequest, + request_type=securitycenter_service.ListAssetsRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5310,47 +6139,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_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListFindingsResponse( + securitycenter_service.ListAssetsResponse( next_page_token="next_page_token_value", total_size=1086, ) ) - response = await client.list_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.ListFindingsRequest() + assert args[0] == securitycenter_service.ListAssetsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListFindingsAsyncPager) + 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_list_findings_async_from_dict(): - await test_list_findings_async(request_type=dict) +async def test_list_assets_async_from_dict(): + await test_list_assets_async(request_type=dict) -def test_list_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.ListFindingsRequest() + 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.list_findings), "__call__") as call: - call.return_value = securitycenter_service.ListFindingsResponse() - client.list_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 @@ -5366,23 +6195,23 @@ def test_list_findings_field_headers(): @pytest.mark.asyncio -async def test_list_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.ListFindingsRequest() + 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.list_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.ListFindingsResponse() + securitycenter_service.ListAssetsResponse() ) - await client.list_findings(request) + await client.list_assets(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -5397,38 +6226,38 @@ async def test_list_findings_field_headers_async(): ) in kw["metadata"] -def test_list_findings_pager(transport_name: str = "grpc"): +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_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.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="abc", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[], + securitycenter_service.ListAssetsResponse( + list_assets_results=[], next_page_token="def", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], ), RuntimeError, @@ -5438,100 +6267,98 @@ def test_list_findings_pager(transport_name: str = "grpc"): metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) - pager = client.list_findings(request={}) + pager = client.list_assets(request={}) assert pager._metadata == metadata results = list(pager) assert len(results) == 6 assert all( - isinstance( - i, securitycenter_service.ListFindingsResponse.ListFindingsResult - ) + isinstance(i, securitycenter_service.ListAssetsResponse.ListAssetsResult) for i in results ) -def test_list_findings_pages(transport_name: str = "grpc"): +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_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.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="abc", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[], + securitycenter_service.ListAssetsResponse( + list_assets_results=[], next_page_token="def", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], ), RuntimeError, ) - pages = list(client.list_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_list_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.list_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.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="abc", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[], + securitycenter_service.ListAssetsResponse( + list_assets_results=[], next_page_token="def", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], ), RuntimeError, ) - async_pager = await client.list_findings( + async_pager = await client.list_assets( request={}, ) assert async_pager.next_page_token == "abc" @@ -5541,54 +6368,52 @@ async def test_list_findings_async_pager(): assert len(responses) == 6 assert all( - isinstance( - i, securitycenter_service.ListFindingsResponse.ListFindingsResult - ) + isinstance(i, securitycenter_service.ListAssetsResponse.ListAssetsResult) for i in responses ) @pytest.mark.asyncio -async def test_list_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.list_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.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="abc", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[], + securitycenter_service.ListAssetsResponse( + list_assets_results=[], next_page_token="def", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), ], ), RuntimeError, ) pages = [] async for page_ in ( - await client.list_findings(request={}) + await client.list_assets(request={}) ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): @@ -5598,11 +6423,13 @@ async def test_list_findings_async_pages(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListMuteConfigsRequest, + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, dict, ], ) -def test_list_mute_configs(request_type, transport: str = "grpc"): +def test_list_descendant_security_health_analytics_custom_modules( + request_type, transport: str = "grpc" +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -5614,25 +6441,33 @@ def test_list_mute_configs(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_mute_configs), "__call__" + type(client.transport.list_descendant_security_health_analytics_custom_modules), + "__call__", ) as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListMuteConfigsResponse( + call.return_value = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( next_page_token="next_page_token_value", ) - response = client.list_mute_configs(request) + response = client.list_descendant_security_health_analytics_custom_modules( + 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.ListMuteConfigsRequest() + assert ( + args[0] + == securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest() + ) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListMuteConfigsPager) + assert isinstance( + response, pagers.ListDescendantSecurityHealthAnalyticsCustomModulesPager + ) assert response.next_page_token == "next_page_token_value" -def test_list_mute_configs_empty_call(): +def test_list_descendant_security_health_analytics_custom_modules_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( @@ -5642,18 +6477,22 @@ def test_list_mute_configs_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_mute_configs), "__call__" + type(client.transport.list_descendant_security_health_analytics_custom_modules), + "__call__", ) as call: - client.list_mute_configs() + client.list_descendant_security_health_analytics_custom_modules() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.ListMuteConfigsRequest() + assert ( + args[0] + == securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest() + ) @pytest.mark.asyncio -async def test_list_mute_configs_async( +async def test_list_descendant_security_health_analytics_custom_modules_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.ListMuteConfigsRequest, + request_type=securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5666,48 +6505,65 @@ async def test_list_mute_configs_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_mute_configs), "__call__" + type(client.transport.list_descendant_security_health_analytics_custom_modules), + "__call__", ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListMuteConfigsResponse( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( next_page_token="next_page_token_value", ) ) - response = await client.list_mute_configs(request) + response = ( + await client.list_descendant_security_health_analytics_custom_modules( + 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.ListMuteConfigsRequest() + assert ( + args[0] + == securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest() + ) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListMuteConfigsAsyncPager) + assert isinstance( + response, pagers.ListDescendantSecurityHealthAnalyticsCustomModulesAsyncPager + ) assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_list_mute_configs_async_from_dict(): - await test_list_mute_configs_async(request_type=dict) +async def test_list_descendant_security_health_analytics_custom_modules_async_from_dict(): + await test_list_descendant_security_health_analytics_custom_modules_async( + request_type=dict + ) -def test_list_mute_configs_field_headers(): +def test_list_descendant_security_health_analytics_custom_modules_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.ListMuteConfigsRequest() + request = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest() + ) request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_mute_configs), "__call__" + type(client.transport.list_descendant_security_health_analytics_custom_modules), + "__call__", ) as call: - call.return_value = securitycenter_service.ListMuteConfigsResponse() - client.list_mute_configs(request) + call.return_value = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse() + ) + client.list_descendant_security_health_analytics_custom_modules(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -5723,25 +6579,28 @@ def test_list_mute_configs_field_headers(): @pytest.mark.asyncio -async def test_list_mute_configs_field_headers_async(): +async def test_list_descendant_security_health_analytics_custom_modules_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.ListMuteConfigsRequest() + request = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest() + ) request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_mute_configs), "__call__" + type(client.transport.list_descendant_security_health_analytics_custom_modules), + "__call__", ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListMuteConfigsResponse() + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse() ) - await client.list_mute_configs(request) + await client.list_descendant_security_health_analytics_custom_modules(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -5756,20 +6615,23 @@ async def test_list_mute_configs_field_headers_async(): ) in kw["metadata"] -def test_list_mute_configs_flattened(): +def test_list_descendant_security_health_analytics_custom_modules_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__" + type(client.transport.list_descendant_security_health_analytics_custom_modules), + "__call__", ) as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListMuteConfigsResponse() + call.return_value = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_mute_configs( + client.list_descendant_security_health_analytics_custom_modules( parent="parent_value", ) @@ -5782,7 +6644,7 @@ def test_list_mute_configs_flattened(): assert arg == mock_val -def test_list_mute_configs_flattened_error(): +def test_list_descendant_security_health_analytics_custom_modules_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5790,32 +6652,37 @@ def test_list_mute_configs_flattened_error(): # 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(), + client.list_descendant_security_health_analytics_custom_modules( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest(), parent="parent_value", ) @pytest.mark.asyncio -async def test_list_mute_configs_flattened_async(): +async def test_list_descendant_security_health_analytics_custom_modules_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__" + type(client.transport.list_descendant_security_health_analytics_custom_modules), + "__call__", ) as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListMuteConfigsResponse() + call.return_value = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse() + ) call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListMuteConfigsResponse() + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse() ) # 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", + response = ( + await client.list_descendant_security_health_analytics_custom_modules( + parent="parent_value", + ) ) # Establish that the underlying call was made with the expected @@ -5828,7 +6695,7 @@ async def test_list_mute_configs_flattened_async(): @pytest.mark.asyncio -async def test_list_mute_configs_flattened_error_async(): +async def test_list_descendant_security_health_analytics_custom_modules_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5836,13 +6703,15 @@ async def test_list_mute_configs_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.list_mute_configs( - securitycenter_service.ListMuteConfigsRequest(), + await client.list_descendant_security_health_analytics_custom_modules( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest(), parent="parent_value", ) -def test_list_mute_configs_pager(transport_name: str = "grpc"): +def test_list_descendant_security_health_analytics_custom_modules_pager( + transport_name: str = "grpc", +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials, transport=transport_name, @@ -5850,32 +6719,33 @@ def test_list_mute_configs_pager(transport_name: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_mute_configs), "__call__" + type(client.transport.list_descendant_security_health_analytics_custom_modules), + "__call__", ) as call: # 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(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], next_page_token="abc", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[], + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[], next_page_token="def", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], next_page_token="ghi", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), - mute_config.MuteConfig(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], ), RuntimeError, @@ -5885,16 +6755,26 @@ def test_list_mute_configs_pager(transport_name: str = "grpc"): metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) - pager = client.list_mute_configs(request={}) + pager = client.list_descendant_security_health_analytics_custom_modules( + request={} + ) assert pager._metadata == metadata results = list(pager) assert len(results) == 6 - assert all(isinstance(i, mute_config.MuteConfig) for i in results) + assert all( + isinstance( + i, + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + for i in results + ) -def test_list_mute_configs_pages(transport_name: str = "grpc"): +def test_list_descendant_security_health_analytics_custom_modules_pages( + transport_name: str = "grpc", +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials, transport=transport_name, @@ -5902,83 +6782,90 @@ def test_list_mute_configs_pages(transport_name: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_mute_configs), "__call__" + type(client.transport.list_descendant_security_health_analytics_custom_modules), + "__call__", ) as call: # 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(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], next_page_token="abc", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[], + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[], next_page_token="def", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], next_page_token="ghi", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), - mute_config.MuteConfig(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], ), RuntimeError, ) - pages = list(client.list_mute_configs(request={}).pages) + pages = list( + client.list_descendant_security_health_analytics_custom_modules( + 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_mute_configs_async_pager(): +async def test_list_descendant_security_health_analytics_custom_modules_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_mute_configs), + type(client.transport.list_descendant_security_health_analytics_custom_modules), "__call__", new_callable=mock.AsyncMock, ) as call: # 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(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], next_page_token="abc", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[], + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[], next_page_token="def", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], next_page_token="ghi", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), - mute_config.MuteConfig(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], ), RuntimeError, ) - async_pager = await client.list_mute_configs( - request={}, + async_pager = ( + await client.list_descendant_security_health_analytics_custom_modules( + request={}, + ) ) assert async_pager.next_page_token == "abc" responses = [] @@ -5986,52 +6873,60 @@ async def test_list_mute_configs_async_pager(): responses.append(response) assert len(responses) == 6 - assert all(isinstance(i, mute_config.MuteConfig) for i in responses) + assert all( + isinstance( + i, + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + for i in responses + ) @pytest.mark.asyncio -async def test_list_mute_configs_async_pages(): +async def test_list_descendant_security_health_analytics_custom_modules_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_mute_configs), + type(client.transport.list_descendant_security_health_analytics_custom_modules), "__call__", new_callable=mock.AsyncMock, ) as call: # 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(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], next_page_token="abc", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[], + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[], next_page_token="def", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], next_page_token="ghi", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), - mute_config.MuteConfig(), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], ), RuntimeError, ) pages = [] async for page_ in ( - await client.list_mute_configs(request={}) + await client.list_descendant_security_health_analytics_custom_modules( + request={} + ) ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): @@ -6041,11 +6936,11 @@ async def test_list_mute_configs_async_pages(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListNotificationConfigsRequest, + securitycenter_service.ListFindingsRequest, dict, ], ) -def test_list_notification_configs(request_type, transport: str = "grpc"): +def test_list_findings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -6056,26 +6951,26 @@ def test_list_notification_configs(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_notification_configs), "__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.ListNotificationConfigsResponse( + call.return_value = securitycenter_service.ListFindingsResponse( next_page_token="next_page_token_value", + total_size=1086, ) - response = client.list_notification_configs(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.ListNotificationConfigsRequest() + assert args[0] == securitycenter_service.ListFindingsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListNotificationConfigsPager) + assert isinstance(response, pagers.ListFindingsPager) assert response.next_page_token == "next_page_token_value" + assert response.total_size == 1086 -def test_list_notification_configs_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( @@ -6084,19 +6979,17 @@ def test_list_notification_configs_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_notification_configs), "__call__" - ) as call: - client.list_notification_configs() + 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.ListNotificationConfigsRequest() + assert args[0] == securitycenter_service.ListFindingsRequest() @pytest.mark.asyncio -async def test_list_notification_configs_async( +async def test_list_findings_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.ListNotificationConfigsRequest, + request_type=securitycenter_service.ListFindingsRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6108,49 +7001,47 @@ async def test_list_notification_configs_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_notification_configs), "__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.ListNotificationConfigsResponse( + securitycenter_service.ListFindingsResponse( next_page_token="next_page_token_value", + total_size=1086, ) ) - response = await client.list_notification_configs(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.ListNotificationConfigsRequest() + assert args[0] == securitycenter_service.ListFindingsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListNotificationConfigsAsyncPager) + 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_notification_configs_async_from_dict(): - await test_list_notification_configs_async(request_type=dict) +async def test_list_findings_async_from_dict(): + await test_list_findings_async(request_type=dict) -def test_list_notification_configs_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.ListNotificationConfigsRequest() + 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_notification_configs), "__call__" - ) as call: - call.return_value = securitycenter_service.ListNotificationConfigsResponse() - client.list_notification_configs(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 @@ -6166,25 +7057,23 @@ def test_list_notification_configs_field_headers(): @pytest.mark.asyncio -async def test_list_notification_configs_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.ListNotificationConfigsRequest() + 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_notification_configs), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListNotificationConfigsResponse() + securitycenter_service.ListFindingsResponse() ) - await client.list_notification_configs(request) + await client.list_findings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6199,230 +7088,141 @@ async def test_list_notification_configs_field_headers_async(): ) in kw["metadata"] -def test_list_notification_configs_flattened(): +def test_list_findings_pager(transport_name: str = "grpc"): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), + 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_notification_configs), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListNotificationConfigsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_notification_configs( - parent="parent_value", + 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.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + ], + next_page_token="abc", + ), + securitycenter_service.ListFindingsResponse( + list_findings_results=[], + next_page_token="def", + ), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + ], + ), + RuntimeError, ) - # 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 - + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_findings(request={}) -def test_list_notification_configs_flattened_error(): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - ) + assert pager._metadata == metadata - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_notification_configs( - securitycenter_service.ListNotificationConfigsRequest(), - parent="parent_value", + results = list(pager) + assert len(results) == 6 + assert all( + isinstance( + i, securitycenter_service.ListFindingsResponse.ListFindingsResult + ) + for i in results ) -@pytest.mark.asyncio -async def test_list_notification_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_notification_configs), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListNotificationConfigsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListNotificationConfigsResponse() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_notification_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_notification_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_notification_configs( - securitycenter_service.ListNotificationConfigsRequest(), - parent="parent_value", - ) - - -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( - type(client.transport.list_notification_configs), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), - ], - next_page_token="abc", - ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[], - next_page_token="def", - ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - ], - next_page_token="ghi", - ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), - ) - pager = client.list_notification_configs(request={}) - - assert pager._metadata == metadata - - results = list(pager) - assert len(results) == 6 - assert all( - isinstance(i, notification_config.NotificationConfig) for i in results - ) - - -def test_list_notification_configs_pages(transport_name: str = "grpc"): +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_notification_configs), "__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.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="abc", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[], + securitycenter_service.ListFindingsResponse( + list_findings_results=[], next_page_token="def", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], ), RuntimeError, ) - pages = list(client.list_notification_configs(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_notification_configs_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_notification_configs), - "__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.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="abc", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[], + securitycenter_service.ListFindingsResponse( + list_findings_results=[], next_page_token="def", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], ), RuntimeError, ) - async_pager = await client.list_notification_configs( + async_pager = await client.list_findings( request={}, ) assert async_pager.next_page_token == "abc" @@ -6432,53 +7232,54 @@ async def test_list_notification_configs_async_pager(): assert len(responses) == 6 assert all( - isinstance(i, notification_config.NotificationConfig) for i in responses + isinstance( + i, securitycenter_service.ListFindingsResponse.ListFindingsResult + ) + for i in responses ) @pytest.mark.asyncio -async def test_list_notification_configs_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_notification_configs), - "__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.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="abc", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[], + securitycenter_service.ListFindingsResponse( + list_findings_results=[], next_page_token="def", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="ghi", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], ), RuntimeError, ) pages = [] async for page_ in ( - await client.list_notification_configs(request={}) + await client.list_findings(request={}) ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): @@ -6488,11 +7289,11 @@ async def test_list_notification_configs_async_pages(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListSourcesRequest, + securitycenter_service.ListMuteConfigsRequest, dict, ], ) -def test_list_sources(request_type, transport: str = "grpc"): +def test_list_mute_configs(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -6503,24 +7304,26 @@ def test_list_sources(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_sources), "__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.ListSourcesResponse( + call.return_value = securitycenter_service.ListMuteConfigsResponse( next_page_token="next_page_token_value", ) - response = client.list_sources(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.ListSourcesRequest() + assert args[0] == securitycenter_service.ListMuteConfigsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSourcesPager) + assert isinstance(response, pagers.ListMuteConfigsPager) assert response.next_page_token == "next_page_token_value" -def test_list_sources_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( @@ -6529,17 +7332,19 @@ def test_list_sources_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_sources), "__call__") as call: - client.list_sources() + 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.ListSourcesRequest() + assert args[0] == securitycenter_service.ListMuteConfigsRequest() @pytest.mark.asyncio -async def test_list_sources_async( +async def test_list_mute_configs_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.ListSourcesRequest, + request_type=securitycenter_service.ListMuteConfigsRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6551,45 +7356,49 @@ async def test_list_sources_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_sources), "__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.ListSourcesResponse( + securitycenter_service.ListMuteConfigsResponse( next_page_token="next_page_token_value", ) ) - response = await client.list_sources(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.ListSourcesRequest() + assert args[0] == securitycenter_service.ListMuteConfigsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSourcesAsyncPager) + assert isinstance(response, pagers.ListMuteConfigsAsyncPager) assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_list_sources_async_from_dict(): - await test_list_sources_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_sources_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.ListSourcesRequest() + 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_sources), "__call__") as call: - call.return_value = securitycenter_service.ListSourcesResponse() - client.list_sources(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 @@ -6605,23 +7414,25 @@ def test_list_sources_field_headers(): @pytest.mark.asyncio -async def test_list_sources_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.ListSourcesRequest() + 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_sources), "__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.ListSourcesResponse() + securitycenter_service.ListMuteConfigsResponse() ) - await client.list_sources(request) + await client.list_mute_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6636,18 +7447,20 @@ async def test_list_sources_field_headers_async(): ) in kw["metadata"] -def test_list_sources_flattened(): +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_sources), "__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.ListSourcesResponse() + 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_sources( + client.list_mute_configs( parent="parent_value", ) @@ -6660,7 +7473,7 @@ def test_list_sources_flattened(): assert arg == mock_val -def test_list_sources_flattened_error(): +def test_list_mute_configs_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6668,29 +7481,31 @@ def test_list_sources_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_sources( - securitycenter_service.ListSourcesRequest(), + client.list_mute_configs( + securitycenter_service.ListMuteConfigsRequest(), parent="parent_value", ) @pytest.mark.asyncio -async def test_list_sources_flattened_async(): +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_sources), "__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.ListSourcesResponse() + call.return_value = securitycenter_service.ListMuteConfigsResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListSourcesResponse() + 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_sources( + response = await client.list_mute_configs( parent="parent_value", ) @@ -6704,7 +7519,7 @@ async def test_list_sources_flattened_async(): @pytest.mark.asyncio -async def test_list_sources_flattened_error_async(): +async def test_list_mute_configs_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6712,44 +7527,46 @@ async def test_list_sources_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.list_sources( - securitycenter_service.ListSourcesRequest(), + await client.list_mute_configs( + securitycenter_service.ListMuteConfigsRequest(), parent="parent_value", ) -def test_list_sources_pager(transport_name: str = "grpc"): +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(type(client.transport.list_sources), "__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.ListSourcesResponse( - sources=[ - source.Source(), - source.Source(), - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], next_page_token="abc", ), - securitycenter_service.ListSourcesResponse( - sources=[], + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[], next_page_token="def", ), - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), ], next_page_token="ghi", ), - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], ), RuntimeError, @@ -6759,95 +7576,99 @@ def test_list_sources_pager(transport_name: str = "grpc"): metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) - pager = client.list_sources(request={}) + pager = client.list_mute_configs(request={}) assert pager._metadata == metadata results = list(pager) assert len(results) == 6 - assert all(isinstance(i, source.Source) for i in results) + assert all(isinstance(i, mute_config.MuteConfig) for i in results) -def test_list_sources_pages(transport_name: str = "grpc"): +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(type(client.transport.list_sources), "__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.ListSourcesResponse( - sources=[ - source.Source(), - source.Source(), - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], next_page_token="abc", ), - securitycenter_service.ListSourcesResponse( - sources=[], + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[], next_page_token="def", ), - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), ], next_page_token="ghi", ), - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], ), RuntimeError, ) - pages = list(client.list_sources(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_sources_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_sources), "__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.ListSourcesResponse( - sources=[ - source.Source(), - source.Source(), - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], next_page_token="abc", ), - securitycenter_service.ListSourcesResponse( - sources=[], + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[], next_page_token="def", ), - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), ], next_page_token="ghi", ), - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], ), RuntimeError, ) - async_pager = await client.list_sources( + async_pager = await client.list_mute_configs( request={}, ) assert async_pager.next_page_token == "abc" @@ -6856,50 +7677,52 @@ async def test_list_sources_async_pager(): responses.append(response) assert len(responses) == 6 - assert all(isinstance(i, source.Source) for i in responses) + assert all(isinstance(i, mute_config.MuteConfig) for i in responses) @pytest.mark.asyncio -async def test_list_sources_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_sources), "__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.ListSourcesResponse( - sources=[ - source.Source(), - source.Source(), - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], next_page_token="abc", ), - securitycenter_service.ListSourcesResponse( - sources=[], + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[], next_page_token="def", ), - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), ], next_page_token="ghi", ), - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), - source.Source(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], ), RuntimeError, ) pages = [] async for page_ in ( - await client.list_sources(request={}) + await client.list_mute_configs(request={}) ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): @@ -6909,11 +7732,11 @@ async def test_list_sources_async_pages(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.RunAssetDiscoveryRequest, + securitycenter_service.ListNotificationConfigsRequest, dict, ], ) -def test_run_asset_discovery(request_type, transport: str = "grpc"): +def test_list_notification_configs(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -6925,22 +7748,25 @@ def test_run_asset_discovery(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.run_asset_discovery), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.run_asset_discovery(request) + call.return_value = securitycenter_service.ListNotificationConfigsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_notification_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.RunAssetDiscoveryRequest() + assert args[0] == securitycenter_service.ListNotificationConfigsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + assert isinstance(response, pagers.ListNotificationConfigsPager) + assert response.next_page_token == "next_page_token_value" -def test_run_asset_discovery_empty_call(): +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. client = SecurityCenterClient( @@ -6950,18 +7776,18 @@ def test_run_asset_discovery_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.run_asset_discovery), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: - client.run_asset_discovery() + client.list_notification_configs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.RunAssetDiscoveryRequest() + assert args[0] == securitycenter_service.ListNotificationConfigsRequest() @pytest.mark.asyncio -async def test_run_asset_discovery_async( +async def test_list_notification_configs_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.RunAssetDiscoveryRequest, + request_type=securitycenter_service.ListNotificationConfigsRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6974,45 +7800,48 @@ async def test_run_asset_discovery_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.run_asset_discovery), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + securitycenter_service.ListNotificationConfigsResponse( + next_page_token="next_page_token_value", + ) ) - response = await client.run_asset_discovery(request) + response = await client.list_notification_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.RunAssetDiscoveryRequest() + assert args[0] == securitycenter_service.ListNotificationConfigsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + assert isinstance(response, pagers.ListNotificationConfigsAsyncPager) + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_run_asset_discovery_async_from_dict(): - await test_run_asset_discovery_async(request_type=dict) +async def test_list_notification_configs_async_from_dict(): + await test_list_notification_configs_async(request_type=dict) -def test_run_asset_discovery_field_headers(): +def test_list_notification_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.RunAssetDiscoveryRequest() + request = securitycenter_service.ListNotificationConfigsRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.run_asset_discovery), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.run_asset_discovery(request) + call.return_value = securitycenter_service.ListNotificationConfigsResponse() + client.list_notification_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -7028,25 +7857,25 @@ def test_run_asset_discovery_field_headers(): @pytest.mark.asyncio -async def test_run_asset_discovery_field_headers_async(): +async def test_list_notification_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.RunAssetDiscoveryRequest() + request = securitycenter_service.ListNotificationConfigsRequest() request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.run_asset_discovery), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") + securitycenter_service.ListNotificationConfigsResponse() ) - await client.run_asset_discovery(request) + await client.list_notification_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -7061,20 +7890,20 @@ async def test_run_asset_discovery_field_headers_async(): ) in kw["metadata"] -def test_run_asset_discovery_flattened(): +def test_list_notification_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.run_asset_discovery), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = securitycenter_service.ListNotificationConfigsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.run_asset_discovery( + client.list_notification_configs( parent="parent_value", ) @@ -7087,7 +7916,7 @@ def test_run_asset_discovery_flattened(): assert arg == mock_val -def test_run_asset_discovery_flattened_error(): +def test_list_notification_configs_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7095,31 +7924,31 @@ def test_run_asset_discovery_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.run_asset_discovery( - securitycenter_service.RunAssetDiscoveryRequest(), + client.list_notification_configs( + securitycenter_service.ListNotificationConfigsRequest(), parent="parent_value", ) @pytest.mark.asyncio -async def test_run_asset_discovery_flattened_async(): +async def test_list_notification_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.run_asset_discovery), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = securitycenter_service.ListNotificationConfigsResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + securitycenter_service.ListNotificationConfigsResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.run_asset_discovery( + response = await client.list_notification_configs( parent="parent_value", ) @@ -7133,7 +7962,7 @@ async def test_run_asset_discovery_flattened_async(): @pytest.mark.asyncio -async def test_run_asset_discovery_flattened_error_async(): +async def test_list_notification_configs_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7141,177 +7970,354 @@ async def test_run_asset_discovery_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.run_asset_discovery( - securitycenter_service.RunAssetDiscoveryRequest(), + await client.list_notification_configs( + securitycenter_service.ListNotificationConfigsRequest(), parent="parent_value", ) -@pytest.mark.parametrize( - "request_type", - [ - securitycenter_service.SetFindingStateRequest, - dict, - ], -) -def test_set_finding_state(request_type, transport: str = "grpc"): +def test_list_notification_configs_pager(transport_name: str = "grpc"): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) - # 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_finding_state), "__call__" + type(client.transport.list_notification_configs), "__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", - parent_display_name="parent_display_name_value", - description="description_value", - next_steps="next_steps_value", + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + ], + next_page_token="abc", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[], + next_page_token="def", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + ], + ), + RuntimeError, ) - response = client.set_finding_state(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.SetFindingStateRequest() + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_notification_configs(request={}) - # 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" - assert response.parent_display_name == "parent_display_name_value" - assert response.description == "description_value" - assert response.next_steps == "next_steps_value" + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all( + isinstance(i, notification_config.NotificationConfig) for i in results + ) -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. +def test_list_notification_configs_pages(transport_name: str = "grpc"): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + 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.set_finding_state), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: - client.set_finding_state() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.SetFindingStateRequest() + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + ], + next_page_token="abc", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[], + next_page_token="def", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + ], + ), + RuntimeError, + ) + pages = list(client.list_notification_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_set_finding_state_async( - transport: str = "grpc_asyncio", - request_type=securitycenter_service.SetFindingStateRequest, -): +async def test_list_notification_configs_async_pager(): client = SecurityCenterAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + credentials=ga_credentials.AnonymousCredentials, ) - # 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_finding_state), "__call__" + type(client.transport.list_notification_configs), + "__call__", + new_callable=mock.AsyncMock, ) 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", - parent_display_name="parent_display_name_value", - description="description_value", - next_steps="next_steps_value", - ) + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + ], + next_page_token="abc", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[], + next_page_token="def", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + ], + ), + RuntimeError, ) - response = await client.set_finding_state(request) + async_pager = await client.list_notification_configs( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.SetFindingStateRequest() + assert len(responses) == 6 + assert all( + isinstance(i, notification_config.NotificationConfig) for i in responses + ) + + +@pytest.mark.asyncio +async def test_list_notification_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_notification_configs), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + ], + next_page_token="abc", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[], + next_page_token="def", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_notification_configs(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, + dict, + ], +) +def test_list_effective_security_health_analytics_custom_modules( + request_type, transport: str = "grpc" +): + 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.list_effective_security_health_analytics_custom_modules), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + next_page_token="next_page_token_value", + ) + response = client.list_effective_security_health_analytics_custom_modules( + 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.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest() + ) # 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" - assert response.parent_display_name == "parent_display_name_value" - assert response.description == "description_value" - assert response.next_steps == "next_steps_value" + assert isinstance( + response, pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesPager + ) + assert response.next_page_token == "next_page_token_value" + + +def test_list_effective_security_health_analytics_custom_modules_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.list_effective_security_health_analytics_custom_modules), + "__call__", + ) as call: + client.list_effective_security_health_analytics_custom_modules() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert ( + args[0] + == securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest() + ) @pytest.mark.asyncio -async def test_set_finding_state_async_from_dict(): - await test_set_finding_state_async(request_type=dict) +async def test_list_effective_security_health_analytics_custom_modules_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, +): + 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.list_effective_security_health_analytics_custom_modules), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_effective_security_health_analytics_custom_modules( + request + ) -def test_set_finding_state_field_headers(): + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert ( + args[0] + == securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest() + ) + + # Establish that the response is the type that we expect. + assert isinstance( + response, pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesAsyncPager + ) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_effective_security_health_analytics_custom_modules_async_from_dict(): + await test_list_effective_security_health_analytics_custom_modules_async( + request_type=dict + ) + + +def test_list_effective_security_health_analytics_custom_modules_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.SetFindingStateRequest() + request = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest() + ) - 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.set_finding_state), "__call__" + type(client.transport.list_effective_security_health_analytics_custom_modules), + "__call__", ) as call: - call.return_value = finding.Finding() - client.set_finding_state(request) + call.return_value = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse() + ) + client.list_effective_security_health_analytics_custom_modules(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -7322,28 +8328,33 @@ def test_set_finding_state_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "parent=parent_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_set_finding_state_field_headers_async(): +async def test_list_effective_security_health_analytics_custom_modules_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.SetFindingStateRequest() + request = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest() + ) - 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.set_finding_state), "__call__" + type(client.transport.list_effective_security_health_analytics_custom_modules), + "__call__", ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) - await client.set_finding_state(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse() + ) + await client.list_effective_security_health_analytics_custom_modules(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -7354,45 +8365,40 @@ async def test_set_finding_state_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "parent=parent_value", ) in kw["metadata"] -def test_set_finding_state_flattened(): +def test_list_effective_security_health_analytics_custom_modules_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__" + type(client.transport.list_effective_security_health_analytics_custom_modules), + "__call__", ) as call: # Designate an appropriate return value for the call. - call.return_value = finding.Finding() + call.return_value = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse() + ) # 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.list_effective_security_health_analytics_custom_modules( + 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].name - mock_val = "name_value" - assert arg == mock_val - arg = args[0].state - mock_val = finding.Finding.State.ACTIVE + arg = args[0].parent + mock_val = "parent_value" 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_list_effective_security_health_analytics_custom_modules_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7400,53 +8406,48 @@ def test_set_finding_state_flattened_error(): # 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), + client.list_effective_security_health_analytics_custom_modules( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_set_finding_state_flattened_async(): +async def test_list_effective_security_health_analytics_custom_modules_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__" + type(client.transport.list_effective_security_health_analytics_custom_modules), + "__call__", ) as call: # Designate an appropriate return value for the call. - call.return_value = finding.Finding() + call.return_value = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse() + ) - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse() + ) # 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.list_effective_security_health_analytics_custom_modules( + 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].name - mock_val = "name_value" - assert arg == mock_val - arg = args[0].state - mock_val = finding.Finding.State.ACTIVE + arg = args[0].parent + mock_val = "parent_value" 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_list_effective_security_health_analytics_custom_modules_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7454,76 +8455,281 @@ 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(), - name="name_value", - state=finding.Finding.State.ACTIVE, - start_time=timestamp_pb2.Timestamp(seconds=751), + await client.list_effective_security_health_analytics_custom_modules( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest(), + parent="parent_value", ) -@pytest.mark.parametrize( - "request_type", - [ - securitycenter_service.SetMuteRequest, - dict, - ], -) -def test_set_mute(request_type, transport: str = "grpc"): +def test_list_effective_security_health_analytics_custom_modules_pager( + transport_name: str = "grpc", +): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) - # 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", - parent_display_name="parent_display_name_value", - description="description_value", - next_steps="next_steps_value", + with mock.patch.object( + type(client.transport.list_effective_security_health_analytics_custom_modules), + "__call__", + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + next_page_token="abc", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[], + next_page_token="def", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + ), + RuntimeError, ) - response = client.set_mute(request) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_effective_security_health_analytics_custom_modules( + request={} + ) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all( + isinstance( + i, + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, + ) + for i in results + ) + + +def test_list_effective_security_health_analytics_custom_modules_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_effective_security_health_analytics_custom_modules), + "__call__", + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + next_page_token="abc", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[], + next_page_token="def", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + ), + RuntimeError, + ) + pages = list( + client.list_effective_security_health_analytics_custom_modules( + 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_effective_security_health_analytics_custom_modules_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_effective_security_health_analytics_custom_modules), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + next_page_token="abc", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[], + next_page_token="def", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + ), + RuntimeError, + ) + async_pager = ( + await client.list_effective_security_health_analytics_custom_modules( + request={}, + ) + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance( + i, + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, + ) + for i in responses + ) + + +@pytest.mark.asyncio +async def test_list_effective_security_health_analytics_custom_modules_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_effective_security_health_analytics_custom_modules), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + next_page_token="abc", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[], + next_page_token="def", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_effective_security_health_analytics_custom_modules( + request={} + ) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, + dict, + ], +) +def test_list_security_health_analytics_custom_modules( + request_type, transport: str = "grpc" +): + 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.list_security_health_analytics_custom_modules), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + next_page_token="next_page_token_value", + ) + ) + response = client.list_security_health_analytics_custom_modules(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() + assert ( + args[0] + == securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest() + ) # 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" - assert response.parent_display_name == "parent_display_name_value" - assert response.description == "description_value" - assert response.next_steps == "next_steps_value" + assert isinstance(response, pagers.ListSecurityHealthAnalyticsCustomModulesPager) + assert response.next_page_token == "next_page_token_value" -def test_set_mute_empty_call(): +def test_list_security_health_analytics_custom_modules_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( @@ -7532,16 +8738,22 @@ def test_set_mute_empty_call(): ) # 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() + with mock.patch.object( + type(client.transport.list_security_health_analytics_custom_modules), "__call__" + ) as call: + client.list_security_health_analytics_custom_modules() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.SetMuteRequest() + assert ( + args[0] + == securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest() + ) @pytest.mark.asyncio -async def test_set_mute_async( - transport: str = "grpc_asyncio", request_type=securitycenter_service.SetMuteRequest +async def test_list_security_health_analytics_custom_modules_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7553,71 +8765,56 @@ async def test_set_mute_async( 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: + with mock.patch.object( + type(client.transport.list_security_health_analytics_custom_modules), "__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", - parent_display_name="parent_display_name_value", - description="description_value", - next_steps="next_steps_value", + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + next_page_token="next_page_token_value", ) ) - response = await client.set_mute(request) + response = await client.list_security_health_analytics_custom_modules(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() + assert ( + args[0] + == securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest() + ) # 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" - assert response.parent_display_name == "parent_display_name_value" - assert response.description == "description_value" - assert response.next_steps == "next_steps_value" + assert isinstance( + response, pagers.ListSecurityHealthAnalyticsCustomModulesAsyncPager + ) + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_set_mute_async_from_dict(): - await test_set_mute_async(request_type=dict) +async def test_list_security_health_analytics_custom_modules_async_from_dict(): + await test_list_security_health_analytics_custom_modules_async(request_type=dict) -def test_set_mute_field_headers(): +def test_list_security_health_analytics_custom_modules_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 = securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest() - 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.set_mute), "__call__") as call: - call.return_value = finding.Finding() - client.set_mute(request) + with mock.patch.object( + type(client.transport.list_security_health_analytics_custom_modules), "__call__" + ) as call: + call.return_value = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse() + ) + client.list_security_health_analytics_custom_modules(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -7628,26 +8825,30 @@ def test_set_mute_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "parent=parent_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_set_mute_field_headers_async(): +async def test_list_security_health_analytics_custom_modules_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 = securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest() - 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.set_mute), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) - await client.set_mute(request) + with mock.patch.object( + type(client.transport.list_security_health_analytics_custom_modules), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse() + ) + await client.list_security_health_analytics_custom_modules(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -7658,39 +8859,39 @@ async def test_set_mute_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "parent=parent_value", ) in kw["metadata"] -def test_set_mute_flattened(): +def test_list_security_health_analytics_custom_modules_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: + with mock.patch.object( + type(client.transport.list_security_health_analytics_custom_modules), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = finding.Finding() + call.return_value = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.set_mute( - name="name_value", - mute=finding.Finding.Mute.MUTED, + client.list_security_health_analytics_custom_modules( + 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].name - mock_val = "name_value" - assert arg == mock_val - arg = args[0].mute - mock_val = finding.Finding.Mute.MUTED + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val -def test_set_mute_flattened_error(): +def test_list_security_health_analytics_custom_modules_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7698,46 +8899,47 @@ def test_set_mute_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.set_mute( - securitycenter_service.SetMuteRequest(), - name="name_value", - mute=finding.Finding.Mute.MUTED, + client.list_security_health_analytics_custom_modules( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_set_mute_flattened_async(): +async def test_list_security_health_analytics_custom_modules_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_mute), "__call__") as call: + with mock.patch.object( + type(client.transport.list_security_health_analytics_custom_modules), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = finding.Finding() + call.return_value = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse() + ) - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.set_mute( - name="name_value", - mute=finding.Finding.Mute.MUTED, + response = await client.list_security_health_analytics_custom_modules( + 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].name - mock_val = "name_value" - assert arg == mock_val - arg = args[0].mute - mock_val = finding.Finding.Mute.MUTED + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val @pytest.mark.asyncio -async def test_set_mute_flattened_error_async(): +async def test_list_security_health_analytics_custom_modules_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7745,21 +8947,234 @@ async def test_set_mute_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_mute( - securitycenter_service.SetMuteRequest(), - name="name_value", - mute=finding.Finding.Mute.MUTED, + await client.list_security_health_analytics_custom_modules( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest(), + parent="parent_value", + ) + + +def test_list_security_health_analytics_custom_modules_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_security_health_analytics_custom_modules), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + next_page_token="abc", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[], + next_page_token="def", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_security_health_analytics_custom_modules(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all( + isinstance( + i, + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + for i in results + ) + + +def test_list_security_health_analytics_custom_modules_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_security_health_analytics_custom_modules), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + next_page_token="abc", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[], + next_page_token="def", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + ), + RuntimeError, + ) + pages = list( + client.list_security_health_analytics_custom_modules(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_security_health_analytics_custom_modules_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_security_health_analytics_custom_modules), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + next_page_token="abc", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[], + next_page_token="def", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_security_health_analytics_custom_modules( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance( + i, + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + for i in responses + ) + + +@pytest.mark.asyncio +async def test_list_security_health_analytics_custom_modules_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_security_health_analytics_custom_modules), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + next_page_token="abc", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[], + next_page_token="def", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_security_health_analytics_custom_modules(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( "request_type", [ - iam_policy_pb2.SetIamPolicyRequest, + securitycenter_service.ListSourcesRequest, dict, ], ) -def test_set_iam_policy(request_type, transport: str = "grpc"): +def test_list_sources(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -7770,26 +9185,24 @@ def test_set_iam_policy(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy( - version=774, - etag=b"etag_blob", + call.return_value = securitycenter_service.ListSourcesResponse( + next_page_token="next_page_token_value", ) - response = client.set_iam_policy(request) + response = client.list_sources(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.SetIamPolicyRequest() + assert args[0] == securitycenter_service.ListSourcesRequest() # 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 isinstance(response, pagers.ListSourcesPager) + assert response.next_page_token == "next_page_token_value" -def test_set_iam_policy_empty_call(): +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. client = SecurityCenterClient( @@ -7798,16 +9211,17 @@ def test_set_iam_policy_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: - client.set_iam_policy() + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: + client.list_sources() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + assert args[0] == securitycenter_service.ListSourcesRequest() @pytest.mark.asyncio -async def test_set_iam_policy_async( - transport: str = "grpc_asyncio", request_type=iam_policy_pb2.SetIamPolicyRequest +async def test_list_sources_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListSourcesRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7819,47 +9233,45 @@ async def test_set_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.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__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", + securitycenter_service.ListSourcesResponse( + next_page_token="next_page_token_value", ) ) - response = await client.set_iam_policy(request) + response = await client.list_sources(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.SetIamPolicyRequest() + assert args[0] == securitycenter_service.ListSourcesRequest() # 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 isinstance(response, pagers.ListSourcesAsyncPager) + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_set_iam_policy_async_from_dict(): - await test_set_iam_policy_async(request_type=dict) +async def test_list_sources_async_from_dict(): + await test_list_sources_async(request_type=dict) -def test_set_iam_policy_field_headers(): +def test_list_sources_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.SetIamPolicyRequest() + request = securitycenter_service.ListSourcesRequest() - request.resource = "resource_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: - call.return_value = policy_pb2.Policy() - client.set_iam_policy(request) + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: + call.return_value = securitycenter_service.ListSourcesResponse() + client.list_sources(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -7870,26 +9282,28 @@ def test_set_iam_policy_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "resource=resource_value", + "parent=parent_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_set_iam_policy_field_headers_async(): +async def test_list_sources_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.SetIamPolicyRequest() + request = securitycenter_service.ListSourcesRequest() - request.resource = "resource_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - await client.set_iam_policy(request) + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListSourcesResponse() + ) + await client.list_sources(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -7900,53 +9314,35 @@ async def test_set_iam_policy_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "resource=resource_value", + "parent=parent_value", ) in kw["metadata"] -def test_set_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.set_iam_policy), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - response = client.set_iam_policy( - request={ - "resource": "resource_value", - "policy": policy_pb2.Policy(version=774), - "update_mask": field_mask_pb2.FieldMask(paths=["paths_value"]), - } - ) - call.assert_called() - - -def test_set_iam_policy_flattened(): +def test_list_sources_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_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() + call.return_value = securitycenter_service.ListSourcesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.set_iam_policy( - resource="resource_value", + client.list_sources( + 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].resource - mock_val = "resource_value" + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val -def test_set_iam_policy_flattened_error(): +def test_list_sources_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7954,41 +9350,43 @@ def test_set_iam_policy_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), - resource="resource_value", + client.list_sources( + securitycenter_service.ListSourcesRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_set_iam_policy_flattened_async(): +async def test_list_sources_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_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() + call.return_value = securitycenter_service.ListSourcesResponse() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListSourcesResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.set_iam_policy( - resource="resource_value", + response = await client.list_sources( + 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].resource - mock_val = "resource_value" + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val @pytest.mark.asyncio -async def test_set_iam_policy_flattened_error_async(): +async def test_list_sources_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7996,125 +9394,307 @@ async def test_set_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.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), - resource="resource_value", + await client.list_sources( + securitycenter_service.ListSourcesRequest(), + parent="parent_value", ) -@pytest.mark.parametrize( - "request_type", - [ - iam_policy_pb2.TestIamPermissionsRequest, - dict, - ], -) -def test_test_iam_permissions(request_type, transport: str = "grpc"): +def test_list_sources_pager(transport_name: str = "grpc"): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) - # 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.test_iam_permissions), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse( - permissions=["permissions_value"], + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + source.Source(), + source.Source(), + ], + next_page_token="abc", + ), + securitycenter_service.ListSourcesResponse( + sources=[], + next_page_token="def", + ), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + source.Source(), + ], + ), + RuntimeError, ) - response = client.test_iam_permissions(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.TestIamPermissionsRequest() + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_sources(request={}) - # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - assert response.permissions == ["permissions_value"] + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, source.Source) for i in results) -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. +def test_list_sources_pages(transport_name: str = "grpc"): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + 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.test_iam_permissions), "__call__" - ) as call: - client.test_iam_permissions() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + source.Source(), + source.Source(), + ], + next_page_token="abc", + ), + securitycenter_service.ListSourcesResponse( + sources=[], + next_page_token="def", + ), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + source.Source(), + ], + ), + RuntimeError, + ) + pages = list(client.list_sources(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_test_iam_permissions_async( - transport: str = "grpc_asyncio", - request_type=iam_policy_pb2.TestIamPermissionsRequest, -): +async def test_list_sources_async_pager(): client = SecurityCenterAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + credentials=ga_credentials.AnonymousCredentials, ) - # 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.test_iam_permissions), "__call__" + type(client.transport.list_sources), "__call__", new_callable=mock.AsyncMock ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - iam_policy_pb2.TestIamPermissionsResponse( - permissions=["permissions_value"], - ) + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + source.Source(), + source.Source(), + ], + next_page_token="abc", + ), + securitycenter_service.ListSourcesResponse( + sources=[], + next_page_token="def", + ), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + source.Source(), + ], + ), + RuntimeError, ) - response = await client.test_iam_permissions(request) + async_pager = await client.list_sources( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, source.Source) for i in responses) + + +@pytest.mark.asyncio +async def test_list_sources_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_sources), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + source.Source(), + source.Source(), + ], + next_page_token="abc", + ), + securitycenter_service.ListSourcesResponse( + sources=[], + next_page_token="def", + ), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + source.Source(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_sources(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@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, + ) + + # 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.run_asset_discovery), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.run_asset_discovery(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.RunAssetDiscoveryRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +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. + 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.run_asset_discovery), "__call__" + ) as call: + client.run_asset_discovery() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.RunAssetDiscoveryRequest() + + +@pytest.mark.asyncio +async def test_run_asset_discovery_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.RunAssetDiscoveryRequest, +): + 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.run_asset_discovery), "__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.run_asset_discovery(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.TestIamPermissionsRequest() + assert args[0] == securitycenter_service.RunAssetDiscoveryRequest() # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - assert response.permissions == ["permissions_value"] + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_test_iam_permissions_async_from_dict(): - await test_test_iam_permissions_async(request_type=dict) +async def test_run_asset_discovery_async_from_dict(): + await test_run_asset_discovery_async(request_type=dict) -def test_test_iam_permissions_field_headers(): +def test_run_asset_discovery_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.TestIamPermissionsRequest() + request = securitycenter_service.RunAssetDiscoveryRequest() - request.resource = "resource_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.test_iam_permissions), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - client.test_iam_permissions(request) + call.return_value = operations_pb2.Operation(name="operations/op") + client.run_asset_discovery(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -8125,30 +9705,30 @@ def test_test_iam_permissions_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "resource=resource_value", + "parent=parent_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_test_iam_permissions_field_headers_async(): +async def test_run_asset_discovery_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.TestIamPermissionsRequest() + request = securitycenter_service.RunAssetDiscoveryRequest() - request.resource = "resource_value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.test_iam_permissions), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - iam_policy_pb2.TestIamPermissionsResponse() + operations_pb2.Operation(name="operations/op") ) - await client.test_iam_permissions(request) + await client.run_asset_discovery(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -8159,60 +9739,37 @@ async def test_test_iam_permissions_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "resource=resource_value", + "parent=parent_value", ) in kw["metadata"] -def test_test_iam_permissions_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.test_iam_permissions), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - response = client.test_iam_permissions( - request={ - "resource": "resource_value", - "permissions": ["permissions_value"], - } - ) - call.assert_called() - - -def test_test_iam_permissions_flattened(): +def test_run_asset_discovery_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.test_iam_permissions), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + 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.test_iam_permissions( - resource="resource_value", - permissions=["permissions_value"], + client.run_asset_discovery( + 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].resource - mock_val = "resource_value" - assert arg == mock_val - arg = args[0].permissions - mock_val = ["permissions_value"] + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val -def test_test_iam_permissions_flattened_error(): +def test_run_asset_discovery_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -8220,50 +9777,45 @@ def test_test_iam_permissions_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.test_iam_permissions( - iam_policy_pb2.TestIamPermissionsRequest(), - resource="resource_value", - permissions=["permissions_value"], + client.run_asset_discovery( + securitycenter_service.RunAssetDiscoveryRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_test_iam_permissions_flattened_async(): +async def test_run_asset_discovery_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.test_iam_permissions), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + call.return_value = operations_pb2.Operation(name="operations/op") call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - iam_policy_pb2.TestIamPermissionsResponse() + 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.test_iam_permissions( - resource="resource_value", - permissions=["permissions_value"], + response = await client.run_asset_discovery( + 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].resource - mock_val = "resource_value" - assert arg == mock_val - arg = args[0].permissions - mock_val = ["permissions_value"] + arg = args[0].parent + mock_val = "parent_value" assert arg == mock_val @pytest.mark.asyncio -async def test_test_iam_permissions_flattened_error_async(): +async def test_run_asset_discovery_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -8271,21 +9823,20 @@ async def test_test_iam_permissions_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.test_iam_permissions( - iam_policy_pb2.TestIamPermissionsRequest(), - resource="resource_value", - permissions=["permissions_value"], + await client.run_asset_discovery( + securitycenter_service.RunAssetDiscoveryRequest(), + parent="parent_value", ) @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateExternalSystemRequest, + securitycenter_service.SetFindingStateRequest, dict, ], ) -def test_update_external_system(request_type, transport: str = "grpc"): +def test_set_finding_state(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -8297,31 +9848,53 @@ def test_update_external_system(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_external_system), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_external_system.ExternalSystem( + call.return_value = finding.Finding( name="name_value", - assignees=["assignees_value"], - external_uid="external_uid_value", - status="status_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", + parent_display_name="parent_display_name_value", + description="description_value", + next_steps="next_steps_value", + module_name="module_name_value", ) - response = client.update_external_system(request) + response = client.set_finding_state(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() + assert args[0] == securitycenter_service.SetFindingStateRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_external_system.ExternalSystem) + assert isinstance(response, finding.Finding) assert response.name == "name_value" - assert response.assignees == ["assignees_value"] - assert response.external_uid == "external_uid_value" - assert response.status == "status_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" + assert response.parent_display_name == "parent_display_name_value" + assert response.description == "description_value" + assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" -def test_update_external_system_empty_call(): +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. client = SecurityCenterClient( @@ -8331,18 +9904,18 @@ def test_update_external_system_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_external_system), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: - client.update_external_system() + client.set_finding_state() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.UpdateExternalSystemRequest() + assert args[0] == securitycenter_service.SetFindingStateRequest() @pytest.mark.asyncio -async def test_update_external_system_async( +async def test_set_finding_state_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.UpdateExternalSystemRequest, + request_type=securitycenter_service.SetFindingStateRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8355,54 +9928,76 @@ async def test_update_external_system_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_external_system), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_external_system.ExternalSystem( + finding.Finding( name="name_value", - assignees=["assignees_value"], - external_uid="external_uid_value", - status="status_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", + parent_display_name="parent_display_name_value", + description="description_value", + next_steps="next_steps_value", + module_name="module_name_value", ) ) - response = await client.update_external_system(request) + response = await client.set_finding_state(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() + assert args[0] == securitycenter_service.SetFindingStateRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_external_system.ExternalSystem) + assert isinstance(response, finding.Finding) assert response.name == "name_value" - assert response.assignees == ["assignees_value"] - assert response.external_uid == "external_uid_value" - assert response.status == "status_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" + assert response.parent_display_name == "parent_display_name_value" + assert response.description == "description_value" + assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" @pytest.mark.asyncio -async def test_update_external_system_async_from_dict(): - await test_update_external_system_async(request_type=dict) +async def test_set_finding_state_async_from_dict(): + await test_set_finding_state_async(request_type=dict) -def test_update_external_system_field_headers(): +def test_set_finding_state_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 = securitycenter_service.SetFindingStateRequest() - request.external_system.name = "name_value" + request.name = "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__" + type(client.transport.set_finding_state), "__call__" ) as call: - call.return_value = gcs_external_system.ExternalSystem() - client.update_external_system(request) + call.return_value = finding.Finding() + client.set_finding_state(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -8413,30 +10008,28 @@ def test_update_external_system_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "external_system.name=name_value", + "name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_external_system_field_headers_async(): +async def test_set_finding_state_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 = securitycenter_service.SetFindingStateRequest() - request.external_system.name = "name_value" + request.name = "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__" + type(client.transport.set_finding_state), "__call__" ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_external_system.ExternalSystem() - ) - await client.update_external_system(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) + await client.set_finding_state(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -8447,41 +10040,45 @@ async def test_update_external_system_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "external_system.name=name_value", + "name=name_value", ) in kw["metadata"] -def test_update_external_system_flattened(): +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.update_external_system), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_external_system.ExternalSystem() + call.return_value = finding.Finding() # 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"]), + 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].external_system - mock_val = gcs_external_system.ExternalSystem(name="name_value") + arg = args[0].name + mock_val = "name_value" assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + 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_update_external_system_flattened_error(): +def test_set_finding_state_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -8489,50 +10086,53 @@ def test_update_external_system_flattened_error(): # 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"]), + 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_update_external_system_flattened_async(): +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.update_external_system), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_external_system.ExternalSystem() + call.return_value = finding.Finding() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_external_system.ExternalSystem() - ) + 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.update_external_system( - external_system=gcs_external_system.ExternalSystem(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + 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].external_system - mock_val = gcs_external_system.ExternalSystem(name="name_value") + arg = args[0].name + mock_val = "name_value" assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + 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_update_external_system_flattened_error_async(): +async def test_set_finding_state_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -8540,21 +10140,22 @@ async def test_update_external_system_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.update_external_system( - securitycenter_service.UpdateExternalSystemRequest(), - external_system=gcs_external_system.ExternalSystem(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + await client.set_finding_state( + securitycenter_service.SetFindingStateRequest(), + name="name_value", + state=finding.Finding.State.ACTIVE, + start_time=timestamp_pb2.Timestamp(seconds=751), ) @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateFindingRequest, + securitycenter_service.SetMuteRequest, dict, ], ) -def test_update_finding(request_type, transport: str = "grpc"): +def test_set_mute(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -8565,50 +10166,52 @@ def test_update_finding(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_finding), "__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 = gcs_finding.Finding( + call.return_value = finding.Finding( name="name_value", parent="parent_value", resource_name="resource_name_value", - state=gcs_finding.Finding.State.ACTIVE, + state=finding.Finding.State.ACTIVE, category="category_value", external_uri="external_uri_value", - severity=gcs_finding.Finding.Severity.CRITICAL, + severity=finding.Finding.Severity.CRITICAL, canonical_name="canonical_name_value", - mute=gcs_finding.Finding.Mute.MUTED, - finding_class=gcs_finding.Finding.FindingClass.THREAT, + mute=finding.Finding.Mute.MUTED, + finding_class=finding.Finding.FindingClass.THREAT, mute_initiator="mute_initiator_value", parent_display_name="parent_display_name_value", description="description_value", next_steps="next_steps_value", + module_name="module_name_value", ) - response = client.update_finding(request) + 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.UpdateFindingRequest() + assert args[0] == securitycenter_service.SetMuteRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_finding.Finding) + 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 == gcs_finding.Finding.State.ACTIVE + assert response.state == finding.Finding.State.ACTIVE assert response.category == "category_value" assert response.external_uri == "external_uri_value" - assert response.severity == gcs_finding.Finding.Severity.CRITICAL + assert response.severity == 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 == finding.Finding.Mute.MUTED + assert response.finding_class == finding.Finding.FindingClass.THREAT assert response.mute_initiator == "mute_initiator_value" assert response.parent_display_name == "parent_display_name_value" assert response.description == "description_value" assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" -def test_update_finding_empty_call(): +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( @@ -8617,17 +10220,16 @@ def test_update_finding_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_finding), "__call__") as call: - client.update_finding() + 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.UpdateFindingRequest() + assert args[0] == securitycenter_service.SetMuteRequest() @pytest.mark.asyncio -async def test_update_finding_async( - transport: str = "grpc_asyncio", - request_type=securitycenter_service.UpdateFindingRequest, +async def test_set_mute_async( + transport: str = "grpc_asyncio", request_type=securitycenter_service.SetMuteRequest ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8639,71 +10241,73 @@ async def test_update_finding_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_finding), "__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 = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_finding.Finding( + finding.Finding( name="name_value", parent="parent_value", resource_name="resource_name_value", - state=gcs_finding.Finding.State.ACTIVE, + state=finding.Finding.State.ACTIVE, category="category_value", external_uri="external_uri_value", - severity=gcs_finding.Finding.Severity.CRITICAL, + severity=finding.Finding.Severity.CRITICAL, canonical_name="canonical_name_value", - mute=gcs_finding.Finding.Mute.MUTED, - finding_class=gcs_finding.Finding.FindingClass.THREAT, + mute=finding.Finding.Mute.MUTED, + finding_class=finding.Finding.FindingClass.THREAT, mute_initiator="mute_initiator_value", parent_display_name="parent_display_name_value", description="description_value", next_steps="next_steps_value", + module_name="module_name_value", ) ) - response = await client.update_finding(request) + 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.UpdateFindingRequest() + assert args[0] == securitycenter_service.SetMuteRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_finding.Finding) + 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 == gcs_finding.Finding.State.ACTIVE + assert response.state == finding.Finding.State.ACTIVE assert response.category == "category_value" assert response.external_uri == "external_uri_value" - assert response.severity == gcs_finding.Finding.Severity.CRITICAL + assert response.severity == 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 == finding.Finding.Mute.MUTED + assert response.finding_class == finding.Finding.FindingClass.THREAT assert response.mute_initiator == "mute_initiator_value" assert response.parent_display_name == "parent_display_name_value" assert response.description == "description_value" assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" @pytest.mark.asyncio -async def test_update_finding_async_from_dict(): - await test_update_finding_async(request_type=dict) +async def test_set_mute_async_from_dict(): + await test_set_mute_async(request_type=dict) -def test_update_finding_field_headers(): +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.UpdateFindingRequest() + request = securitycenter_service.SetMuteRequest() - request.finding.name = "name_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_finding), "__call__") as call: - call.return_value = gcs_finding.Finding() - client.update_finding(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 @@ -8714,26 +10318,26 @@ def test_update_finding_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "finding.name=name_value", + "name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_finding_field_headers_async(): +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.UpdateFindingRequest() + request = securitycenter_service.SetMuteRequest() - request.finding.name = "name_value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_finding), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_finding.Finding()) - await client.update_finding(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) @@ -8744,35 +10348,39 @@ async def test_update_finding_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "finding.name=name_value", + "name=name_value", ) in kw["metadata"] -def test_update_finding_flattened(): +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.update_finding), "__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 = gcs_finding.Finding() + call.return_value = finding.Finding() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_finding( - finding=gcs_finding.Finding(name="name_value"), + client.set_mute( + name="name_value", + mute=finding.Finding.Mute.MUTED, ) # 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].finding - mock_val = gcs_finding.Finding(name="name_value") + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].mute + mock_val = finding.Finding.Mute.MUTED assert arg == mock_val -def test_update_finding_flattened_error(): +def test_set_mute_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -8780,41 +10388,46 @@ def test_update_finding_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_finding( - securitycenter_service.UpdateFindingRequest(), - finding=gcs_finding.Finding(name="name_value"), + client.set_mute( + securitycenter_service.SetMuteRequest(), + name="name_value", + mute=finding.Finding.Mute.MUTED, ) @pytest.mark.asyncio -async def test_update_finding_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.update_finding), "__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 = gcs_finding.Finding() + call.return_value = finding.Finding() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_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.update_finding( - finding=gcs_finding.Finding(name="name_value"), + response = await client.set_mute( + name="name_value", + mute=finding.Finding.Mute.MUTED, ) # 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].finding - mock_val = gcs_finding.Finding(name="name_value") + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].mute + mock_val = finding.Finding.Mute.MUTED assert arg == mock_val @pytest.mark.asyncio -async def test_update_finding_flattened_error_async(): +async def test_set_mute_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -8822,20 +10435,21 @@ async def test_update_finding_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.update_finding( - securitycenter_service.UpdateFindingRequest(), - finding=gcs_finding.Finding(name="name_value"), + await client.set_mute( + securitycenter_service.SetMuteRequest(), + name="name_value", + mute=finding.Finding.Mute.MUTED, ) @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateMuteConfigRequest, + iam_policy_pb2.SetIamPolicyRequest, dict, ], ) -def test_update_mute_config(request_type, transport: str = "grpc"): +def test_set_iam_policy(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -8846,34 +10460,26 @@ def test_update_mute_config(request_type, transport: str = "grpc"): 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: + with mock.patch.object(type(client.transport.set_iam_policy), "__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", + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", ) - response = client.update_mute_config(request) + response = client.set_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.UpdateMuteConfigRequest() + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() # 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" + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b"etag_blob" -def test_update_mute_config_empty_call(): +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. client = SecurityCenterClient( @@ -8882,19 +10488,16 @@ def test_update_mute_config_empty_call(): ) # 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() + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + client.set_iam_policy() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.UpdateMuteConfigRequest() + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() @pytest.mark.asyncio -async def test_update_mute_config_async( - transport: str = "grpc_asyncio", - request_type=securitycenter_service.UpdateMuteConfigRequest, +async def test_set_iam_policy_async( + transport: str = "grpc_asyncio", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8906,57 +10509,47 @@ async def test_update_mute_config_async( 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: + with mock.patch.object(type(client.transport.set_iam_policy), "__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", + policy_pb2.Policy( + version=774, + etag=b"etag_blob", ) ) - response = await client.update_mute_config(request) + response = await client.set_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.UpdateMuteConfigRequest() + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() # 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" + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b"etag_blob" @pytest.mark.asyncio -async def test_update_mute_config_async_from_dict(): - await test_update_mute_config_async(request_type=dict) +async def test_set_iam_policy_async_from_dict(): + await test_set_iam_policy_async(request_type=dict) -def test_update_mute_config_field_headers(): +def test_set_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.UpdateMuteConfigRequest() + request = iam_policy_pb2.SetIamPolicyRequest() - request.mute_config.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.update_mute_config), "__call__" - ) as call: - call.return_value = gcs_mute_config.MuteConfig() - client.update_mute_config(request) + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -8967,30 +10560,26 @@ def test_update_mute_config_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "mute_config.name=name_value", + "resource=resource_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_mute_config_field_headers_async(): +async def test_set_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.UpdateMuteConfigRequest() + request = iam_policy_pb2.SetIamPolicyRequest() - request.mute_config.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.update_mute_config), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_mute_config.MuteConfig() - ) - await client.update_mute_config(request) + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + await client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -9001,41 +10590,53 @@ async def test_update_mute_config_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "mute_config.name=name_value", + "resource=resource_value", ) in kw["metadata"] -def test_update_mute_config_flattened(): +def test_set_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.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + "update_mask": field_mask_pb2.FieldMask(paths=["paths_value"]), + } + ) + call.assert_called() + + +def test_set_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.update_mute_config), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gcs_mute_config.MuteConfig() + 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.update_mute_config( - mute_config=gcs_mute_config.MuteConfig(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.set_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].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"]) + arg = args[0].resource + mock_val = "resource_value" assert arg == mock_val -def test_update_mute_config_flattened_error(): +def test_set_iam_policy_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -9043,50 +10644,41 @@ def test_update_mute_config_flattened_error(): # 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"]), + client.set_iam_policy( + iam_policy_pb2.SetIamPolicyRequest(), + resource="resource_value", ) @pytest.mark.asyncio -async def test_update_mute_config_flattened_async(): +async def test_set_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.update_mute_config), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gcs_mute_config.MuteConfig() + call.return_value = policy_pb2.Policy() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_mute_config.MuteConfig() - ) + 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.update_mute_config( - mute_config=gcs_mute_config.MuteConfig(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + response = await client.set_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].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"]) + arg = args[0].resource + mock_val = "resource_value" assert arg == mock_val @pytest.mark.asyncio -async def test_update_mute_config_flattened_error_async(): +async def test_set_iam_policy_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -9094,21 +10686,20 @@ async def test_update_mute_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.update_mute_config( - securitycenter_service.UpdateMuteConfigRequest(), - mute_config=gcs_mute_config.MuteConfig(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + await client.set_iam_policy( + iam_policy_pb2.SetIamPolicyRequest(), + resource="resource_value", ) @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateNotificationConfigRequest, + iam_policy_pb2.TestIamPermissionsRequest, dict, ], ) -def test_update_notification_config(request_type, transport: str = "grpc"): +def test_test_iam_permissions(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -9120,34 +10711,25 @@ def test_update_notification_config(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_notification_config), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. - 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" - ), + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], ) - response = client.update_notification_config(request) + response = client.test_iam_permissions(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.UpdateNotificationConfigRequest() + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() # Establish that the response is the type that we expect. - 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" + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ["permissions_value"] -def test_update_notification_config_empty_call(): +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. client = SecurityCenterClient( @@ -9157,18 +10739,18 @@ def test_update_notification_config_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_notification_config), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: - client.update_notification_config() + client.test_iam_permissions() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.UpdateNotificationConfigRequest() + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() @pytest.mark.asyncio -async def test_update_notification_config_async( +async def test_test_iam_permissions_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.UpdateNotificationConfigRequest, + request_type=iam_policy_pb2.TestIamPermissionsRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9181,54 +10763,48 @@ async def test_update_notification_config_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_notification_config), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. 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", + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], ) ) - response = await client.update_notification_config(request) + response = await client.test_iam_permissions(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.UpdateNotificationConfigRequest() + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() # Establish that the response is the type that we expect. - 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" + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ["permissions_value"] @pytest.mark.asyncio -async def test_update_notification_config_async_from_dict(): - await test_update_notification_config_async(request_type=dict) +async def test_test_iam_permissions_async_from_dict(): + await test_test_iam_permissions_async(request_type=dict) -def test_update_notification_config_field_headers(): +def test_test_iam_permissions_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.UpdateNotificationConfigRequest() + request = iam_policy_pb2.TestIamPermissionsRequest() - request.notification_config.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.update_notification_config), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: - call.return_value = gcs_notification_config.NotificationConfig() - client.update_notification_config(request) + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + client.test_iam_permissions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -9239,30 +10815,30 @@ def test_update_notification_config_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "notification_config.name=name_value", + "resource=resource_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_notification_config_field_headers_async(): +async def test_test_iam_permissions_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.UpdateNotificationConfigRequest() + request = iam_policy_pb2.TestIamPermissionsRequest() - request.notification_config.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.update_notification_config), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_notification_config.NotificationConfig() + iam_policy_pb2.TestIamPermissionsResponse() ) - await client.update_notification_config(request) + await client.test_iam_permissions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -9273,43 +10849,60 @@ async def test_update_notification_config_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "notification_config.name=name_value", + "resource=resource_value", ) in kw["metadata"] -def test_update_notification_config_flattened(): +def test_test_iam_permissions_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.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_test_iam_permissions_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_notification_config), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_notification_config.NotificationConfig() + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_notification_config( - notification_config=gcs_notification_config.NotificationConfig( - name="name_value" - ), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.test_iam_permissions( + resource="resource_value", + permissions=["permissions_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].notification_config - mock_val = gcs_notification_config.NotificationConfig(name="name_value") + arg = args[0].resource + mock_val = "resource_value" assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].permissions + mock_val = ["permissions_value"] assert arg == mock_val -def test_update_notification_config_flattened_error(): +def test_test_iam_permissions_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -9317,54 +10910,50 @@ def test_update_notification_config_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_notification_config( - securitycenter_service.UpdateNotificationConfigRequest(), - notification_config=gcs_notification_config.NotificationConfig( - name="name_value" - ), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.test_iam_permissions( + iam_policy_pb2.TestIamPermissionsRequest(), + resource="resource_value", + permissions=["permissions_value"], ) @pytest.mark.asyncio -async def test_update_notification_config_flattened_async(): +async def test_test_iam_permissions_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_notification_config), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_notification_config.NotificationConfig() + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_notification_config.NotificationConfig() + iam_policy_pb2.TestIamPermissionsResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_notification_config( - notification_config=gcs_notification_config.NotificationConfig( - name="name_value" - ), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + response = await client.test_iam_permissions( + resource="resource_value", + permissions=["permissions_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].notification_config - mock_val = gcs_notification_config.NotificationConfig(name="name_value") + arg = args[0].resource + mock_val = "resource_value" assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].permissions + mock_val = ["permissions_value"] assert arg == mock_val @pytest.mark.asyncio -async def test_update_notification_config_flattened_error_async(): +async def test_test_iam_permissions_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -9372,23 +10961,21 @@ async def test_update_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.update_notification_config( - securitycenter_service.UpdateNotificationConfigRequest(), - notification_config=gcs_notification_config.NotificationConfig( - name="name_value" - ), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + await client.test_iam_permissions( + iam_policy_pb2.TestIamPermissionsRequest(), + resource="resource_value", + permissions=["permissions_value"], ) @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateOrganizationSettingsRequest, + securitycenter_service.UpdateExternalSystemRequest, dict, ], ) -def test_update_organization_settings(request_type, transport: str = "grpc"): +def test_update_external_system(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -9400,27 +10987,31 @@ def test_update_organization_settings(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_organization_settings), "__call__" + type(client.transport.update_external_system), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_organization_settings.OrganizationSettings( + call.return_value = gcs_external_system.ExternalSystem( name="name_value", - enable_asset_discovery=True, + assignees=["assignees_value"], + external_uid="external_uid_value", + status="status_value", ) - response = client.update_organization_settings(request) + 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.UpdateOrganizationSettingsRequest() + assert args[0] == securitycenter_service.UpdateExternalSystemRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_organization_settings.OrganizationSettings) + assert isinstance(response, gcs_external_system.ExternalSystem) assert response.name == "name_value" - assert response.enable_asset_discovery is True + assert response.assignees == ["assignees_value"] + assert response.external_uid == "external_uid_value" + assert response.status == "status_value" -def test_update_organization_settings_empty_call(): +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( @@ -9430,18 +11021,18 @@ def test_update_organization_settings_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_organization_settings), "__call__" + type(client.transport.update_external_system), "__call__" ) as call: - client.update_organization_settings() + client.update_external_system() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.UpdateOrganizationSettingsRequest() + assert args[0] == securitycenter_service.UpdateExternalSystemRequest() @pytest.mark.asyncio -async def test_update_organization_settings_async( +async def test_update_external_system_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.UpdateOrganizationSettingsRequest, + request_type=securitycenter_service.UpdateExternalSystemRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9454,50 +11045,54 @@ async def test_update_organization_settings_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_organization_settings), "__call__" + 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_organization_settings.OrganizationSettings( + gcs_external_system.ExternalSystem( name="name_value", - enable_asset_discovery=True, + assignees=["assignees_value"], + external_uid="external_uid_value", + status="status_value", ) ) - response = await client.update_organization_settings(request) + 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.UpdateOrganizationSettingsRequest() + assert args[0] == securitycenter_service.UpdateExternalSystemRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_organization_settings.OrganizationSettings) + assert isinstance(response, gcs_external_system.ExternalSystem) assert response.name == "name_value" - assert response.enable_asset_discovery is True + assert response.assignees == ["assignees_value"] + assert response.external_uid == "external_uid_value" + assert response.status == "status_value" @pytest.mark.asyncio -async def test_update_organization_settings_async_from_dict(): - await test_update_organization_settings_async(request_type=dict) +async def test_update_external_system_async_from_dict(): + await test_update_external_system_async(request_type=dict) -def test_update_organization_settings_field_headers(): +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.UpdateOrganizationSettingsRequest() + request = securitycenter_service.UpdateExternalSystemRequest() - request.organization_settings.name = "name_value" + request.external_system.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_organization_settings), "__call__" + type(client.transport.update_external_system), "__call__" ) as call: - call.return_value = gcs_organization_settings.OrganizationSettings() - client.update_organization_settings(request) + 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 @@ -9508,30 +11103,30 @@ def test_update_organization_settings_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "organization_settings.name=name_value", + "external_system.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_organization_settings_field_headers_async(): +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.UpdateOrganizationSettingsRequest() + request = securitycenter_service.UpdateExternalSystemRequest() - request.organization_settings.name = "name_value" + request.external_system.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_organization_settings), "__call__" + type(client.transport.update_external_system), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_organization_settings.OrganizationSettings() + gcs_external_system.ExternalSystem() ) - await client.update_organization_settings(request) + await client.update_external_system(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -9542,39 +11137,41 @@ async def test_update_organization_settings_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "organization_settings.name=name_value", + "external_system.name=name_value", ) in kw["metadata"] -def test_update_organization_settings_flattened(): +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_organization_settings), "__call__" + type(client.transport.update_external_system), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_organization_settings.OrganizationSettings() + 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_organization_settings( - organization_settings=gcs_organization_settings.OrganizationSettings( - name="name_value" - ), + 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].organization_settings - mock_val = gcs_organization_settings.OrganizationSettings(name="name_value") + 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_organization_settings_flattened_error(): +def test_update_external_system_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -9582,49 +11179,50 @@ def test_update_organization_settings_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_organization_settings( - securitycenter_service.UpdateOrganizationSettingsRequest(), - organization_settings=gcs_organization_settings.OrganizationSettings( - name="name_value" - ), + 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_organization_settings_flattened_async(): +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_organization_settings), "__call__" + type(client.transport.update_external_system), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_organization_settings.OrganizationSettings() + call.return_value = gcs_external_system.ExternalSystem() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_organization_settings.OrganizationSettings() + 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_organization_settings( - organization_settings=gcs_organization_settings.OrganizationSettings( - name="name_value" - ), + 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].organization_settings - mock_val = gcs_organization_settings.OrganizationSettings(name="name_value") + 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_organization_settings_flattened_error_async(): +async def test_update_external_system_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -9632,22 +11230,21 @@ async def test_update_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.update_organization_settings( - securitycenter_service.UpdateOrganizationSettingsRequest(), - organization_settings=gcs_organization_settings.OrganizationSettings( - name="name_value" - ), + 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"]), ) @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateSourceRequest, + securitycenter_service.UpdateFindingRequest, dict, ], ) -def test_update_source(request_type, transport: str = "grpc"): +def test_update_finding(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -9658,30 +11255,52 @@ def test_update_source(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gcs_source.Source( + call.return_value = gcs_finding.Finding( name="name_value", - display_name="display_name_value", - description="description_value", + parent="parent_value", + resource_name="resource_name_value", + state=gcs_finding.Finding.State.ACTIVE, + category="category_value", + 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", + parent_display_name="parent_display_name_value", + description="description_value", + next_steps="next_steps_value", + module_name="module_name_value", ) - response = client.update_source(request) + response = client.update_finding(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.UpdateSourceRequest() + assert args[0] == securitycenter_service.UpdateFindingRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_source.Source) + assert isinstance(response, gcs_finding.Finding) assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" + assert response.parent == "parent_value" + assert response.resource_name == "resource_name_value" + assert response.state == gcs_finding.Finding.State.ACTIVE + assert response.category == "category_value" + 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" + assert response.parent_display_name == "parent_display_name_value" + assert response.description == "description_value" + assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" -def test_update_source_empty_call(): +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. client = SecurityCenterClient( @@ -9690,17 +11309,17 @@ def test_update_source_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_source), "__call__") as call: - client.update_source() + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: + client.update_finding() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.UpdateSourceRequest() + assert args[0] == securitycenter_service.UpdateFindingRequest() @pytest.mark.asyncio -async def test_update_source_async( +async def test_update_finding_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.UpdateSourceRequest, + request_type=securitycenter_service.UpdateFindingRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9712,51 +11331,73 @@ async def test_update_source_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_source.Source( + gcs_finding.Finding( name="name_value", - display_name="display_name_value", - description="description_value", + parent="parent_value", + resource_name="resource_name_value", + state=gcs_finding.Finding.State.ACTIVE, + category="category_value", + 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", + parent_display_name="parent_display_name_value", + description="description_value", + next_steps="next_steps_value", + module_name="module_name_value", ) ) - response = await client.update_source(request) + response = await client.update_finding(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.UpdateSourceRequest() + assert args[0] == securitycenter_service.UpdateFindingRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_source.Source) + assert isinstance(response, gcs_finding.Finding) assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" + assert response.parent == "parent_value" + assert response.resource_name == "resource_name_value" + assert response.state == gcs_finding.Finding.State.ACTIVE + assert response.category == "category_value" + 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" + assert response.parent_display_name == "parent_display_name_value" + assert response.description == "description_value" + assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" @pytest.mark.asyncio -async def test_update_source_async_from_dict(): - await test_update_source_async(request_type=dict) +async def test_update_finding_async_from_dict(): + await test_update_finding_async(request_type=dict) -def test_update_source_field_headers(): +def test_update_finding_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.UpdateSourceRequest() + request = securitycenter_service.UpdateFindingRequest() - request.source.name = "name_value" + request.finding.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_source), "__call__") as call: - call.return_value = gcs_source.Source() - client.update_source(request) + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: + call.return_value = gcs_finding.Finding() + client.update_finding(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -9767,26 +11408,26 @@ def test_update_source_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "source.name=name_value", + "finding.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_source_field_headers_async(): +async def test_update_finding_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.UpdateSourceRequest() + request = securitycenter_service.UpdateFindingRequest() - request.source.name = "name_value" + request.finding.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_source), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_source.Source()) - await client.update_source(request) + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_finding.Finding()) + await client.update_finding(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -9797,35 +11438,35 @@ async def test_update_source_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "source.name=name_value", + "finding.name=name_value", ) in kw["metadata"] -def test_update_source_flattened(): +def test_update_finding_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_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gcs_source.Source() + call.return_value = gcs_finding.Finding() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_source( - source=gcs_source.Source(name="name_value"), + client.update_finding( + finding=gcs_finding.Finding(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].source - mock_val = gcs_source.Source(name="name_value") + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") assert arg == mock_val -def test_update_source_flattened_error(): +def test_update_finding_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -9833,41 +11474,41 @@ def test_update_source_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_source( - securitycenter_service.UpdateSourceRequest(), - source=gcs_source.Source(name="name_value"), + client.update_finding( + securitycenter_service.UpdateFindingRequest(), + finding=gcs_finding.Finding(name="name_value"), ) @pytest.mark.asyncio -async def test_update_source_flattened_async(): +async def test_update_finding_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_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gcs_source.Source() + call.return_value = gcs_finding.Finding() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_source.Source()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_finding.Finding()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_source( - source=gcs_source.Source(name="name_value"), + response = await client.update_finding( + finding=gcs_finding.Finding(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].source - mock_val = gcs_source.Source(name="name_value") + arg = args[0].finding + mock_val = gcs_finding.Finding(name="name_value") assert arg == mock_val @pytest.mark.asyncio -async def test_update_source_flattened_error_async(): +async def test_update_finding_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -9875,20 +11516,20 @@ async def test_update_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.update_source( - securitycenter_service.UpdateSourceRequest(), - source=gcs_source.Source(name="name_value"), + await client.update_finding( + securitycenter_service.UpdateFindingRequest(), + finding=gcs_finding.Finding(name="name_value"), ) @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateSecurityMarksRequest, + securitycenter_service.UpdateMuteConfigRequest, dict, ], ) -def test_update_security_marks(request_type, transport: str = "grpc"): +def test_update_mute_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -9900,27 +11541,33 @@ def test_update_security_marks(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_security_marks), "__call__" + type(client.transport.update_mute_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_security_marks.SecurityMarks( + call.return_value = gcs_mute_config.MuteConfig( name="name_value", - canonical_name="canonical_name_value", + display_name="display_name_value", + description="description_value", + filter="filter_value", + most_recent_editor="most_recent_editor_value", ) - response = client.update_security_marks(request) + 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.UpdateSecurityMarksRequest() + assert args[0] == securitycenter_service.UpdateMuteConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_security_marks.SecurityMarks) + assert isinstance(response, gcs_mute_config.MuteConfig) assert response.name == "name_value" - assert response.canonical_name == "canonical_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_security_marks_empty_call(): +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( @@ -9930,18 +11577,18 @@ def test_update_security_marks_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_security_marks), "__call__" + type(client.transport.update_mute_config), "__call__" ) as call: - client.update_security_marks() + client.update_mute_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.UpdateSecurityMarksRequest() + assert args[0] == securitycenter_service.UpdateMuteConfigRequest() @pytest.mark.asyncio -async def test_update_security_marks_async( +async def test_update_mute_config_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.UpdateSecurityMarksRequest, + request_type=securitycenter_service.UpdateMuteConfigRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9954,50 +11601,56 @@ async def test_update_security_marks_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_security_marks), "__call__" + 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_security_marks.SecurityMarks( + gcs_mute_config.MuteConfig( name="name_value", - canonical_name="canonical_name_value", + display_name="display_name_value", + description="description_value", + filter="filter_value", + most_recent_editor="most_recent_editor_value", ) ) - response = await client.update_security_marks(request) + 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.UpdateSecurityMarksRequest() + assert args[0] == securitycenter_service.UpdateMuteConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_security_marks.SecurityMarks) + assert isinstance(response, gcs_mute_config.MuteConfig) assert response.name == "name_value" - assert response.canonical_name == "canonical_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_security_marks_async_from_dict(): - await test_update_security_marks_async(request_type=dict) +async def test_update_mute_config_async_from_dict(): + await test_update_mute_config_async(request_type=dict) -def test_update_security_marks_field_headers(): +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.UpdateSecurityMarksRequest() + request = securitycenter_service.UpdateMuteConfigRequest() - request.security_marks.name = "name_value" + request.mute_config.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_security_marks), "__call__" + type(client.transport.update_mute_config), "__call__" ) as call: - call.return_value = gcs_security_marks.SecurityMarks() - client.update_security_marks(request) + 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 @@ -10008,30 +11661,30 @@ def test_update_security_marks_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "security_marks.name=name_value", + "mute_config.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_security_marks_field_headers_async(): +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.UpdateSecurityMarksRequest() + request = securitycenter_service.UpdateMuteConfigRequest() - request.security_marks.name = "name_value" + request.mute_config.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_security_marks), "__call__" + type(client.transport.update_mute_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_security_marks.SecurityMarks() + gcs_mute_config.MuteConfig() ) - await client.update_security_marks(request) + await client.update_mute_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -10042,37 +11695,41 @@ async def test_update_security_marks_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "security_marks.name=name_value", + "mute_config.name=name_value", ) in kw["metadata"] -def test_update_security_marks_flattened(): +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_security_marks), "__call__" + type(client.transport.update_mute_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_security_marks.SecurityMarks() + 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_security_marks( - security_marks=gcs_security_marks.SecurityMarks(name="name_value"), + 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].security_marks - mock_val = gcs_security_marks.SecurityMarks(name="name_value") + 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_security_marks_flattened_error(): +def test_update_mute_config_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -10080,45 +11737,50 @@ def test_update_security_marks_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_security_marks( - securitycenter_service.UpdateSecurityMarksRequest(), - security_marks=gcs_security_marks.SecurityMarks(name="name_value"), + 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_security_marks_flattened_async(): +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_security_marks), "__call__" + type(client.transport.update_mute_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gcs_security_marks.SecurityMarks() + call.return_value = gcs_mute_config.MuteConfig() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gcs_security_marks.SecurityMarks() + 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_security_marks( - security_marks=gcs_security_marks.SecurityMarks(name="name_value"), + 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].security_marks - mock_val = gcs_security_marks.SecurityMarks(name="name_value") + 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_security_marks_flattened_error_async(): +async def test_update_mute_config_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -10126,20 +11788,21 @@ async def test_update_security_marks_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.update_security_marks( - securitycenter_service.UpdateSecurityMarksRequest(), - security_marks=gcs_security_marks.SecurityMarks(name="name_value"), + 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"]), ) @pytest.mark.parametrize( "request_type", [ - securitycenter_service.CreateBigQueryExportRequest, + securitycenter_service.UpdateNotificationConfigRequest, dict, ], ) -def test_create_big_query_export(request_type, transport: str = "grpc"): +def test_update_notification_config(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -10151,35 +11814,34 @@ def test_create_big_query_export(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_big_query_export), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = bigquery_export.BigQueryExport( + call.return_value = gcs_notification_config.NotificationConfig( name="name_value", description="description_value", - filter="filter_value", - dataset="dataset_value", - most_recent_editor="most_recent_editor_value", - principal="principal_value", + pubsub_topic="pubsub_topic_value", + service_account="service_account_value", + streaming_config=gcs_notification_config.NotificationConfig.StreamingConfig( + filter="filter_value" + ), ) - response = client.create_big_query_export(request) + response = client.update_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.CreateBigQueryExportRequest() + assert args[0] == securitycenter_service.UpdateNotificationConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, bigquery_export.BigQueryExport) + assert isinstance(response, gcs_notification_config.NotificationConfig) assert response.name == "name_value" assert response.description == "description_value" - assert response.filter == "filter_value" - assert response.dataset == "dataset_value" - assert response.most_recent_editor == "most_recent_editor_value" - assert response.principal == "principal_value" + assert response.pubsub_topic == "pubsub_topic_value" + assert response.service_account == "service_account_value" -def test_create_big_query_export_empty_call(): +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. client = SecurityCenterClient( @@ -10189,18 +11851,18 @@ def test_create_big_query_export_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_big_query_export), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: - client.create_big_query_export() + client.update_notification_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.CreateBigQueryExportRequest() + assert args[0] == securitycenter_service.UpdateNotificationConfigRequest() @pytest.mark.asyncio -async def test_create_big_query_export_async( +async def test_update_notification_config_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.CreateBigQueryExportRequest, + request_type=securitycenter_service.UpdateNotificationConfigRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10213,58 +11875,54 @@ async def test_create_big_query_export_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_big_query_export), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - bigquery_export.BigQueryExport( + gcs_notification_config.NotificationConfig( name="name_value", description="description_value", - filter="filter_value", - dataset="dataset_value", - most_recent_editor="most_recent_editor_value", - principal="principal_value", + pubsub_topic="pubsub_topic_value", + service_account="service_account_value", ) ) - response = await client.create_big_query_export(request) + response = await client.update_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.CreateBigQueryExportRequest() + assert args[0] == securitycenter_service.UpdateNotificationConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, bigquery_export.BigQueryExport) + assert isinstance(response, gcs_notification_config.NotificationConfig) assert response.name == "name_value" assert response.description == "description_value" - assert response.filter == "filter_value" - assert response.dataset == "dataset_value" - assert response.most_recent_editor == "most_recent_editor_value" - assert response.principal == "principal_value" + assert response.pubsub_topic == "pubsub_topic_value" + assert response.service_account == "service_account_value" @pytest.mark.asyncio -async def test_create_big_query_export_async_from_dict(): - await test_create_big_query_export_async(request_type=dict) +async def test_update_notification_config_async_from_dict(): + await test_update_notification_config_async(request_type=dict) -def test_create_big_query_export_field_headers(): +def test_update_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.CreateBigQueryExportRequest() + request = securitycenter_service.UpdateNotificationConfigRequest() - request.parent = "parent_value" + request.notification_config.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_big_query_export), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: - call.return_value = bigquery_export.BigQueryExport() - client.create_big_query_export(request) + call.return_value = gcs_notification_config.NotificationConfig() + client.update_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -10275,30 +11933,30 @@ def test_create_big_query_export_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "notification_config.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_create_big_query_export_field_headers_async(): +async def test_update_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.CreateBigQueryExportRequest() + request = securitycenter_service.UpdateNotificationConfigRequest() - request.parent = "parent_value" + request.notification_config.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_big_query_export), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - bigquery_export.BigQueryExport() + gcs_notification_config.NotificationConfig() ) - await client.create_big_query_export(request) + await client.update_notification_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -10309,45 +11967,43 @@ async def test_create_big_query_export_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "notification_config.name=name_value", ) in kw["metadata"] -def test_create_big_query_export_flattened(): +def test_update_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.create_big_query_export), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = bigquery_export.BigQueryExport() + 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.create_big_query_export( - parent="parent_value", - big_query_export=bigquery_export.BigQueryExport(name="name_value"), - big_query_export_id="big_query_export_id_value", + client.update_notification_config( + notification_config=gcs_notification_config.NotificationConfig( + 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].parent - mock_val = "parent_value" - assert arg == mock_val - arg = args[0].big_query_export - mock_val = bigquery_export.BigQueryExport(name="name_value") + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") assert arg == mock_val - arg = args[0].big_query_export_id - mock_val = "big_query_export_id_value" + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) assert arg == mock_val -def test_create_big_query_export_flattened_error(): +def test_update_notification_config_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -10355,55 +12011,54 @@ def test_create_big_query_export_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_big_query_export( - securitycenter_service.CreateBigQueryExportRequest(), - parent="parent_value", - big_query_export=bigquery_export.BigQueryExport(name="name_value"), - big_query_export_id="big_query_export_id_value", + client.update_notification_config( + securitycenter_service.UpdateNotificationConfigRequest(), + notification_config=gcs_notification_config.NotificationConfig( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_create_big_query_export_flattened_async(): +async def test_update_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.create_big_query_export), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = bigquery_export.BigQueryExport() + call.return_value = gcs_notification_config.NotificationConfig() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - bigquery_export.BigQueryExport() + 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.create_big_query_export( - parent="parent_value", - big_query_export=bigquery_export.BigQueryExport(name="name_value"), - big_query_export_id="big_query_export_id_value", + response = await client.update_notification_config( + notification_config=gcs_notification_config.NotificationConfig( + 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].parent - mock_val = "parent_value" - assert arg == mock_val - arg = args[0].big_query_export - mock_val = bigquery_export.BigQueryExport(name="name_value") + arg = args[0].notification_config + mock_val = gcs_notification_config.NotificationConfig(name="name_value") assert arg == mock_val - arg = args[0].big_query_export_id - mock_val = "big_query_export_id_value" + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) assert arg == mock_val @pytest.mark.asyncio -async def test_create_big_query_export_flattened_error_async(): +async def test_update_notification_config_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -10411,22 +12066,23 @@ async def test_create_big_query_export_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_big_query_export( - securitycenter_service.CreateBigQueryExportRequest(), - parent="parent_value", - big_query_export=bigquery_export.BigQueryExport(name="name_value"), - big_query_export_id="big_query_export_id_value", + await client.update_notification_config( + securitycenter_service.UpdateNotificationConfigRequest(), + notification_config=gcs_notification_config.NotificationConfig( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.parametrize( "request_type", [ - securitycenter_service.DeleteBigQueryExportRequest, + securitycenter_service.UpdateOrganizationSettingsRequest, dict, ], ) -def test_delete_big_query_export(request_type, transport: str = "grpc"): +def test_update_organization_settings(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -10438,22 +12094,27 @@ def test_delete_big_query_export(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_big_query_export), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_big_query_export(request) + call.return_value = gcs_organization_settings.OrganizationSettings( + name="name_value", + enable_asset_discovery=True, + ) + response = client.update_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.DeleteBigQueryExportRequest() + assert args[0] == securitycenter_service.UpdateOrganizationSettingsRequest() # Establish that the response is the type that we expect. - assert response is None + assert isinstance(response, gcs_organization_settings.OrganizationSettings) + assert response.name == "name_value" + assert response.enable_asset_discovery is True -def test_delete_big_query_export_empty_call(): +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. client = SecurityCenterClient( @@ -10463,18 +12124,18 @@ def test_delete_big_query_export_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_big_query_export), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: - client.delete_big_query_export() + client.update_organization_settings() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.DeleteBigQueryExportRequest() + assert args[0] == securitycenter_service.UpdateOrganizationSettingsRequest() @pytest.mark.asyncio -async def test_delete_big_query_export_async( +async def test_update_organization_settings_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.DeleteBigQueryExportRequest, + request_type=securitycenter_service.UpdateOrganizationSettingsRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10487,43 +12148,50 @@ async def test_delete_big_query_export_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_big_query_export), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_big_query_export(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_organization_settings.OrganizationSettings( + name="name_value", + enable_asset_discovery=True, + ) + ) + response = await client.update_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.DeleteBigQueryExportRequest() + assert args[0] == securitycenter_service.UpdateOrganizationSettingsRequest() # Establish that the response is the type that we expect. - assert response is None + assert isinstance(response, gcs_organization_settings.OrganizationSettings) + assert response.name == "name_value" + assert response.enable_asset_discovery is True @pytest.mark.asyncio -async def test_delete_big_query_export_async_from_dict(): - await test_delete_big_query_export_async(request_type=dict) +async def test_update_organization_settings_async_from_dict(): + await test_update_organization_settings_async(request_type=dict) -def test_delete_big_query_export_field_headers(): +def test_update_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.DeleteBigQueryExportRequest() + request = securitycenter_service.UpdateOrganizationSettingsRequest() - request.name = "name_value" + request.organization_settings.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_big_query_export), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: - call.return_value = None - client.delete_big_query_export(request) + call.return_value = gcs_organization_settings.OrganizationSettings() + client.update_organization_settings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -10534,28 +12202,30 @@ def test_delete_big_query_export_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "organization_settings.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_delete_big_query_export_field_headers_async(): +async def test_update_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.DeleteBigQueryExportRequest() + request = securitycenter_service.UpdateOrganizationSettingsRequest() - request.name = "name_value" + request.organization_settings.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_big_query_export), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_big_query_export(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_organization_settings.OrganizationSettings() + ) + await client.update_organization_settings(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -10566,37 +12236,39 @@ async def test_delete_big_query_export_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "name=name_value", + "organization_settings.name=name_value", ) in kw["metadata"] -def test_delete_big_query_export_flattened(): +def test_update_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.delete_big_query_export), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = None + call.return_value = gcs_organization_settings.OrganizationSettings() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_big_query_export( - name="name_value", + client.update_organization_settings( + organization_settings=gcs_organization_settings.OrganizationSettings( + 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].organization_settings + mock_val = gcs_organization_settings.OrganizationSettings(name="name_value") assert arg == mock_val -def test_delete_big_query_export_flattened_error(): +def test_update_organization_settings_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -10604,43 +12276,49 @@ def test_delete_big_query_export_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_big_query_export( - securitycenter_service.DeleteBigQueryExportRequest(), - name="name_value", + client.update_organization_settings( + securitycenter_service.UpdateOrganizationSettingsRequest(), + organization_settings=gcs_organization_settings.OrganizationSettings( + name="name_value" + ), ) @pytest.mark.asyncio -async def test_delete_big_query_export_flattened_async(): +async def test_update_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.delete_big_query_export), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = None + call.return_value = gcs_organization_settings.OrganizationSettings() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_organization_settings.OrganizationSettings() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_big_query_export( - name="name_value", + response = await client.update_organization_settings( + organization_settings=gcs_organization_settings.OrganizationSettings( + 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].organization_settings + mock_val = gcs_organization_settings.OrganizationSettings(name="name_value") assert arg == mock_val @pytest.mark.asyncio -async def test_delete_big_query_export_flattened_error_async(): +async def test_update_organization_settings_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -10648,20 +12326,24 @@ async def test_delete_big_query_export_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_big_query_export( - securitycenter_service.DeleteBigQueryExportRequest(), - name="name_value", + await client.update_organization_settings( + securitycenter_service.UpdateOrganizationSettingsRequest(), + organization_settings=gcs_organization_settings.OrganizationSettings( + name="name_value" + ), ) @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateBigQueryExportRequest, + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, dict, ], ) -def test_update_big_query_export(request_type, transport: str = "grpc"): +def test_update_security_health_analytics_custom_module( + request_type, transport: str = "grpc" +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -10673,35 +12355,43 @@ def test_update_big_query_export(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_big_query_export), "__call__" + type(client.transport.update_security_health_analytics_custom_module), + "__call__", ) as call: # Designate an appropriate return value for the call. - call.return_value = bigquery_export.BigQueryExport( + call.return_value = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( name="name_value", - description="description_value", - filter="filter_value", - dataset="dataset_value", - most_recent_editor="most_recent_editor_value", - principal="principal_value", + display_name="display_name_value", + enablement_state=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, + last_editor="last_editor_value", + ancestor_module="ancestor_module_value", ) - response = client.update_big_query_export(request) + response = client.update_security_health_analytics_custom_module(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.UpdateBigQueryExportRequest() + assert ( + args[0] + == securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest() + ) # Establish that the response is the type that we expect. - assert isinstance(response, bigquery_export.BigQueryExport) + assert isinstance( + response, + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) assert response.name == "name_value" - assert response.description == "description_value" - assert response.filter == "filter_value" - assert response.dataset == "dataset_value" - assert response.most_recent_editor == "most_recent_editor_value" - assert response.principal == "principal_value" + assert response.display_name == "display_name_value" + assert ( + response.enablement_state + == gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) + assert response.last_editor == "last_editor_value" + assert response.ancestor_module == "ancestor_module_value" -def test_update_big_query_export_empty_call(): +def test_update_security_health_analytics_custom_module_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( @@ -10711,18 +12401,22 @@ def test_update_big_query_export_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_big_query_export), "__call__" + type(client.transport.update_security_health_analytics_custom_module), + "__call__", ) as call: - client.update_big_query_export() + client.update_security_health_analytics_custom_module() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.UpdateBigQueryExportRequest() + assert ( + args[0] + == securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest() + ) @pytest.mark.asyncio -async def test_update_big_query_export_async( +async def test_update_security_health_analytics_custom_module_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.UpdateBigQueryExportRequest, + request_type=securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10735,58 +12429,69 @@ async def test_update_big_query_export_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_big_query_export), "__call__" + type(client.transport.update_security_health_analytics_custom_module), + "__call__", ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - bigquery_export.BigQueryExport( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( name="name_value", - description="description_value", - filter="filter_value", - dataset="dataset_value", - most_recent_editor="most_recent_editor_value", - principal="principal_value", + display_name="display_name_value", + enablement_state=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, + last_editor="last_editor_value", + ancestor_module="ancestor_module_value", ) ) - response = await client.update_big_query_export(request) + response = await client.update_security_health_analytics_custom_module(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.UpdateBigQueryExportRequest() + assert ( + args[0] + == securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest() + ) # Establish that the response is the type that we expect. - assert isinstance(response, bigquery_export.BigQueryExport) + assert isinstance( + response, + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) assert response.name == "name_value" - assert response.description == "description_value" - assert response.filter == "filter_value" - assert response.dataset == "dataset_value" - assert response.most_recent_editor == "most_recent_editor_value" - assert response.principal == "principal_value" + assert response.display_name == "display_name_value" + assert ( + response.enablement_state + == gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) + assert response.last_editor == "last_editor_value" + assert response.ancestor_module == "ancestor_module_value" @pytest.mark.asyncio -async def test_update_big_query_export_async_from_dict(): - await test_update_big_query_export_async(request_type=dict) +async def test_update_security_health_analytics_custom_module_async_from_dict(): + await test_update_security_health_analytics_custom_module_async(request_type=dict) -def test_update_big_query_export_field_headers(): +def test_update_security_health_analytics_custom_module_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.UpdateBigQueryExportRequest() + request = securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest() - request.big_query_export.name = "name_value" + request.security_health_analytics_custom_module.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_big_query_export), "__call__" + type(client.transport.update_security_health_analytics_custom_module), + "__call__", ) as call: - call.return_value = bigquery_export.BigQueryExport() - client.update_big_query_export(request) + call.return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + client.update_security_health_analytics_custom_module(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -10797,30 +12502,31 @@ def test_update_big_query_export_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "big_query_export.name=name_value", + "security_health_analytics_custom_module.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_big_query_export_field_headers_async(): +async def test_update_security_health_analytics_custom_module_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.UpdateBigQueryExportRequest() + request = securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest() - request.big_query_export.name = "name_value" + request.security_health_analytics_custom_module.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_big_query_export), "__call__" + type(client.transport.update_security_health_analytics_custom_module), + "__call__", ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - bigquery_export.BigQueryExport() + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() ) - await client.update_big_query_export(request) + await client.update_security_health_analytics_custom_module(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -10831,25 +12537,30 @@ async def test_update_big_query_export_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "big_query_export.name=name_value", + "security_health_analytics_custom_module.name=name_value", ) in kw["metadata"] -def test_update_big_query_export_flattened(): +def test_update_security_health_analytics_custom_module_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_big_query_export), "__call__" + type(client.transport.update_security_health_analytics_custom_module), + "__call__", ) as call: # Designate an appropriate return value for the call. - call.return_value = bigquery_export.BigQueryExport() + call.return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_big_query_export( - big_query_export=bigquery_export.BigQueryExport(name="name_value"), + client.update_security_health_analytics_custom_module( + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ), update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -10857,15 +12568,17 @@ def test_update_big_query_export_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - arg = args[0].big_query_export - mock_val = bigquery_export.BigQueryExport(name="name_value") + arg = args[0].security_health_analytics_custom_module + mock_val = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + 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_big_query_export_flattened_error(): +def test_update_security_health_analytics_custom_module_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -10873,33 +12586,40 @@ def test_update_big_query_export_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_big_query_export( - securitycenter_service.UpdateBigQueryExportRequest(), - big_query_export=bigquery_export.BigQueryExport(name="name_value"), + client.update_security_health_analytics_custom_module( + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest(), + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ), update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_update_big_query_export_flattened_async(): +async def test_update_security_health_analytics_custom_module_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_big_query_export), "__call__" + type(client.transport.update_security_health_analytics_custom_module), + "__call__", ) as call: # Designate an appropriate return value for the call. - call.return_value = bigquery_export.BigQueryExport() + call.return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - bigquery_export.BigQueryExport() + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_big_query_export( - big_query_export=bigquery_export.BigQueryExport(name="name_value"), + response = await client.update_security_health_analytics_custom_module( + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ), update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -10907,8 +12627,10 @@ async def test_update_big_query_export_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - arg = args[0].big_query_export - mock_val = bigquery_export.BigQueryExport(name="name_value") + arg = args[0].security_health_analytics_custom_module + mock_val = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ) assert arg == mock_val arg = args[0].update_mask mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) @@ -10916,7 +12638,7 @@ async def test_update_big_query_export_flattened_async(): @pytest.mark.asyncio -async def test_update_big_query_export_flattened_error_async(): +async def test_update_security_health_analytics_custom_module_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -10924,9 +12646,11 @@ async def test_update_big_query_export_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.update_big_query_export( - securitycenter_service.UpdateBigQueryExportRequest(), - big_query_export=bigquery_export.BigQueryExport(name="name_value"), + await client.update_security_health_analytics_custom_module( + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest(), + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ), update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -10934,11 +12658,11 @@ async def test_update_big_query_export_flattened_error_async(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListBigQueryExportsRequest, + securitycenter_service.UpdateSourceRequest, dict, ], ) -def test_list_big_query_exports(request_type, transport: str = "grpc"): +def test_update_source(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -10949,26 +12673,30 @@ def test_list_big_query_exports(request_type, transport: str = "grpc"): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_big_query_exports), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListBigQueryExportsResponse( - next_page_token="next_page_token_value", + call.return_value = gcs_source.Source( + name="name_value", + display_name="display_name_value", + description="description_value", + canonical_name="canonical_name_value", ) - response = client.list_big_query_exports(request) + response = client.update_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.ListBigQueryExportsRequest() + assert args[0] == securitycenter_service.UpdateSourceRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListBigQueryExportsPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, gcs_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_list_big_query_exports_empty_call(): +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. client = SecurityCenterClient( @@ -10977,19 +12705,17 @@ def test_list_big_query_exports_empty_call(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_big_query_exports), "__call__" - ) as call: - client.list_big_query_exports() + with mock.patch.object(type(client.transport.update_source), "__call__") as call: + client.update_source() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == securitycenter_service.ListBigQueryExportsRequest() + assert args[0] == securitycenter_service.UpdateSourceRequest() @pytest.mark.asyncio -async def test_list_big_query_exports_async( +async def test_update_source_async( transport: str = "grpc_asyncio", - request_type=securitycenter_service.ListBigQueryExportsRequest, + request_type=securitycenter_service.UpdateSourceRequest, ): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11001,49 +12727,51 @@ async def test_list_big_query_exports_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_big_query_exports), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListBigQueryExportsResponse( - next_page_token="next_page_token_value", + gcs_source.Source( + name="name_value", + display_name="display_name_value", + description="description_value", + canonical_name="canonical_name_value", ) ) - response = await client.list_big_query_exports(request) + response = await client.update_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.ListBigQueryExportsRequest() + assert args[0] == securitycenter_service.UpdateSourceRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListBigQueryExportsAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, gcs_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_list_big_query_exports_async_from_dict(): - await test_list_big_query_exports_async(request_type=dict) +async def test_update_source_async_from_dict(): + await test_update_source_async(request_type=dict) -def test_list_big_query_exports_field_headers(): +def test_update_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.ListBigQueryExportsRequest() + request = securitycenter_service.UpdateSourceRequest() - request.parent = "parent_value" + request.source.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_big_query_exports), "__call__" - ) as call: - call.return_value = securitycenter_service.ListBigQueryExportsResponse() - client.list_big_query_exports(request) + with mock.patch.object(type(client.transport.update_source), "__call__") as call: + call.return_value = gcs_source.Source() + client.update_source(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -11054,30 +12782,26 @@ def test_list_big_query_exports_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "source.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_big_query_exports_field_headers_async(): +async def test_update_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.ListBigQueryExportsRequest() + request = securitycenter_service.UpdateSourceRequest() - request.parent = "parent_value" + request.source.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_big_query_exports), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListBigQueryExportsResponse() - ) - await client.list_big_query_exports(request) + with mock.patch.object(type(client.transport.update_source), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_source.Source()) + await client.update_source(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -11088,37 +12812,35 @@ async def test_list_big_query_exports_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "parent=parent_value", + "source.name=name_value", ) in kw["metadata"] -def test_list_big_query_exports_flattened(): +def test_update_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.list_big_query_exports), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListBigQueryExportsResponse() + call.return_value = gcs_source.Source() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_big_query_exports( - parent="parent_value", + client.update_source( + source=gcs_source.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].parent - mock_val = "parent_value" + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") assert arg == mock_val -def test_list_big_query_exports_flattened_error(): +def test_update_source_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -11126,45 +12848,41 @@ def test_list_big_query_exports_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_big_query_exports( - securitycenter_service.ListBigQueryExportsRequest(), - parent="parent_value", + client.update_source( + securitycenter_service.UpdateSourceRequest(), + source=gcs_source.Source(name="name_value"), ) @pytest.mark.asyncio -async def test_list_big_query_exports_flattened_async(): +async def test_update_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.list_big_query_exports), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = securitycenter_service.ListBigQueryExportsResponse() + call.return_value = gcs_source.Source() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - securitycenter_service.ListBigQueryExportsResponse() - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_source.Source()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_big_query_exports( - parent="parent_value", + response = await client.update_source( + source=gcs_source.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].parent - mock_val = "parent_value" + arg = args[0].source + mock_val = gcs_source.Source(name="name_value") assert arg == mock_val @pytest.mark.asyncio -async def test_list_big_query_exports_flattened_error_async(): +async def test_update_source_flattened_error_async(): client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -11172,1231 +12890,2907 @@ async def test_list_big_query_exports_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.list_big_query_exports( - securitycenter_service.ListBigQueryExportsRequest(), - parent="parent_value", + await client.update_source( + securitycenter_service.UpdateSourceRequest(), + source=gcs_source.Source(name="name_value"), ) -def test_list_big_query_exports_pager(transport_name: str = "grpc"): +@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_name, + 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.list_big_query_exports), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - ], - next_page_token="abc", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[], - next_page_token="def", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - ], - next_page_token="ghi", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Designate an appropriate return value for the call. + call.return_value = gcs_security_marks.SecurityMarks( + name="name_value", + canonical_name="canonical_name_value", ) - pager = client.list_big_query_exports(request={}) + response = client.update_security_marks(request) - assert pager._metadata == metadata + # 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.UpdateSecurityMarksRequest() - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, bigquery_export.BigQueryExport) for i in results) + # Establish that the response is the type that we expect. + assert isinstance(response, gcs_security_marks.SecurityMarks) + assert response.name == "name_value" + assert response.canonical_name == "canonical_name_value" -def test_list_big_query_exports_pages(transport_name: str = "grpc"): +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. client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, + 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.list_big_query_exports), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - ], - next_page_token="abc", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[], - next_page_token="def", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - ], - next_page_token="ghi", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - ], - ), - RuntimeError, - ) - pages = list(client.list_big_query_exports(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + client.update_security_marks() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.UpdateSecurityMarksRequest() @pytest.mark.asyncio -async def test_list_big_query_exports_async_pager(): +async def test_update_security_marks_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateSecurityMarksRequest, +): client = SecurityCenterAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + 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.list_big_query_exports), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.update_security_marks), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - ], - next_page_token="abc", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[], - next_page_token="def", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - ], - next_page_token="ghi", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_big_query_exports( - request={}, + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_security_marks.SecurityMarks( + name="name_value", + canonical_name="canonical_name_value", + ) ) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) + response = await client.update_security_marks(request) - assert len(responses) == 6 - assert all(isinstance(i, bigquery_export.BigQueryExport) for i in responses) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.UpdateSecurityMarksRequest() + # Establish that the response is the type that we expect. + assert isinstance(response, gcs_security_marks.SecurityMarks) + assert response.name == "name_value" + assert response.canonical_name == "canonical_name_value" -@pytest.mark.asyncio -async def test_list_big_query_exports_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_big_query_exports), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - ], - next_page_token="abc", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[], - next_page_token="def", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - ], - next_page_token="ghi", - ), - securitycenter_service.ListBigQueryExportsResponse( - big_query_exports=[ - bigquery_export.BigQueryExport(), - bigquery_export.BigQueryExport(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in ( - await client.list_big_query_exports(request={}) - ).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token +@pytest.mark.asyncio +async def test_update_security_marks_async_from_dict(): + await test_update_security_marks_async(request_type=dict) -@pytest.mark.parametrize( - "request_type", - [ - securitycenter_service.BulkMuteFindingsRequest, - dict, - ], -) -def test_bulk_mute_findings_rest(request_type): +def test_update_security_marks_field_headers(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + # 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.UpdateSecurityMarksRequest() - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) + request.security_marks.name = "name_value" - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - response = client.bulk_mute_findings(request) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_security_marks), "__call__" + ) as call: + call.return_value = gcs_security_marks.SecurityMarks() + client.update_security_marks(request) - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" + # 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", + "security_marks.name=name_value", + ) in kw["metadata"] -def test_bulk_mute_findings_rest_required_fields( - request_type=securitycenter_service.BulkMuteFindingsRequest, -): - transport_class = transports.SecurityCenterRestTransport - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) +@pytest.mark.asyncio +async def test_update_security_marks_field_headers_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - # verify fields with default values are dropped + # 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.UpdateSecurityMarksRequest() - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).bulk_mute_findings._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + request.security_marks.name = "name_value" - # verify required fields with default values are now present + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_security_marks), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_security_marks.SecurityMarks() + ) + await client.update_security_marks(request) - jsonified_request["parent"] = "parent_value" + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).bulk_mute_findings._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "security_marks.name=name_value", + ) in kw["metadata"] - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" +def test_update_security_marks_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "post", - "query_params": pb_request, - } - transcode_result["body"] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - - response = client.bulk_mute_findings(request) - - expected_params = [("$alt", "json;enum-encoding=int")] - actual_params = req.call_args.kwargs["params"] - assert expected_params == actual_params - - -def test_bulk_mute_findings_rest_unset_required_fields(): - transport = transports.SecurityCenterRestTransport( - credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.bulk_mute_findings._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("parent",))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_bulk_mute_findings_rest_interceptors(null_interceptor): - transport = transports.SecurityCenterRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None - if null_interceptor - else transports.SecurityCenterRestInterceptor(), - ) - client = SecurityCenterClient(transport=transport) + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_bulk_mute_findings" - ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_bulk_mute_findings" - ) as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = securitycenter_service.BulkMuteFindingsRequest.pb( - securitycenter_service.BulkMuteFindingsRequest() - ) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson( - operations_pb2.Operation() - ) - - request = securitycenter_service.BulkMuteFindingsRequest() - metadata = [ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.bulk_mute_findings( - request, - metadata=[ - ("key", "val"), - ("cephalopod", "squid"), - ], + type(client.transport.update_security_marks), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gcs_security_marks.SecurityMarks() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_security_marks( + security_marks=gcs_security_marks.SecurityMarks(name="name_value"), ) - pre.assert_called_once() - post.assert_called_once() + # 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].security_marks + mock_val = gcs_security_marks.SecurityMarks(name="name_value") + assert arg == mock_val -def test_bulk_mute_findings_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.BulkMuteFindingsRequest -): +def test_update_security_marks_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, ) - # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest - ): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.bulk_mute_findings(request) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_security_marks( + securitycenter_service.UpdateSecurityMarksRequest(), + security_marks=gcs_security_marks.SecurityMarks(name="name_value"), + ) -def test_bulk_mute_findings_rest_flattened(): - client = SecurityCenterClient( +@pytest.mark.asyncio +async def test_update_security_marks_flattened_async(): + client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") - - # get arguments that satisfy an http rule for this method - sample_request = {"parent": "organizations/sample1"} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_security_marks), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gcs_security_marks.SecurityMarks() - # get truthy value for each flattened field - mock_args = dict( - parent="parent_value", + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gcs_security_marks.SecurityMarks() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_security_marks( + security_marks=gcs_security_marks.SecurityMarks(name="name_value"), ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - - client.bulk_mute_findings(**mock_args) # Establish that the underlying call was made with the expected # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{parent=organizations/*}/findings:bulkMute" % client.transport._host, - args[1], - ) + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].security_marks + mock_val = gcs_security_marks.SecurityMarks(name="name_value") + assert arg == mock_val -def test_bulk_mute_findings_rest_flattened_error(transport: str = "rest"): - client = SecurityCenterClient( +@pytest.mark.asyncio +async def test_update_security_marks_flattened_error_async(): + client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, ) # 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", + await client.update_security_marks( + securitycenter_service.UpdateSecurityMarksRequest(), + security_marks=gcs_security_marks.SecurityMarks(name="name_value"), ) -def test_bulk_mute_findings_rest_error(): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" - ) - - @pytest.mark.parametrize( "request_type", [ - securitycenter_service.CreateSourceRequest, + securitycenter_service.CreateBigQueryExportRequest, dict, ], ) -def test_create_source_rest(request_type): +def test_create_big_query_export(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport=transport, ) - # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} - request_init["source"] = { - "name": "name_value", - "display_name": "display_name_value", - "description": "description_value", - "canonical_name": "canonical_name_value", - } - request = request_type(**request_init) + # 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 http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = gcs_source.Source( + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = bigquery_export.BigQueryExport( name="name_value", - display_name="display_name_value", description="description_value", - canonical_name="canonical_name_value", + filter="filter_value", + dataset="dataset_value", + most_recent_editor="most_recent_editor_value", + principal="principal_value", ) + response = client.create_big_query_export(request) - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = gcs_source.Source.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - response = client.create_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.CreateBigQueryExportRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_source.Source) + assert isinstance(response, bigquery_export.BigQueryExport) 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.dataset == "dataset_value" + assert response.most_recent_editor == "most_recent_editor_value" + assert response.principal == "principal_value" -def test_create_source_rest_required_fields( - request_type=securitycenter_service.CreateSourceRequest, -): - transport_class = transports.SecurityCenterRestTransport +def test_create_big_query_export_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", + ) - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_big_query_export), "__call__" + ) as call: + client.create_big_query_export() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.CreateBigQueryExportRequest() + + +@pytest.mark.asyncio +async def test_create_big_query_export_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.CreateBigQueryExportRequest, +): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - # verify fields with default values are dropped + # 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() - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).create_source._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + bigquery_export.BigQueryExport( + name="name_value", + description="description_value", + filter="filter_value", + dataset="dataset_value", + most_recent_editor="most_recent_editor_value", + principal="principal_value", + ) + ) + response = await client.create_big_query_export(request) - # verify required fields with default values are now present + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.CreateBigQueryExportRequest() - jsonified_request["parent"] = "parent_value" + # Establish that the response is the type that we expect. + assert isinstance(response, bigquery_export.BigQueryExport) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.filter == "filter_value" + assert response.dataset == "dataset_value" + assert response.most_recent_editor == "most_recent_editor_value" + assert response.principal == "principal_value" - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).create_source._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" +@pytest.mark.asyncio +async def test_create_big_query_export_async_from_dict(): + await test_create_big_query_export_async(request_type=dict) + +def test_create_big_query_export_field_headers(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = gcs_source.Source() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "post", - "query_params": pb_request, - } - transcode_result["body"] = pb_request - transcode.return_value = transcode_result - response_value = Response() - response_value.status_code = 200 + # 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.CreateBigQueryExportRequest() - pb_return_value = gcs_source.Source.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + request.parent = "parent_value" - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_big_query_export), "__call__" + ) as call: + call.return_value = bigquery_export.BigQueryExport() + client.create_big_query_export(request) - response = client.create_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 - expected_params = [("$alt", "json;enum-encoding=int")] - actual_params = req.call_args.kwargs["params"] - assert expected_params == actual_params + # 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_create_source_rest_unset_required_fields(): - transport = transports.SecurityCenterRestTransport( - credentials=ga_credentials.AnonymousCredentials +@pytest.mark.asyncio +async def test_create_big_query_export_field_headers_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - unset_fields = transport.create_source._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(()) - & set( - ( - "parent", - "source", - ) + # 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.CreateBigQueryExportRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_big_query_export), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + bigquery_export.BigQueryExport() ) - ) + await client.create_big_query_export(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_source_rest_interceptors(null_interceptor): - transport = transports.SecurityCenterRestTransport( + # 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_create_big_query_export_flattened(): + client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - interceptor=None - if null_interceptor - else transports.SecurityCenterRestInterceptor(), ) - client = SecurityCenterClient(transport=transport) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_create_source" - ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_create_source" - ) as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = securitycenter_service.CreateSourceRequest.pb( - securitycenter_service.CreateSourceRequest() - ) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = gcs_source.Source.to_json(gcs_source.Source()) - - request = securitycenter_service.CreateSourceRequest() - metadata = [ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = gcs_source.Source() - - client.create_source( - request, - metadata=[ - ("key", "val"), - ("cephalopod", "squid"), - ], + type(client.transport.create_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = bigquery_export.BigQueryExport() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_big_query_export( + parent="parent_value", + big_query_export=bigquery_export.BigQueryExport(name="name_value"), + big_query_export_id="big_query_export_id_value", ) - pre.assert_called_once() - post.assert_called_once() + # 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].big_query_export + mock_val = bigquery_export.BigQueryExport(name="name_value") + assert arg == mock_val + arg = args[0].big_query_export_id + mock_val = "big_query_export_id_value" + assert arg == mock_val -def test_create_source_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.CreateSourceRequest -): +def test_create_big_query_export_flattened_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, ) - # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} - request_init["source"] = { - "name": "name_value", - "display_name": "display_name_value", - "description": "description_value", - "canonical_name": "canonical_name_value", - } - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest - ): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.create_source(request) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_big_query_export( + securitycenter_service.CreateBigQueryExportRequest(), + parent="parent_value", + big_query_export=bigquery_export.BigQueryExport(name="name_value"), + big_query_export_id="big_query_export_id_value", + ) -def test_create_source_rest_flattened(): - client = SecurityCenterClient( +@pytest.mark.asyncio +async def test_create_big_query_export_flattened_async(): + client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = gcs_source.Source() - - # get arguments that satisfy an http rule for this method - sample_request = {"parent": "organizations/sample1"} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = bigquery_export.BigQueryExport() - # get truthy value for each flattened field - mock_args = dict( + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + bigquery_export.BigQueryExport() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_big_query_export( parent="parent_value", - source=gcs_source.Source(name="name_value"), + big_query_export=bigquery_export.BigQueryExport(name="name_value"), + big_query_export_id="big_query_export_id_value", ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = gcs_source.Source.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - - client.create_source(**mock_args) # Establish that the underlying call was made with the expected # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{parent=organizations/*}/sources" % client.transport._host, args[1] - ) + 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].big_query_export + mock_val = bigquery_export.BigQueryExport(name="name_value") + assert arg == mock_val + arg = args[0].big_query_export_id + mock_val = "big_query_export_id_value" + assert arg == mock_val -def test_create_source_rest_flattened_error(transport: str = "rest"): - client = SecurityCenterClient( +@pytest.mark.asyncio +async def test_create_big_query_export_flattened_error_async(): + client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_source( - securitycenter_service.CreateSourceRequest(), + await client.create_big_query_export( + securitycenter_service.CreateBigQueryExportRequest(), parent="parent_value", - source=gcs_source.Source(name="name_value"), + big_query_export=bigquery_export.BigQueryExport(name="name_value"), + big_query_export_id="big_query_export_id_value", ) -def test_create_source_rest_error(): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" - ) - - @pytest.mark.parametrize( "request_type", [ - securitycenter_service.CreateFindingRequest, + securitycenter_service.DeleteBigQueryExportRequest, dict, ], ) -def test_create_finding_rest(request_type): +def test_delete_big_query_export(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport=transport, ) - # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1/sources/sample2"} - request_init["finding"] = { - "name": "name_value", - "parent": "parent_value", - "resource_name": "resource_name_value", - "state": 1, - "category": "category_value", - "external_uri": "external_uri_value", - "source_properties": {}, - "security_marks": { - "name": "name_value", - "marks": {}, - "canonical_name": "canonical_name_value", - }, - "event_time": {"seconds": 751, "nanos": 543}, - "create_time": {}, - "severity": 1, - "canonical_name": "canonical_name_value", - "mute": 1, - "finding_class": 1, - "indicator": { - "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], - "domains": ["domains_value1", "domains_value2"], - "signatures": [ - { - "memory_hash_signature": { - "binary_family": "binary_family_value", - "detections": [ - {"binary": "binary_value", "percent_pages_matched": 0.2197} - ], - }, - "yara_rule_signature": {"yara_rule": "yara_rule_value"}, - } - ], - "uris": ["uris_value1", "uris_value2"], - }, - "vulnerability": { - "cve": { - "id": "id_value", - "references": [{"source": "source_value", "uri": "uri_value"}], - "cvssv3": { - "base_score": 0.1046, - "attack_vector": 1, - "attack_complexity": 1, - "privileges_required": 1, - "user_interaction": 1, - "scope": 1, - "confidentiality_impact": 1, - "integrity_impact": 1, - "availability_impact": 1, - }, - "upstream_fix_available": True, - } - }, - "mute_update_time": {}, - "external_systems": {}, - "mitre_attack": { - "primary_tactic": 1, - "primary_techniques": [1], - "additional_tactics": [1], - "additional_techniques": [1], - "version": "version_value", - }, - "access": { - "principal_email": "principal_email_value", - "caller_ip": "caller_ip_value", - "caller_ip_geo": {"region_code": "region_code_value"}, - "user_agent_family": "user_agent_family_value", - "service_name": "service_name_value", - "method_name": "method_name_value", - "principal_subject": "principal_subject_value", - "service_account_key_name": "service_account_key_name_value", - "service_account_delegation_info": [ - { - "principal_email": "principal_email_value", - "principal_subject": "principal_subject_value", - } - ], - "user_name": "user_name_value", - }, - "connections": [ - { - "destination_ip": "destination_ip_value", - "destination_port": 1734, - "source_ip": "source_ip_value", - "source_port": 1205, - "protocol": 1, - } - ], - "mute_initiator": "mute_initiator_value", - "processes": [ - { - "name": "name_value", - "binary": { - "path": "path_value", - "size": 443, - "sha256": "sha256_value", - "hashed_size": 1159, - "partially_hashed": True, - "contents": "contents_value", - }, - "libraries": {}, - "script": {}, - "args": ["args_value1", "args_value2"], - "arguments_truncated": True, - "env_variables": [{"name": "name_value", "val": "val_value"}], - "env_variables_truncated": True, - "pid": 317, - "parent_pid": 1062, - } - ], - "contacts": {}, - "compliances": [ - { - "standard": "standard_value", - "version": "version_value", - "ids": ["ids_value1", "ids_value2"], - } - ], - "parent_display_name": "parent_display_name_value", - "description": "description_value", - "exfiltration": { - "sources": [ - { - "name": "name_value", - "components": ["components_value1", "components_value2"], - } - ], - "targets": {}, - }, - "iam_bindings": [{"action": 1, "role": "role_value", "member": "member_value"}], - "next_steps": "next_steps_value", - "containers": [ - { - "name": "name_value", - "uri": "uri_value", - "image_id": "image_id_value", - "labels": [{"name": "name_value", "value": "value_value"}], - } - ], - "kubernetes": { - "pods": [ - {"ns": "ns_value", "name": "name_value", "labels": {}, "containers": {}} - ], - "nodes": [{"name": "name_value"}], - "node_pools": [{"name": "name_value", "nodes": {}}], - "roles": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], - "bindings": [ - { - "ns": "ns_value", - "name": "name_value", - "role": {}, - "subjects": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], - } - ], - "access_reviews": [ - { - "group": "group_value", - "ns": "ns_value", - "name": "name_value", - "resource": "resource_value", - "subresource": "subresource_value", - "verb": "verb_value", - "version": "version_value", - } - ], - }, - "database": { - "name": "name_value", - "display_name": "display_name_value", - "user_name": "user_name_value", - "query": "query_value", - "grantees": ["grantees_value1", "grantees_value2"], - }, - "files": {}, - "kernel_rootkit": { - "name": "name_value", - "unexpected_code_modification": True, - "unexpected_read_only_data_modification": True, - "unexpected_ftrace_handler": True, - "unexpected_kprobe_handler": True, - "unexpected_kernel_code_pages": True, - "unexpected_system_call_handler": True, - "unexpected_interrupt_handler": True, - "unexpected_processes_in_runqueue": True, - }, - } - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = gcs_finding.Finding( - name="name_value", - parent="parent_value", - resource_name="resource_name_value", - state=gcs_finding.Finding.State.ACTIVE, - category="category_value", - 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", - parent_display_name="parent_display_name_value", - description="description_value", - next_steps="next_steps_value", - ) + # 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() - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = gcs_finding.Finding.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_big_query_export(request) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - response = client.create_finding(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.DeleteBigQueryExportRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gcs_finding.Finding) - assert response.name == "name_value" - assert response.parent == "parent_value" - assert response.resource_name == "resource_name_value" - assert response.state == gcs_finding.Finding.State.ACTIVE - assert response.category == "category_value" - 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" - assert response.parent_display_name == "parent_display_name_value" - assert response.description == "description_value" - assert response.next_steps == "next_steps_value" + assert response is None -def test_create_finding_rest_required_fields( - request_type=securitycenter_service.CreateFindingRequest, -): - transport_class = transports.SecurityCenterRestTransport +def test_delete_big_query_export_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", + ) - request_init = {} - request_init["parent"] = "" - request_init["finding_id"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads( - json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False, - ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_big_query_export), "__call__" + ) as call: + client.delete_big_query_export() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.DeleteBigQueryExportRequest() + + +@pytest.mark.asyncio +async def test_delete_big_query_export_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.DeleteBigQueryExportRequest, +): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - # verify fields with default values are dropped - assert "findingId" not in jsonified_request + # 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() - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).create_finding._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_big_query_export(request) - # verify required fields with default values are now present - assert "findingId" in jsonified_request - assert jsonified_request["findingId"] == request_init["finding_id"] + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.DeleteBigQueryExportRequest() - jsonified_request["parent"] = "parent_value" - jsonified_request["findingId"] = "finding_id_value" + # Establish that the response is the type that we expect. + assert response is None - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).create_finding._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("finding_id",)) - jsonified_request.update(unset_fields) - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" - assert "findingId" in jsonified_request - assert jsonified_request["findingId"] == "finding_id_value" +@pytest.mark.asyncio +async def test_delete_big_query_export_async_from_dict(): + await test_delete_big_query_export_async(request_type=dict) + +def test_delete_big_query_export_field_headers(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", ) - request = request_type(**request_init) - # Designate an appropriate value for the returned response. - return_value = gcs_finding.Finding() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, "transcode") as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - "uri": "v1/sample_method", - "method": "post", - "query_params": pb_request, - } - transcode_result["body"] = pb_request - transcode.return_value = transcode_result + # 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.DeleteBigQueryExportRequest() - response_value = Response() - response_value.status_code = 200 + request.name = "name_value" - pb_return_value = gcs_finding.Finding.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_big_query_export), "__call__" + ) as call: + call.return_value = None + client.delete_big_query_export(request) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - response = client.create_finding(request) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] - expected_params = [ - ( - "findingId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] - actual_params = req.call_args.kwargs["params"] - assert expected_params == actual_params +@pytest.mark.asyncio +async def test_delete_big_query_export_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.DeleteBigQueryExportRequest() + + request.name = "name_value" -def test_create_finding_rest_unset_required_fields(): - transport = transports.SecurityCenterRestTransport( - credentials=ga_credentials.AnonymousCredentials + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_big_query_export), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_big_query_export(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_delete_big_query_export_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), ) - unset_fields = transport.create_finding._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(("findingId",)) - & set( - ( - "parent", - "findingId", - "finding", - ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_big_query_export( + 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_delete_big_query_export_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_big_query_export( + securitycenter_service.DeleteBigQueryExportRequest(), + name="name_value", + ) + -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_finding_rest_interceptors(null_interceptor): - transport = transports.SecurityCenterRestTransport( +@pytest.mark.asyncio +async def test_delete_big_query_export_flattened_async(): + client = SecurityCenterAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - interceptor=None - if null_interceptor - else transports.SecurityCenterRestInterceptor(), ) - client = SecurityCenterClient(transport=transport) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_create_finding" - ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_create_finding" - ) as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = securitycenter_service.CreateFindingRequest.pb( - securitycenter_service.CreateFindingRequest() + type(client.transport.delete_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + + 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.delete_big_query_export( + name="name_value", ) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = gcs_finding.Finding.to_json(gcs_finding.Finding()) + # 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 - request = securitycenter_service.CreateFindingRequest() - metadata = [ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = gcs_finding.Finding() - client.create_finding( - request, - metadata=[ - ("key", "val"), - ("cephalopod", "squid"), - ], - ) +@pytest.mark.asyncio +async def test_delete_big_query_export_flattened_error_async(): + client = SecurityCenterAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) - pre.assert_called_once() - post.assert_called_once() + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_big_query_export( + securitycenter_service.DeleteBigQueryExportRequest(), + name="name_value", + ) -def test_create_finding_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.CreateFindingRequest -): +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.UpdateBigQueryExportRequest, + dict, + ], +) +def test_update_big_query_export(request_type, transport: str = "grpc"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) - # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1/sources/sample2"} - request_init["finding"] = { - "name": "name_value", - "parent": "parent_value", - "resource_name": "resource_name_value", - "state": 1, - "category": "category_value", - "external_uri": "external_uri_value", - "source_properties": {}, - "security_marks": { - "name": "name_value", - "marks": {}, - "canonical_name": "canonical_name_value", - }, - "event_time": {"seconds": 751, "nanos": 543}, - "create_time": {}, - "severity": 1, - "canonical_name": "canonical_name_value", - "mute": 1, - "finding_class": 1, - "indicator": { - "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], - "domains": ["domains_value1", "domains_value2"], - "signatures": [ - { - "memory_hash_signature": { - "binary_family": "binary_family_value", - "detections": [ - {"binary": "binary_value", "percent_pages_matched": 0.2197} - ], - }, - "yara_rule_signature": {"yara_rule": "yara_rule_value"}, - } - ], - "uris": ["uris_value1", "uris_value2"], - }, - "vulnerability": { - "cve": { - "id": "id_value", - "references": [{"source": "source_value", "uri": "uri_value"}], - "cvssv3": { + # 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_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = bigquery_export.BigQueryExport( + name="name_value", + description="description_value", + filter="filter_value", + dataset="dataset_value", + most_recent_editor="most_recent_editor_value", + principal="principal_value", + ) + response = client.update_big_query_export(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.UpdateBigQueryExportRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, bigquery_export.BigQueryExport) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.filter == "filter_value" + assert response.dataset == "dataset_value" + assert response.most_recent_editor == "most_recent_editor_value" + assert response.principal == "principal_value" + + +def test_update_big_query_export_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_big_query_export), "__call__" + ) as call: + client.update_big_query_export() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.UpdateBigQueryExportRequest() + + +@pytest.mark.asyncio +async def test_update_big_query_export_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateBigQueryExportRequest, +): + 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_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + bigquery_export.BigQueryExport( + name="name_value", + description="description_value", + filter="filter_value", + dataset="dataset_value", + most_recent_editor="most_recent_editor_value", + principal="principal_value", + ) + ) + response = await client.update_big_query_export(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.UpdateBigQueryExportRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, bigquery_export.BigQueryExport) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.filter == "filter_value" + assert response.dataset == "dataset_value" + assert response.most_recent_editor == "most_recent_editor_value" + assert response.principal == "principal_value" + + +@pytest.mark.asyncio +async def test_update_big_query_export_async_from_dict(): + await test_update_big_query_export_async(request_type=dict) + + +def test_update_big_query_export_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.UpdateBigQueryExportRequest() + + request.big_query_export.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_big_query_export), "__call__" + ) as call: + call.return_value = bigquery_export.BigQueryExport() + client.update_big_query_export(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", + "big_query_export.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_big_query_export_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.UpdateBigQueryExportRequest() + + request.big_query_export.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_big_query_export), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + bigquery_export.BigQueryExport() + ) + await client.update_big_query_export(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", + "big_query_export.name=name_value", + ) in kw["metadata"] + + +def test_update_big_query_export_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_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = bigquery_export.BigQueryExport() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_big_query_export( + big_query_export=bigquery_export.BigQueryExport(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].big_query_export + mock_val = bigquery_export.BigQueryExport(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_big_query_export_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_big_query_export( + securitycenter_service.UpdateBigQueryExportRequest(), + big_query_export=bigquery_export.BigQueryExport(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_big_query_export_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_big_query_export), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = bigquery_export.BigQueryExport() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + bigquery_export.BigQueryExport() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_big_query_export( + big_query_export=bigquery_export.BigQueryExport(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].big_query_export + mock_val = bigquery_export.BigQueryExport(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_big_query_export_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_big_query_export( + securitycenter_service.UpdateBigQueryExportRequest(), + big_query_export=bigquery_export.BigQueryExport(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.ListBigQueryExportsRequest, + dict, + ], +) +def test_list_big_query_exports(request_type, transport: str = "grpc"): + 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.list_big_query_exports), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = securitycenter_service.ListBigQueryExportsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_big_query_exports(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.ListBigQueryExportsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListBigQueryExportsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_big_query_exports_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.list_big_query_exports), "__call__" + ) as call: + client.list_big_query_exports() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == securitycenter_service.ListBigQueryExportsRequest() + + +@pytest.mark.asyncio +async def test_list_big_query_exports_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListBigQueryExportsRequest, +): + 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.list_big_query_exports), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListBigQueryExportsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_big_query_exports(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.ListBigQueryExportsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListBigQueryExportsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_big_query_exports_async_from_dict(): + await test_list_big_query_exports_async(request_type=dict) + + +def test_list_big_query_exports_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.ListBigQueryExportsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_big_query_exports), "__call__" + ) as call: + call.return_value = securitycenter_service.ListBigQueryExportsResponse() + client.list_big_query_exports(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_list_big_query_exports_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.ListBigQueryExportsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_big_query_exports), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListBigQueryExportsResponse() + ) + await client.list_big_query_exports(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_list_big_query_exports_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_big_query_exports), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = securitycenter_service.ListBigQueryExportsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_big_query_exports( + 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_big_query_exports_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_big_query_exports( + securitycenter_service.ListBigQueryExportsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_big_query_exports_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_big_query_exports), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = securitycenter_service.ListBigQueryExportsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.ListBigQueryExportsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_big_query_exports( + 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_big_query_exports_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_big_query_exports( + securitycenter_service.ListBigQueryExportsRequest(), + parent="parent_value", + ) + + +def test_list_big_query_exports_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_big_query_exports), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + ], + next_page_token="abc", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[], + next_page_token="def", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_big_query_exports(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, bigquery_export.BigQueryExport) for i in results) + + +def test_list_big_query_exports_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_big_query_exports), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + ], + next_page_token="abc", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[], + next_page_token="def", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + ], + ), + RuntimeError, + ) + pages = list(client.list_big_query_exports(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_big_query_exports_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_big_query_exports), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + ], + next_page_token="abc", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[], + next_page_token="def", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_big_query_exports( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, bigquery_export.BigQueryExport) for i in responses) + + +@pytest.mark.asyncio +async def test_list_big_query_exports_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_big_query_exports), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + ], + next_page_token="abc", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[], + next_page_token="def", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListBigQueryExportsResponse( + big_query_exports=[ + bigquery_export.BigQueryExport(), + bigquery_export.BigQueryExport(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_big_query_exports(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.BulkMuteFindingsRequest, + dict, + ], +) +def test_bulk_mute_findings_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.bulk_mute_findings(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_bulk_mute_findings_rest_required_fields( + request_type=securitycenter_service.BulkMuteFindingsRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).bulk_mute_findings._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).bulk_mute_findings._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.bulk_mute_findings(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_bulk_mute_findings_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.bulk_mute_findings._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("parent",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_bulk_mute_findings_rest_interceptors(null_interceptor): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.SecurityCenterRestInterceptor, "post_bulk_mute_findings" + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_bulk_mute_findings" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = securitycenter_service.BulkMuteFindingsRequest.pb( + securitycenter_service.BulkMuteFindingsRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) + + request = securitycenter_service.BulkMuteFindingsRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.bulk_mute_findings( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_bulk_mute_findings_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.BulkMuteFindingsRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.bulk_mute_findings(request) + + +def test_bulk_mute_findings_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "organizations/sample1"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.bulk_mute_findings(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=organizations/*}/findings:bulkMute" % client.transport._host, + args[1], + ) + + +def test_bulk_mute_findings_rest_flattened_error(transport: str = "rest"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # 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", + ) + + +def test_bulk_mute_findings_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, + dict, + ], +) +def test_create_security_health_analytics_custom_module_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1/securityHealthAnalyticsSettings"} + request_init["security_health_analytics_custom_module"] = { + "name": "name_value", + "display_name": "display_name_value", + "enablement_state": 1, + "update_time": {"seconds": 751, "nanos": 543}, + "last_editor": "last_editor_value", + "ancestor_module": "ancestor_module_value", + "custom_config": { + "predicate": { + "expression": "expression_value", + "title": "title_value", + "description": "description_value", + "location": "location_value", + }, + "custom_output": { + "properties": [{"name": "name_value", "value_expression": {}}] + }, + "resource_selector": { + "resource_types": ["resource_types_value1", "resource_types_value2"] + }, + "severity": 1, + "description": "description_value", + "recommendation": "recommendation_value", + }, + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value", + display_name="display_name_value", + enablement_state=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, + last_editor="last_editor_value", + ancestor_module="ancestor_module_value", + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.create_security_health_analytics_custom_module(request) + + # Establish that the response is the type that we expect. + assert isinstance( + response, + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert ( + response.enablement_state + == gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) + assert response.last_editor == "last_editor_value" + assert response.ancestor_module == "ancestor_module_value" + + +def test_create_security_health_analytics_custom_module_rest_required_fields( + request_type=securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_security_health_analytics_custom_module._get_unset_required_fields( + jsonified_request + ) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_security_health_analytics_custom_module._get_unset_required_fields( + jsonified_request + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.create_security_health_analytics_custom_module(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_security_health_analytics_custom_module_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_security_health_analytics_custom_module._get_unset_required_fields( + {} + ) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "securityHealthAnalyticsCustomModule", + ) + ) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_security_health_analytics_custom_module_rest_interceptors( + null_interceptor, +): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, + "post_create_security_health_analytics_custom_module", + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, + "pre_create_security_health_analytics_custom_module", + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest.pb( + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.to_json( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + + request = ( + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest() + ) + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + + client.create_security_health_analytics_custom_module( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_security_health_analytics_custom_module_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest, +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1/securityHealthAnalyticsSettings"} + request_init["security_health_analytics_custom_module"] = { + "name": "name_value", + "display_name": "display_name_value", + "enablement_state": 1, + "update_time": {"seconds": 751, "nanos": 543}, + "last_editor": "last_editor_value", + "ancestor_module": "ancestor_module_value", + "custom_config": { + "predicate": { + "expression": "expression_value", + "title": "title_value", + "description": "description_value", + "location": "location_value", + }, + "custom_output": { + "properties": [{"name": "name_value", "value_expression": {}}] + }, + "resource_selector": { + "resource_types": ["resource_types_value1", "resource_types_value2"] + }, + "severity": 1, + "description": "description_value", + "recommendation": "recommendation_value", + }, + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_security_health_analytics_custom_module(request) + + +def test_create_security_health_analytics_custom_module_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) + + # get arguments that satisfy an http rule for this method + sample_request = { + "parent": "organizations/sample1/securityHealthAnalyticsSettings" + } + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.create_security_health_analytics_custom_module(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=organizations/*/securityHealthAnalyticsSettings}/customModules" + % client.transport._host, + args[1], + ) + + +def test_create_security_health_analytics_custom_module_rest_flattened_error( + transport: str = "rest", +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_security_health_analytics_custom_module( + securitycenter_service.CreateSecurityHealthAnalyticsCustomModuleRequest(), + parent="parent_value", + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( + name="name_value" + ), + ) + + +def test_create_security_health_analytics_custom_module_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.CreateSourceRequest, + dict, + ], +) +def test_create_source_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1"} + request_init["source"] = { + "name": "name_value", + "display_name": "display_name_value", + "description": "description_value", + "canonical_name": "canonical_name_value", + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = gcs_source.Source( + name="name_value", + display_name="display_name_value", + description="description_value", + canonical_name="canonical_name_value", + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_source.Source.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.create_source(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, gcs_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_create_source_rest_required_fields( + request_type=securitycenter_service.CreateSourceRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_source._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_source._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = gcs_source.Source() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = gcs_source.Source.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.create_source(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_source_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_source._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "source", + ) + ) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_source_rest_interceptors(null_interceptor): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, "post_create_source" + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_create_source" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = securitycenter_service.CreateSourceRequest.pb( + securitycenter_service.CreateSourceRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = gcs_source.Source.to_json(gcs_source.Source()) + + request = securitycenter_service.CreateSourceRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = gcs_source.Source() + + client.create_source( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_source_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.CreateSourceRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1"} + request_init["source"] = { + "name": "name_value", + "display_name": "display_name_value", + "description": "description_value", + "canonical_name": "canonical_name_value", + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_source(request) + + +def test_create_source_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = gcs_source.Source() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "organizations/sample1"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + source=gcs_source.Source(name="name_value"), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_source.Source.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.create_source(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=organizations/*}/sources" % client.transport._host, args[1] + ) + + +def test_create_source_rest_flattened_error(transport: str = "rest"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_source( + securitycenter_service.CreateSourceRequest(), + parent="parent_value", + source=gcs_source.Source(name="name_value"), + ) + + +def test_create_source_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.CreateFindingRequest, + dict, + ], +) +def test_create_finding_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1/sources/sample2"} + request_init["finding"] = { + "name": "name_value", + "parent": "parent_value", + "resource_name": "resource_name_value", + "state": 1, + "category": "category_value", + "external_uri": "external_uri_value", + "source_properties": {}, + "security_marks": { + "name": "name_value", + "marks": {}, + "canonical_name": "canonical_name_value", + }, + "event_time": {"seconds": 751, "nanos": 543}, + "create_time": {}, + "severity": 1, + "canonical_name": "canonical_name_value", + "mute": 1, + "finding_class": 1, + "indicator": { + "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], + "domains": ["domains_value1", "domains_value2"], + "signatures": [ + { + "memory_hash_signature": { + "binary_family": "binary_family_value", + "detections": [ + {"binary": "binary_value", "percent_pages_matched": 0.2197} + ], + }, + "yara_rule_signature": {"yara_rule": "yara_rule_value"}, + } + ], + "uris": ["uris_value1", "uris_value2"], + }, + "vulnerability": { + "cve": { + "id": "id_value", + "references": [{"source": "source_value", "uri": "uri_value"}], + "cvssv3": { + "base_score": 0.1046, + "attack_vector": 1, + "attack_complexity": 1, + "privileges_required": 1, + "user_interaction": 1, + "scope": 1, + "confidentiality_impact": 1, + "integrity_impact": 1, + "availability_impact": 1, + }, + "upstream_fix_available": True, + } + }, + "mute_update_time": {}, + "external_systems": {}, + "mitre_attack": { + "primary_tactic": 1, + "primary_techniques": [1], + "additional_tactics": [1], + "additional_techniques": [1], + "version": "version_value", + }, + "access": { + "principal_email": "principal_email_value", + "caller_ip": "caller_ip_value", + "caller_ip_geo": {"region_code": "region_code_value"}, + "user_agent_family": "user_agent_family_value", + "service_name": "service_name_value", + "method_name": "method_name_value", + "principal_subject": "principal_subject_value", + "service_account_key_name": "service_account_key_name_value", + "service_account_delegation_info": [ + { + "principal_email": "principal_email_value", + "principal_subject": "principal_subject_value", + } + ], + "user_name": "user_name_value", + }, + "connections": [ + { + "destination_ip": "destination_ip_value", + "destination_port": 1734, + "source_ip": "source_ip_value", + "source_port": 1205, + "protocol": 1, + } + ], + "mute_initiator": "mute_initiator_value", + "processes": [ + { + "name": "name_value", + "binary": { + "path": "path_value", + "size": 443, + "sha256": "sha256_value", + "hashed_size": 1159, + "partially_hashed": True, + "contents": "contents_value", + }, + "libraries": {}, + "script": {}, + "args": ["args_value1", "args_value2"], + "arguments_truncated": True, + "env_variables": [{"name": "name_value", "val": "val_value"}], + "env_variables_truncated": True, + "pid": 317, + "parent_pid": 1062, + } + ], + "contacts": {}, + "compliances": [ + { + "standard": "standard_value", + "version": "version_value", + "ids": ["ids_value1", "ids_value2"], + } + ], + "parent_display_name": "parent_display_name_value", + "description": "description_value", + "exfiltration": { + "sources": [ + { + "name": "name_value", + "components": ["components_value1", "components_value2"], + } + ], + "targets": {}, + }, + "iam_bindings": [{"action": 1, "role": "role_value", "member": "member_value"}], + "next_steps": "next_steps_value", + "module_name": "module_name_value", + "containers": [ + { + "name": "name_value", + "uri": "uri_value", + "image_id": "image_id_value", + "labels": [{"name": "name_value", "value": "value_value"}], + } + ], + "kubernetes": { + "pods": [ + {"ns": "ns_value", "name": "name_value", "labels": {}, "containers": {}} + ], + "nodes": [{"name": "name_value"}], + "node_pools": [{"name": "name_value", "nodes": {}}], + "roles": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], + "bindings": [ + { + "ns": "ns_value", + "name": "name_value", + "role": {}, + "subjects": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], + } + ], + "access_reviews": [ + { + "group": "group_value", + "ns": "ns_value", + "name": "name_value", + "resource": "resource_value", + "subresource": "subresource_value", + "verb": "verb_value", + "version": "version_value", + } + ], + }, + "database": { + "name": "name_value", + "display_name": "display_name_value", + "user_name": "user_name_value", + "query": "query_value", + "grantees": ["grantees_value1", "grantees_value2"], + }, + "files": {}, + "kernel_rootkit": { + "name": "name_value", + "unexpected_code_modification": True, + "unexpected_read_only_data_modification": True, + "unexpected_ftrace_handler": True, + "unexpected_kprobe_handler": True, + "unexpected_kernel_code_pages": True, + "unexpected_system_call_handler": True, + "unexpected_interrupt_handler": True, + "unexpected_processes_in_runqueue": True, + }, + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = gcs_finding.Finding( + name="name_value", + parent="parent_value", + resource_name="resource_name_value", + state=gcs_finding.Finding.State.ACTIVE, + category="category_value", + 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", + parent_display_name="parent_display_name_value", + description="description_value", + next_steps="next_steps_value", + module_name="module_name_value", + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_finding.Finding.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.create_finding(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, gcs_finding.Finding) + assert response.name == "name_value" + assert response.parent == "parent_value" + assert response.resource_name == "resource_name_value" + assert response.state == gcs_finding.Finding.State.ACTIVE + assert response.category == "category_value" + 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" + assert response.parent_display_name == "parent_display_name_value" + assert response.description == "description_value" + assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" + + +def test_create_finding_rest_required_fields( + request_type=securitycenter_service.CreateFindingRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["finding_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + assert "findingId" not in jsonified_request + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_finding._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "findingId" in jsonified_request + assert jsonified_request["findingId"] == request_init["finding_id"] + + jsonified_request["parent"] = "parent_value" + jsonified_request["findingId"] = "finding_id_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_finding._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("finding_id",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "findingId" in jsonified_request + assert jsonified_request["findingId"] == "finding_id_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = gcs_finding.Finding() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = gcs_finding.Finding.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.create_finding(request) + + expected_params = [ + ( + "findingId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_finding_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_finding._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("findingId",)) + & set( + ( + "parent", + "findingId", + "finding", + ) + ) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_finding_rest_interceptors(null_interceptor): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, "post_create_finding" + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_create_finding" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = securitycenter_service.CreateFindingRequest.pb( + securitycenter_service.CreateFindingRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = gcs_finding.Finding.to_json(gcs_finding.Finding()) + + request = securitycenter_service.CreateFindingRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = gcs_finding.Finding() + + client.create_finding( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_finding_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.CreateFindingRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1/sources/sample2"} + request_init["finding"] = { + "name": "name_value", + "parent": "parent_value", + "resource_name": "resource_name_value", + "state": 1, + "category": "category_value", + "external_uri": "external_uri_value", + "source_properties": {}, + "security_marks": { + "name": "name_value", + "marks": {}, + "canonical_name": "canonical_name_value", + }, + "event_time": {"seconds": 751, "nanos": 543}, + "create_time": {}, + "severity": 1, + "canonical_name": "canonical_name_value", + "mute": 1, + "finding_class": 1, + "indicator": { + "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], + "domains": ["domains_value1", "domains_value2"], + "signatures": [ + { + "memory_hash_signature": { + "binary_family": "binary_family_value", + "detections": [ + {"binary": "binary_value", "percent_pages_matched": 0.2197} + ], + }, + "yara_rule_signature": {"yara_rule": "yara_rule_value"}, + } + ], + "uris": ["uris_value1", "uris_value2"], + }, + "vulnerability": { + "cve": { + "id": "id_value", + "references": [{"source": "source_value", "uri": "uri_value"}], + "cvssv3": { "base_score": 0.1046, "attack_vector": 1, "attack_complexity": 1, @@ -12409,140 +15803,2118 @@ def test_create_finding_rest_bad_request( }, "upstream_fix_available": True, } - }, - "mute_update_time": {}, - "external_systems": {}, - "mitre_attack": { - "primary_tactic": 1, - "primary_techniques": [1], - "additional_tactics": [1], - "additional_techniques": [1], - "version": "version_value", - }, - "access": { - "principal_email": "principal_email_value", - "caller_ip": "caller_ip_value", - "caller_ip_geo": {"region_code": "region_code_value"}, - "user_agent_family": "user_agent_family_value", - "service_name": "service_name_value", - "method_name": "method_name_value", - "principal_subject": "principal_subject_value", - "service_account_key_name": "service_account_key_name_value", - "service_account_delegation_info": [ - { - "principal_email": "principal_email_value", - "principal_subject": "principal_subject_value", - } + }, + "mute_update_time": {}, + "external_systems": {}, + "mitre_attack": { + "primary_tactic": 1, + "primary_techniques": [1], + "additional_tactics": [1], + "additional_techniques": [1], + "version": "version_value", + }, + "access": { + "principal_email": "principal_email_value", + "caller_ip": "caller_ip_value", + "caller_ip_geo": {"region_code": "region_code_value"}, + "user_agent_family": "user_agent_family_value", + "service_name": "service_name_value", + "method_name": "method_name_value", + "principal_subject": "principal_subject_value", + "service_account_key_name": "service_account_key_name_value", + "service_account_delegation_info": [ + { + "principal_email": "principal_email_value", + "principal_subject": "principal_subject_value", + } + ], + "user_name": "user_name_value", + }, + "connections": [ + { + "destination_ip": "destination_ip_value", + "destination_port": 1734, + "source_ip": "source_ip_value", + "source_port": 1205, + "protocol": 1, + } + ], + "mute_initiator": "mute_initiator_value", + "processes": [ + { + "name": "name_value", + "binary": { + "path": "path_value", + "size": 443, + "sha256": "sha256_value", + "hashed_size": 1159, + "partially_hashed": True, + "contents": "contents_value", + }, + "libraries": {}, + "script": {}, + "args": ["args_value1", "args_value2"], + "arguments_truncated": True, + "env_variables": [{"name": "name_value", "val": "val_value"}], + "env_variables_truncated": True, + "pid": 317, + "parent_pid": 1062, + } + ], + "contacts": {}, + "compliances": [ + { + "standard": "standard_value", + "version": "version_value", + "ids": ["ids_value1", "ids_value2"], + } + ], + "parent_display_name": "parent_display_name_value", + "description": "description_value", + "exfiltration": { + "sources": [ + { + "name": "name_value", + "components": ["components_value1", "components_value2"], + } + ], + "targets": {}, + }, + "iam_bindings": [{"action": 1, "role": "role_value", "member": "member_value"}], + "next_steps": "next_steps_value", + "module_name": "module_name_value", + "containers": [ + { + "name": "name_value", + "uri": "uri_value", + "image_id": "image_id_value", + "labels": [{"name": "name_value", "value": "value_value"}], + } + ], + "kubernetes": { + "pods": [ + {"ns": "ns_value", "name": "name_value", "labels": {}, "containers": {}} + ], + "nodes": [{"name": "name_value"}], + "node_pools": [{"name": "name_value", "nodes": {}}], + "roles": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], + "bindings": [ + { + "ns": "ns_value", + "name": "name_value", + "role": {}, + "subjects": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], + } + ], + "access_reviews": [ + { + "group": "group_value", + "ns": "ns_value", + "name": "name_value", + "resource": "resource_value", + "subresource": "subresource_value", + "verb": "verb_value", + "version": "version_value", + } + ], + }, + "database": { + "name": "name_value", + "display_name": "display_name_value", + "user_name": "user_name_value", + "query": "query_value", + "grantees": ["grantees_value1", "grantees_value2"], + }, + "files": {}, + "kernel_rootkit": { + "name": "name_value", + "unexpected_code_modification": True, + "unexpected_read_only_data_modification": True, + "unexpected_ftrace_handler": True, + "unexpected_kprobe_handler": True, + "unexpected_kernel_code_pages": True, + "unexpected_system_call_handler": True, + "unexpected_interrupt_handler": True, + "unexpected_processes_in_runqueue": True, + }, + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_finding(request) + + +def test_create_finding_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = gcs_finding.Finding() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "organizations/sample1/sources/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + finding_id="finding_id_value", + finding=gcs_finding.Finding(name="name_value"), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_finding.Finding.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.create_finding(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=organizations/*/sources/*}/findings" + % client.transport._host, + args[1], + ) + + +def test_create_finding_rest_flattened_error(transport: str = "rest"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_finding( + securitycenter_service.CreateFindingRequest(), + parent="parent_value", + finding_id="finding_id_value", + finding=gcs_finding.Finding(name="name_value"), + ) + + +def test_create_finding_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.CreateMuteConfigRequest, + dict, + ], +) +def test_create_mute_config_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1"} + request_init["mute_config"] = { + "name": "name_value", + "display_name": "display_name_value", + "description": "description_value", + "filter": "filter_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "most_recent_editor": "most_recent_editor_value", + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + 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", + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.create_mute_config(request) + + # 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_create_mute_config_rest_required_fields( + request_type=securitycenter_service.CreateMuteConfigRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["mute_config_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + assert "muteConfigId" not in jsonified_request + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_mute_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "muteConfigId" in jsonified_request + assert jsonified_request["muteConfigId"] == request_init["mute_config_id"] + + jsonified_request["parent"] = "parent_value" + jsonified_request["muteConfigId"] = "mute_config_id_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_mute_config._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("mute_config_id",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "muteConfigId" in jsonified_request + assert jsonified_request["muteConfigId"] == "mute_config_id_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = gcs_mute_config.MuteConfig() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.create_mute_config(request) + + expected_params = [ + ( + "muteConfigId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_mute_config_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_mute_config._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("muteConfigId",)) + & set( + ( + "parent", + "muteConfig", + "muteConfigId", + ) + ) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_mute_config_rest_interceptors(null_interceptor): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, "post_create_mute_config" + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_create_mute_config" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = securitycenter_service.CreateMuteConfigRequest.pb( + securitycenter_service.CreateMuteConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = gcs_mute_config.MuteConfig.to_json( + gcs_mute_config.MuteConfig() + ) + + request = securitycenter_service.CreateMuteConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = gcs_mute_config.MuteConfig() + + client.create_mute_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_mute_config_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.CreateMuteConfigRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1"} + request_init["mute_config"] = { + "name": "name_value", + "display_name": "display_name_value", + "description": "description_value", + "filter": "filter_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "most_recent_editor": "most_recent_editor_value", + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_mute_config(request) + + +def test_create_mute_config_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = gcs_mute_config.MuteConfig() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "organizations/sample1"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + mute_config_id="mute_config_id_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.create_mute_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=organizations/*}/muteConfigs" % client.transport._host, + args[1], + ) + + +def test_create_mute_config_rest_flattened_error(transport: str = "rest"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_mute_config( + securitycenter_service.CreateMuteConfigRequest(), + parent="parent_value", + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + mute_config_id="mute_config_id_value", + ) + + +def test_create_mute_config_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.CreateNotificationConfigRequest, + dict, + ], +) +def test_create_notification_config_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1"} + request_init["notification_config"] = { + "name": "name_value", + "description": "description_value", + "pubsub_topic": "pubsub_topic_value", + "service_account": "service_account_value", + "streaming_config": {"filter": "filter_value"}, + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + 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" + ), + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_notification_config.NotificationConfig.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.create_notification_config(request) + + # Establish that the response is the type that we expect. + 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_create_notification_config_rest_required_fields( + request_type=securitycenter_service.CreateNotificationConfigRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["config_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + assert "configId" not in jsonified_request + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_notification_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "configId" in jsonified_request + assert jsonified_request["configId"] == request_init["config_id"] + + jsonified_request["parent"] = "parent_value" + jsonified_request["configId"] = "config_id_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_notification_config._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("config_id",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "configId" in jsonified_request + assert jsonified_request["configId"] == "config_id_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = gcs_notification_config.NotificationConfig() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = gcs_notification_config.NotificationConfig.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.create_notification_config(request) + + expected_params = [ + ( + "configId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_notification_config_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_notification_config._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("configId",)) + & set( + ( + "parent", + "configId", + "notificationConfig", + ) + ) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_notification_config_rest_interceptors(null_interceptor): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, "post_create_notification_config" + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_create_notification_config" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = securitycenter_service.CreateNotificationConfigRequest.pb( + securitycenter_service.CreateNotificationConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = gcs_notification_config.NotificationConfig.to_json( + gcs_notification_config.NotificationConfig() + ) + + request = securitycenter_service.CreateNotificationConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = gcs_notification_config.NotificationConfig() + + client.create_notification_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_notification_config_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.CreateNotificationConfigRequest, +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1"} + request_init["notification_config"] = { + "name": "name_value", + "description": "description_value", + "pubsub_topic": "pubsub_topic_value", + "service_account": "service_account_value", + "streaming_config": {"filter": "filter_value"}, + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_notification_config(request) + + +def test_create_notification_config_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = gcs_notification_config.NotificationConfig() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "organizations/sample1"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + config_id="config_id_value", + notification_config=gcs_notification_config.NotificationConfig( + name="name_value" + ), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_notification_config.NotificationConfig.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.create_notification_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=organizations/*}/notificationConfigs" + % client.transport._host, + args[1], + ) + + +def test_create_notification_config_rest_flattened_error(transport: str = "rest"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # 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(), + parent="parent_value", + config_id="config_id_value", + notification_config=gcs_notification_config.NotificationConfig( + name="name_value" + ), + ) + + +def test_create_notification_config_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.DeleteMuteConfigRequest, + dict, + ], +) +def test_delete_mute_config_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"name": "organizations/sample1/muteConfigs/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.delete_mute_config(request) + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_mute_config_rest_required_fields( + request_type=securitycenter_service.DeleteMuteConfigRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_mute_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_mute_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.delete_mute_config(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_delete_mute_config_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_mute_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_mute_config_rest_interceptors(null_interceptor): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_delete_mute_config" + ) as pre: + pre.assert_not_called() + pb_message = securitycenter_service.DeleteMuteConfigRequest.pb( + securitycenter_service.DeleteMuteConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + + request = securitycenter_service.DeleteMuteConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.delete_mute_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + + +def test_delete_mute_config_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.DeleteMuteConfigRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"name": "organizations/sample1/muteConfigs/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.delete_mute_config(request) + + +def test_delete_mute_config_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = {"name": "organizations/sample1/muteConfigs/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.delete_mute_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=organizations/*/muteConfigs/*}" % client.transport._host, + args[1], + ) + + +def test_delete_mute_config_rest_flattened_error(transport: str = "rest"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_mute_config( + securitycenter_service.DeleteMuteConfigRequest(), + name="name_value", + ) + + +def test_delete_mute_config_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.DeleteNotificationConfigRequest, + dict, + ], +) +def test_delete_notification_config_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"name": "organizations/sample1/notificationConfigs/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.delete_notification_config(request) + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_notification_config_rest_required_fields( + request_type=securitycenter_service.DeleteNotificationConfigRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_notification_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_notification_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.delete_notification_config(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_delete_notification_config_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_notification_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_notification_config_rest_interceptors(null_interceptor): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_delete_notification_config" + ) as pre: + pre.assert_not_called() + pb_message = securitycenter_service.DeleteNotificationConfigRequest.pb( + securitycenter_service.DeleteNotificationConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + + request = securitycenter_service.DeleteNotificationConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.delete_notification_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), ], - "user_name": "user_name_value", - }, - "connections": [ - { - "destination_ip": "destination_ip_value", - "destination_port": 1734, - "source_ip": "source_ip_value", - "source_port": 1205, - "protocol": 1, - } - ], - "mute_initiator": "mute_initiator_value", - "processes": [ - { - "name": "name_value", - "binary": { - "path": "path_value", - "size": 443, - "sha256": "sha256_value", - "hashed_size": 1159, - "partially_hashed": True, - "contents": "contents_value", - }, - "libraries": {}, - "script": {}, - "args": ["args_value1", "args_value2"], - "arguments_truncated": True, - "env_variables": [{"name": "name_value", "val": "val_value"}], - "env_variables_truncated": True, - "pid": 317, - "parent_pid": 1062, + ) + + pre.assert_called_once() + + +def test_delete_notification_config_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.DeleteNotificationConfigRequest, +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"name": "organizations/sample1/notificationConfigs/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.delete_notification_config(request) + + +def test_delete_notification_config_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = {"name": "organizations/sample1/notificationConfigs/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.delete_notification_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=organizations/*/notificationConfigs/*}" + % client.transport._host, + args[1], + ) + + +def test_delete_notification_config_rest_flattened_error(transport: str = "rest"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # 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", + ) + + +def test_delete_notification_config_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, + dict, + ], +) +def test_delete_security_health_analytics_custom_module_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.delete_security_health_analytics_custom_module(request) + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_security_health_analytics_custom_module_rest_required_fields( + request_type=securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_security_health_analytics_custom_module._get_unset_required_fields( + jsonified_request + ) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_security_health_analytics_custom_module._get_unset_required_fields( + jsonified_request + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, } - ], - "contacts": {}, - "compliances": [ - { - "standard": "standard_value", - "version": "version_value", - "ids": ["ids_value1", "ids_value2"], + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.delete_security_health_analytics_custom_module(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_delete_security_health_analytics_custom_module_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_security_health_analytics_custom_module._get_unset_required_fields( + {} + ) + assert set(unset_fields) == (set(()) & set(("name",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_security_health_analytics_custom_module_rest_interceptors( + null_interceptor, +): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, + "pre_delete_security_health_analytics_custom_module", + ) as pre: + pre.assert_not_called() + pb_message = securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest.pb( + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + + request = ( + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest() + ) + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.delete_security_health_analytics_custom_module( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + + +def test_delete_security_health_analytics_custom_module_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest, +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.delete_security_health_analytics_custom_module(request) + + +def test_delete_security_health_analytics_custom_module_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "" + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.delete_security_health_analytics_custom_module(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=organizations/*/securityHealthAnalyticsSettings/customModules/*}" + % client.transport._host, + args[1], + ) + + +def test_delete_security_health_analytics_custom_module_rest_flattened_error( + transport: str = "rest", +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_security_health_analytics_custom_module( + securitycenter_service.DeleteSecurityHealthAnalyticsCustomModuleRequest(), + name="name_value", + ) + + +def test_delete_security_health_analytics_custom_module_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.GetBigQueryExportRequest, + dict, + ], +) +def test_get_big_query_export_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"name": "organizations/sample1/bigQueryExports/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = bigquery_export.BigQueryExport( + name="name_value", + description="description_value", + filter="filter_value", + dataset="dataset_value", + most_recent_editor="most_recent_editor_value", + principal="principal_value", + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = bigquery_export.BigQueryExport.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.get_big_query_export(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, bigquery_export.BigQueryExport) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.filter == "filter_value" + assert response.dataset == "dataset_value" + assert response.most_recent_editor == "most_recent_editor_value" + assert response.principal == "principal_value" + + +def test_get_big_query_export_rest_required_fields( + request_type=securitycenter_service.GetBigQueryExportRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_big_query_export._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_big_query_export._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = bigquery_export.BigQueryExport() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, } - ], - "parent_display_name": "parent_display_name_value", - "description": "description_value", - "exfiltration": { - "sources": [ - { - "name": "name_value", - "components": ["components_value1", "components_value2"], - } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = bigquery_export.BigQueryExport.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.get_big_query_export(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_big_query_export_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_big_query_export._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_big_query_export_rest_interceptors(null_interceptor): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, "post_get_big_query_export" + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_get_big_query_export" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = securitycenter_service.GetBigQueryExportRequest.pb( + securitycenter_service.GetBigQueryExportRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = bigquery_export.BigQueryExport.to_json( + bigquery_export.BigQueryExport() + ) + + request = securitycenter_service.GetBigQueryExportRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = bigquery_export.BigQueryExport() + + client.get_big_query_export( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), ], - "targets": {}, - }, - "iam_bindings": [{"action": 1, "role": "role_value", "member": "member_value"}], - "next_steps": "next_steps_value", - "containers": [ - { - "name": "name_value", - "uri": "uri_value", - "image_id": "image_id_value", - "labels": [{"name": "name_value", "value": "value_value"}], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_big_query_export_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.GetBigQueryExportRequest, +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"name": "organizations/sample1/bigQueryExports/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_big_query_export(request) + + +def test_get_big_query_export_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = bigquery_export.BigQueryExport() + + # get arguments that satisfy an http rule for this method + sample_request = {"name": "organizations/sample1/bigQueryExports/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = bigquery_export.BigQueryExport.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.get_big_query_export(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=organizations/*/bigQueryExports/*}" % client.transport._host, + args[1], + ) + + +def test_get_big_query_export_rest_flattened_error(transport: str = "rest"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_big_query_export( + securitycenter_service.GetBigQueryExportRequest(), + name="name_value", + ) + + +def test_get_big_query_export_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + iam_policy_pb2.GetIamPolicyRequest, + dict, + ], +) +def test_get_iam_policy_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"resource": "organizations/sample1/sources/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.get_iam_policy(request) + + # 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" + + +def test_get_iam_policy_rest_required_fields( + request_type=iam_policy_pb2.GetIamPolicyRequest, +): + transport_class = transports.SecurityCenterRestTransport + + request_init = {} + request_init["resource"] = "" + request = request_type(**request_init) + pb_request = request + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_iam_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["resource"] = "resource_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_iam_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "resource" in jsonified_request + assert jsonified_request["resource"] == "resource_value" + + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, } - ], - "kubernetes": { - "pods": [ - {"ns": "ns_value", "name": "name_value", "labels": {}, "containers": {}} - ], - "nodes": [{"name": "name_value"}], - "node_pools": [{"name": "name_value", "nodes": {}}], - "roles": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], - "bindings": [ - { - "ns": "ns_value", - "name": "name_value", - "role": {}, - "subjects": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], - } - ], - "access_reviews": [ - { - "group": "group_value", - "ns": "ns_value", - "name": "name_value", - "resource": "resource_value", - "subresource": "subresource_value", - "verb": "verb_value", - "version": "version_value", - } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.get_iam_policy(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_iam_policy_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_iam_policy._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("resource",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_iam_policy_rest_interceptors(null_interceptor): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), + ) + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, "post_get_iam_policy" + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_get_iam_policy" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = iam_policy_pb2.GetIamPolicyRequest() + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) + + request = iam_policy_pb2.GetIamPolicyRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = policy_pb2.Policy() + + client.get_iam_policy( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), ], - }, - "database": { - "name": "name_value", - "display_name": "display_name_value", - "user_name": "user_name_value", - "query": "query_value", - "grantees": ["grantees_value1", "grantees_value2"], - }, - "files": {}, - "kernel_rootkit": { - "name": "name_value", - "unexpected_code_modification": True, - "unexpected_read_only_data_modification": True, - "unexpected_ftrace_handler": True, - "unexpected_kprobe_handler": True, - "unexpected_kernel_code_pages": True, - "unexpected_system_call_handler": True, - "unexpected_interrupt_handler": True, - "unexpected_processes_in_runqueue": True, - }, - } + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_iam_policy_rest_bad_request( + transport: str = "rest", request_type=iam_policy_pb2.GetIamPolicyRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"resource": "organizations/sample1/sources/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -12554,10 +17926,10 @@ def test_create_finding_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.create_finding(request) + client.get_iam_policy(request) -def test_create_finding_rest_flattened(): +def test_get_iam_policy_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -12566,41 +17938,39 @@ def test_create_finding_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_finding.Finding() + return_value = policy_pb2.Policy() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "organizations/sample1/sources/sample2"} + sample_request = {"resource": "organizations/sample1/sources/sample2"} # get truthy value for each flattened field mock_args = dict( - parent="parent_value", - finding_id="finding_id_value", - finding=gcs_finding.Finding(name="name_value"), + resource="resource_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_finding.Finding.pb(return_value) + pb_return_value = return_value json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.create_finding(**mock_args) + client.get_iam_policy(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=organizations/*/sources/*}/findings" + "%s/v1/{resource=organizations/*/sources/*}:getIamPolicy" % client.transport._host, args[1], ) -def test_create_finding_rest_flattened_error(transport: str = "rest"): +def test_get_iam_policy_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -12609,15 +17979,13 @@ def test_create_finding_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_finding( - securitycenter_service.CreateFindingRequest(), - parent="parent_value", - finding_id="finding_id_value", - finding=gcs_finding.Finding(name="name_value"), + client.get_iam_policy( + iam_policy_pb2.GetIamPolicyRequest(), + resource="resource_value", ) -def test_create_finding_rest_error(): +def test_get_iam_policy_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -12626,33 +17994,24 @@ def test_create_finding_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.CreateMuteConfigRequest, + securitycenter_service.GetMuteConfigRequest, dict, ], ) -def test_create_mute_config_rest(request_type): +def test_get_mute_config_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} - request_init["mute_config"] = { - "name": "name_value", - "display_name": "display_name_value", - "description": "description_value", - "filter": "filter_value", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "most_recent_editor": "most_recent_editor_value", - } + request_init = {"name": "organizations/sample1/muteConfigs/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_mute_config.MuteConfig( + return_value = mute_config.MuteConfig( name="name_value", display_name="display_name_value", description="description_value", @@ -12663,15 +18022,15 @@ def test_create_mute_config_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) + pb_return_value = mute_config.MuteConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_mute_config(request) + response = client.get_mute_config(request) # Establish that the response is the type that we expect. - assert isinstance(response, gcs_mute_config.MuteConfig) + assert isinstance(response, mute_config.MuteConfig) assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.description == "description_value" @@ -12679,14 +18038,13 @@ def test_create_mute_config_rest(request_type): assert response.most_recent_editor == "most_recent_editor_value" -def test_create_mute_config_rest_required_fields( - request_type=securitycenter_service.CreateMuteConfigRequest, +def test_get_mute_config_rest_required_fields( + request_type=securitycenter_service.GetMuteConfigRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} - request_init["parent"] = "" - request_init["mute_config_id"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -12698,32 +18056,24 @@ def test_create_mute_config_rest_required_fields( ) # verify fields with default values are dropped - assert "muteConfigId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_mute_config._get_unset_required_fields(jsonified_request) + ).get_mute_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "muteConfigId" in jsonified_request - assert jsonified_request["muteConfigId"] == request_init["mute_config_id"] - jsonified_request["parent"] = "parent_value" - jsonified_request["muteConfigId"] = "mute_config_id_value" + jsonified_request["name"] = "name_value" - unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ).create_mute_config._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("mute_config_id",)) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_mute_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" - assert "muteConfigId" in jsonified_request - assert jsonified_request["muteConfigId"] == "mute_config_id_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12732,7 +18082,7 @@ def test_create_mute_config_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gcs_mute_config.MuteConfig() + return_value = mute_config.MuteConfig() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -12744,54 +18094,38 @@ def test_create_mute_config_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) + pb_return_value = mute_config.MuteConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_mute_config(request) + response = client.get_mute_config(request) - expected_params = [ - ( - "muteConfigId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_mute_config_rest_unset_required_fields(): +def test_get_mute_config_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_mute_config._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(("muteConfigId",)) - & set( - ( - "parent", - "muteConfig", - "muteConfigId", - ) - ) - ) + unset_fields = transport.get_mute_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_mute_config_rest_interceptors(null_interceptor): +def test_get_mute_config_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -12804,14 +18138,14 @@ def test_create_mute_config_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_create_mute_config" + transports.SecurityCenterRestInterceptor, "post_get_mute_config" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_create_mute_config" + transports.SecurityCenterRestInterceptor, "pre_get_mute_config" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.CreateMuteConfigRequest.pb( - securitycenter_service.CreateMuteConfigRequest() + pb_message = securitycenter_service.GetMuteConfigRequest.pb( + securitycenter_service.GetMuteConfigRequest() ) transcode.return_value = { "method": "post", @@ -12823,19 +18157,19 @@ def test_create_mute_config_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = gcs_mute_config.MuteConfig.to_json( - gcs_mute_config.MuteConfig() + req.return_value._content = mute_config.MuteConfig.to_json( + mute_config.MuteConfig() ) - request = securitycenter_service.CreateMuteConfigRequest() + request = securitycenter_service.GetMuteConfigRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = gcs_mute_config.MuteConfig() + post.return_value = mute_config.MuteConfig() - client.create_mute_config( + client.get_mute_config( request, metadata=[ ("key", "val"), @@ -12847,8 +18181,8 @@ def test_create_mute_config_rest_interceptors(null_interceptor): post.assert_called_once() -def test_create_mute_config_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.CreateMuteConfigRequest +def test_get_mute_config_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.GetMuteConfigRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12856,16 +18190,7 @@ def test_create_mute_config_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} - request_init["mute_config"] = { - "name": "name_value", - "display_name": "display_name_value", - "description": "description_value", - "filter": "filter_value", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "most_recent_editor": "most_recent_editor_value", - } + request_init = {"name": "organizations/sample1/muteConfigs/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -12877,10 +18202,10 @@ def test_create_mute_config_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.create_mute_config(request) + client.get_mute_config(request) -def test_create_mute_config_rest_flattened(): +def test_get_mute_config_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -12889,40 +18214,38 @@ def test_create_mute_config_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_mute_config.MuteConfig() + return_value = mute_config.MuteConfig() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "organizations/sample1"} + sample_request = {"name": "organizations/sample1/muteConfigs/sample2"} # get truthy value for each flattened field mock_args = dict( - parent="parent_value", - mute_config=gcs_mute_config.MuteConfig(name="name_value"), - mute_config_id="mute_config_id_value", + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) + pb_return_value = mute_config.MuteConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.create_mute_config(**mock_args) + client.get_mute_config(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=organizations/*}/muteConfigs" % client.transport._host, + "%s/v1/{name=organizations/*/muteConfigs/*}" % client.transport._host, args[1], ) -def test_create_mute_config_rest_flattened_error(transport: str = "rest"): +def test_get_mute_config_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -12931,15 +18254,13 @@ def test_create_mute_config_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_mute_config( - securitycenter_service.CreateMuteConfigRequest(), - parent="parent_value", - mute_config=gcs_mute_config.MuteConfig(name="name_value"), - mute_config_id="mute_config_id_value", + client.get_mute_config( + securitycenter_service.GetMuteConfigRequest(), + name="name_value", ) -def test_create_mute_config_rest_error(): +def test_get_mute_config_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -12948,36 +18269,29 @@ def test_create_mute_config_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.CreateNotificationConfigRequest, + securitycenter_service.GetNotificationConfigRequest, dict, ], ) -def test_create_notification_config_rest(request_type): +def test_get_notification_config_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} - request_init["notification_config"] = { - "name": "name_value", - "description": "description_value", - "pubsub_topic": "pubsub_topic_value", - "service_account": "service_account_value", - "streaming_config": {"filter": "filter_value"}, - } + request_init = {"name": "organizations/sample1/notificationConfigs/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_notification_config.NotificationConfig( + return_value = 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( + streaming_config=notification_config.NotificationConfig.StreamingConfig( filter="filter_value" ), ) @@ -12985,29 +18299,28 @@ def test_create_notification_config_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_notification_config.NotificationConfig.pb(return_value) + pb_return_value = notification_config.NotificationConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_notification_config(request) + response = client.get_notification_config(request) # Establish that the response is the type that we expect. - assert isinstance(response, gcs_notification_config.NotificationConfig) + 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_create_notification_config_rest_required_fields( - request_type=securitycenter_service.CreateNotificationConfigRequest, +def test_get_notification_config_rest_required_fields( + request_type=securitycenter_service.GetNotificationConfigRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} - request_init["parent"] = "" - request_init["config_id"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -13019,32 +18332,24 @@ def test_create_notification_config_rest_required_fields( ) # verify fields with default values are dropped - assert "configId" not in jsonified_request unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_notification_config._get_unset_required_fields(jsonified_request) + ).get_notification_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - assert "configId" in jsonified_request - assert jsonified_request["configId"] == request_init["config_id"] - jsonified_request["parent"] = "parent_value" - jsonified_request["configId"] = "config_id_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).create_notification_config._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("config_id",)) + ).get_notification_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" - assert "configId" in jsonified_request - assert jsonified_request["configId"] == "config_id_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13053,7 +18358,7 @@ def test_create_notification_config_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gcs_notification_config.NotificationConfig() + return_value = notification_config.NotificationConfig() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -13065,56 +18370,38 @@ def test_create_notification_config_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_notification_config.NotificationConfig.pb( - return_value - ) + pb_return_value = notification_config.NotificationConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.create_notification_config(request) + response = client.get_notification_config(request) - expected_params = [ - ( - "configId", - "", - ), - ("$alt", "json;enum-encoding=int"), - ] + expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_create_notification_config_rest_unset_required_fields(): +def test_get_notification_config_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.create_notification_config._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(("configId",)) - & set( - ( - "parent", - "configId", - "notificationConfig", - ) - ) - ) + unset_fields = transport.get_notification_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_notification_config_rest_interceptors(null_interceptor): +def test_get_notification_config_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -13127,14 +18414,14 @@ def test_create_notification_config_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_create_notification_config" + transports.SecurityCenterRestInterceptor, "post_get_notification_config" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_create_notification_config" + transports.SecurityCenterRestInterceptor, "pre_get_notification_config" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.CreateNotificationConfigRequest.pb( - securitycenter_service.CreateNotificationConfigRequest() + pb_message = securitycenter_service.GetNotificationConfigRequest.pb( + securitycenter_service.GetNotificationConfigRequest() ) transcode.return_value = { "method": "post", @@ -13146,19 +18433,19 @@ def test_create_notification_config_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = gcs_notification_config.NotificationConfig.to_json( - gcs_notification_config.NotificationConfig() + req.return_value._content = notification_config.NotificationConfig.to_json( + notification_config.NotificationConfig() ) - request = securitycenter_service.CreateNotificationConfigRequest() + request = securitycenter_service.GetNotificationConfigRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = gcs_notification_config.NotificationConfig() + post.return_value = notification_config.NotificationConfig() - client.create_notification_config( + client.get_notification_config( request, metadata=[ ("key", "val"), @@ -13170,9 +18457,9 @@ def test_create_notification_config_rest_interceptors(null_interceptor): post.assert_called_once() -def test_create_notification_config_rest_bad_request( +def test_get_notification_config_rest_bad_request( transport: str = "rest", - request_type=securitycenter_service.CreateNotificationConfigRequest, + request_type=securitycenter_service.GetNotificationConfigRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13180,14 +18467,7 @@ def test_create_notification_config_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} - request_init["notification_config"] = { - "name": "name_value", - "description": "description_value", - "pubsub_topic": "pubsub_topic_value", - "service_account": "service_account_value", - "streaming_config": {"filter": "filter_value"}, - } + request_init = {"name": "organizations/sample1/notificationConfigs/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -13199,10 +18479,10 @@ def test_create_notification_config_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.create_notification_config(request) + client.get_notification_config(request) -def test_create_notification_config_rest_flattened(): +def test_get_notification_config_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -13211,43 +18491,39 @@ def test_create_notification_config_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_notification_config.NotificationConfig() + return_value = notification_config.NotificationConfig() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "organizations/sample1"} + sample_request = {"name": "organizations/sample1/notificationConfigs/sample2"} # get truthy value for each flattened field mock_args = dict( - parent="parent_value", - config_id="config_id_value", - notification_config=gcs_notification_config.NotificationConfig( - name="name_value" - ), + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_notification_config.NotificationConfig.pb(return_value) + pb_return_value = notification_config.NotificationConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.create_notification_config(**mock_args) + client.get_notification_config(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=organizations/*}/notificationConfigs" + "%s/v1/{name=organizations/*/notificationConfigs/*}" % client.transport._host, args[1], ) -def test_create_notification_config_rest_flattened_error(transport: str = "rest"): +def test_get_notification_config_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -13256,17 +18532,13 @@ def test_create_notification_config_rest_flattened_error(transport: str = "rest" # 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(), - parent="parent_value", - config_id="config_id_value", - notification_config=gcs_notification_config.NotificationConfig( - name="name_value" - ), + client.get_notification_config( + securitycenter_service.GetNotificationConfigRequest(), + name="name_value", ) -def test_create_notification_config_rest_error(): +def test_get_notification_config_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -13275,40 +18547,46 @@ def test_create_notification_config_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.DeleteMuteConfigRequest, + securitycenter_service.GetOrganizationSettingsRequest, dict, ], ) -def test_delete_mute_config_rest(request_type): +def test_get_organization_settings_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/muteConfigs/sample2"} + request_init = {"name": "organizations/sample1/organizationSettings"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = None + return_value = organization_settings.OrganizationSettings( + name="name_value", + enable_asset_discovery=True, + ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - json_return_value = "" + pb_return_value = organization_settings.OrganizationSettings.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_mute_config(request) + response = client.get_organization_settings(request) # Establish that the response is the type that we expect. - assert response is None + assert isinstance(response, organization_settings.OrganizationSettings) + assert response.name == "name_value" + assert response.enable_asset_discovery is True -def test_delete_mute_config_rest_required_fields( - request_type=securitycenter_service.DeleteMuteConfigRequest, +def test_get_organization_settings_rest_required_fields( + request_type=securitycenter_service.GetOrganizationSettingsRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -13328,7 +18606,7 @@ def test_delete_mute_config_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_mute_config._get_unset_required_fields(jsonified_request) + ).get_organization_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -13337,7 +18615,7 @@ def test_delete_mute_config_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_mute_config._get_unset_required_fields(jsonified_request) + ).get_organization_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -13351,7 +18629,7 @@ def test_delete_mute_config_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = None + return_value = organization_settings.OrganizationSettings() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -13363,36 +18641,40 @@ def test_delete_mute_config_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "get", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - json_return_value = "" + + pb_return_value = organization_settings.OrganizationSettings.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_mute_config(request) + response = client.get_organization_settings(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_delete_mute_config_rest_unset_required_fields(): +def test_get_organization_settings_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_mute_config._get_unset_required_fields({}) + unset_fields = transport.get_organization_settings._get_unset_required_fields({}) assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_mute_config_rest_interceptors(null_interceptor): +def test_get_organization_settings_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -13405,11 +18687,14 @@ def test_delete_mute_config_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_delete_mute_config" + transports.SecurityCenterRestInterceptor, "post_get_organization_settings" + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_get_organization_settings" ) as pre: pre.assert_not_called() - pb_message = securitycenter_service.DeleteMuteConfigRequest.pb( - securitycenter_service.DeleteMuteConfigRequest() + post.assert_not_called() + pb_message = securitycenter_service.GetOrganizationSettingsRequest.pb( + securitycenter_service.GetOrganizationSettingsRequest() ) transcode.return_value = { "method": "post", @@ -13421,15 +18706,19 @@ def test_delete_mute_config_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() + req.return_value._content = organization_settings.OrganizationSettings.to_json( + organization_settings.OrganizationSettings() + ) - request = securitycenter_service.DeleteMuteConfigRequest() + request = securitycenter_service.GetOrganizationSettingsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata + post.return_value = organization_settings.OrganizationSettings() - client.delete_mute_config( + client.get_organization_settings( request, metadata=[ ("key", "val"), @@ -13438,10 +18727,12 @@ def test_delete_mute_config_rest_interceptors(null_interceptor): ) pre.assert_called_once() + post.assert_called_once() -def test_delete_mute_config_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.DeleteMuteConfigRequest +def test_get_organization_settings_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.GetOrganizationSettingsRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13449,7 +18740,7 @@ def test_delete_mute_config_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/muteConfigs/sample2"} + request_init = {"name": "organizations/sample1/organizationSettings"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -13461,10 +18752,10 @@ def test_delete_mute_config_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.delete_mute_config(request) + client.get_organization_settings(request) -def test_delete_mute_config_rest_flattened(): +def test_get_organization_settings_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -13473,10 +18764,10 @@ def test_delete_mute_config_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = None + return_value = organization_settings.OrganizationSettings() # get arguments that satisfy an http rule for this method - sample_request = {"name": "organizations/sample1/muteConfigs/sample2"} + sample_request = {"name": "organizations/sample1/organizationSettings"} # get truthy value for each flattened field mock_args = dict( @@ -13487,23 +18778,25 @@ def test_delete_mute_config_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - json_return_value = "" + pb_return_value = organization_settings.OrganizationSettings.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.delete_mute_config(**mock_args) + client.get_organization_settings(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=organizations/*/muteConfigs/*}" % client.transport._host, + "%s/v1/{name=organizations/*/organizationSettings}" + % client.transport._host, args[1], ) -def test_delete_mute_config_rest_flattened_error(transport: str = "rest"): +def test_get_organization_settings_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -13512,13 +18805,13 @@ def test_delete_mute_config_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_mute_config( - securitycenter_service.DeleteMuteConfigRequest(), + client.get_organization_settings( + securitycenter_service.GetOrganizationSettingsRequest(), name="name_value", ) -def test_delete_mute_config_rest_error(): +def test_get_organization_settings_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -13527,40 +18820,58 @@ def test_delete_mute_config_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.DeleteNotificationConfigRequest, + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, dict, ], ) -def test_delete_notification_config_rest(request_type): +def test_get_effective_security_health_analytics_custom_module_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/notificationConfigs/sample2"} + request_init = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/effectiveCustomModules/sample2" + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = None + return_value = effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule( + name="name_value", + enablement_state=effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, + display_name="display_name_value", + ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - json_return_value = "" + pb_return_value = effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_notification_config(request) + response = client.get_effective_security_health_analytics_custom_module(request) # Establish that the response is the type that we expect. - assert response is None + assert isinstance( + response, + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, + ) + assert response.name == "name_value" + assert ( + response.enablement_state + == effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) + assert response.display_name == "display_name_value" -def test_delete_notification_config_rest_required_fields( - request_type=securitycenter_service.DeleteNotificationConfigRequest, +def test_get_effective_security_health_analytics_custom_module_rest_required_fields( + request_type=securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -13580,7 +18891,9 @@ def test_delete_notification_config_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_notification_config._get_unset_required_fields(jsonified_request) + ).get_effective_security_health_analytics_custom_module._get_unset_required_fields( + jsonified_request + ) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -13589,7 +18902,9 @@ def test_delete_notification_config_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).delete_notification_config._get_unset_required_fields(jsonified_request) + ).get_effective_security_health_analytics_custom_module._get_unset_required_fields( + jsonified_request + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -13603,7 +18918,9 @@ def test_delete_notification_config_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = None + return_value = ( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule() + ) # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -13615,36 +18932,46 @@ def test_delete_notification_config_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "delete", + "method": "get", "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - json_return_value = "" + + pb_return_value = effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.delete_notification_config(request) + response = client.get_effective_security_health_analytics_custom_module( + request + ) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_delete_notification_config_rest_unset_required_fields(): +def test_get_effective_security_health_analytics_custom_module_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.delete_notification_config._get_unset_required_fields({}) + unset_fields = transport.get_effective_security_health_analytics_custom_module._get_unset_required_fields( + {} + ) assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_notification_config_rest_interceptors(null_interceptor): +def test_get_effective_security_health_analytics_custom_module_rest_interceptors( + null_interceptor, +): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -13657,11 +18984,16 @@ def test_delete_notification_config_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_delete_notification_config" + transports.SecurityCenterRestInterceptor, + "post_get_effective_security_health_analytics_custom_module", + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, + "pre_get_effective_security_health_analytics_custom_module", ) as pre: pre.assert_not_called() - pb_message = securitycenter_service.DeleteNotificationConfigRequest.pb( - securitycenter_service.DeleteNotificationConfigRequest() + post.assert_not_called() + pb_message = securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest.pb( + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest() ) transcode.return_value = { "method": "post", @@ -13673,15 +19005,23 @@ def test_delete_notification_config_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() + req.return_value._content = effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.to_json( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule() + ) - request = securitycenter_service.DeleteNotificationConfigRequest() + request = ( + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest() + ) metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata + post.return_value = ( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule() + ) - client.delete_notification_config( + client.get_effective_security_health_analytics_custom_module( request, metadata=[ ("key", "val"), @@ -13690,11 +19030,12 @@ def test_delete_notification_config_rest_interceptors(null_interceptor): ) pre.assert_called_once() + post.assert_called_once() -def test_delete_notification_config_rest_bad_request( +def test_get_effective_security_health_analytics_custom_module_rest_bad_request( transport: str = "rest", - request_type=securitycenter_service.DeleteNotificationConfigRequest, + request_type=securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13702,7 +19043,9 @@ def test_delete_notification_config_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/notificationConfigs/sample2"} + request_init = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/effectiveCustomModules/sample2" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -13714,10 +19057,10 @@ def test_delete_notification_config_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.delete_notification_config(request) + client.get_effective_security_health_analytics_custom_module(request) -def test_delete_notification_config_rest_flattened(): +def test_get_effective_security_health_analytics_custom_module_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -13726,10 +19069,14 @@ def test_delete_notification_config_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = None + return_value = ( + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule() + ) # get arguments that satisfy an http rule for this method - sample_request = {"name": "organizations/sample1/notificationConfigs/sample2"} + sample_request = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/effectiveCustomModules/sample2" + } # get truthy value for each flattened field mock_args = dict( @@ -13740,24 +19087,29 @@ def test_delete_notification_config_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - json_return_value = "" + pb_return_value = effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.delete_notification_config(**mock_args) + client.get_effective_security_health_analytics_custom_module(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=organizations/*/notificationConfigs/*}" + "%s/v1/{name=organizations/*/securityHealthAnalyticsSettings/effectiveCustomModules/*}" % client.transport._host, args[1], ) -def test_delete_notification_config_rest_flattened_error(transport: str = "rest"): +def test_get_effective_security_health_analytics_custom_module_rest_flattened_error( + transport: str = "rest", +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -13766,13 +19118,13 @@ def test_delete_notification_config_rest_flattened_error(transport: str = "rest" # 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(), + client.get_effective_security_health_analytics_custom_module( + securitycenter_service.GetEffectiveSecurityHealthAnalyticsCustomModuleRequest(), name="name_value", ) -def test_delete_notification_config_rest_error(): +def test_get_effective_security_health_analytics_custom_module_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -13781,54 +19133,62 @@ def test_delete_notification_config_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GetBigQueryExportRequest, + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, dict, ], ) -def test_get_big_query_export_rest(request_type): +def test_get_security_health_analytics_custom_module_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/bigQueryExports/sample2"} + request_init = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2" + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = bigquery_export.BigQueryExport( + return_value = security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( name="name_value", - description="description_value", - filter="filter_value", - dataset="dataset_value", - most_recent_editor="most_recent_editor_value", - principal="principal_value", + display_name="display_name_value", + enablement_state=security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, + last_editor="last_editor_value", + ancestor_module="ancestor_module_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = bigquery_export.BigQueryExport.pb(return_value) + pb_return_value = security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_big_query_export(request) + response = client.get_security_health_analytics_custom_module(request) # Establish that the response is the type that we expect. - assert isinstance(response, bigquery_export.BigQueryExport) + assert isinstance( + response, + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) assert response.name == "name_value" - assert response.description == "description_value" - assert response.filter == "filter_value" - assert response.dataset == "dataset_value" - assert response.most_recent_editor == "most_recent_editor_value" - assert response.principal == "principal_value" + assert response.display_name == "display_name_value" + assert ( + response.enablement_state + == security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) + assert response.last_editor == "last_editor_value" + assert response.ancestor_module == "ancestor_module_value" -def test_get_big_query_export_rest_required_fields( - request_type=securitycenter_service.GetBigQueryExportRequest, +def test_get_security_health_analytics_custom_module_rest_required_fields( + request_type=securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -13848,7 +19208,9 @@ def test_get_big_query_export_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_big_query_export._get_unset_required_fields(jsonified_request) + ).get_security_health_analytics_custom_module._get_unset_required_fields( + jsonified_request + ) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -13857,7 +19219,9 @@ def test_get_big_query_export_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_big_query_export._get_unset_required_fields(jsonified_request) + ).get_security_health_analytics_custom_module._get_unset_required_fields( + jsonified_request + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -13871,7 +19235,9 @@ def test_get_big_query_export_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = bigquery_export.BigQueryExport() + return_value = ( + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -13891,30 +19257,36 @@ def test_get_big_query_export_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = bigquery_export.BigQueryExport.pb(return_value) + pb_return_value = security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_big_query_export(request) + response = client.get_security_health_analytics_custom_module(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_big_query_export_rest_unset_required_fields(): +def test_get_security_health_analytics_custom_module_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_big_query_export._get_unset_required_fields({}) + unset_fields = transport.get_security_health_analytics_custom_module._get_unset_required_fields( + {} + ) assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_big_query_export_rest_interceptors(null_interceptor): +def test_get_security_health_analytics_custom_module_rest_interceptors( + null_interceptor, +): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -13927,14 +19299,18 @@ def test_get_big_query_export_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_get_big_query_export" + transports.SecurityCenterRestInterceptor, + "post_get_security_health_analytics_custom_module", ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_get_big_query_export" + transports.SecurityCenterRestInterceptor, + "pre_get_security_health_analytics_custom_module", ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.GetBigQueryExportRequest.pb( - securitycenter_service.GetBigQueryExportRequest() + pb_message = ( + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest.pb( + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest() + ) ) transcode.return_value = { "method": "post", @@ -13946,19 +19322,21 @@ def test_get_big_query_export_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = bigquery_export.BigQueryExport.to_json( - bigquery_export.BigQueryExport() + req.return_value._content = security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.to_json( + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() ) - request = securitycenter_service.GetBigQueryExportRequest() + request = securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = bigquery_export.BigQueryExport() + post.return_value = ( + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) - client.get_big_query_export( + client.get_security_health_analytics_custom_module( request, metadata=[ ("key", "val"), @@ -13970,9 +19348,9 @@ def test_get_big_query_export_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_big_query_export_rest_bad_request( +def test_get_security_health_analytics_custom_module_rest_bad_request( transport: str = "rest", - request_type=securitycenter_service.GetBigQueryExportRequest, + request_type=securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13980,7 +19358,9 @@ def test_get_big_query_export_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/bigQueryExports/sample2"} + request_init = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2" + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -13992,10 +19372,10 @@ def test_get_big_query_export_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_big_query_export(request) + client.get_security_health_analytics_custom_module(request) -def test_get_big_query_export_rest_flattened(): +def test_get_security_health_analytics_custom_module_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -14004,10 +19384,14 @@ def test_get_big_query_export_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = bigquery_export.BigQueryExport() + return_value = ( + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) # get arguments that satisfy an http rule for this method - sample_request = {"name": "organizations/sample1/bigQueryExports/sample2"} + sample_request = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2" + } # get truthy value for each flattened field mock_args = dict( @@ -14018,24 +19402,29 @@ def test_get_big_query_export_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = bigquery_export.BigQueryExport.pb(return_value) + pb_return_value = security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.get_big_query_export(**mock_args) + client.get_security_health_analytics_custom_module(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=organizations/*/bigQueryExports/*}" % client.transport._host, + "%s/v1/{name=organizations/*/securityHealthAnalyticsSettings/customModules/*}" + % client.transport._host, args[1], ) -def test_get_big_query_export_rest_flattened_error(transport: str = "rest"): +def test_get_security_health_analytics_custom_module_rest_flattened_error( + transport: str = "rest", +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -14044,13 +19433,13 @@ def test_get_big_query_export_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_big_query_export( - securitycenter_service.GetBigQueryExportRequest(), + client.get_security_health_analytics_custom_module( + securitycenter_service.GetSecurityHealthAnalyticsCustomModuleRequest(), name="name_value", ) -def test_get_big_query_export_rest_error(): +def test_get_security_health_analytics_custom_module_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -14059,53 +19448,57 @@ def test_get_big_query_export_rest_error(): @pytest.mark.parametrize( "request_type", [ - iam_policy_pb2.GetIamPolicyRequest, + securitycenter_service.GetSourceRequest, dict, ], ) -def test_get_iam_policy_rest(request_type): +def test_get_source_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"resource": "organizations/sample1/sources/sample2"} + request_init = {"name": "organizations/sample1/sources/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy( - version=774, - etag=b"etag_blob", + return_value = source.Source( + name="name_value", + display_name="display_name_value", + description="description_value", + canonical_name="canonical_name_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = return_value + pb_return_value = source.Source.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_iam_policy(request) + response = client.get_source(request) # 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 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_iam_policy_rest_required_fields( - request_type=iam_policy_pb2.GetIamPolicyRequest, +def test_get_source_rest_required_fields( + request_type=securitycenter_service.GetSourceRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} - request_init["resource"] = "" + request_init["name"] = "" request = request_type(**request_init) - pb_request = request + pb_request = request_type.pb(request) jsonified_request = json.loads( json_format.MessageToJson( pb_request, @@ -14118,21 +19511,21 @@ def test_get_iam_policy_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_iam_policy._get_unset_required_fields(jsonified_request) + ).get_source._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["resource"] = "resource_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_iam_policy._get_unset_required_fields(jsonified_request) + ).get_source._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "resource" in jsonified_request - assert jsonified_request["resource"] == "resource_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14141,7 +19534,7 @@ def test_get_iam_policy_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() + return_value = source.Source() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -14150,42 +19543,41 @@ def test_get_iam_policy_rest_required_fields( with mock.patch.object(path_template, "transcode") as transcode: # A uri without fields and an empty body will force all the # request fields to show up in the query_params. - pb_request = request + pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - pb_return_value = return_value + pb_return_value = source.Source.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_iam_policy(request) + response = client.get_source(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_iam_policy_rest_unset_required_fields(): +def test_get_source_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_iam_policy._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("resource",))) + unset_fields = transport.get_source._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_iam_policy_rest_interceptors(null_interceptor): +def test_get_source_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -14198,13 +19590,15 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_get_iam_policy" + transports.SecurityCenterRestInterceptor, "post_get_source" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_get_iam_policy" + transports.SecurityCenterRestInterceptor, "pre_get_source" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = iam_policy_pb2.GetIamPolicyRequest() + pb_message = securitycenter_service.GetSourceRequest.pb( + securitycenter_service.GetSourceRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -14215,17 +19609,17 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) + req.return_value._content = source.Source.to_json(source.Source()) - request = iam_policy_pb2.GetIamPolicyRequest() + request = securitycenter_service.GetSourceRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = policy_pb2.Policy() + post.return_value = source.Source() - client.get_iam_policy( + client.get_source( request, metadata=[ ("key", "val"), @@ -14237,8 +19631,8 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_iam_policy_rest_bad_request( - transport: str = "rest", request_type=iam_policy_pb2.GetIamPolicyRequest +def test_get_source_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.GetSourceRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14246,7 +19640,7 @@ def test_get_iam_policy_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"resource": "organizations/sample1/sources/sample2"} + request_init = {"name": "organizations/sample1/sources/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -14258,10 +19652,10 @@ def test_get_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_iam_policy(request) + client.get_source(request) -def test_get_iam_policy_rest_flattened(): +def test_get_source_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -14270,39 +19664,37 @@ def test_get_iam_policy_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() + return_value = source.Source() # get arguments that satisfy an http rule for this method - sample_request = {"resource": "organizations/sample1/sources/sample2"} + sample_request = {"name": "organizations/sample1/sources/sample2"} # get truthy value for each flattened field mock_args = dict( - resource="resource_value", + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = return_value + pb_return_value = source.Source.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.get_iam_policy(**mock_args) + client.get_source(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{resource=organizations/*/sources/*}:getIamPolicy" - % client.transport._host, - args[1], + "%s/v1/{name=organizations/*/sources/*}" % client.transport._host, args[1] ) -def test_get_iam_policy_rest_flattened_error(transport: str = "rest"): +def test_get_source_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -14311,13 +19703,13 @@ def test_get_iam_policy_rest_flattened_error(transport: str = "rest"): # 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.get_source( + securitycenter_service.GetSourceRequest(), + name="name_value", ) -def test_get_iam_policy_rest_error(): +def test_get_source_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -14326,57 +19718,52 @@ def test_get_iam_policy_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GetMuteConfigRequest, + securitycenter_service.GroupAssetsRequest, dict, ], ) -def test_get_mute_config_rest(request_type): +def test_group_assets_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/muteConfigs/sample2"} + request_init = {"parent": "organizations/sample1"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = mute_config.MuteConfig( - name="name_value", - display_name="display_name_value", - description="description_value", - filter="filter_value", - most_recent_editor="most_recent_editor_value", + return_value = securitycenter_service.GroupAssetsResponse( + next_page_token="next_page_token_value", + total_size=1086, ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = mute_config.MuteConfig.pb(return_value) + pb_return_value = securitycenter_service.GroupAssetsResponse.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_mute_config(request) + response = client.group_assets(request) # Establish that the response is the type that we expect. - 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.filter == "filter_value" - assert response.most_recent_editor == "most_recent_editor_value" + assert isinstance(response, pagers.GroupAssetsPager) + assert response.next_page_token == "next_page_token_value" + assert response.total_size == 1086 -def test_get_mute_config_rest_required_fields( - request_type=securitycenter_service.GetMuteConfigRequest, +def test_group_assets_rest_required_fields( + request_type=securitycenter_service.GroupAssetsRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" + request_init["group_by"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -14391,21 +19778,24 @@ def test_get_mute_config_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_mute_config._get_unset_required_fields(jsonified_request) + ).group_assets._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" + jsonified_request["groupBy"] = "group_by_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_mute_config._get_unset_required_fields(jsonified_request) + ).group_assets._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "groupBy" in jsonified_request + assert jsonified_request["groupBy"] == "group_by_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14414,7 +19804,7 @@ def test_get_mute_config_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = mute_config.MuteConfig() + return_value = securitycenter_service.GroupAssetsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -14426,38 +19816,49 @@ def test_get_mute_config_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - pb_return_value = mute_config.MuteConfig.pb(return_value) + pb_return_value = securitycenter_service.GroupAssetsResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_mute_config(request) + response = client.group_assets(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_mute_config_rest_unset_required_fields(): +def test_group_assets_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_mute_config._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.group_assets._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "groupBy", + ) + ) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_mute_config_rest_interceptors(null_interceptor): +def test_group_assets_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -14470,14 +19871,14 @@ def test_get_mute_config_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_get_mute_config" + transports.SecurityCenterRestInterceptor, "post_group_assets" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_get_mute_config" + transports.SecurityCenterRestInterceptor, "pre_group_assets" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.GetMuteConfigRequest.pb( - securitycenter_service.GetMuteConfigRequest() + pb_message = securitycenter_service.GroupAssetsRequest.pb( + securitycenter_service.GroupAssetsRequest() ) transcode.return_value = { "method": "post", @@ -14489,19 +19890,19 @@ def test_get_mute_config_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = mute_config.MuteConfig.to_json( - mute_config.MuteConfig() + req.return_value._content = securitycenter_service.GroupAssetsResponse.to_json( + securitycenter_service.GroupAssetsResponse() ) - request = securitycenter_service.GetMuteConfigRequest() + request = securitycenter_service.GroupAssetsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = mute_config.MuteConfig() + post.return_value = securitycenter_service.GroupAssetsResponse() - client.get_mute_config( + client.group_assets( request, metadata=[ ("key", "val"), @@ -14513,8 +19914,8 @@ def test_get_mute_config_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_mute_config_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.GetMuteConfigRequest +def test_group_assets_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.GroupAssetsRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14522,7 +19923,7 @@ def test_get_mute_config_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/muteConfigs/sample2"} + request_init = {"parent": "organizations/sample1"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -14534,125 +19935,121 @@ def test_get_mute_config_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_mute_config(request) + client.group_assets(request) -def test_get_mute_config_rest_flattened(): +def test_group_assets_rest_pager(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport=transport, ) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = mute_config.MuteConfig() - - # get arguments that satisfy an http rule for this method - sample_request = {"name": "organizations/sample1/muteConfigs/sample2"} - - # get truthy value for each flattened field - mock_args = dict( - name="name_value", - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = mute_config.MuteConfig.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - - client.get_mute_config(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{name=organizations/*/muteConfigs/*}" % client.transport._host, - args[1], + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + 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(), + ], + ), ) + # Two responses for two calls + response = response + response + # Wrap the values into proper Response objs + response = tuple( + securitycenter_service.GroupAssetsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values -def test_get_mute_config_rest_flattened_error(transport: str = "rest"): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) + sample_request = {"parent": "organizations/sample1"} - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_mute_config( - securitycenter_service.GetMuteConfigRequest(), - name="name_value", - ) + pager = client.group_assets(request=sample_request) + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) -def test_get_mute_config_rest_error(): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" - ) + pages = list(client.group_assets(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GetNotificationConfigRequest, + securitycenter_service.GroupFindingsRequest, dict, ], ) -def test_get_notification_config_rest(request_type): +def test_group_findings_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/notificationConfigs/sample2"} + request_init = {"parent": "organizations/sample1/sources/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - 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" - ), + return_value = securitycenter_service.GroupFindingsResponse( + next_page_token="next_page_token_value", + total_size=1086, ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = notification_config.NotificationConfig.pb(return_value) + pb_return_value = securitycenter_service.GroupFindingsResponse.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_notification_config(request) + response = client.group_findings(request) # 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 isinstance(response, pagers.GroupFindingsPager) + assert response.next_page_token == "next_page_token_value" + assert response.total_size == 1086 -def test_get_notification_config_rest_required_fields( - request_type=securitycenter_service.GetNotificationConfigRequest, +def test_group_findings_rest_required_fields( + request_type=securitycenter_service.GroupFindingsRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" + request_init["group_by"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -14667,21 +20064,24 @@ def test_get_notification_config_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_notification_config._get_unset_required_fields(jsonified_request) + ).group_findings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" + jsonified_request["groupBy"] = "group_by_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_notification_config._get_unset_required_fields(jsonified_request) + ).group_findings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "groupBy" in jsonified_request + assert jsonified_request["groupBy"] == "group_by_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14690,7 +20090,7 @@ def test_get_notification_config_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = notification_config.NotificationConfig() + return_value = securitycenter_service.GroupFindingsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -14702,38 +20102,49 @@ def test_get_notification_config_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - pb_return_value = notification_config.NotificationConfig.pb(return_value) + pb_return_value = securitycenter_service.GroupFindingsResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_notification_config(request) + response = client.group_findings(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_notification_config_rest_unset_required_fields(): +def test_group_findings_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_notification_config._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.group_findings._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "groupBy", + ) + ) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_notification_config_rest_interceptors(null_interceptor): +def test_group_findings_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -14746,14 +20157,14 @@ def test_get_notification_config_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_get_notification_config" + transports.SecurityCenterRestInterceptor, "post_group_findings" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_get_notification_config" + transports.SecurityCenterRestInterceptor, "pre_group_findings" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.GetNotificationConfigRequest.pb( - securitycenter_service.GetNotificationConfigRequest() + pb_message = securitycenter_service.GroupFindingsRequest.pb( + securitycenter_service.GroupFindingsRequest() ) transcode.return_value = { "method": "post", @@ -14765,19 +20176,21 @@ def test_get_notification_config_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = notification_config.NotificationConfig.to_json( - notification_config.NotificationConfig() + req.return_value._content = ( + securitycenter_service.GroupFindingsResponse.to_json( + securitycenter_service.GroupFindingsResponse() + ) ) - request = securitycenter_service.GetNotificationConfigRequest() + request = securitycenter_service.GroupFindingsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = notification_config.NotificationConfig() + post.return_value = securitycenter_service.GroupFindingsResponse() - client.get_notification_config( + client.group_findings( request, metadata=[ ("key", "val"), @@ -14789,9 +20202,8 @@ def test_get_notification_config_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_notification_config_rest_bad_request( - transport: str = "rest", - request_type=securitycenter_service.GetNotificationConfigRequest, +def test_group_findings_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.GroupFindingsRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14799,7 +20211,7 @@ def test_get_notification_config_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/notificationConfigs/sample2"} + request_init = {"parent": "organizations/sample1/sources/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -14811,10 +20223,10 @@ def test_get_notification_config_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_notification_config(request) + client.group_findings(request) -def test_get_notification_config_rest_flattened(): +def test_group_findings_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -14823,39 +20235,40 @@ def test_get_notification_config_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = notification_config.NotificationConfig() + return_value = securitycenter_service.GroupFindingsResponse() # get arguments that satisfy an http rule for this method - sample_request = {"name": "organizations/sample1/notificationConfigs/sample2"} + sample_request = {"parent": "organizations/sample1/sources/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", + group_by="group_by_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = notification_config.NotificationConfig.pb(return_value) + pb_return_value = securitycenter_service.GroupFindingsResponse.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.get_notification_config(**mock_args) + client.group_findings(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=organizations/*/notificationConfigs/*}" + "%s/v1/{parent=organizations/*/sources/*}/findings:group" % client.transport._host, args[1], ) -def test_get_notification_config_rest_flattened_error(transport: str = "rest"): +def test_group_findings_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -14864,66 +20277,124 @@ def test_get_notification_config_rest_flattened_error(transport: str = "rest"): # 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.group_findings( + securitycenter_service.GroupFindingsRequest(), + parent="parent_value", + group_by="group_by_value", ) -def test_get_notification_config_rest_error(): +def test_group_findings_rest_pager(transport: str = "rest"): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + 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(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + securitycenter_service.GroupFindingsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "organizations/sample1/sources/sample2"} + + pager = client.group_findings(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) + + pages = list(client.group_findings(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GetOrganizationSettingsRequest, + securitycenter_service.ListAssetsRequest, dict, ], ) -def test_get_organization_settings_rest(request_type): +def test_list_assets_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/organizationSettings"} + request_init = {"parent": "organizations/sample1"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = organization_settings.OrganizationSettings( - name="name_value", - enable_asset_discovery=True, + return_value = securitycenter_service.ListAssetsResponse( + next_page_token="next_page_token_value", + total_size=1086, ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = organization_settings.OrganizationSettings.pb(return_value) + pb_return_value = securitycenter_service.ListAssetsResponse.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_organization_settings(request) + response = client.list_assets(request) # 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, pagers.ListAssetsPager) + assert response.next_page_token == "next_page_token_value" + assert response.total_size == 1086 -def test_get_organization_settings_rest_required_fields( - request_type=securitycenter_service.GetOrganizationSettingsRequest, +def test_list_assets_rest_required_fields( + request_type=securitycenter_service.ListAssetsRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -14938,21 +20409,33 @@ def test_get_organization_settings_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_organization_settings._get_unset_required_fields(jsonified_request) + ).list_assets._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_organization_settings._get_unset_required_fields(jsonified_request) + ).list_assets._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "compare_duration", + "field_mask", + "filter", + "order_by", + "page_size", + "page_token", + "read_time", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14961,7 +20444,7 @@ def test_get_organization_settings_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = organization_settings.OrganizationSettings() + return_value = securitycenter_service.ListAssetsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -14981,32 +20464,43 @@ def test_get_organization_settings_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = organization_settings.OrganizationSettings.pb( - return_value - ) + pb_return_value = securitycenter_service.ListAssetsResponse.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_organization_settings(request) + response = client.list_assets(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_organization_settings_rest_unset_required_fields(): +def test_list_assets_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_organization_settings._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.list_assets._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "compareDuration", + "fieldMask", + "filter", + "orderBy", + "pageSize", + "pageToken", + "readTime", + ) + ) + & set(("parent",)) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_organization_settings_rest_interceptors(null_interceptor): +def test_list_assets_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -15019,14 +20513,14 @@ def test_get_organization_settings_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_get_organization_settings" + transports.SecurityCenterRestInterceptor, "post_list_assets" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_get_organization_settings" + transports.SecurityCenterRestInterceptor, "pre_list_assets" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.GetOrganizationSettingsRequest.pb( - securitycenter_service.GetOrganizationSettingsRequest() + pb_message = securitycenter_service.ListAssetsRequest.pb( + securitycenter_service.ListAssetsRequest() ) transcode.return_value = { "method": "post", @@ -15038,19 +20532,19 @@ def test_get_organization_settings_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = organization_settings.OrganizationSettings.to_json( - organization_settings.OrganizationSettings() + req.return_value._content = securitycenter_service.ListAssetsResponse.to_json( + securitycenter_service.ListAssetsResponse() ) - request = securitycenter_service.GetOrganizationSettingsRequest() + request = securitycenter_service.ListAssetsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = organization_settings.OrganizationSettings() + post.return_value = securitycenter_service.ListAssetsResponse() - client.get_organization_settings( + client.list_assets( request, metadata=[ ("key", "val"), @@ -15062,9 +20556,8 @@ def test_get_organization_settings_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_organization_settings_rest_bad_request( - transport: str = "rest", - request_type=securitycenter_service.GetOrganizationSettingsRequest, +def test_list_assets_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.ListAssetsRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15072,7 +20565,7 @@ def test_get_organization_settings_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/organizationSettings"} + request_init = {"parent": "organizations/sample1"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -15084,123 +20577,127 @@ def test_get_organization_settings_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_organization_settings(request) + client.list_assets(request) -def test_get_organization_settings_rest_flattened(): +def test_list_assets_rest_pager(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport=transport, ) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = organization_settings.OrganizationSettings() - - # get arguments that satisfy an http rule for this method - sample_request = {"name": "organizations/sample1/organizationSettings"} - - # get truthy value for each flattened field - mock_args = dict( - name="name_value", + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + ], + next_page_token="abc", + ), + securitycenter_service.ListAssetsResponse( + list_assets_results=[], + next_page_token="def", + ), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListAssetsResponse( + list_assets_results=[ + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListAssetsResponse.ListAssetsResult(), + ], + ), ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = organization_settings.OrganizationSettings.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - - client.get_organization_settings(**mock_args) + # Two responses for two calls + response = response + response - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{name=organizations/*/organizationSettings}" - % client.transport._host, - args[1], + # Wrap the values into proper Response objs + response = tuple( + securitycenter_service.ListAssetsResponse.to_json(x) for x in response ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + sample_request = {"parent": "organizations/sample1"} -def test_get_organization_settings_rest_flattened_error(transport: str = "rest"): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) + pager = client.list_assets(request=sample_request) - # 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", + results = list(pager) + assert len(results) == 6 + assert all( + isinstance(i, securitycenter_service.ListAssetsResponse.ListAssetsResult) + for i in results ) - -def test_get_organization_settings_rest_error(): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" - ) + pages = list(client.list_assets(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GetSourceRequest, + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, dict, ], ) -def test_get_source_rest(request_type): +def test_list_descendant_security_health_analytics_custom_modules_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/sources/sample2"} + request_init = {"parent": "organizations/sample1/securityHealthAnalyticsSettings"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = source.Source( - name="name_value", - display_name="display_name_value", - description="description_value", - canonical_name="canonical_name_value", + return_value = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + next_page_token="next_page_token_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = source.Source.pb(return_value) + pb_return_value = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_source(request) + response = client.list_descendant_security_health_analytics_custom_modules( + request + ) # 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" + assert isinstance( + response, pagers.ListDescendantSecurityHealthAnalyticsCustomModulesPager + ) + assert response.next_page_token == "next_page_token_value" -def test_get_source_rest_required_fields( - request_type=securitycenter_service.GetSourceRequest, +def test_list_descendant_security_health_analytics_custom_modules_rest_required_fields( + request_type=securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} - request_init["name"] = "" + request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -15215,21 +20712,32 @@ def test_get_source_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_source._get_unset_required_fields(jsonified_request) + ).list_descendant_security_health_analytics_custom_modules._get_unset_required_fields( + jsonified_request + ) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["parent"] = "parent_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).get_source._get_unset_required_fields(jsonified_request) + ).list_descendant_security_health_analytics_custom_modules._get_unset_required_fields( + jsonified_request + ) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15238,7 +20746,9 @@ def test_get_source_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = source.Source() + return_value = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse() + ) # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -15258,30 +20768,46 @@ def test_get_source_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = source.Source.pb(return_value) + pb_return_value = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.get_source(request) + response = client.list_descendant_security_health_analytics_custom_modules( + request + ) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_get_source_rest_unset_required_fields(): +def test_list_descendant_security_health_analytics_custom_modules_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.get_source._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name",))) + unset_fields = transport.list_descendant_security_health_analytics_custom_modules._get_unset_required_fields( + {} + ) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_source_rest_interceptors(null_interceptor): +def test_list_descendant_security_health_analytics_custom_modules_rest_interceptors( + null_interceptor, +): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -15294,14 +20820,16 @@ def test_get_source_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_get_source" + transports.SecurityCenterRestInterceptor, + "post_list_descendant_security_health_analytics_custom_modules", ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_get_source" + transports.SecurityCenterRestInterceptor, + "pre_list_descendant_security_health_analytics_custom_modules", ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.GetSourceRequest.pb( - securitycenter_service.GetSourceRequest() + pb_message = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest.pb( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest() ) transcode.return_value = { "method": "post", @@ -15313,17 +20841,23 @@ def test_get_source_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = source.Source.to_json(source.Source()) + req.return_value._content = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse.to_json( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse() + ) - request = securitycenter_service.GetSourceRequest() + request = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest() + ) metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = source.Source() + post.return_value = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse() + ) - client.get_source( + client.list_descendant_security_health_analytics_custom_modules( request, metadata=[ ("key", "val"), @@ -15335,8 +20869,9 @@ def test_get_source_rest_interceptors(null_interceptor): post.assert_called_once() -def test_get_source_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.GetSourceRequest +def test_list_descendant_security_health_analytics_custom_modules_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15344,7 +20879,7 @@ def test_get_source_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/sources/sample2"} + request_init = {"parent": "organizations/sample1/securityHealthAnalyticsSettings"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -15356,10 +20891,10 @@ def test_get_source_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.get_source(request) + client.list_descendant_security_health_analytics_custom_modules(request) -def test_get_source_rest_flattened(): +def test_list_descendant_security_health_analytics_custom_modules_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -15368,37 +20903,47 @@ def test_get_source_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = source.Source() + return_value = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse() + ) # get arguments that satisfy an http rule for this method - sample_request = {"name": "organizations/sample1/sources/sample2"} + sample_request = { + "parent": "organizations/sample1/securityHealthAnalyticsSettings" + } # get truthy value for each flattened field mock_args = dict( - name="name_value", + parent="parent_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = source.Source.pb(return_value) + pb_return_value = securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.get_source(**mock_args) + client.list_descendant_security_health_analytics_custom_modules(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=organizations/*/sources/*}" % client.transport._host, args[1] + "%s/v1/{parent=organizations/*/securityHealthAnalyticsSettings}/customModules:listDescendant" + % client.transport._host, + args[1], ) -def test_get_source_rest_flattened_error(transport: str = "rest"): +def test_list_descendant_security_health_analytics_custom_modules_rest_flattened_error( + transport: str = "rest", +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -15407,39 +20952,115 @@ def test_get_source_rest_flattened_error(transport: str = "rest"): # 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.list_descendant_security_health_analytics_custom_modules( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesRequest(), + parent="parent_value", ) -def test_get_source_rest_error(): +def test_list_descendant_security_health_analytics_custom_modules_rest_pager( + transport: str = "rest", +): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + next_page_token="abc", + ), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[], + next_page_token="def", + ), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + next_page_token="ghi", + ), + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + securitycenter_service.ListDescendantSecurityHealthAnalyticsCustomModulesResponse.to_json( + x + ) + for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = { + "parent": "organizations/sample1/securityHealthAnalyticsSettings" + } + + pager = client.list_descendant_security_health_analytics_custom_modules( + request=sample_request + ) + + results = list(pager) + assert len(results) == 6 + assert all( + isinstance( + i, + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + for i in results + ) + + pages = list( + client.list_descendant_security_health_analytics_custom_modules( + request=sample_request + ).pages + ) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GroupAssetsRequest, + securitycenter_service.ListFindingsRequest, dict, ], ) -def test_group_assets_rest(request_type): +def test_list_findings_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} + request_init = {"parent": "organizations/sample1/sources/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.GroupAssetsResponse( + return_value = securitycenter_service.ListFindingsResponse( next_page_token="next_page_token_value", total_size=1086, ) @@ -15447,27 +21068,26 @@ def test_group_assets_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.GroupAssetsResponse.pb(return_value) + pb_return_value = securitycenter_service.ListFindingsResponse.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.group_assets(request) + response = client.list_findings(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.GroupAssetsPager) + assert isinstance(response, pagers.ListFindingsPager) assert response.next_page_token == "next_page_token_value" assert response.total_size == 1086 -def test_group_assets_rest_required_fields( - request_type=securitycenter_service.GroupAssetsRequest, +def test_list_findings_rest_required_fields( + request_type=securitycenter_service.ListFindingsRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} request_init["parent"] = "" - request_init["group_by"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -15482,24 +21102,33 @@ def test_group_assets_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).group_assets._get_unset_required_fields(jsonified_request) + ).list_findings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present jsonified_request["parent"] = "parent_value" - jsonified_request["groupBy"] = "group_by_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).group_assets._get_unset_required_fields(jsonified_request) + ).list_findings._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "compare_duration", + "field_mask", + "filter", + "order_by", + "page_size", + "page_token", + "read_time", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "groupBy" in jsonified_request - assert jsonified_request["groupBy"] == "group_by_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15508,7 +21137,7 @@ def test_group_assets_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = securitycenter_service.GroupAssetsResponse() + return_value = securitycenter_service.ListFindingsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -15520,16 +21149,15 @@ def test_group_assets_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.GroupAssetsResponse.pb( + pb_return_value = securitycenter_service.ListFindingsResponse.pb( return_value ) json_return_value = json_format.MessageToJson(pb_return_value) @@ -15537,32 +21165,37 @@ def test_group_assets_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.group_assets(request) + response = client.list_findings(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_group_assets_rest_unset_required_fields(): +def test_list_findings_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.group_assets._get_unset_required_fields({}) + unset_fields = transport.list_findings._get_unset_required_fields({}) assert set(unset_fields) == ( - set(()) - & set( + set( ( - "parent", - "groupBy", + "compareDuration", + "fieldMask", + "filter", + "orderBy", + "pageSize", + "pageToken", + "readTime", ) ) + & set(("parent",)) ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_group_assets_rest_interceptors(null_interceptor): +def test_list_findings_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -15575,14 +21208,14 @@ def test_group_assets_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_group_assets" + transports.SecurityCenterRestInterceptor, "post_list_findings" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_group_assets" + transports.SecurityCenterRestInterceptor, "pre_list_findings" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.GroupAssetsRequest.pb( - securitycenter_service.GroupAssetsRequest() + pb_message = securitycenter_service.ListFindingsRequest.pb( + securitycenter_service.ListFindingsRequest() ) transcode.return_value = { "method": "post", @@ -15594,19 +21227,19 @@ def test_group_assets_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = securitycenter_service.GroupAssetsResponse.to_json( - securitycenter_service.GroupAssetsResponse() + req.return_value._content = securitycenter_service.ListFindingsResponse.to_json( + securitycenter_service.ListFindingsResponse() ) - request = securitycenter_service.GroupAssetsRequest() + request = securitycenter_service.ListFindingsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = securitycenter_service.GroupAssetsResponse() + post.return_value = securitycenter_service.ListFindingsResponse() - client.group_assets( + client.list_findings( request, metadata=[ ("key", "val"), @@ -15618,8 +21251,8 @@ def test_group_assets_rest_interceptors(null_interceptor): post.assert_called_once() -def test_group_assets_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.GroupAssetsRequest +def test_list_findings_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.ListFindingsRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15627,7 +21260,7 @@ def test_group_assets_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} + request_init = {"parent": "organizations/sample1/sources/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -15639,10 +21272,10 @@ def test_group_assets_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.group_assets(request) + client.list_findings(request) -def test_group_assets_rest_pager(transport: str = "rest"): +def test_list_findings_rest_pager(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -15654,28 +21287,28 @@ def test_group_assets_rest_pager(transport: str = "rest"): # with mock.patch.object(path_template, 'transcode') as transcode: # Set the response as a series of pages response = ( - securitycenter_service.GroupAssetsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="abc", ), - securitycenter_service.GroupAssetsResponse( - group_by_results=[], + securitycenter_service.ListFindingsResponse( + list_findings_results=[], next_page_token="def", ), - securitycenter_service.GroupAssetsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], next_page_token="ghi", ), - securitycenter_service.GroupAssetsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListFindingsResponse( + list_findings_results=[ + securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListFindingsResponse.ListFindingsResult(), ], ), ) @@ -15684,7 +21317,7 @@ def test_group_assets_rest_pager(transport: str = "rest"): # Wrap the values into proper Response objs response = tuple( - securitycenter_service.GroupAssetsResponse.to_json(x) for x in response + securitycenter_service.ListFindingsResponse.to_json(x) for x in response ) return_values = tuple(Response() for i in response) for return_val, response_val in zip(return_values, response): @@ -15692,15 +21325,20 @@ def test_group_assets_rest_pager(transport: str = "rest"): return_val.status_code = 200 req.side_effect = return_values - sample_request = {"parent": "organizations/sample1"} + sample_request = {"parent": "organizations/sample1/sources/sample2"} - pager = client.group_assets(request=sample_request) + pager = client.list_findings(request=sample_request) results = list(pager) assert len(results) == 6 - assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) + assert all( + isinstance( + i, securitycenter_service.ListFindingsResponse.ListFindingsResult + ) + for i in results + ) - pages = list(client.group_assets(request=sample_request).pages) + pages = list(client.list_findings(request=sample_request).pages) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -15708,52 +21346,51 @@ def test_group_assets_rest_pager(transport: str = "rest"): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.GroupFindingsRequest, + securitycenter_service.ListMuteConfigsRequest, dict, ], ) -def test_group_findings_rest(request_type): +def test_list_mute_configs_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1/sources/sample2"} + request_init = {"parent": "organizations/sample1"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.GroupFindingsResponse( + return_value = securitycenter_service.ListMuteConfigsResponse( next_page_token="next_page_token_value", - total_size=1086, ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.GroupFindingsResponse.pb(return_value) + pb_return_value = securitycenter_service.ListMuteConfigsResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.group_findings(request) + response = client.list_mute_configs(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.GroupFindingsPager) + assert isinstance(response, pagers.ListMuteConfigsPager) assert response.next_page_token == "next_page_token_value" - assert response.total_size == 1086 -def test_group_findings_rest_required_fields( - request_type=securitycenter_service.GroupFindingsRequest, +def test_list_mute_configs_rest_required_fields( + request_type=securitycenter_service.ListMuteConfigsRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} request_init["parent"] = "" - request_init["group_by"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -15768,24 +21405,28 @@ def test_group_findings_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).group_findings._get_unset_required_fields(jsonified_request) + ).list_mute_configs._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present jsonified_request["parent"] = "parent_value" - jsonified_request["groupBy"] = "group_by_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).group_findings._get_unset_required_fields(jsonified_request) + ).list_mute_configs._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request assert jsonified_request["parent"] == "parent_value" - assert "groupBy" in jsonified_request - assert jsonified_request["groupBy"] == "group_by_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15794,7 +21435,7 @@ def test_group_findings_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = securitycenter_service.GroupFindingsResponse() + return_value = securitycenter_service.ListMuteConfigsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -15806,16 +21447,15 @@ def test_group_findings_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "get", "query_params": pb_request, } - transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.GroupFindingsResponse.pb( + pb_return_value = securitycenter_service.ListMuteConfigsResponse.pb( return_value ) json_return_value = json_format.MessageToJson(pb_return_value) @@ -15823,32 +21463,32 @@ def test_group_findings_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.group_findings(request) + response = client.list_mute_configs(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_group_findings_rest_unset_required_fields(): +def test_list_mute_configs_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.group_findings._get_unset_required_fields({}) + unset_fields = transport.list_mute_configs._get_unset_required_fields({}) assert set(unset_fields) == ( - set(()) - & set( + set( ( - "parent", - "groupBy", + "pageSize", + "pageToken", ) ) + & set(("parent",)) ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_group_findings_rest_interceptors(null_interceptor): +def test_list_mute_configs_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -15861,14 +21501,14 @@ def test_group_findings_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_group_findings" + transports.SecurityCenterRestInterceptor, "post_list_mute_configs" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_group_findings" + transports.SecurityCenterRestInterceptor, "pre_list_mute_configs" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.GroupFindingsRequest.pb( - securitycenter_service.GroupFindingsRequest() + pb_message = securitycenter_service.ListMuteConfigsRequest.pb( + securitycenter_service.ListMuteConfigsRequest() ) transcode.return_value = { "method": "post", @@ -15881,20 +21521,20 @@ def test_group_findings_rest_interceptors(null_interceptor): req.return_value.status_code = 200 req.return_value.request = PreparedRequest() req.return_value._content = ( - securitycenter_service.GroupFindingsResponse.to_json( - securitycenter_service.GroupFindingsResponse() + securitycenter_service.ListMuteConfigsResponse.to_json( + securitycenter_service.ListMuteConfigsResponse() ) ) - request = securitycenter_service.GroupFindingsRequest() + request = securitycenter_service.ListMuteConfigsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = securitycenter_service.GroupFindingsResponse() + post.return_value = securitycenter_service.ListMuteConfigsResponse() - client.group_findings( + client.list_mute_configs( request, metadata=[ ("key", "val"), @@ -15906,8 +21546,8 @@ def test_group_findings_rest_interceptors(null_interceptor): post.assert_called_once() -def test_group_findings_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.GroupFindingsRequest +def test_list_mute_configs_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.ListMuteConfigsRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15915,7 +21555,7 @@ def test_group_findings_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1/sources/sample2"} + request_init = {"parent": "organizations/sample1"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -15927,10 +21567,10 @@ def test_group_findings_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.group_findings(request) + client.list_mute_configs(request) -def test_group_findings_rest_flattened(): +def test_list_mute_configs_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -15939,40 +21579,40 @@ def test_group_findings_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.GroupFindingsResponse() + return_value = securitycenter_service.ListMuteConfigsResponse() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "organizations/sample1/sources/sample2"} + sample_request = {"parent": "organizations/sample1"} # get truthy value for each flattened field mock_args = dict( parent="parent_value", - group_by="group_by_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.GroupFindingsResponse.pb(return_value) + pb_return_value = securitycenter_service.ListMuteConfigsResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.group_findings(**mock_args) + client.list_mute_configs(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=organizations/*/sources/*}/findings:group" - % client.transport._host, + "%s/v1/{parent=organizations/*}/muteConfigs" % client.transport._host, args[1], ) -def test_group_findings_rest_flattened_error(transport: str = "rest"): +def test_list_mute_configs_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -15981,14 +21621,13 @@ def test_group_findings_rest_flattened_error(transport: str = "rest"): # 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(), + client.list_mute_configs( + securitycenter_service.ListMuteConfigsRequest(), parent="parent_value", - group_by="group_by_value", ) -def test_group_findings_rest_pager(transport: str = "rest"): +def test_list_mute_configs_rest_pager(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -16000,28 +21639,28 @@ def test_group_findings_rest_pager(transport: str = "rest"): # with mock.patch.object(path_template, 'transcode') as transcode: # Set the response as a series of pages response = ( - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], next_page_token="abc", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[], + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[], next_page_token="def", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), ], next_page_token="ghi", ), - securitycenter_service.GroupFindingsResponse( - group_by_results=[ - securitycenter_service.GroupResult(), - securitycenter_service.GroupResult(), + securitycenter_service.ListMuteConfigsResponse( + mute_configs=[ + mute_config.MuteConfig(), + mute_config.MuteConfig(), ], ), ) @@ -16030,7 +21669,7 @@ def test_group_findings_rest_pager(transport: str = "rest"): # Wrap the values into proper Response objs response = tuple( - securitycenter_service.GroupFindingsResponse.to_json(x) for x in response + securitycenter_service.ListMuteConfigsResponse.to_json(x) for x in response ) return_values = tuple(Response() for i in response) for return_val, response_val in zip(return_values, response): @@ -16038,15 +21677,15 @@ def test_group_findings_rest_pager(transport: str = "rest"): return_val.status_code = 200 req.side_effect = return_values - sample_request = {"parent": "organizations/sample1/sources/sample2"} + sample_request = {"parent": "organizations/sample1"} - pager = client.group_findings(request=sample_request) + pager = client.list_mute_configs(request=sample_request) results = list(pager) assert len(results) == 6 - assert all(isinstance(i, securitycenter_service.GroupResult) for i in results) + assert all(isinstance(i, mute_config.MuteConfig) for i in results) - pages = list(client.group_findings(request=sample_request).pages) + pages = list(client.list_mute_configs(request=sample_request).pages) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -16054,11 +21693,11 @@ def test_group_findings_rest_pager(transport: str = "rest"): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListAssetsRequest, + securitycenter_service.ListNotificationConfigsRequest, dict, ], ) -def test_list_assets_rest(request_type): +def test_list_notification_configs_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -16071,29 +21710,29 @@ def test_list_assets_rest(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListAssetsResponse( + return_value = securitycenter_service.ListNotificationConfigsResponse( next_page_token="next_page_token_value", - total_size=1086, ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListAssetsResponse.pb(return_value) + pb_return_value = securitycenter_service.ListNotificationConfigsResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_assets(request) + response = client.list_notification_configs(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListAssetsPager) + assert isinstance(response, pagers.ListNotificationConfigsPager) assert response.next_page_token == "next_page_token_value" - assert response.total_size == 1086 -def test_list_assets_rest_required_fields( - request_type=securitycenter_service.ListAssetsRequest, +def test_list_notification_configs_rest_required_fields( + request_type=securitycenter_service.ListNotificationConfigsRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -16113,7 +21752,7 @@ def test_list_assets_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_assets._get_unset_required_fields(jsonified_request) + ).list_notification_configs._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -16122,17 +21761,12 @@ def test_list_assets_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_assets._get_unset_required_fields(jsonified_request) + ).list_notification_configs._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( ( - "compare_duration", - "field_mask", - "filter", - "order_by", "page_size", "page_token", - "read_time", ) ) jsonified_request.update(unset_fields) @@ -16148,7 +21782,7 @@ def test_list_assets_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListAssetsResponse() + return_value = securitycenter_service.ListNotificationConfigsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -16168,35 +21802,32 @@ def test_list_assets_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListAssetsResponse.pb(return_value) + pb_return_value = securitycenter_service.ListNotificationConfigsResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_assets(request) + response = client.list_notification_configs(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_assets_rest_unset_required_fields(): +def test_list_notification_configs_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_assets._get_unset_required_fields({}) + unset_fields = transport.list_notification_configs._get_unset_required_fields({}) assert set(unset_fields) == ( set( ( - "compareDuration", - "fieldMask", - "filter", - "orderBy", "pageSize", "pageToken", - "readTime", ) ) & set(("parent",)) @@ -16204,7 +21835,7 @@ def test_list_assets_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_assets_rest_interceptors(null_interceptor): +def test_list_notification_configs_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -16217,14 +21848,14 @@ def test_list_assets_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_list_assets" + transports.SecurityCenterRestInterceptor, "post_list_notification_configs" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_list_assets" + transports.SecurityCenterRestInterceptor, "pre_list_notification_configs" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.ListAssetsRequest.pb( - securitycenter_service.ListAssetsRequest() + pb_message = securitycenter_service.ListNotificationConfigsRequest.pb( + securitycenter_service.ListNotificationConfigsRequest() ) transcode.return_value = { "method": "post", @@ -16236,19 +21867,21 @@ def test_list_assets_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = securitycenter_service.ListAssetsResponse.to_json( - securitycenter_service.ListAssetsResponse() + req.return_value._content = ( + securitycenter_service.ListNotificationConfigsResponse.to_json( + securitycenter_service.ListNotificationConfigsResponse() + ) ) - request = securitycenter_service.ListAssetsRequest() + request = securitycenter_service.ListNotificationConfigsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = securitycenter_service.ListAssetsResponse() + post.return_value = securitycenter_service.ListNotificationConfigsResponse() - client.list_assets( + client.list_notification_configs( request, metadata=[ ("key", "val"), @@ -16260,31 +21893,90 @@ def test_list_assets_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_assets_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.ListAssetsRequest -): +def test_list_notification_configs_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.ListNotificationConfigsRequest, +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_notification_configs(request) + + +def test_list_notification_configs_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = securitycenter_service.ListNotificationConfigsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "organizations/sample1"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = securitycenter_service.ListNotificationConfigsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.list_notification_configs(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=organizations/*}/notificationConfigs" + % client.transport._host, + args[1], + ) + + +def test_list_notification_configs_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) - # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest - ): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_assets(request) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_notification_configs( + securitycenter_service.ListNotificationConfigsRequest(), + parent="parent_value", + ) -def test_list_assets_rest_pager(transport: str = "rest"): +def test_list_notification_configs_rest_pager(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -16296,28 +21988,28 @@ def test_list_assets_rest_pager(transport: str = "rest"): # with mock.patch.object(path_template, 'transcode') as transcode: # Set the response as a series of pages response = ( - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), ], next_page_token="abc", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[], + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[], next_page_token="def", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), ], next_page_token="ghi", ), - securitycenter_service.ListAssetsResponse( - list_assets_results=[ - securitycenter_service.ListAssetsResponse.ListAssetsResult(), - securitycenter_service.ListAssetsResponse.ListAssetsResult(), + securitycenter_service.ListNotificationConfigsResponse( + notification_configs=[ + notification_config.NotificationConfig(), + notification_config.NotificationConfig(), ], ), ) @@ -16326,7 +22018,8 @@ def test_list_assets_rest_pager(transport: str = "rest"): # Wrap the values into proper Response objs response = tuple( - securitycenter_service.ListAssetsResponse.to_json(x) for x in response + securitycenter_service.ListNotificationConfigsResponse.to_json(x) + for x in response ) return_values = tuple(Response() for i in response) for return_val, response_val in zip(return_values, response): @@ -16336,16 +22029,15 @@ def test_list_assets_rest_pager(transport: str = "rest"): sample_request = {"parent": "organizations/sample1"} - pager = client.list_assets(request=sample_request) + pager = client.list_notification_configs(request=sample_request) results = list(pager) assert len(results) == 6 assert all( - isinstance(i, securitycenter_service.ListAssetsResponse.ListAssetsResult) - for i in results + isinstance(i, notification_config.NotificationConfig) for i in results ) - pages = list(client.list_assets(request=sample_request).pages) + pages = list(client.list_notification_configs(request=sample_request).pages) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -16353,46 +22045,50 @@ def test_list_assets_rest_pager(transport: str = "rest"): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListFindingsRequest, + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, dict, ], ) -def test_list_findings_rest(request_type): +def test_list_effective_security_health_analytics_custom_modules_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1/sources/sample2"} + request_init = {"parent": "organizations/sample1/securityHealthAnalyticsSettings"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListFindingsResponse( + return_value = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( next_page_token="next_page_token_value", - total_size=1086, ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListFindingsResponse.pb(return_value) + pb_return_value = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_findings(request) + response = client.list_effective_security_health_analytics_custom_modules( + request + ) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListFindingsPager) + assert isinstance( + response, pagers.ListEffectiveSecurityHealthAnalyticsCustomModulesPager + ) assert response.next_page_token == "next_page_token_value" - assert response.total_size == 1086 -def test_list_findings_rest_required_fields( - request_type=securitycenter_service.ListFindingsRequest, +def test_list_effective_security_health_analytics_custom_modules_rest_required_fields( + request_type=securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -16412,7 +22108,9 @@ def test_list_findings_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_findings._get_unset_required_fields(jsonified_request) + ).list_effective_security_health_analytics_custom_modules._get_unset_required_fields( + jsonified_request + ) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -16421,17 +22119,14 @@ def test_list_findings_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_findings._get_unset_required_fields(jsonified_request) + ).list_effective_security_health_analytics_custom_modules._get_unset_required_fields( + jsonified_request + ) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( ( - "compare_duration", - "field_mask", - "filter", - "order_by", "page_size", "page_token", - "read_time", ) ) jsonified_request.update(unset_fields) @@ -16447,7 +22142,9 @@ def test_list_findings_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListFindingsResponse() + return_value = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse() + ) # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -16467,7 +22164,7 @@ def test_list_findings_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListFindingsResponse.pb( + pb_return_value = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse.pb( return_value ) json_return_value = json_format.MessageToJson(pb_return_value) @@ -16475,29 +22172,28 @@ def test_list_findings_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_findings(request) + response = client.list_effective_security_health_analytics_custom_modules( + request + ) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_findings_rest_unset_required_fields(): +def test_list_effective_security_health_analytics_custom_modules_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_findings._get_unset_required_fields({}) + unset_fields = transport.list_effective_security_health_analytics_custom_modules._get_unset_required_fields( + {} + ) assert set(unset_fields) == ( set( ( - "compareDuration", - "fieldMask", - "filter", - "orderBy", "pageSize", "pageToken", - "readTime", ) ) & set(("parent",)) @@ -16505,7 +22201,9 @@ def test_list_findings_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_findings_rest_interceptors(null_interceptor): +def test_list_effective_security_health_analytics_custom_modules_rest_interceptors( + null_interceptor, +): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -16518,14 +22216,16 @@ def test_list_findings_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_list_findings" + transports.SecurityCenterRestInterceptor, + "post_list_effective_security_health_analytics_custom_modules", ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_list_findings" + transports.SecurityCenterRestInterceptor, + "pre_list_effective_security_health_analytics_custom_modules", ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.ListFindingsRequest.pb( - securitycenter_service.ListFindingsRequest() + pb_message = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest.pb( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest() ) transcode.return_value = { "method": "post", @@ -16537,19 +22237,23 @@ def test_list_findings_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = securitycenter_service.ListFindingsResponse.to_json( - securitycenter_service.ListFindingsResponse() + req.return_value._content = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse.to_json( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse() ) - request = securitycenter_service.ListFindingsRequest() + request = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest() + ) metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = securitycenter_service.ListFindingsResponse() + post.return_value = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse() + ) - client.list_findings( + client.list_effective_security_health_analytics_custom_modules( request, metadata=[ ("key", "val"), @@ -16561,8 +22265,9 @@ def test_list_findings_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_findings_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.ListFindingsRequest +def test_list_effective_security_health_analytics_custom_modules_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16570,7 +22275,7 @@ def test_list_findings_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1/sources/sample2"} + request_init = {"parent": "organizations/sample1/securityHealthAnalyticsSettings"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -16582,10 +22287,76 @@ def test_list_findings_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.list_findings(request) + client.list_effective_security_health_analytics_custom_modules(request) -def test_list_findings_rest_pager(transport: str = "rest"): +def test_list_effective_security_health_analytics_custom_modules_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = ( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse() + ) + + # get arguments that satisfy an http rule for this method + sample_request = { + "parent": "organizations/sample1/securityHealthAnalyticsSettings" + } + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.list_effective_security_health_analytics_custom_modules(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=organizations/*/securityHealthAnalyticsSettings}/effectiveCustomModules" + % client.transport._host, + args[1], + ) + + +def test_list_effective_security_health_analytics_custom_modules_rest_flattened_error( + transport: str = "rest", +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_effective_security_health_analytics_custom_modules( + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest(), + parent="parent_value", + ) + + +def test_list_effective_security_health_analytics_custom_modules_rest_pager( + transport: str = "rest", +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -16597,28 +22368,28 @@ def test_list_findings_rest_pager(transport: str = "rest"): # with mock.patch.object(path_template, 'transcode') as transcode: # Set the response as a series of pages response = ( - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), ], next_page_token="abc", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[], + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[], next_page_token="def", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), ], next_page_token="ghi", ), - securitycenter_service.ListFindingsResponse( - list_findings_results=[ - securitycenter_service.ListFindingsResponse.ListFindingsResult(), - securitycenter_service.ListFindingsResponse.ListFindingsResult(), + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse( + effective_security_health_analytics_custom_modules=[ + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule(), ], ), ) @@ -16627,7 +22398,10 @@ def test_list_findings_rest_pager(transport: str = "rest"): # Wrap the values into proper Response objs response = tuple( - securitycenter_service.ListFindingsResponse.to_json(x) for x in response + securitycenter_service.ListEffectiveSecurityHealthAnalyticsCustomModulesResponse.to_json( + x + ) + for x in response ) return_values = tuple(Response() for i in response) for return_val, response_val in zip(return_values, response): @@ -16635,20 +22409,29 @@ def test_list_findings_rest_pager(transport: str = "rest"): return_val.status_code = 200 req.side_effect = return_values - sample_request = {"parent": "organizations/sample1/sources/sample2"} + sample_request = { + "parent": "organizations/sample1/securityHealthAnalyticsSettings" + } - pager = client.list_findings(request=sample_request) + pager = client.list_effective_security_health_analytics_custom_modules( + request=sample_request + ) results = list(pager) assert len(results) == 6 assert all( isinstance( - i, securitycenter_service.ListFindingsResponse.ListFindingsResult + i, + effective_security_health_analytics_custom_module.EffectiveSecurityHealthAnalyticsCustomModule, ) for i in results ) - pages = list(client.list_findings(request=sample_request).pages) + pages = list( + client.list_effective_security_health_analytics_custom_modules( + request=sample_request + ).pages + ) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -16656,46 +22439,50 @@ def test_list_findings_rest_pager(transport: str = "rest"): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListMuteConfigsRequest, + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, dict, ], ) -def test_list_mute_configs_rest(request_type): +def test_list_security_health_analytics_custom_modules_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} + request_init = {"parent": "organizations/sample1/securityHealthAnalyticsSettings"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListMuteConfigsResponse( - next_page_token="next_page_token_value", + return_value = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + next_page_token="next_page_token_value", + ) ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListMuteConfigsResponse.pb( - return_value + pb_return_value = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse.pb( + return_value + ) ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_mute_configs(request) + response = client.list_security_health_analytics_custom_modules(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListMuteConfigsPager) + assert isinstance(response, pagers.ListSecurityHealthAnalyticsCustomModulesPager) assert response.next_page_token == "next_page_token_value" -def test_list_mute_configs_rest_required_fields( - request_type=securitycenter_service.ListMuteConfigsRequest, +def test_list_security_health_analytics_custom_modules_rest_required_fields( + request_type=securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -16715,7 +22502,9 @@ def test_list_mute_configs_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_mute_configs._get_unset_required_fields(jsonified_request) + ).list_security_health_analytics_custom_modules._get_unset_required_fields( + jsonified_request + ) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -16724,7 +22513,9 @@ def test_list_mute_configs_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_mute_configs._get_unset_required_fields(jsonified_request) + ).list_security_health_analytics_custom_modules._get_unset_required_fields( + jsonified_request + ) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( ( @@ -16745,7 +22536,9 @@ def test_list_mute_configs_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListMuteConfigsResponse() + return_value = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse() + ) # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -16765,7 +22558,7 @@ def test_list_mute_configs_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListMuteConfigsResponse.pb( + pb_return_value = securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse.pb( return_value ) json_return_value = json_format.MessageToJson(pb_return_value) @@ -16773,19 +22566,21 @@ def test_list_mute_configs_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_mute_configs(request) + response = client.list_security_health_analytics_custom_modules(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_mute_configs_rest_unset_required_fields(): +def test_list_security_health_analytics_custom_modules_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_mute_configs._get_unset_required_fields({}) + unset_fields = transport.list_security_health_analytics_custom_modules._get_unset_required_fields( + {} + ) assert set(unset_fields) == ( set( ( @@ -16798,7 +22593,9 @@ def test_list_mute_configs_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_mute_configs_rest_interceptors(null_interceptor): +def test_list_security_health_analytics_custom_modules_rest_interceptors( + null_interceptor, +): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -16811,14 +22608,18 @@ def test_list_mute_configs_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_list_mute_configs" + transports.SecurityCenterRestInterceptor, + "post_list_security_health_analytics_custom_modules", ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_list_mute_configs" + transports.SecurityCenterRestInterceptor, + "pre_list_security_health_analytics_custom_modules", ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.ListMuteConfigsRequest.pb( - securitycenter_service.ListMuteConfigsRequest() + pb_message = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest.pb( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest() + ) ) transcode.return_value = { "method": "post", @@ -16830,21 +22631,23 @@ def test_list_mute_configs_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = ( - securitycenter_service.ListMuteConfigsResponse.to_json( - securitycenter_service.ListMuteConfigsResponse() - ) + req.return_value._content = securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse.to_json( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse() ) - request = securitycenter_service.ListMuteConfigsRequest() + request = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest() + ) metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = securitycenter_service.ListMuteConfigsResponse() + post.return_value = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse() + ) - client.list_mute_configs( + client.list_security_health_analytics_custom_modules( request, metadata=[ ("key", "val"), @@ -16856,8 +22659,9 @@ def test_list_mute_configs_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_mute_configs_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.ListMuteConfigsRequest +def test_list_security_health_analytics_custom_modules_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16865,7 +22669,7 @@ def test_list_mute_configs_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} + request_init = {"parent": "organizations/sample1/securityHealthAnalyticsSettings"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -16877,10 +22681,10 @@ def test_list_mute_configs_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.list_mute_configs(request) + client.list_security_health_analytics_custom_modules(request) -def test_list_mute_configs_rest_flattened(): +def test_list_security_health_analytics_custom_modules_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -16889,10 +22693,14 @@ def test_list_mute_configs_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListMuteConfigsResponse() + return_value = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse() + ) # get arguments that satisfy an http rule for this method - sample_request = {"parent": "organizations/sample1"} + sample_request = { + "parent": "organizations/sample1/securityHealthAnalyticsSettings" + } # get truthy value for each flattened field mock_args = dict( @@ -16903,26 +22711,31 @@ def test_list_mute_configs_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListMuteConfigsResponse.pb( - return_value + pb_return_value = ( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse.pb( + return_value + ) ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.list_mute_configs(**mock_args) + client.list_security_health_analytics_custom_modules(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=organizations/*}/muteConfigs" % client.transport._host, + "%s/v1/{parent=organizations/*/securityHealthAnalyticsSettings}/customModules" + % client.transport._host, args[1], ) -def test_list_mute_configs_rest_flattened_error(transport: str = "rest"): +def test_list_security_health_analytics_custom_modules_rest_flattened_error( + transport: str = "rest", +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -16931,13 +22744,15 @@ def test_list_mute_configs_rest_flattened_error(transport: str = "rest"): # 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(), + client.list_security_health_analytics_custom_modules( + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesRequest(), parent="parent_value", ) -def test_list_mute_configs_rest_pager(transport: str = "rest"): +def test_list_security_health_analytics_custom_modules_rest_pager( + transport: str = "rest", +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -16949,28 +22764,28 @@ def test_list_mute_configs_rest_pager(transport: str = "rest"): # with mock.patch.object(path_template, 'transcode') as transcode: # Set the response as a series of pages response = ( - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), - mute_config.MuteConfig(), - mute_config.MuteConfig(), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], next_page_token="abc", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[], + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[], next_page_token="def", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], next_page_token="ghi", ), - securitycenter_service.ListMuteConfigsResponse( - mute_configs=[ - mute_config.MuteConfig(), - mute_config.MuteConfig(), + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse( + security_health_analytics_custom_modules=[ + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule(), ], ), ) @@ -16979,7 +22794,10 @@ def test_list_mute_configs_rest_pager(transport: str = "rest"): # Wrap the values into proper Response objs response = tuple( - securitycenter_service.ListMuteConfigsResponse.to_json(x) for x in response + securitycenter_service.ListSecurityHealthAnalyticsCustomModulesResponse.to_json( + x + ) + for x in response ) return_values = tuple(Response() for i in response) for return_val, response_val in zip(return_values, response): @@ -16987,15 +22805,29 @@ def test_list_mute_configs_rest_pager(transport: str = "rest"): return_val.status_code = 200 req.side_effect = return_values - sample_request = {"parent": "organizations/sample1"} + sample_request = { + "parent": "organizations/sample1/securityHealthAnalyticsSettings" + } - pager = client.list_mute_configs(request=sample_request) + pager = client.list_security_health_analytics_custom_modules( + request=sample_request + ) results = list(pager) assert len(results) == 6 - assert all(isinstance(i, mute_config.MuteConfig) for i in results) + assert all( + isinstance( + i, + security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) + for i in results + ) - pages = list(client.list_mute_configs(request=sample_request).pages) + pages = list( + client.list_security_health_analytics_custom_modules( + request=sample_request + ).pages + ) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -17003,11 +22835,11 @@ def test_list_mute_configs_rest_pager(transport: str = "rest"): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListNotificationConfigsRequest, + securitycenter_service.ListSourcesRequest, dict, ], ) -def test_list_notification_configs_rest(request_type): +def test_list_sources_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -17020,29 +22852,27 @@ def test_list_notification_configs_rest(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListNotificationConfigsResponse( + return_value = securitycenter_service.ListSourcesResponse( next_page_token="next_page_token_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListNotificationConfigsResponse.pb( - return_value - ) + pb_return_value = securitycenter_service.ListSourcesResponse.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_notification_configs(request) + response = client.list_sources(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListNotificationConfigsPager) + assert isinstance(response, pagers.ListSourcesPager) assert response.next_page_token == "next_page_token_value" -def test_list_notification_configs_rest_required_fields( - request_type=securitycenter_service.ListNotificationConfigsRequest, +def test_list_sources_rest_required_fields( + request_type=securitycenter_service.ListSourcesRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -17062,7 +22892,7 @@ def test_list_notification_configs_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_notification_configs._get_unset_required_fields(jsonified_request) + ).list_sources._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -17071,7 +22901,7 @@ def test_list_notification_configs_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_notification_configs._get_unset_required_fields(jsonified_request) + ).list_sources._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( ( @@ -17092,7 +22922,7 @@ def test_list_notification_configs_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListNotificationConfigsResponse() + return_value = securitycenter_service.ListSourcesResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -17112,7 +22942,7 @@ def test_list_notification_configs_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListNotificationConfigsResponse.pb( + pb_return_value = securitycenter_service.ListSourcesResponse.pb( return_value ) json_return_value = json_format.MessageToJson(pb_return_value) @@ -17120,19 +22950,19 @@ def test_list_notification_configs_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_notification_configs(request) + response = client.list_sources(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_notification_configs_rest_unset_required_fields(): +def test_list_sources_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_notification_configs._get_unset_required_fields({}) + unset_fields = transport.list_sources._get_unset_required_fields({}) assert set(unset_fields) == ( set( ( @@ -17145,7 +22975,7 @@ def test_list_notification_configs_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_notification_configs_rest_interceptors(null_interceptor): +def test_list_sources_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -17158,14 +22988,14 @@ def test_list_notification_configs_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_list_notification_configs" + transports.SecurityCenterRestInterceptor, "post_list_sources" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_list_notification_configs" + transports.SecurityCenterRestInterceptor, "pre_list_sources" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.ListNotificationConfigsRequest.pb( - securitycenter_service.ListNotificationConfigsRequest() + pb_message = securitycenter_service.ListSourcesRequest.pb( + securitycenter_service.ListSourcesRequest() ) transcode.return_value = { "method": "post", @@ -17177,21 +23007,19 @@ def test_list_notification_configs_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = ( - securitycenter_service.ListNotificationConfigsResponse.to_json( - securitycenter_service.ListNotificationConfigsResponse() - ) + req.return_value._content = securitycenter_service.ListSourcesResponse.to_json( + securitycenter_service.ListSourcesResponse() ) - request = securitycenter_service.ListNotificationConfigsRequest() + request = securitycenter_service.ListSourcesRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = securitycenter_service.ListNotificationConfigsResponse() + post.return_value = securitycenter_service.ListSourcesResponse() - client.list_notification_configs( + client.list_sources( request, metadata=[ ("key", "val"), @@ -17203,9 +23031,8 @@ def test_list_notification_configs_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_notification_configs_rest_bad_request( - transport: str = "rest", - request_type=securitycenter_service.ListNotificationConfigsRequest, +def test_list_sources_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.ListSourcesRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17225,10 +23052,10 @@ def test_list_notification_configs_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.list_notification_configs(request) + client.list_sources(request) -def test_list_notification_configs_rest_flattened(): +def test_list_sources_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -17237,7 +23064,7 @@ def test_list_notification_configs_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListNotificationConfigsResponse() + return_value = securitycenter_service.ListSourcesResponse() # get arguments that satisfy an http rule for this method sample_request = {"parent": "organizations/sample1"} @@ -17251,27 +23078,23 @@ def test_list_notification_configs_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListNotificationConfigsResponse.pb( - return_value - ) + pb_return_value = securitycenter_service.ListSourcesResponse.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.list_notification_configs(**mock_args) + client.list_sources(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=organizations/*}/notificationConfigs" - % client.transport._host, - args[1], + "%s/v1/{parent=organizations/*}/sources" % client.transport._host, args[1] ) -def test_list_notification_configs_rest_flattened_error(transport: str = "rest"): +def test_list_sources_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -17280,13 +23103,13 @@ def test_list_notification_configs_rest_flattened_error(transport: str = "rest") # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_notification_configs( - securitycenter_service.ListNotificationConfigsRequest(), + client.list_sources( + securitycenter_service.ListSourcesRequest(), parent="parent_value", ) -def test_list_notification_configs_rest_pager(transport: str = "rest"): +def test_list_sources_rest_pager(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -17298,28 +23121,28 @@ def test_list_notification_configs_rest_pager(transport: str = "rest"): # with mock.patch.object(path_template, 'transcode') as transcode: # Set the response as a series of pages response = ( - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + source.Source(), + source.Source(), ], next_page_token="abc", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[], + securitycenter_service.ListSourcesResponse( + sources=[], next_page_token="def", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), ], next_page_token="ghi", ), - securitycenter_service.ListNotificationConfigsResponse( - notification_configs=[ - notification_config.NotificationConfig(), - notification_config.NotificationConfig(), + securitycenter_service.ListSourcesResponse( + sources=[ + source.Source(), + source.Source(), ], ), ) @@ -17328,8 +23151,7 @@ def test_list_notification_configs_rest_pager(transport: str = "rest"): # Wrap the values into proper Response objs response = tuple( - securitycenter_service.ListNotificationConfigsResponse.to_json(x) - for x in response + securitycenter_service.ListSourcesResponse.to_json(x) for x in response ) return_values = tuple(Response() for i in response) for return_val, response_val in zip(return_values, response): @@ -17339,15 +23161,13 @@ def test_list_notification_configs_rest_pager(transport: str = "rest"): sample_request = {"parent": "organizations/sample1"} - pager = client.list_notification_configs(request=sample_request) + pager = client.list_sources(request=sample_request) results = list(pager) assert len(results) == 6 - assert all( - isinstance(i, notification_config.NotificationConfig) for i in results - ) + assert all(isinstance(i, source.Source) for i in results) - pages = list(client.list_notification_configs(request=sample_request).pages) + pages = list(client.list_sources(request=sample_request).pages) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -17355,11 +23175,11 @@ def test_list_notification_configs_rest_pager(transport: str = "rest"): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.ListSourcesRequest, + securitycenter_service.RunAssetDiscoveryRequest, dict, ], ) -def test_list_sources_rest(request_type): +def test_run_asset_discovery_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -17372,27 +23192,23 @@ def test_list_sources_rest(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListSourcesResponse( - next_page_token="next_page_token_value", - ) + return_value = operations_pb2.Operation(name="operations/spam") # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListSourcesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_sources(request) + response = client.run_asset_discovery(request) # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSourcesPager) - assert response.next_page_token == "next_page_token_value" + assert response.operation.name == "operations/spam" -def test_list_sources_rest_required_fields( - request_type=securitycenter_service.ListSourcesRequest, +def test_run_asset_discovery_rest_required_fields( + request_type=securitycenter_service.RunAssetDiscoveryRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -17412,7 +23228,7 @@ def test_list_sources_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_sources._get_unset_required_fields(jsonified_request) + ).run_asset_discovery._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -17421,14 +23237,7 @@ def test_list_sources_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).list_sources._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set( - ( - "page_size", - "page_token", - ) - ) + ).run_asset_discovery._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -17442,7 +23251,7 @@ def test_list_sources_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListSourcesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -17454,48 +23263,37 @@ def test_list_sources_rest_required_fields( pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "get", + "method": "post", "query_params": pb_request, } + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - - pb_return_value = securitycenter_service.ListSourcesResponse.pb( - return_value - ) - json_return_value = json_format.MessageToJson(pb_return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.list_sources(request) + response = client.run_asset_discovery(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_list_sources_rest_unset_required_fields(): +def test_run_asset_discovery_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.list_sources._get_unset_required_fields({}) - assert set(unset_fields) == ( - set( - ( - "pageSize", - "pageToken", - ) - ) - & set(("parent",)) - ) + unset_fields = transport.run_asset_discovery._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("parent",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_sources_rest_interceptors(null_interceptor): +def test_run_asset_discovery_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -17508,14 +23306,16 @@ def test_list_sources_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_list_sources" + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.SecurityCenterRestInterceptor, "post_run_asset_discovery" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_list_sources" + transports.SecurityCenterRestInterceptor, "pre_run_asset_discovery" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.ListSourcesRequest.pb( - securitycenter_service.ListSourcesRequest() + pb_message = securitycenter_service.RunAssetDiscoveryRequest.pb( + securitycenter_service.RunAssetDiscoveryRequest() ) transcode.return_value = { "method": "post", @@ -17527,19 +23327,19 @@ def test_list_sources_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = securitycenter_service.ListSourcesResponse.to_json( - securitycenter_service.ListSourcesResponse() + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() ) - request = securitycenter_service.ListSourcesRequest() + request = securitycenter_service.RunAssetDiscoveryRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = securitycenter_service.ListSourcesResponse() + post.return_value = operations_pb2.Operation() - client.list_sources( + client.run_asset_discovery( request, metadata=[ ("key", "val"), @@ -17551,8 +23351,9 @@ def test_list_sources_rest_interceptors(null_interceptor): post.assert_called_once() -def test_list_sources_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.ListSourcesRequest +def test_run_asset_discovery_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.RunAssetDiscoveryRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17572,10 +23373,10 @@ def test_list_sources_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.list_sources(request) + client.run_asset_discovery(request) -def test_list_sources_rest_flattened(): +def test_run_asset_discovery_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -17584,7 +23385,7 @@ def test_list_sources_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = securitycenter_service.ListSourcesResponse() + return_value = operations_pb2.Operation(name="operations/spam") # get arguments that satisfy an http rule for this method sample_request = {"parent": "organizations/sample1"} @@ -17598,23 +23399,24 @@ def test_list_sources_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = securitycenter_service.ListSourcesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.list_sources(**mock_args) + client.run_asset_discovery(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=organizations/*}/sources" % client.transport._host, args[1] + "%s/v1/{parent=organizations/*}/assets:runDiscovery" + % client.transport._host, + args[1], ) -def test_list_sources_rest_flattened_error(transport: str = "rest"): +def test_run_asset_discovery_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -17623,117 +23425,92 @@ def test_list_sources_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_sources( - securitycenter_service.ListSourcesRequest(), + client.run_asset_discovery( + securitycenter_service.RunAssetDiscoveryRequest(), parent="parent_value", ) -def test_list_sources_rest_pager(transport: str = "rest"): +def test_run_asset_discovery_rest_error(): client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, "request") as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - # with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), - source.Source(), - source.Source(), - ], - next_page_token="abc", - ), - securitycenter_service.ListSourcesResponse( - sources=[], - next_page_token="def", - ), - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), - ], - next_page_token="ghi", - ), - securitycenter_service.ListSourcesResponse( - sources=[ - source.Source(), - source.Source(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple( - securitycenter_service.ListSourcesResponse.to_json(x) for x in response - ) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode("UTF-8") - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {"parent": "organizations/sample1"} - - pager = client.list_sources(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, source.Source) for i in results) - - pages = list(client.list_sources(request=sample_request).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - @pytest.mark.parametrize( "request_type", [ - securitycenter_service.RunAssetDiscoveryRequest, + securitycenter_service.SetFindingStateRequest, dict, ], ) -def test_run_asset_discovery_rest(request_type): +def test_set_finding_state_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} + request_init = {"name": "organizations/sample1/sources/sample2/findings/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + 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", + parent_display_name="parent_display_name_value", + description="description_value", + next_steps="next_steps_value", + module_name="module_name_value", + ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) + pb_return_value = finding.Finding.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.run_asset_discovery(request) + response = client.set_finding_state(request) # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" + 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" + assert response.parent_display_name == "parent_display_name_value" + assert response.description == "description_value" + assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" -def test_run_asset_discovery_rest_required_fields( - request_type=securitycenter_service.RunAssetDiscoveryRequest, +def test_set_finding_state_rest_required_fields( + request_type=securitycenter_service.SetFindingStateRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} - request_init["parent"] = "" + request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) jsonified_request = json.loads( @@ -17748,21 +23525,21 @@ def test_run_asset_discovery_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).run_asset_discovery._get_unset_required_fields(jsonified_request) + ).set_finding_state._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = "parent_value" + jsonified_request["name"] = "name_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).run_asset_discovery._get_unset_required_fields(jsonified_request) + ).set_finding_state._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == "parent_value" + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17771,7 +23548,7 @@ def test_run_asset_discovery_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = finding.Finding() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -17791,29 +23568,40 @@ def test_run_asset_discovery_rest_required_fields( response_value = Response() response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) + + pb_return_value = finding.Finding.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.run_asset_discovery(request) + response = client.set_finding_state(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_run_asset_discovery_rest_unset_required_fields(): +def test_set_finding_state_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.run_asset_discovery._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("parent",))) + unset_fields = transport.set_finding_state._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(()) + & set( + ( + "name", + "state", + "startTime", + ) + ) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_run_asset_discovery_rest_interceptors(null_interceptor): +def test_set_finding_state_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -17826,16 +23614,14 @@ def test_run_asset_discovery_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_run_asset_discovery" + transports.SecurityCenterRestInterceptor, "post_set_finding_state" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_run_asset_discovery" + transports.SecurityCenterRestInterceptor, "pre_set_finding_state" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.RunAssetDiscoveryRequest.pb( - securitycenter_service.RunAssetDiscoveryRequest() + pb_message = securitycenter_service.SetFindingStateRequest.pb( + securitycenter_service.SetFindingStateRequest() ) transcode.return_value = { "method": "post", @@ -17847,19 +23633,17 @@ def test_run_asset_discovery_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson( - operations_pb2.Operation() - ) + req.return_value._content = finding.Finding.to_json(finding.Finding()) - request = securitycenter_service.RunAssetDiscoveryRequest() + request = securitycenter_service.SetFindingStateRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() + post.return_value = finding.Finding() - client.run_asset_discovery( + client.set_finding_state( request, metadata=[ ("key", "val"), @@ -17871,9 +23655,8 @@ def test_run_asset_discovery_rest_interceptors(null_interceptor): post.assert_called_once() -def test_run_asset_discovery_rest_bad_request( - transport: str = "rest", - request_type=securitycenter_service.RunAssetDiscoveryRequest, +def test_set_finding_state_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.SetFindingStateRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17881,7 +23664,7 @@ def test_run_asset_discovery_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"parent": "organizations/sample1"} + request_init = {"name": "organizations/sample1/sources/sample2/findings/sample3"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -17893,10 +23676,10 @@ def test_run_asset_discovery_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.run_asset_discovery(request) + client.set_finding_state(request) -def test_run_asset_discovery_rest_flattened(): +def test_set_finding_state_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -17905,38 +23688,43 @@ def test_run_asset_discovery_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name="operations/spam") + return_value = finding.Finding() # get arguments that satisfy an http rule for this method - sample_request = {"parent": "organizations/sample1"} + sample_request = { + "name": "organizations/sample1/sources/sample2/findings/sample3" + } # get truthy value for each flattened field mock_args = dict( - parent="parent_value", + name="name_value", + state=finding.Finding.State.ACTIVE, + start_time=timestamp_pb2.Timestamp(seconds=751), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) + pb_return_value = finding.Finding.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.run_asset_discovery(**mock_args) + client.set_finding_state(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{parent=organizations/*}/assets:runDiscovery" + "%s/v1/{name=organizations/*/sources/*/findings/*}:setState" % client.transport._host, args[1], ) -def test_run_asset_discovery_rest_flattened_error(transport: str = "rest"): +def test_set_finding_state_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -17945,13 +23733,15 @@ def test_run_asset_discovery_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.run_asset_discovery( - securitycenter_service.RunAssetDiscoveryRequest(), - parent="parent_value", + client.set_finding_state( + securitycenter_service.SetFindingStateRequest(), + name="name_value", + state=finding.Finding.State.ACTIVE, + start_time=timestamp_pb2.Timestamp(seconds=751), ) -def test_run_asset_discovery_rest_error(): +def test_set_finding_state_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -17960,11 +23750,11 @@ def test_run_asset_discovery_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.SetFindingStateRequest, + securitycenter_service.SetMuteRequest, dict, ], ) -def test_set_finding_state_rest(request_type): +def test_set_mute_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -17992,6 +23782,7 @@ def test_set_finding_state_rest(request_type): parent_display_name="parent_display_name_value", description="description_value", next_steps="next_steps_value", + module_name="module_name_value", ) # Wrap the value into a proper Response obj @@ -18002,7 +23793,7 @@ def test_set_finding_state_rest(request_type): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.set_finding_state(request) + response = client.set_mute(request) # Establish that the response is the type that we expect. assert isinstance(response, finding.Finding) @@ -18020,10 +23811,11 @@ def test_set_finding_state_rest(request_type): assert response.parent_display_name == "parent_display_name_value" assert response.description == "description_value" assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" -def test_set_finding_state_rest_required_fields( - request_type=securitycenter_service.SetFindingStateRequest, +def test_set_mute_rest_required_fields( + request_type=securitycenter_service.SetMuteRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -18043,7 +23835,7 @@ def test_set_finding_state_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).set_finding_state._get_unset_required_fields(jsonified_request) + ).set_mute._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present @@ -18052,7 +23844,7 @@ def test_set_finding_state_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).set_finding_state._get_unset_required_fields(jsonified_request) + ).set_mute._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -18093,33 +23885,32 @@ def test_set_finding_state_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.set_finding_state(request) + response = client.set_mute(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_set_finding_state_rest_unset_required_fields(): +def test_set_mute_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.set_finding_state._get_unset_required_fields({}) + unset_fields = transport.set_mute._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) & set( ( "name", - "state", - "startTime", + "mute", ) ) ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_set_finding_state_rest_interceptors(null_interceptor): +def test_set_mute_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -18132,14 +23923,14 @@ def test_set_finding_state_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_set_finding_state" + transports.SecurityCenterRestInterceptor, "post_set_mute" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_set_finding_state" + transports.SecurityCenterRestInterceptor, "pre_set_mute" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.SetFindingStateRequest.pb( - securitycenter_service.SetFindingStateRequest() + pb_message = securitycenter_service.SetMuteRequest.pb( + securitycenter_service.SetMuteRequest() ) transcode.return_value = { "method": "post", @@ -18153,7 +23944,7 @@ def test_set_finding_state_rest_interceptors(null_interceptor): req.return_value.request = PreparedRequest() req.return_value._content = finding.Finding.to_json(finding.Finding()) - request = securitycenter_service.SetFindingStateRequest() + request = securitycenter_service.SetMuteRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), @@ -18161,7 +23952,7 @@ def test_set_finding_state_rest_interceptors(null_interceptor): pre.return_value = request, metadata post.return_value = finding.Finding() - client.set_finding_state( + client.set_mute( request, metadata=[ ("key", "val"), @@ -18173,8 +23964,8 @@ def test_set_finding_state_rest_interceptors(null_interceptor): post.assert_called_once() -def test_set_finding_state_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.SetFindingStateRequest +def test_set_mute_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.SetMuteRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18194,10 +23985,10 @@ def test_set_finding_state_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.set_finding_state(request) + client.set_mute(request) -def test_set_finding_state_rest_flattened(): +def test_set_mute_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -18216,8 +24007,7 @@ def test_set_finding_state_rest_flattened(): # get truthy value for each flattened field mock_args = dict( name="name_value", - state=finding.Finding.State.ACTIVE, - start_time=timestamp_pb2.Timestamp(seconds=751), + mute=finding.Finding.Mute.MUTED, ) mock_args.update(sample_request) @@ -18229,20 +24019,20 @@ def test_set_finding_state_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.set_finding_state(**mock_args) + client.set_mute(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=organizations/*/sources/*/findings/*}:setState" + "%s/v1/{name=organizations/*/sources/*/findings/*}:setMute" % client.transport._host, args[1], ) -def test_set_finding_state_rest_flattened_error(transport: str = "rest"): +def test_set_mute_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -18251,15 +24041,14 @@ def test_set_finding_state_rest_flattened_error(transport: str = "rest"): # 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, ) -def test_set_finding_state_rest_error(): +def test_set_mute_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -18268,77 +24057,53 @@ def test_set_finding_state_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.SetMuteRequest, + iam_policy_pb2.SetIamPolicyRequest, dict, ], ) -def test_set_mute_rest(request_type): +def test_set_iam_policy_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/sources/sample2/findings/sample3"} + request_init = {"resource": "organizations/sample1/sources/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - 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", - parent_display_name="parent_display_name_value", - description="description_value", - next_steps="next_steps_value", + return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = finding.Finding.pb(return_value) + pb_return_value = return_value json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.set_mute(request) + response = client.set_iam_policy(request) # 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" - assert response.parent_display_name == "parent_display_name_value" - assert response.description == "description_value" - assert response.next_steps == "next_steps_value" + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b"etag_blob" -def test_set_mute_rest_required_fields( - request_type=securitycenter_service.SetMuteRequest, +def test_set_iam_policy_rest_required_fields( + request_type=iam_policy_pb2.SetIamPolicyRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} - request_init["name"] = "" + request_init["resource"] = "" request = request_type(**request_init) - pb_request = request_type.pb(request) + pb_request = request jsonified_request = json.loads( json_format.MessageToJson( pb_request, @@ -18351,21 +24116,21 @@ def test_set_mute_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).set_mute._get_unset_required_fields(jsonified_request) + ).set_iam_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = "name_value" + jsonified_request["resource"] = "resource_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).set_mute._get_unset_required_fields(jsonified_request) + ).set_iam_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == "name_value" + assert "resource" in jsonified_request + assert jsonified_request["resource"] == "resource_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18374,7 +24139,7 @@ def test_set_mute_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = finding.Finding() + return_value = policy_pb2.Policy() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -18383,7 +24148,7 @@ def test_set_mute_rest_required_fields( with mock.patch.object(path_template, "transcode") as transcode: # A uri without fields and an empty body will force all the # request fields to show up in the query_params. - pb_request = request_type.pb(request) + pb_request = request transcode_result = { "uri": "v1/sample_method", "method": "post", @@ -18395,38 +24160,38 @@ def test_set_mute_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = finding.Finding.pb(return_value) + pb_return_value = return_value json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.set_mute(request) + response = client.set_iam_policy(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_set_mute_rest_unset_required_fields(): +def test_set_iam_policy_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.set_mute._get_unset_required_fields({}) + unset_fields = transport.set_iam_policy._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) & set( ( - "name", - "mute", + "resource", + "policy", ) ) ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_set_mute_rest_interceptors(null_interceptor): +def test_set_iam_policy_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -18439,15 +24204,13 @@ def test_set_mute_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_set_mute" + transports.SecurityCenterRestInterceptor, "post_set_iam_policy" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_set_mute" + transports.SecurityCenterRestInterceptor, "pre_set_iam_policy" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.SetMuteRequest.pb( - securitycenter_service.SetMuteRequest() - ) + pb_message = iam_policy_pb2.SetIamPolicyRequest() transcode.return_value = { "method": "post", "uri": "my_uri", @@ -18458,17 +24221,17 @@ def test_set_mute_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = finding.Finding.to_json(finding.Finding()) + req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) - request = securitycenter_service.SetMuteRequest() + request = iam_policy_pb2.SetIamPolicyRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = finding.Finding() + post.return_value = policy_pb2.Policy() - client.set_mute( + client.set_iam_policy( request, metadata=[ ("key", "val"), @@ -18480,8 +24243,8 @@ def test_set_mute_rest_interceptors(null_interceptor): post.assert_called_once() -def test_set_mute_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.SetMuteRequest +def test_set_iam_policy_rest_bad_request( + transport: str = "rest", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18489,7 +24252,7 @@ def test_set_mute_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"name": "organizations/sample1/sources/sample2/findings/sample3"} + request_init = {"resource": "organizations/sample1/sources/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -18501,10 +24264,10 @@ def test_set_mute_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.set_mute(request) + client.set_iam_policy(request) -def test_set_mute_rest_flattened(): +def test_set_iam_policy_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -18513,42 +24276,39 @@ def test_set_mute_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = finding.Finding() + return_value = policy_pb2.Policy() # get arguments that satisfy an http rule for this method - sample_request = { - "name": "organizations/sample1/sources/sample2/findings/sample3" - } + sample_request = {"resource": "organizations/sample1/sources/sample2"} # get truthy value for each flattened field mock_args = dict( - name="name_value", - mute=finding.Finding.Mute.MUTED, + resource="resource_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = finding.Finding.pb(return_value) + pb_return_value = return_value json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.set_mute(**mock_args) + client.set_iam_policy(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{name=organizations/*/sources/*/findings/*}:setMute" + "%s/v1/{resource=organizations/*/sources/*}:setIamPolicy" % client.transport._host, args[1], ) -def test_set_mute_rest_flattened_error(transport: str = "rest"): +def test_set_iam_policy_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -18557,14 +24317,13 @@ def test_set_mute_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.set_mute( - securitycenter_service.SetMuteRequest(), - name="name_value", - mute=finding.Finding.Mute.MUTED, + client.set_iam_policy( + iam_policy_pb2.SetIamPolicyRequest(), + resource="resource_value", ) -def test_set_mute_rest_error(): +def test_set_iam_policy_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -18573,11 +24332,11 @@ def test_set_mute_rest_error(): @pytest.mark.parametrize( "request_type", [ - iam_policy_pb2.SetIamPolicyRequest, + iam_policy_pb2.TestIamPermissionsRequest, dict, ], ) -def test_set_iam_policy_rest(request_type): +def test_test_iam_permissions_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -18590,9 +24349,8 @@ def test_set_iam_policy_rest(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy( - version=774, - etag=b"etag_blob", + return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], ) # Wrap the value into a proper Response obj @@ -18603,21 +24361,21 @@ def test_set_iam_policy_rest(request_type): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.set_iam_policy(request) + response = client.test_iam_permissions(request) # 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 isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ["permissions_value"] -def test_set_iam_policy_rest_required_fields( - request_type=iam_policy_pb2.SetIamPolicyRequest, +def test_test_iam_permissions_rest_required_fields( + request_type=iam_policy_pb2.TestIamPermissionsRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} request_init["resource"] = "" + request_init["permissions"] = "" request = request_type(**request_init) pb_request = request jsonified_request = json.loads( @@ -18632,21 +24390,24 @@ def test_set_iam_policy_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).set_iam_policy._get_unset_required_fields(jsonified_request) + ).test_iam_permissions._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present jsonified_request["resource"] = "resource_value" + jsonified_request["permissions"] = "permissions_value" unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).set_iam_policy._get_unset_required_fields(jsonified_request) + ).test_iam_permissions._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "resource" in jsonified_request assert jsonified_request["resource"] == "resource_value" + assert "permissions" in jsonified_request + assert jsonified_request["permissions"] == "permissions_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18655,7 +24416,7 @@ def test_set_iam_policy_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() + return_value = iam_policy_pb2.TestIamPermissionsResponse() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -18682,32 +24443,32 @@ def test_set_iam_policy_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.set_iam_policy(request) + response = client.test_iam_permissions(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_set_iam_policy_rest_unset_required_fields(): +def test_test_iam_permissions_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.set_iam_policy._get_unset_required_fields({}) + unset_fields = transport.test_iam_permissions._get_unset_required_fields({}) assert set(unset_fields) == ( set(()) & set( ( "resource", - "policy", + "permissions", ) ) ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_set_iam_policy_rest_interceptors(null_interceptor): +def test_test_iam_permissions_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -18720,13 +24481,13 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_set_iam_policy" + transports.SecurityCenterRestInterceptor, "post_test_iam_permissions" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_set_iam_policy" + transports.SecurityCenterRestInterceptor, "pre_test_iam_permissions" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = iam_policy_pb2.SetIamPolicyRequest() + pb_message = iam_policy_pb2.TestIamPermissionsRequest() transcode.return_value = { "method": "post", "uri": "my_uri", @@ -18737,17 +24498,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) + req.return_value._content = json_format.MessageToJson( + iam_policy_pb2.TestIamPermissionsResponse() + ) - request = iam_policy_pb2.SetIamPolicyRequest() + request = iam_policy_pb2.TestIamPermissionsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = policy_pb2.Policy() + post.return_value = iam_policy_pb2.TestIamPermissionsResponse() - client.set_iam_policy( + client.test_iam_permissions( request, metadata=[ ("key", "val"), @@ -18759,8 +24522,8 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): post.assert_called_once() -def test_set_iam_policy_rest_bad_request( - transport: str = "rest", request_type=iam_policy_pb2.SetIamPolicyRequest +def test_test_iam_permissions_rest_bad_request( + transport: str = "rest", request_type=iam_policy_pb2.TestIamPermissionsRequest ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18780,10 +24543,10 @@ def test_set_iam_policy_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.set_iam_policy(request) + client.test_iam_permissions(request) -def test_set_iam_policy_rest_flattened(): +def test_test_iam_permissions_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -18792,7 +24555,7 @@ def test_set_iam_policy_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() + return_value = iam_policy_pb2.TestIamPermissionsResponse() # get arguments that satisfy an http rule for this method sample_request = {"resource": "organizations/sample1/sources/sample2"} @@ -18800,6 +24563,7 @@ def test_set_iam_policy_rest_flattened(): # get truthy value for each flattened field mock_args = dict( resource="resource_value", + permissions=["permissions_value"], ) mock_args.update(sample_request) @@ -18811,20 +24575,20 @@ def test_set_iam_policy_rest_flattened(): response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.set_iam_policy(**mock_args) + client.test_iam_permissions(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{resource=organizations/*/sources/*}:setIamPolicy" + "%s/v1/{resource=organizations/*/sources/*}:testIamPermissions" % client.transport._host, args[1], ) -def test_set_iam_policy_rest_flattened_error(transport: str = "rest"): +def test_test_iam_permissions_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -18833,13 +24597,14 @@ def test_set_iam_policy_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), + client.test_iam_permissions( + iam_policy_pb2.TestIamPermissionsRequest(), resource="resource_value", + permissions=["permissions_value"], ) -def test_set_iam_policy_rest_error(): +def test_test_iam_permissions_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -18848,52 +24613,67 @@ def test_set_iam_policy_rest_error(): @pytest.mark.parametrize( "request_type", [ - iam_policy_pb2.TestIamPermissionsRequest, + securitycenter_service.UpdateExternalSystemRequest, dict, ], ) -def test_test_iam_permissions_rest(request_type): +def test_update_external_system_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", ) # send a request that will satisfy transcoding - request_init = {"resource": "organizations/sample1/sources/sample2"} + request_init = { + "external_system": { + "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4" + } + } + request_init["external_system"] = { + "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4", + "assignees": ["assignees_value1", "assignees_value2"], + "external_uid": "external_uid_value", + "status": "status_value", + "external_system_update_time": {"seconds": 751, "nanos": 543}, + } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = iam_policy_pb2.TestIamPermissionsResponse( - permissions=["permissions_value"], + return_value = gcs_external_system.ExternalSystem( + name="name_value", + assignees=["assignees_value"], + external_uid="external_uid_value", + status="status_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = return_value + pb_return_value = gcs_external_system.ExternalSystem.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.test_iam_permissions(request) + response = client.update_external_system(request) # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - assert response.permissions == ["permissions_value"] + 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_test_iam_permissions_rest_required_fields( - request_type=iam_policy_pb2.TestIamPermissionsRequest, +def test_update_external_system_rest_required_fields( + request_type=securitycenter_service.UpdateExternalSystemRequest, ): transport_class = transports.SecurityCenterRestTransport request_init = {} - request_init["resource"] = "" - request_init["permissions"] = "" request = request_type(**request_init) - pb_request = request + pb_request = request_type.pb(request) jsonified_request = json.loads( json_format.MessageToJson( pb_request, @@ -18906,24 +24686,19 @@ def test_test_iam_permissions_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).test_iam_permissions._get_unset_required_fields(jsonified_request) + ).update_external_system._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["resource"] = "resource_value" - jsonified_request["permissions"] = "permissions_value" - unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).test_iam_permissions._get_unset_required_fields(jsonified_request) + ).update_external_system._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone - assert "resource" in jsonified_request - assert jsonified_request["resource"] == "resource_value" - assert "permissions" in jsonified_request - assert jsonified_request["permissions"] == "permissions_value" client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18932,7 +24707,7 @@ def test_test_iam_permissions_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = iam_policy_pb2.TestIamPermissionsResponse() + return_value = gcs_external_system.ExternalSystem() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -18941,10 +24716,10 @@ def test_test_iam_permissions_rest_required_fields( with mock.patch.object(path_template, "transcode") as transcode: # A uri without fields and an empty body will force all the # request fields to show up in the query_params. - pb_request = request + pb_request = request_type.pb(request) transcode_result = { "uri": "v1/sample_method", - "method": "post", + "method": "patch", "query_params": pb_request, } transcode_result["body"] = pb_request @@ -18953,38 +24728,30 @@ def test_test_iam_permissions_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = return_value + pb_return_value = gcs_external_system.ExternalSystem.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.test_iam_permissions(request) + response = client.update_external_system(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_test_iam_permissions_rest_unset_required_fields(): +def test_update_external_system_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.test_iam_permissions._get_unset_required_fields({}) - assert set(unset_fields) == ( - set(()) - & set( - ( - "resource", - "permissions", - ) - ) - ) + unset_fields = transport.update_external_system._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("externalSystem",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_test_iam_permissions_rest_interceptors(null_interceptor): +def test_update_external_system_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -18997,13 +24764,15 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_test_iam_permissions" + transports.SecurityCenterRestInterceptor, "post_update_external_system" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_test_iam_permissions" + transports.SecurityCenterRestInterceptor, "pre_update_external_system" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = iam_policy_pb2.TestIamPermissionsRequest() + pb_message = securitycenter_service.UpdateExternalSystemRequest.pb( + securitycenter_service.UpdateExternalSystemRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -19014,19 +24783,19 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson( - iam_policy_pb2.TestIamPermissionsResponse() + req.return_value._content = gcs_external_system.ExternalSystem.to_json( + gcs_external_system.ExternalSystem() ) - request = iam_policy_pb2.TestIamPermissionsRequest() + request = securitycenter_service.UpdateExternalSystemRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = iam_policy_pb2.TestIamPermissionsResponse() + post.return_value = gcs_external_system.ExternalSystem() - client.test_iam_permissions( + client.update_external_system( request, metadata=[ ("key", "val"), @@ -19038,8 +24807,9 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): post.assert_called_once() -def test_test_iam_permissions_rest_bad_request( - transport: str = "rest", request_type=iam_policy_pb2.TestIamPermissionsRequest +def test_update_external_system_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.UpdateExternalSystemRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19047,7 +24817,18 @@ def test_test_iam_permissions_rest_bad_request( ) # send a request that will satisfy transcoding - request_init = {"resource": "organizations/sample1/sources/sample2"} + request_init = { + "external_system": { + "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4" + } + } + request_init["external_system"] = { + "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4", + "assignees": ["assignees_value1", "assignees_value2"], + "external_uid": "external_uid_value", + "status": "status_value", + "external_system_update_time": {"seconds": 751, "nanos": 543}, + } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -19059,10 +24840,10 @@ def test_test_iam_permissions_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.test_iam_permissions(request) + client.update_external_system(request) -def test_test_iam_permissions_rest_flattened(): +def test_update_external_system_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -19071,40 +24852,44 @@ def test_test_iam_permissions_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = iam_policy_pb2.TestIamPermissionsResponse() + return_value = gcs_external_system.ExternalSystem() # get arguments that satisfy an http rule for this method - sample_request = {"resource": "organizations/sample1/sources/sample2"} + sample_request = { + "external_system": { + "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4" + } + } # get truthy value for each flattened field mock_args = dict( - resource="resource_value", - permissions=["permissions_value"], + external_system=gcs_external_system.ExternalSystem(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = return_value + pb_return_value = gcs_external_system.ExternalSystem.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.test_iam_permissions(**mock_args) + client.update_external_system(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{resource=organizations/*/sources/*}:testIamPermissions" + "%s/v1/{external_system.name=organizations/*/sources/*/findings/*/externalSystems/*}" % client.transport._host, args[1], ) -def test_test_iam_permissions_rest_flattened_error(transport: str = "rest"): +def test_update_external_system_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -19113,14 +24898,14 @@ def test_test_iam_permissions_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.test_iam_permissions( - iam_policy_pb2.TestIamPermissionsRequest(), - resource="resource_value", - permissions=["permissions_value"], + 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_test_iam_permissions_rest_error(): +def test_update_external_system_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -19129,11 +24914,11 @@ def test_test_iam_permissions_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateExternalSystemRequest, + securitycenter_service.UpdateFindingRequest, dict, ], ) -def test_update_external_system_rest(request_type): +def test_update_finding_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -19141,49 +24926,249 @@ def test_update_external_system_rest(request_type): # send a request that will satisfy transcoding request_init = { - "external_system": { - "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4" - } + "finding": {"name": "organizations/sample1/sources/sample2/findings/sample3"} } - request_init["external_system"] = { - "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4", - "assignees": ["assignees_value1", "assignees_value2"], - "external_uid": "external_uid_value", - "status": "status_value", - "external_system_update_time": {"seconds": 751, "nanos": 543}, + request_init["finding"] = { + "name": "organizations/sample1/sources/sample2/findings/sample3", + "parent": "parent_value", + "resource_name": "resource_name_value", + "state": 1, + "category": "category_value", + "external_uri": "external_uri_value", + "source_properties": {}, + "security_marks": { + "name": "name_value", + "marks": {}, + "canonical_name": "canonical_name_value", + }, + "event_time": {"seconds": 751, "nanos": 543}, + "create_time": {}, + "severity": 1, + "canonical_name": "canonical_name_value", + "mute": 1, + "finding_class": 1, + "indicator": { + "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], + "domains": ["domains_value1", "domains_value2"], + "signatures": [ + { + "memory_hash_signature": { + "binary_family": "binary_family_value", + "detections": [ + {"binary": "binary_value", "percent_pages_matched": 0.2197} + ], + }, + "yara_rule_signature": {"yara_rule": "yara_rule_value"}, + } + ], + "uris": ["uris_value1", "uris_value2"], + }, + "vulnerability": { + "cve": { + "id": "id_value", + "references": [{"source": "source_value", "uri": "uri_value"}], + "cvssv3": { + "base_score": 0.1046, + "attack_vector": 1, + "attack_complexity": 1, + "privileges_required": 1, + "user_interaction": 1, + "scope": 1, + "confidentiality_impact": 1, + "integrity_impact": 1, + "availability_impact": 1, + }, + "upstream_fix_available": True, + } + }, + "mute_update_time": {}, + "external_systems": {}, + "mitre_attack": { + "primary_tactic": 1, + "primary_techniques": [1], + "additional_tactics": [1], + "additional_techniques": [1], + "version": "version_value", + }, + "access": { + "principal_email": "principal_email_value", + "caller_ip": "caller_ip_value", + "caller_ip_geo": {"region_code": "region_code_value"}, + "user_agent_family": "user_agent_family_value", + "service_name": "service_name_value", + "method_name": "method_name_value", + "principal_subject": "principal_subject_value", + "service_account_key_name": "service_account_key_name_value", + "service_account_delegation_info": [ + { + "principal_email": "principal_email_value", + "principal_subject": "principal_subject_value", + } + ], + "user_name": "user_name_value", + }, + "connections": [ + { + "destination_ip": "destination_ip_value", + "destination_port": 1734, + "source_ip": "source_ip_value", + "source_port": 1205, + "protocol": 1, + } + ], + "mute_initiator": "mute_initiator_value", + "processes": [ + { + "name": "name_value", + "binary": { + "path": "path_value", + "size": 443, + "sha256": "sha256_value", + "hashed_size": 1159, + "partially_hashed": True, + "contents": "contents_value", + }, + "libraries": {}, + "script": {}, + "args": ["args_value1", "args_value2"], + "arguments_truncated": True, + "env_variables": [{"name": "name_value", "val": "val_value"}], + "env_variables_truncated": True, + "pid": 317, + "parent_pid": 1062, + } + ], + "contacts": {}, + "compliances": [ + { + "standard": "standard_value", + "version": "version_value", + "ids": ["ids_value1", "ids_value2"], + } + ], + "parent_display_name": "parent_display_name_value", + "description": "description_value", + "exfiltration": { + "sources": [ + { + "name": "name_value", + "components": ["components_value1", "components_value2"], + } + ], + "targets": {}, + }, + "iam_bindings": [{"action": 1, "role": "role_value", "member": "member_value"}], + "next_steps": "next_steps_value", + "module_name": "module_name_value", + "containers": [ + { + "name": "name_value", + "uri": "uri_value", + "image_id": "image_id_value", + "labels": [{"name": "name_value", "value": "value_value"}], + } + ], + "kubernetes": { + "pods": [ + {"ns": "ns_value", "name": "name_value", "labels": {}, "containers": {}} + ], + "nodes": [{"name": "name_value"}], + "node_pools": [{"name": "name_value", "nodes": {}}], + "roles": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], + "bindings": [ + { + "ns": "ns_value", + "name": "name_value", + "role": {}, + "subjects": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], + } + ], + "access_reviews": [ + { + "group": "group_value", + "ns": "ns_value", + "name": "name_value", + "resource": "resource_value", + "subresource": "subresource_value", + "verb": "verb_value", + "version": "version_value", + } + ], + }, + "database": { + "name": "name_value", + "display_name": "display_name_value", + "user_name": "user_name_value", + "query": "query_value", + "grantees": ["grantees_value1", "grantees_value2"], + }, + "files": {}, + "kernel_rootkit": { + "name": "name_value", + "unexpected_code_modification": True, + "unexpected_read_only_data_modification": True, + "unexpected_ftrace_handler": True, + "unexpected_kprobe_handler": True, + "unexpected_kernel_code_pages": True, + "unexpected_system_call_handler": True, + "unexpected_interrupt_handler": True, + "unexpected_processes_in_runqueue": True, + }, } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_external_system.ExternalSystem( + return_value = gcs_finding.Finding( name="name_value", - assignees=["assignees_value"], - external_uid="external_uid_value", - status="status_value", + parent="parent_value", + resource_name="resource_name_value", + state=gcs_finding.Finding.State.ACTIVE, + category="category_value", + 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", + parent_display_name="parent_display_name_value", + description="description_value", + next_steps="next_steps_value", + module_name="module_name_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_external_system.ExternalSystem.pb(return_value) + pb_return_value = gcs_finding.Finding.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_external_system(request) + response = client.update_finding(request) # Establish that the response is the type that we expect. - assert isinstance(response, gcs_external_system.ExternalSystem) + assert isinstance(response, gcs_finding.Finding) assert response.name == "name_value" - assert response.assignees == ["assignees_value"] - assert response.external_uid == "external_uid_value" - assert response.status == "status_value" + assert response.parent == "parent_value" + assert response.resource_name == "resource_name_value" + assert response.state == gcs_finding.Finding.State.ACTIVE + assert response.category == "category_value" + 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" + assert response.parent_display_name == "parent_display_name_value" + assert response.description == "description_value" + assert response.next_steps == "next_steps_value" + assert response.module_name == "module_name_value" -def test_update_external_system_rest_required_fields( - request_type=securitycenter_service.UpdateExternalSystemRequest, +def test_update_finding_rest_required_fields( + request_type=securitycenter_service.UpdateFindingRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -19202,14 +25187,14 @@ def test_update_external_system_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_external_system._get_unset_required_fields(jsonified_request) + ).update_finding._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_external_system._get_unset_required_fields(jsonified_request) + ).update_finding._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) @@ -19223,7 +25208,7 @@ def test_update_external_system_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gcs_external_system.ExternalSystem() + return_value = gcs_finding.Finding() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -19244,200 +25229,89 @@ def test_update_external_system_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_external_system.ExternalSystem.pb(return_value) + pb_return_value = gcs_finding.Finding.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - - response = client.update_external_system(request) - - expected_params = [("$alt", "json;enum-encoding=int")] - actual_params = req.call_args.kwargs["params"] - assert expected_params == actual_params - - -def test_update_external_system_rest_unset_required_fields(): - transport = transports.SecurityCenterRestTransport( - credentials=ga_credentials.AnonymousCredentials - ) - - unset_fields = transport.update_external_system._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("externalSystem",))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_external_system_rest_interceptors(null_interceptor): - transport = transports.SecurityCenterRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None - if null_interceptor - else transports.SecurityCenterRestInterceptor(), - ) - client = SecurityCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_update_external_system" - ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_update_external_system" - ) as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = securitycenter_service.UpdateExternalSystemRequest.pb( - securitycenter_service.UpdateExternalSystemRequest() - ) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = gcs_external_system.ExternalSystem.to_json( - gcs_external_system.ExternalSystem() - ) - - request = securitycenter_service.UpdateExternalSystemRequest() - metadata = [ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = gcs_external_system.ExternalSystem() - - client.update_external_system( - request, - metadata=[ - ("key", "val"), - ("cephalopod", "squid"), - ], - ) - - pre.assert_called_once() - post.assert_called_once() - - -def test_update_external_system_rest_bad_request( - transport: str = "rest", - request_type=securitycenter_service.UpdateExternalSystemRequest, -): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = { - "external_system": { - "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4" - } - } - request_init["external_system"] = { - "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4", - "assignees": ["assignees_value1", "assignees_value2"], - "external_uid": "external_uid_value", - "status": "status_value", - "external_system_update_time": {"seconds": 751, "nanos": 543}, - } - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest - ): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.update_external_system(request) - - -def test_update_external_system_rest_flattened(): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = gcs_external_system.ExternalSystem() + req.return_value = response_value - # get arguments that satisfy an http rule for this method - sample_request = { - "external_system": { - "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4" - } - } + response = client.update_finding(request) - # get truthy value for each flattened field - mock_args = dict( - external_system=gcs_external_system.ExternalSystem(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), - ) - mock_args.update(sample_request) + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = gcs_external_system.ExternalSystem.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - client.update_external_system(**mock_args) +def test_update_finding_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate( - "%s/v1/{external_system.name=organizations/*/sources/*/findings/*/externalSystems/*}" - % client.transport._host, - args[1], - ) + unset_fields = transport.update_finding._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("finding",))) -def test_update_external_system_rest_flattened_error(transport: str = "rest"): - client = SecurityCenterClient( +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_finding_rest_interceptors(null_interceptor): + transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + interceptor=None + if null_interceptor + else transports.SecurityCenterRestInterceptor(), ) - - # 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"]), + client = SecurityCenterClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.SecurityCenterRestInterceptor, "post_update_finding" + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, "pre_update_finding" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = securitycenter_service.UpdateFindingRequest.pb( + securitycenter_service.UpdateFindingRequest() ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = gcs_finding.Finding.to_json(gcs_finding.Finding()) + request = securitycenter_service.UpdateFindingRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = gcs_finding.Finding() -def test_update_external_system_rest_error(): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" - ) + client.update_finding( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + pre.assert_called_once() + post.assert_called_once() -@pytest.mark.parametrize( - "request_type", - [ - securitycenter_service.UpdateFindingRequest, - dict, - ], -) -def test_update_finding_rest(request_type): + +def test_update_finding_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.UpdateFindingRequest +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport=transport, ) # send a request that will satisfy transcoding @@ -19575,6 +25449,7 @@ def test_update_finding_rest(request_type): }, "iam_bindings": [{"action": 1, "role": "role_value", "member": "member_value"}], "next_steps": "next_steps_value", + "module_name": "module_name_value", "containers": [ { "name": "name_value", @@ -19632,56 +25507,144 @@ def test_update_finding_rest(request_type): } request = request_type(**request_init) + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.update_finding(request) + + +def test_update_finding_rest_flattened(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = gcs_finding.Finding() + + # get arguments that satisfy an http rule for this method + sample_request = { + "finding": { + "name": "organizations/sample1/sources/sample2/findings/sample3" + } + } + + # get truthy value for each flattened field + mock_args = dict( + finding=gcs_finding.Finding(name="name_value"), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gcs_finding.Finding.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.update_finding(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{finding.name=organizations/*/sources/*/findings/*}" + % client.transport._host, + args[1], + ) + + +def test_update_finding_rest_flattened_error(transport: str = "rest"): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_finding( + securitycenter_service.UpdateFindingRequest(), + finding=gcs_finding.Finding(name="name_value"), + ) + + +def test_update_finding_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.UpdateMuteConfigRequest, + dict, + ], +) +def test_update_mute_config_rest(request_type): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = { + "mute_config": {"name": "organizations/sample1/muteConfigs/sample2"} + } + request_init["mute_config"] = { + "name": "organizations/sample1/muteConfigs/sample2", + "display_name": "display_name_value", + "description": "description_value", + "filter": "filter_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "most_recent_editor": "most_recent_editor_value", + } + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_finding.Finding( + return_value = gcs_mute_config.MuteConfig( name="name_value", - parent="parent_value", - resource_name="resource_name_value", - state=gcs_finding.Finding.State.ACTIVE, - category="category_value", - 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", - parent_display_name="parent_display_name_value", + display_name="display_name_value", description="description_value", - next_steps="next_steps_value", + filter="filter_value", + most_recent_editor="most_recent_editor_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_finding.Finding.pb(return_value) + pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_finding(request) + response = client.update_mute_config(request) # Establish that the response is the type that we expect. - assert isinstance(response, gcs_finding.Finding) - assert response.name == "name_value" - assert response.parent == "parent_value" - assert response.resource_name == "resource_name_value" - assert response.state == gcs_finding.Finding.State.ACTIVE - assert response.category == "category_value" - 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" - assert response.parent_display_name == "parent_display_name_value" + 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.next_steps == "next_steps_value" + assert response.filter == "filter_value" + assert response.most_recent_editor == "most_recent_editor_value" -def test_update_finding_rest_required_fields( - request_type=securitycenter_service.UpdateFindingRequest, +def test_update_mute_config_rest_required_fields( + request_type=securitycenter_service.UpdateMuteConfigRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -19700,14 +25663,14 @@ def test_update_finding_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_finding._get_unset_required_fields(jsonified_request) + ).update_mute_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_finding._get_unset_required_fields(jsonified_request) + ).update_mute_config._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) @@ -19721,7 +25684,7 @@ def test_update_finding_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gcs_finding.Finding() + return_value = gcs_mute_config.MuteConfig() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -19742,30 +25705,30 @@ def test_update_finding_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_finding.Finding.pb(return_value) + pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_finding(request) + response = client.update_mute_config(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_update_finding_rest_unset_required_fields(): +def test_update_mute_config_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_finding._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("finding",))) + unset_fields = transport.update_mute_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("muteConfig",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_finding_rest_interceptors(null_interceptor): +def test_update_mute_config_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -19778,14 +25741,14 @@ def test_update_finding_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_update_finding" + transports.SecurityCenterRestInterceptor, "post_update_mute_config" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_update_finding" + transports.SecurityCenterRestInterceptor, "pre_update_mute_config" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.UpdateFindingRequest.pb( - securitycenter_service.UpdateFindingRequest() + pb_message = securitycenter_service.UpdateMuteConfigRequest.pb( + securitycenter_service.UpdateMuteConfigRequest() ) transcode.return_value = { "method": "post", @@ -19797,225 +25760,50 @@ def test_update_finding_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = gcs_finding.Finding.to_json(gcs_finding.Finding()) - - request = securitycenter_service.UpdateFindingRequest() - metadata = [ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = gcs_finding.Finding() - - client.update_finding( - request, - metadata=[ - ("key", "val"), - ("cephalopod", "squid"), - ], - ) - - pre.assert_called_once() - post.assert_called_once() - - -def test_update_finding_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.UpdateFindingRequest -): - client = SecurityCenterClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = { - "finding": {"name": "organizations/sample1/sources/sample2/findings/sample3"} - } - request_init["finding"] = { - "name": "organizations/sample1/sources/sample2/findings/sample3", - "parent": "parent_value", - "resource_name": "resource_name_value", - "state": 1, - "category": "category_value", - "external_uri": "external_uri_value", - "source_properties": {}, - "security_marks": { - "name": "name_value", - "marks": {}, - "canonical_name": "canonical_name_value", - }, - "event_time": {"seconds": 751, "nanos": 543}, - "create_time": {}, - "severity": 1, - "canonical_name": "canonical_name_value", - "mute": 1, - "finding_class": 1, - "indicator": { - "ip_addresses": ["ip_addresses_value1", "ip_addresses_value2"], - "domains": ["domains_value1", "domains_value2"], - "signatures": [ - { - "memory_hash_signature": { - "binary_family": "binary_family_value", - "detections": [ - {"binary": "binary_value", "percent_pages_matched": 0.2197} - ], - }, - "yara_rule_signature": {"yara_rule": "yara_rule_value"}, - } - ], - "uris": ["uris_value1", "uris_value2"], - }, - "vulnerability": { - "cve": { - "id": "id_value", - "references": [{"source": "source_value", "uri": "uri_value"}], - "cvssv3": { - "base_score": 0.1046, - "attack_vector": 1, - "attack_complexity": 1, - "privileges_required": 1, - "user_interaction": 1, - "scope": 1, - "confidentiality_impact": 1, - "integrity_impact": 1, - "availability_impact": 1, - }, - "upstream_fix_available": True, - } - }, - "mute_update_time": {}, - "external_systems": {}, - "mitre_attack": { - "primary_tactic": 1, - "primary_techniques": [1], - "additional_tactics": [1], - "additional_techniques": [1], - "version": "version_value", - }, - "access": { - "principal_email": "principal_email_value", - "caller_ip": "caller_ip_value", - "caller_ip_geo": {"region_code": "region_code_value"}, - "user_agent_family": "user_agent_family_value", - "service_name": "service_name_value", - "method_name": "method_name_value", - "principal_subject": "principal_subject_value", - "service_account_key_name": "service_account_key_name_value", - "service_account_delegation_info": [ - { - "principal_email": "principal_email_value", - "principal_subject": "principal_subject_value", - } - ], - "user_name": "user_name_value", - }, - "connections": [ - { - "destination_ip": "destination_ip_value", - "destination_port": 1734, - "source_ip": "source_ip_value", - "source_port": 1205, - "protocol": 1, - } - ], - "mute_initiator": "mute_initiator_value", - "processes": [ - { - "name": "name_value", - "binary": { - "path": "path_value", - "size": 443, - "sha256": "sha256_value", - "hashed_size": 1159, - "partially_hashed": True, - "contents": "contents_value", - }, - "libraries": {}, - "script": {}, - "args": ["args_value1", "args_value2"], - "arguments_truncated": True, - "env_variables": [{"name": "name_value", "val": "val_value"}], - "env_variables_truncated": True, - "pid": 317, - "parent_pid": 1062, - } - ], - "contacts": {}, - "compliances": [ - { - "standard": "standard_value", - "version": "version_value", - "ids": ["ids_value1", "ids_value2"], - } - ], - "parent_display_name": "parent_display_name_value", - "description": "description_value", - "exfiltration": { - "sources": [ - { - "name": "name_value", - "components": ["components_value1", "components_value2"], - } - ], - "targets": {}, - }, - "iam_bindings": [{"action": 1, "role": "role_value", "member": "member_value"}], - "next_steps": "next_steps_value", - "containers": [ - { - "name": "name_value", - "uri": "uri_value", - "image_id": "image_id_value", - "labels": [{"name": "name_value", "value": "value_value"}], - } - ], - "kubernetes": { - "pods": [ - {"ns": "ns_value", "name": "name_value", "labels": {}, "containers": {}} - ], - "nodes": [{"name": "name_value"}], - "node_pools": [{"name": "name_value", "nodes": {}}], - "roles": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], - "bindings": [ - { - "ns": "ns_value", - "name": "name_value", - "role": {}, - "subjects": [{"kind": 1, "ns": "ns_value", "name": "name_value"}], - } - ], - "access_reviews": [ - { - "group": "group_value", - "ns": "ns_value", - "name": "name_value", - "resource": "resource_value", - "subresource": "subresource_value", - "verb": "verb_value", - "version": "version_value", - } - ], - }, - "database": { - "name": "name_value", - "display_name": "display_name_value", - "user_name": "user_name_value", - "query": "query_value", - "grantees": ["grantees_value1", "grantees_value2"], - }, - "files": {}, - "kernel_rootkit": { - "name": "name_value", - "unexpected_code_modification": True, - "unexpected_read_only_data_modification": True, - "unexpected_ftrace_handler": True, - "unexpected_kprobe_handler": True, - "unexpected_kernel_code_pages": True, - "unexpected_system_call_handler": True, - "unexpected_interrupt_handler": True, - "unexpected_processes_in_runqueue": True, - }, + req.return_value._content = gcs_mute_config.MuteConfig.to_json( + gcs_mute_config.MuteConfig() + ) + + request = securitycenter_service.UpdateMuteConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = gcs_mute_config.MuteConfig() + + client.update_mute_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_update_mute_config_rest_bad_request( + transport: str = "rest", request_type=securitycenter_service.UpdateMuteConfigRequest +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = { + "mute_config": {"name": "organizations/sample1/muteConfigs/sample2"} + } + request_init["mute_config"] = { + "name": "organizations/sample1/muteConfigs/sample2", + "display_name": "display_name_value", + "description": "description_value", + "filter": "filter_value", + "create_time": {"seconds": 751, "nanos": 543}, + "update_time": {}, + "most_recent_editor": "most_recent_editor_value", } request = request_type(**request_init) @@ -20028,10 +25816,10 @@ def test_update_finding_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.update_finding(request) + client.update_mute_config(request) -def test_update_finding_rest_flattened(): +def test_update_mute_config_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20040,43 +25828,42 @@ def test_update_finding_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_finding.Finding() + return_value = gcs_mute_config.MuteConfig() # get arguments that satisfy an http rule for this method sample_request = { - "finding": { - "name": "organizations/sample1/sources/sample2/findings/sample3" - } + "mute_config": {"name": "organizations/sample1/muteConfigs/sample2"} } # get truthy value for each flattened field mock_args = dict( - finding=gcs_finding.Finding(name="name_value"), + mute_config=gcs_mute_config.MuteConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_finding.Finding.pb(return_value) + pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.update_finding(**mock_args) + client.update_mute_config(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{finding.name=organizations/*/sources/*/findings/*}" + "%s/v1/{mute_config.name=organizations/*/muteConfigs/*}" % client.transport._host, args[1], ) -def test_update_finding_rest_flattened_error(transport: str = "rest"): +def test_update_mute_config_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -20085,13 +25872,14 @@ def test_update_finding_rest_flattened_error(transport: str = "rest"): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_finding( - securitycenter_service.UpdateFindingRequest(), - finding=gcs_finding.Finding(name="name_value"), + 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_finding_rest_error(): +def test_update_mute_config_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -20100,11 +25888,11 @@ def test_update_finding_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateMuteConfigRequest, + securitycenter_service.UpdateNotificationConfigRequest, dict, ], ) -def test_update_mute_config_rest(request_type): +def test_update_notification_config_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20112,51 +25900,52 @@ def test_update_mute_config_rest(request_type): # send a request that will satisfy transcoding request_init = { - "mute_config": {"name": "organizations/sample1/muteConfigs/sample2"} + "notification_config": { + "name": "organizations/sample1/notificationConfigs/sample2" + } } - request_init["mute_config"] = { - "name": "organizations/sample1/muteConfigs/sample2", - "display_name": "display_name_value", + request_init["notification_config"] = { + "name": "organizations/sample1/notificationConfigs/sample2", "description": "description_value", - "filter": "filter_value", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "most_recent_editor": "most_recent_editor_value", + "pubsub_topic": "pubsub_topic_value", + "service_account": "service_account_value", + "streaming_config": {"filter": "filter_value"}, } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_mute_config.MuteConfig( + return_value = gcs_notification_config.NotificationConfig( name="name_value", - display_name="display_name_value", description="description_value", - filter="filter_value", - most_recent_editor="most_recent_editor_value", + pubsub_topic="pubsub_topic_value", + service_account="service_account_value", + streaming_config=gcs_notification_config.NotificationConfig.StreamingConfig( + filter="filter_value" + ), ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) + pb_return_value = gcs_notification_config.NotificationConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_mute_config(request) + response = client.update_notification_config(request) # Establish that the response is the type that we expect. - assert isinstance(response, gcs_mute_config.MuteConfig) + assert isinstance(response, gcs_notification_config.NotificationConfig) 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" + assert response.pubsub_topic == "pubsub_topic_value" + assert response.service_account == "service_account_value" -def test_update_mute_config_rest_required_fields( - request_type=securitycenter_service.UpdateMuteConfigRequest, +def test_update_notification_config_rest_required_fields( + request_type=securitycenter_service.UpdateNotificationConfigRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -20175,14 +25964,14 @@ def test_update_mute_config_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_mute_config._get_unset_required_fields(jsonified_request) + ).update_notification_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_mute_config._get_unset_required_fields(jsonified_request) + ).update_notification_config._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) @@ -20196,7 +25985,7 @@ def test_update_mute_config_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gcs_mute_config.MuteConfig() + return_value = gcs_notification_config.NotificationConfig() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -20217,30 +26006,32 @@ def test_update_mute_config_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) + pb_return_value = gcs_notification_config.NotificationConfig.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_mute_config(request) + response = client.update_notification_config(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_update_mute_config_rest_unset_required_fields(): +def test_update_notification_config_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_mute_config._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("muteConfig",))) + unset_fields = transport.update_notification_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("notificationConfig",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_mute_config_rest_interceptors(null_interceptor): +def test_update_notification_config_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -20253,14 +26044,14 @@ def test_update_mute_config_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_update_mute_config" + transports.SecurityCenterRestInterceptor, "post_update_notification_config" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_update_mute_config" + transports.SecurityCenterRestInterceptor, "pre_update_notification_config" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.UpdateMuteConfigRequest.pb( - securitycenter_service.UpdateMuteConfigRequest() + pb_message = securitycenter_service.UpdateNotificationConfigRequest.pb( + securitycenter_service.UpdateNotificationConfigRequest() ) transcode.return_value = { "method": "post", @@ -20272,19 +26063,19 @@ def test_update_mute_config_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = gcs_mute_config.MuteConfig.to_json( - gcs_mute_config.MuteConfig() + req.return_value._content = gcs_notification_config.NotificationConfig.to_json( + gcs_notification_config.NotificationConfig() ) - request = securitycenter_service.UpdateMuteConfigRequest() + request = securitycenter_service.UpdateNotificationConfigRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = gcs_mute_config.MuteConfig() + post.return_value = gcs_notification_config.NotificationConfig() - client.update_mute_config( + client.update_notification_config( request, metadata=[ ("key", "val"), @@ -20296,8 +26087,9 @@ def test_update_mute_config_rest_interceptors(null_interceptor): post.assert_called_once() -def test_update_mute_config_rest_bad_request( - transport: str = "rest", request_type=securitycenter_service.UpdateMuteConfigRequest +def test_update_notification_config_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.UpdateNotificationConfigRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20306,16 +26098,16 @@ def test_update_mute_config_rest_bad_request( # send a request that will satisfy transcoding request_init = { - "mute_config": {"name": "organizations/sample1/muteConfigs/sample2"} + "notification_config": { + "name": "organizations/sample1/notificationConfigs/sample2" + } } - request_init["mute_config"] = { - "name": "organizations/sample1/muteConfigs/sample2", - "display_name": "display_name_value", + request_init["notification_config"] = { + "name": "organizations/sample1/notificationConfigs/sample2", "description": "description_value", - "filter": "filter_value", - "create_time": {"seconds": 751, "nanos": 543}, - "update_time": {}, - "most_recent_editor": "most_recent_editor_value", + "pubsub_topic": "pubsub_topic_value", + "service_account": "service_account_value", + "streaming_config": {"filter": "filter_value"}, } request = request_type(**request_init) @@ -20328,10 +26120,10 @@ def test_update_mute_config_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.update_mute_config(request) + client.update_notification_config(request) -def test_update_mute_config_rest_flattened(): +def test_update_notification_config_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20340,16 +26132,20 @@ def test_update_mute_config_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_mute_config.MuteConfig() + return_value = gcs_notification_config.NotificationConfig() # get arguments that satisfy an http rule for this method sample_request = { - "mute_config": {"name": "organizations/sample1/muteConfigs/sample2"} + "notification_config": { + "name": "organizations/sample1/notificationConfigs/sample2" + } } # get truthy value for each flattened field mock_args = dict( - mute_config=gcs_mute_config.MuteConfig(name="name_value"), + notification_config=gcs_notification_config.NotificationConfig( + name="name_value" + ), update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) @@ -20357,25 +26153,25 @@ def test_update_mute_config_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_mute_config.MuteConfig.pb(return_value) + pb_return_value = gcs_notification_config.NotificationConfig.pb(return_value) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.update_mute_config(**mock_args) + client.update_notification_config(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{mute_config.name=organizations/*/muteConfigs/*}" + "%s/v1/{notification_config.name=organizations/*/notificationConfigs/*}" % client.transport._host, args[1], ) -def test_update_mute_config_rest_flattened_error(transport: str = "rest"): +def test_update_notification_config_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -20384,14 +26180,16 @@ def test_update_mute_config_rest_flattened_error(transport: str = "rest"): # 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"), + client.update_notification_config( + securitycenter_service.UpdateNotificationConfigRequest(), + notification_config=gcs_notification_config.NotificationConfig( + name="name_value" + ), update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_update_mute_config_rest_error(): +def test_update_notification_config_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -20400,11 +26198,11 @@ def test_update_mute_config_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateNotificationConfigRequest, + securitycenter_service.UpdateOrganizationSettingsRequest, dict, ], ) -def test_update_notification_config_rest(request_type): +def test_update_organization_settings_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20412,52 +26210,47 @@ def test_update_notification_config_rest(request_type): # send a request that will satisfy transcoding request_init = { - "notification_config": { - "name": "organizations/sample1/notificationConfigs/sample2" - } + "organization_settings": {"name": "organizations/sample1/organizationSettings"} } - request_init["notification_config"] = { - "name": "organizations/sample1/notificationConfigs/sample2", - "description": "description_value", - "pubsub_topic": "pubsub_topic_value", - "service_account": "service_account_value", - "streaming_config": {"filter": "filter_value"}, + request_init["organization_settings"] = { + "name": "organizations/sample1/organizationSettings", + "enable_asset_discovery": True, + "asset_discovery_config": { + "project_ids": ["project_ids_value1", "project_ids_value2"], + "inclusion_mode": 1, + "folder_ids": ["folder_ids_value1", "folder_ids_value2"], + }, } request = request_type(**request_init) # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_notification_config.NotificationConfig( + return_value = gcs_organization_settings.OrganizationSettings( 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" - ), + enable_asset_discovery=True, ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_notification_config.NotificationConfig.pb(return_value) + pb_return_value = gcs_organization_settings.OrganizationSettings.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_notification_config(request) + response = client.update_organization_settings(request) # Establish that the response is the type that we expect. - assert isinstance(response, gcs_notification_config.NotificationConfig) + assert isinstance(response, gcs_organization_settings.OrganizationSettings) 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.enable_asset_discovery is True -def test_update_notification_config_rest_required_fields( - request_type=securitycenter_service.UpdateNotificationConfigRequest, +def test_update_organization_settings_rest_required_fields( + request_type=securitycenter_service.UpdateOrganizationSettingsRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -20476,14 +26269,14 @@ def test_update_notification_config_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_notification_config._get_unset_required_fields(jsonified_request) + ).update_organization_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_notification_config._get_unset_required_fields(jsonified_request) + ).update_organization_settings._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) @@ -20497,7 +26290,7 @@ def test_update_notification_config_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gcs_notification_config.NotificationConfig() + return_value = gcs_organization_settings.OrganizationSettings() # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -20518,7 +26311,7 @@ def test_update_notification_config_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_notification_config.NotificationConfig.pb( + pb_return_value = gcs_organization_settings.OrganizationSettings.pb( return_value ) json_return_value = json_format.MessageToJson(pb_return_value) @@ -20526,24 +26319,24 @@ def test_update_notification_config_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_notification_config(request) + response = client.update_organization_settings(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_update_notification_config_rest_unset_required_fields(): +def test_update_organization_settings_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_notification_config._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("notificationConfig",))) + unset_fields = transport.update_organization_settings._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask",)) & set(("organizationSettings",))) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_notification_config_rest_interceptors(null_interceptor): +def test_update_organization_settings_rest_interceptors(null_interceptor): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -20556,14 +26349,14 @@ def test_update_notification_config_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_update_notification_config" + transports.SecurityCenterRestInterceptor, "post_update_organization_settings" ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_update_notification_config" + transports.SecurityCenterRestInterceptor, "pre_update_organization_settings" ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.UpdateNotificationConfigRequest.pb( - securitycenter_service.UpdateNotificationConfigRequest() + pb_message = securitycenter_service.UpdateOrganizationSettingsRequest.pb( + securitycenter_service.UpdateOrganizationSettingsRequest() ) transcode.return_value = { "method": "post", @@ -20575,19 +26368,21 @@ def test_update_notification_config_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = gcs_notification_config.NotificationConfig.to_json( - gcs_notification_config.NotificationConfig() + req.return_value._content = ( + gcs_organization_settings.OrganizationSettings.to_json( + gcs_organization_settings.OrganizationSettings() + ) ) - request = securitycenter_service.UpdateNotificationConfigRequest() + request = securitycenter_service.UpdateOrganizationSettingsRequest() metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = gcs_notification_config.NotificationConfig() + post.return_value = gcs_organization_settings.OrganizationSettings() - client.update_notification_config( + client.update_organization_settings( request, metadata=[ ("key", "val"), @@ -20599,9 +26394,9 @@ def test_update_notification_config_rest_interceptors(null_interceptor): post.assert_called_once() -def test_update_notification_config_rest_bad_request( +def test_update_organization_settings_rest_bad_request( transport: str = "rest", - request_type=securitycenter_service.UpdateNotificationConfigRequest, + request_type=securitycenter_service.UpdateOrganizationSettingsRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20610,16 +26405,16 @@ def test_update_notification_config_rest_bad_request( # send a request that will satisfy transcoding request_init = { - "notification_config": { - "name": "organizations/sample1/notificationConfigs/sample2" - } + "organization_settings": {"name": "organizations/sample1/organizationSettings"} } - request_init["notification_config"] = { - "name": "organizations/sample1/notificationConfigs/sample2", - "description": "description_value", - "pubsub_topic": "pubsub_topic_value", - "service_account": "service_account_value", - "streaming_config": {"filter": "filter_value"}, + request_init["organization_settings"] = { + "name": "organizations/sample1/organizationSettings", + "enable_asset_discovery": True, + "asset_discovery_config": { + "project_ids": ["project_ids_value1", "project_ids_value2"], + "inclusion_mode": 1, + "folder_ids": ["folder_ids_value1", "folder_ids_value2"], + }, } request = request_type(**request_init) @@ -20632,10 +26427,10 @@ def test_update_notification_config_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.update_notification_config(request) + client.update_organization_settings(request) -def test_update_notification_config_rest_flattened(): +def test_update_organization_settings_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20644,46 +26439,47 @@ def test_update_notification_config_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_notification_config.NotificationConfig() + return_value = gcs_organization_settings.OrganizationSettings() # get arguments that satisfy an http rule for this method sample_request = { - "notification_config": { - "name": "organizations/sample1/notificationConfigs/sample2" + "organization_settings": { + "name": "organizations/sample1/organizationSettings" } } # get truthy value for each flattened field mock_args = dict( - notification_config=gcs_notification_config.NotificationConfig( + organization_settings=gcs_organization_settings.OrganizationSettings( name="name_value" ), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_notification_config.NotificationConfig.pb(return_value) + pb_return_value = gcs_organization_settings.OrganizationSettings.pb( + return_value + ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.update_notification_config(**mock_args) + client.update_organization_settings(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{notification_config.name=organizations/*/notificationConfigs/*}" + "%s/v1/{organization_settings.name=organizations/*/organizationSettings}" % client.transport._host, args[1], ) -def test_update_notification_config_rest_flattened_error(transport: str = "rest"): +def test_update_organization_settings_rest_flattened_error(transport: str = "rest"): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -20692,16 +26488,15 @@ def test_update_notification_config_rest_flattened_error(transport: str = "rest" # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_notification_config( - securitycenter_service.UpdateNotificationConfigRequest(), - notification_config=gcs_notification_config.NotificationConfig( + client.update_organization_settings( + securitycenter_service.UpdateOrganizationSettingsRequest(), + organization_settings=gcs_organization_settings.OrganizationSettings( name="name_value" ), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_update_notification_config_rest_error(): +def test_update_organization_settings_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -20710,11 +26505,11 @@ def test_update_notification_config_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateOrganizationSettingsRequest, + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, dict, ], ) -def test_update_organization_settings_rest(request_type): +def test_update_security_health_analytics_custom_module_rest(request_type): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20722,15 +26517,33 @@ def test_update_organization_settings_rest(request_type): # send a request that will satisfy transcoding request_init = { - "organization_settings": {"name": "organizations/sample1/organizationSettings"} + "security_health_analytics_custom_module": { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2" + } } - request_init["organization_settings"] = { - "name": "organizations/sample1/organizationSettings", - "enable_asset_discovery": True, - "asset_discovery_config": { - "project_ids": ["project_ids_value1", "project_ids_value2"], - "inclusion_mode": 1, - "folder_ids": ["folder_ids_value1", "folder_ids_value2"], + request_init["security_health_analytics_custom_module"] = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2", + "display_name": "display_name_value", + "enablement_state": 1, + "update_time": {"seconds": 751, "nanos": 543}, + "last_editor": "last_editor_value", + "ancestor_module": "ancestor_module_value", + "custom_config": { + "predicate": { + "expression": "expression_value", + "title": "title_value", + "description": "description_value", + "location": "location_value", + }, + "custom_output": { + "properties": [{"name": "name_value", "value_expression": {}}] + }, + "resource_selector": { + "resource_types": ["resource_types_value1", "resource_types_value2"] + }, + "severity": 1, + "description": "description_value", + "recommendation": "recommendation_value", }, } request = request_type(**request_init) @@ -20738,31 +26551,43 @@ def test_update_organization_settings_rest(request_type): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_organization_settings.OrganizationSettings( + return_value = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( name="name_value", - enable_asset_discovery=True, + display_name="display_name_value", + enablement_state=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED, + last_editor="last_editor_value", + ancestor_module="ancestor_module_value", ) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_organization_settings.OrganizationSettings.pb( + pb_return_value = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( return_value ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_organization_settings(request) + response = client.update_security_health_analytics_custom_module(request) # Establish that the response is the type that we expect. - assert isinstance(response, gcs_organization_settings.OrganizationSettings) + assert isinstance( + response, + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule, + ) assert response.name == "name_value" - assert response.enable_asset_discovery is True + assert response.display_name == "display_name_value" + assert ( + response.enablement_state + == gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.EnablementState.ENABLED + ) + assert response.last_editor == "last_editor_value" + assert response.ancestor_module == "ancestor_module_value" -def test_update_organization_settings_rest_required_fields( - request_type=securitycenter_service.UpdateOrganizationSettingsRequest, +def test_update_security_health_analytics_custom_module_rest_required_fields( + request_type=securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, ): transport_class = transports.SecurityCenterRestTransport @@ -20781,14 +26606,18 @@ def test_update_organization_settings_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_organization_settings._get_unset_required_fields(jsonified_request) + ).update_security_health_analytics_custom_module._get_unset_required_fields( + jsonified_request + ) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ).update_organization_settings._get_unset_required_fields(jsonified_request) + ).update_security_health_analytics_custom_module._get_unset_required_fields( + jsonified_request + ) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) jsonified_request.update(unset_fields) @@ -20802,7 +26631,9 @@ def test_update_organization_settings_rest_required_fields( request = request_type(**request_init) # Designate an appropriate value for the returned response. - return_value = gcs_organization_settings.OrganizationSettings() + return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) # Mock the http request call within the method and fake a response. with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values @@ -20823,7 +26654,7 @@ def test_update_organization_settings_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_organization_settings.OrganizationSettings.pb( + pb_return_value = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( return_value ) json_return_value = json_format.MessageToJson(pb_return_value) @@ -20831,24 +26662,30 @@ def test_update_organization_settings_rest_required_fields( response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - response = client.update_organization_settings(request) + response = client.update_security_health_analytics_custom_module(request) expected_params = [("$alt", "json;enum-encoding=int")] actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params -def test_update_organization_settings_rest_unset_required_fields(): +def test_update_security_health_analytics_custom_module_rest_unset_required_fields(): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials ) - unset_fields = transport.update_organization_settings._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask",)) & set(("organizationSettings",))) + unset_fields = transport.update_security_health_analytics_custom_module._get_unset_required_fields( + {} + ) + assert set(unset_fields) == ( + set(("updateMask",)) & set(("securityHealthAnalyticsCustomModule",)) + ) @pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_organization_settings_rest_interceptors(null_interceptor): +def test_update_security_health_analytics_custom_module_rest_interceptors( + null_interceptor, +): transport = transports.SecurityCenterRestTransport( credentials=ga_credentials.AnonymousCredentials(), interceptor=None @@ -20861,14 +26698,16 @@ def test_update_organization_settings_rest_interceptors(null_interceptor): ) as req, mock.patch.object( path_template, "transcode" ) as transcode, mock.patch.object( - transports.SecurityCenterRestInterceptor, "post_update_organization_settings" + transports.SecurityCenterRestInterceptor, + "post_update_security_health_analytics_custom_module", ) as post, mock.patch.object( - transports.SecurityCenterRestInterceptor, "pre_update_organization_settings" + transports.SecurityCenterRestInterceptor, + "pre_update_security_health_analytics_custom_module", ) as pre: pre.assert_not_called() post.assert_not_called() - pb_message = securitycenter_service.UpdateOrganizationSettingsRequest.pb( - securitycenter_service.UpdateOrganizationSettingsRequest() + pb_message = securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest.pb( + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest() ) transcode.return_value = { "method": "post", @@ -20880,21 +26719,23 @@ def test_update_organization_settings_rest_interceptors(null_interceptor): req.return_value = Response() req.return_value.status_code = 200 req.return_value.request = PreparedRequest() - req.return_value._content = ( - gcs_organization_settings.OrganizationSettings.to_json( - gcs_organization_settings.OrganizationSettings() - ) + req.return_value._content = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.to_json( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() ) - request = securitycenter_service.UpdateOrganizationSettingsRequest() + request = ( + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest() + ) metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - post.return_value = gcs_organization_settings.OrganizationSettings() + post.return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) - client.update_organization_settings( + client.update_security_health_analytics_custom_module( request, metadata=[ ("key", "val"), @@ -20906,9 +26747,9 @@ def test_update_organization_settings_rest_interceptors(null_interceptor): post.assert_called_once() -def test_update_organization_settings_rest_bad_request( +def test_update_security_health_analytics_custom_module_rest_bad_request( transport: str = "rest", - request_type=securitycenter_service.UpdateOrganizationSettingsRequest, + request_type=securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest, ): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20917,15 +26758,33 @@ def test_update_organization_settings_rest_bad_request( # send a request that will satisfy transcoding request_init = { - "organization_settings": {"name": "organizations/sample1/organizationSettings"} + "security_health_analytics_custom_module": { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2" + } } - request_init["organization_settings"] = { - "name": "organizations/sample1/organizationSettings", - "enable_asset_discovery": True, - "asset_discovery_config": { - "project_ids": ["project_ids_value1", "project_ids_value2"], - "inclusion_mode": 1, - "folder_ids": ["folder_ids_value1", "folder_ids_value2"], + request_init["security_health_analytics_custom_module"] = { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2", + "display_name": "display_name_value", + "enablement_state": 1, + "update_time": {"seconds": 751, "nanos": 543}, + "last_editor": "last_editor_value", + "ancestor_module": "ancestor_module_value", + "custom_config": { + "predicate": { + "expression": "expression_value", + "title": "title_value", + "description": "description_value", + "location": "location_value", + }, + "custom_output": { + "properties": [{"name": "name_value", "value_expression": {}}] + }, + "resource_selector": { + "resource_types": ["resource_types_value1", "resource_types_value2"] + }, + "severity": 1, + "description": "description_value", + "recommendation": "recommendation_value", }, } request = request_type(**request_init) @@ -20939,10 +26798,10 @@ def test_update_organization_settings_rest_bad_request( response_value.status_code = 400 response_value.request = Request() req.return_value = response_value - client.update_organization_settings(request) + client.update_security_health_analytics_custom_module(request) -def test_update_organization_settings_rest_flattened(): +def test_update_security_health_analytics_custom_module_rest_flattened(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest", @@ -20951,47 +26810,52 @@ def test_update_organization_settings_rest_flattened(): # Mock the http request call within the method and fake a response. with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. - return_value = gcs_organization_settings.OrganizationSettings() + return_value = ( + gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule() + ) # get arguments that satisfy an http rule for this method sample_request = { - "organization_settings": { - "name": "organizations/sample1/organizationSettings" + "security_health_analytics_custom_module": { + "name": "organizations/sample1/securityHealthAnalyticsSettings/customModules/sample2" } } # get truthy value for each flattened field mock_args = dict( - organization_settings=gcs_organization_settings.OrganizationSettings( + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( name="name_value" ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = gcs_organization_settings.OrganizationSettings.pb( + pb_return_value = gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule.pb( return_value ) json_return_value = json_format.MessageToJson(pb_return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value - client.update_organization_settings(**mock_args) + client.update_security_health_analytics_custom_module(**mock_args) # Establish that the underlying call was made with the expected # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] assert path_template.validate( - "%s/v1/{organization_settings.name=organizations/*/organizationSettings}" + "%s/v1/{security_health_analytics_custom_module.name=organizations/*/securityHealthAnalyticsSettings/customModules/*}" % client.transport._host, args[1], ) -def test_update_organization_settings_rest_flattened_error(transport: str = "rest"): +def test_update_security_health_analytics_custom_module_rest_flattened_error( + transport: str = "rest", +): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -21000,15 +26864,16 @@ def test_update_organization_settings_rest_flattened_error(transport: str = "res # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_organization_settings( - securitycenter_service.UpdateOrganizationSettingsRequest(), - organization_settings=gcs_organization_settings.OrganizationSettings( + client.update_security_health_analytics_custom_module( + securitycenter_service.UpdateSecurityHealthAnalyticsCustomModuleRequest(), + security_health_analytics_custom_module=gcs_security_health_analytics_custom_module.SecurityHealthAnalyticsCustomModule( name="name_value" ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_update_organization_settings_rest_error(): +def test_update_security_health_analytics_custom_module_rest_error(): client = SecurityCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) @@ -22971,24 +28836,31 @@ def test_security_center_base_transport(): # raise NotImplementedError. methods = ( "bulk_mute_findings", + "create_security_health_analytics_custom_module", "create_source", "create_finding", "create_mute_config", "create_notification_config", "delete_mute_config", "delete_notification_config", + "delete_security_health_analytics_custom_module", "get_big_query_export", "get_iam_policy", "get_mute_config", "get_notification_config", "get_organization_settings", + "get_effective_security_health_analytics_custom_module", + "get_security_health_analytics_custom_module", "get_source", "group_assets", "group_findings", "list_assets", + "list_descendant_security_health_analytics_custom_modules", "list_findings", "list_mute_configs", "list_notification_configs", + "list_effective_security_health_analytics_custom_modules", + "list_security_health_analytics_custom_modules", "list_sources", "run_asset_discovery", "set_finding_state", @@ -23000,6 +28872,7 @@ def test_security_center_base_transport(): "update_mute_config", "update_notification_config", "update_organization_settings", + "update_security_health_analytics_custom_module", "update_source", "update_security_marks", "create_big_query_export", @@ -23293,6 +29166,9 @@ def test_security_center_client_transport_session_collision(transport_name): session1 = client1.transport.bulk_mute_findings._session session2 = client2.transport.bulk_mute_findings._session assert session1 != session2 + session1 = client1.transport.create_security_health_analytics_custom_module._session + session2 = client2.transport.create_security_health_analytics_custom_module._session + assert session1 != session2 session1 = client1.transport.create_source._session session2 = client2.transport.create_source._session assert session1 != session2 @@ -23311,6 +29187,9 @@ def test_security_center_client_transport_session_collision(transport_name): session1 = client1.transport.delete_notification_config._session session2 = client2.transport.delete_notification_config._session assert session1 != session2 + session1 = client1.transport.delete_security_health_analytics_custom_module._session + session2 = client2.transport.delete_security_health_analytics_custom_module._session + assert session1 != session2 session1 = client1.transport.get_big_query_export._session session2 = client2.transport.get_big_query_export._session assert session1 != session2 @@ -23326,6 +29205,16 @@ def test_security_center_client_transport_session_collision(transport_name): session1 = client1.transport.get_organization_settings._session session2 = client2.transport.get_organization_settings._session assert session1 != session2 + session1 = ( + client1.transport.get_effective_security_health_analytics_custom_module._session + ) + session2 = ( + client2.transport.get_effective_security_health_analytics_custom_module._session + ) + assert session1 != session2 + session1 = client1.transport.get_security_health_analytics_custom_module._session + session2 = client2.transport.get_security_health_analytics_custom_module._session + assert session1 != session2 session1 = client1.transport.get_source._session session2 = client2.transport.get_source._session assert session1 != session2 @@ -23338,6 +29227,13 @@ def test_security_center_client_transport_session_collision(transport_name): session1 = client1.transport.list_assets._session session2 = client2.transport.list_assets._session assert session1 != session2 + session1 = ( + client1.transport.list_descendant_security_health_analytics_custom_modules._session + ) + session2 = ( + client2.transport.list_descendant_security_health_analytics_custom_modules._session + ) + assert session1 != session2 session1 = client1.transport.list_findings._session session2 = client2.transport.list_findings._session assert session1 != session2 @@ -23347,6 +29243,16 @@ def test_security_center_client_transport_session_collision(transport_name): session1 = client1.transport.list_notification_configs._session session2 = client2.transport.list_notification_configs._session assert session1 != session2 + session1 = ( + client1.transport.list_effective_security_health_analytics_custom_modules._session + ) + session2 = ( + client2.transport.list_effective_security_health_analytics_custom_modules._session + ) + assert session1 != session2 + session1 = client1.transport.list_security_health_analytics_custom_modules._session + session2 = client2.transport.list_security_health_analytics_custom_modules._session + assert session1 != session2 session1 = client1.transport.list_sources._session session2 = client2.transport.list_sources._session assert session1 != session2 @@ -23380,6 +29286,9 @@ def test_security_center_client_transport_session_collision(transport_name): session1 = client1.transport.update_organization_settings._session session2 = client2.transport.update_organization_settings._session assert session1 != session2 + session1 = client1.transport.update_security_health_analytics_custom_module._session + session2 = client2.transport.update_security_health_analytics_custom_module._session + assert session1 != session2 session1 = client1.transport.update_source._session session2 = client2.transport.update_source._session assert session1 != session2 @@ -23606,11 +29515,42 @@ def test_parse_big_query_export_path(): assert expected == actual -def test_external_system_path(): +def test_effective_security_health_analytics_custom_module_path(): organization = "winkle" - source = "nautilus" - finding = "scallop" - externalsystem = "abalone" + effective_custom_module = "nautilus" + expected = "organizations/{organization}/securityHealthAnalyticsSettings/effectiveCustomModules/{effective_custom_module}".format( + organization=organization, + effective_custom_module=effective_custom_module, + ) + actual = ( + SecurityCenterClient.effective_security_health_analytics_custom_module_path( + organization, effective_custom_module + ) + ) + assert expected == actual + + +def test_parse_effective_security_health_analytics_custom_module_path(): + expected = { + "organization": "scallop", + "effective_custom_module": "abalone", + } + path = SecurityCenterClient.effective_security_health_analytics_custom_module_path( + **expected + ) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_effective_security_health_analytics_custom_module_path( + path + ) + assert expected == actual + + +def test_external_system_path(): + organization = "squid" + source = "clam" + finding = "whelk" + externalsystem = "octopus" expected = "organizations/{organization}/sources/{source}/findings/{finding}/externalSystems/{externalsystem}".format( organization=organization, source=source, @@ -23625,10 +29565,10 @@ def test_external_system_path(): def test_parse_external_system_path(): expected = { - "organization": "squid", - "source": "clam", - "finding": "whelk", - "externalsystem": "octopus", + "organization": "oyster", + "source": "nudibranch", + "finding": "cuttlefish", + "externalsystem": "mussel", } path = SecurityCenterClient.external_system_path(**expected) @@ -23638,9 +29578,9 @@ def test_parse_external_system_path(): def test_finding_path(): - organization = "oyster" - source = "nudibranch" - finding = "cuttlefish" + organization = "winkle" + source = "nautilus" + finding = "scallop" expected = ( "organizations/{organization}/sources/{source}/findings/{finding}".format( organization=organization, @@ -23654,9 +29594,9 @@ def test_finding_path(): def test_parse_finding_path(): expected = { - "organization": "mussel", - "source": "winkle", - "finding": "nautilus", + "organization": "abalone", + "source": "squid", + "finding": "clam", } path = SecurityCenterClient.finding_path(**expected) @@ -23666,8 +29606,8 @@ def test_parse_finding_path(): def test_mute_config_path(): - organization = "scallop" - mute_config = "abalone" + organization = "whelk" + mute_config = "octopus" expected = "organizations/{organization}/muteConfigs/{mute_config}".format( organization=organization, mute_config=mute_config, @@ -23678,8 +29618,8 @@ def test_mute_config_path(): def test_parse_mute_config_path(): expected = { - "organization": "squid", - "mute_config": "clam", + "organization": "oyster", + "mute_config": "nudibranch", } path = SecurityCenterClient.mute_config_path(**expected) @@ -23689,8 +29629,8 @@ def test_parse_mute_config_path(): def test_notification_config_path(): - organization = "whelk" - notification_config = "octopus" + organization = "cuttlefish" + notification_config = "mussel" expected = ( "organizations/{organization}/notificationConfigs/{notification_config}".format( organization=organization, @@ -23705,8 +29645,8 @@ def test_notification_config_path(): def test_parse_notification_config_path(): expected = { - "organization": "oyster", - "notification_config": "nudibranch", + "organization": "winkle", + "notification_config": "nautilus", } path = SecurityCenterClient.notification_config_path(**expected) @@ -23716,7 +29656,7 @@ def test_parse_notification_config_path(): def test_organization_settings_path(): - organization = "cuttlefish" + organization = "scallop" expected = "organizations/{organization}/organizationSettings".format( organization=organization, ) @@ -23726,7 +29666,7 @@ def test_organization_settings_path(): def test_parse_organization_settings_path(): expected = { - "organization": "mussel", + "organization": "abalone", } path = SecurityCenterClient.organization_settings_path(**expected) @@ -23735,9 +29675,36 @@ def test_parse_organization_settings_path(): assert expected == actual +def test_security_health_analytics_custom_module_path(): + organization = "squid" + custom_module = "clam" + expected = "organizations/{organization}/securityHealthAnalyticsSettings/customModules/{custom_module}".format( + organization=organization, + custom_module=custom_module, + ) + actual = SecurityCenterClient.security_health_analytics_custom_module_path( + organization, custom_module + ) + assert expected == actual + + +def test_parse_security_health_analytics_custom_module_path(): + expected = { + "organization": "whelk", + "custom_module": "octopus", + } + path = SecurityCenterClient.security_health_analytics_custom_module_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_security_health_analytics_custom_module_path( + path + ) + assert expected == actual + + def test_security_marks_path(): - organization = "winkle" - asset = "nautilus" + organization = "oyster" + asset = "nudibranch" expected = "organizations/{organization}/assets/{asset}/securityMarks".format( organization=organization, asset=asset, @@ -23748,8 +29715,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) @@ -23759,8 +29726,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, @@ -23771,8 +29738,8 @@ def test_source_path(): def test_parse_source_path(): expected = { - "organization": "whelk", - "source": "octopus", + "organization": "scallop", + "source": "abalone", } path = SecurityCenterClient.source_path(**expected) @@ -23782,8 +29749,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, @@ -23794,8 +29761,8 @@ def test_topic_path(): def test_parse_topic_path(): expected = { - "project": "cuttlefish", - "topic": "mussel", + "project": "whelk", + "topic": "octopus", } path = SecurityCenterClient.topic_path(**expected) @@ -23805,7 +29772,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, ) @@ -23815,7 +29782,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) @@ -23825,7 +29792,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "scallop" + folder = "cuttlefish" expected = "folders/{folder}".format( folder=folder, ) @@ -23835,7 +29802,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "abalone", + "folder": "mussel", } path = SecurityCenterClient.common_folder_path(**expected) @@ -23845,7 +29812,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "squid" + organization = "winkle" expected = "organizations/{organization}".format( organization=organization, ) @@ -23855,7 +29822,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "clam", + "organization": "nautilus", } path = SecurityCenterClient.common_organization_path(**expected) @@ -23865,7 +29832,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "whelk" + project = "scallop" expected = "projects/{project}".format( project=project, ) @@ -23875,7 +29842,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "octopus", + "project": "abalone", } path = SecurityCenterClient.common_project_path(**expected) @@ -23885,8 +29852,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, @@ -23897,8 +29864,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)