diff --git a/packages/google-cloud-securitycenter/docs/index.rst b/packages/google-cloud-securitycenter/docs/index.rst index d83c7ebcca1a..3d7c999e8772 100644 --- a/packages/google-cloud-securitycenter/docs/index.rst +++ b/packages/google-cloud-securitycenter/docs/index.rst @@ -11,24 +11,24 @@ API Reference .. toctree:: :maxdepth: 2 - securitycenter_v1/services - securitycenter_v1/types + securitycenter_v1/services_ + securitycenter_v1/types_ API Reference ------------- .. toctree:: :maxdepth: 2 - securitycenter_v1beta1/services - securitycenter_v1beta1/types + securitycenter_v1beta1/services_ + securitycenter_v1beta1/types_ API Reference ------------- .. toctree:: :maxdepth: 2 - securitycenter_v1p1beta1/services - securitycenter_v1p1beta1/types + securitycenter_v1p1beta1/services_ + securitycenter_v1p1beta1/types_ Changelog diff --git a/packages/google-cloud-securitycenter/docs/securitycenter_v1/services.rst b/packages/google-cloud-securitycenter/docs/securitycenter_v1/services_.rst similarity index 100% rename from packages/google-cloud-securitycenter/docs/securitycenter_v1/services.rst rename to packages/google-cloud-securitycenter/docs/securitycenter_v1/services_.rst diff --git a/packages/google-cloud-securitycenter/docs/securitycenter_v1/types.rst b/packages/google-cloud-securitycenter/docs/securitycenter_v1/types_.rst similarity index 100% rename from packages/google-cloud-securitycenter/docs/securitycenter_v1/types.rst rename to packages/google-cloud-securitycenter/docs/securitycenter_v1/types_.rst diff --git a/packages/google-cloud-securitycenter/docs/securitycenter_v1beta1/services.rst b/packages/google-cloud-securitycenter/docs/securitycenter_v1beta1/services_.rst similarity index 100% rename from packages/google-cloud-securitycenter/docs/securitycenter_v1beta1/services.rst rename to packages/google-cloud-securitycenter/docs/securitycenter_v1beta1/services_.rst diff --git a/packages/google-cloud-securitycenter/docs/securitycenter_v1beta1/types.rst b/packages/google-cloud-securitycenter/docs/securitycenter_v1beta1/types_.rst similarity index 100% rename from packages/google-cloud-securitycenter/docs/securitycenter_v1beta1/types.rst rename to packages/google-cloud-securitycenter/docs/securitycenter_v1beta1/types_.rst diff --git a/packages/google-cloud-securitycenter/docs/securitycenter_v1p1beta1/services_.rst b/packages/google-cloud-securitycenter/docs/securitycenter_v1p1beta1/services_.rst new file mode 100644 index 000000000000..7f537e851e63 --- /dev/null +++ b/packages/google-cloud-securitycenter/docs/securitycenter_v1p1beta1/services_.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Securitycenter v1p1beta1 API +====================================================== +.. toctree:: + :maxdepth: 2 + + security_center diff --git a/packages/google-cloud-securitycenter/docs/securitycenter_v1p1beta1/types_.rst b/packages/google-cloud-securitycenter/docs/securitycenter_v1p1beta1/types_.rst new file mode 100644 index 000000000000..a68ac5c68cff --- /dev/null +++ b/packages/google-cloud-securitycenter/docs/securitycenter_v1p1beta1/types_.rst @@ -0,0 +1,6 @@ +Types for Google Cloud Securitycenter v1p1beta1 API +=================================================== + +.. automodule:: google.cloud.securitycenter_v1p1beta1.types + :members: + :show-inheritance: diff --git a/packages/google-cloud-securitycenter/google/cloud/securitycenter/__init__.py b/packages/google-cloud-securitycenter/google/cloud/securitycenter/__init__.py index 32a738ed690d..c44053f533f3 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter/__init__.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter/__init__.py @@ -123,6 +123,8 @@ RunAssetDiscoveryRequest, SetFindingStateRequest, SetMuteRequest, + SimulateSecurityHealthAnalyticsCustomModuleRequest, + SimulateSecurityHealthAnalyticsCustomModuleResponse, UpdateBigQueryExportRequest, UpdateExternalSystemRequest, UpdateFindingRequest, @@ -226,6 +228,8 @@ "RunAssetDiscoveryRequest", "SetFindingStateRequest", "SetMuteRequest", + "SimulateSecurityHealthAnalyticsCustomModuleRequest", + "SimulateSecurityHealthAnalyticsCustomModuleResponse", "UpdateBigQueryExportRequest", "UpdateExternalSystemRequest", "UpdateFindingRequest", 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 5a2c6893eee7..708d42fb19b6 100644 --- a/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/__init__.py +++ b/packages/google-cloud-securitycenter/google/cloud/securitycenter_v1/__init__.py @@ -101,6 +101,8 @@ RunAssetDiscoveryRequest, SetFindingStateRequest, SetMuteRequest, + SimulateSecurityHealthAnalyticsCustomModuleRequest, + SimulateSecurityHealthAnalyticsCustomModuleResponse, UpdateBigQueryExportRequest, UpdateExternalSystemRequest, UpdateFindingRequest, @@ -202,6 +204,8 @@ "ServiceAccountDelegationInfo", "SetFindingStateRequest", "SetMuteRequest", + "SimulateSecurityHealthAnalyticsCustomModuleRequest", + "SimulateSecurityHealthAnalyticsCustomModuleResponse", "Source", "UpdateBigQueryExportRequest", "UpdateExternalSystemRequest", 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 5c23812a9d9e..42ff9fc06957 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 @@ -180,6 +180,11 @@ "set_mute" ] }, + "SimulateSecurityHealthAnalyticsCustomModule": { + "methods": [ + "simulate_security_health_analytics_custom_module" + ] + }, "TestIamPermissions": { "methods": [ "test_iam_permissions" @@ -405,6 +410,11 @@ "set_mute" ] }, + "SimulateSecurityHealthAnalyticsCustomModule": { + "methods": [ + "simulate_security_health_analytics_custom_module" + ] + }, "TestIamPermissions": { "methods": [ "test_iam_permissions" @@ -630,6 +640,11 @@ "set_mute" ] }, + "SimulateSecurityHealthAnalyticsCustomModule": { + "methods": [ + "simulate_security_health_analytics_custom_module" + ] + }, "TestIamPermissions": { "methods": [ "test_iam_permissions" 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 13714657e031..24077854534f 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 @@ -4355,6 +4355,151 @@ async def sample_test_iam_permissions(): # Done; return the response. return response + async def simulate_security_health_analytics_custom_module( + self, + request: Optional[ + Union[ + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] + ] = None, + *, + parent: Optional[str] = None, + custom_config: Optional[ + security_health_analytics_custom_config.CustomConfig + ] = None, + resource: Optional[ + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse: + r"""Simulates a given SecurityHealthAnalyticsCustomModule + and Resource. + + .. 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_simulate_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + resource = securitycenter_v1.SimulatedResource() + resource.resource_type = "resource_type_value" + + request = securitycenter_v1.SimulateSecurityHealthAnalyticsCustomModuleRequest( + parent="parent_value", + resource=resource, + ) + + # Make the request + response = await client.simulate_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.securitycenter_v1.types.SimulateSecurityHealthAnalyticsCustomModuleRequest, dict]]): + The request object. Request message to simulate a + CustomConfig against a given test + resource. Maximum size of the request is + 4 MB by default. + parent (:class:`str`): + Required. The relative resource name of the + organization, project, or folder. See: + https://cloud.google.com/apis/design/resource_names#relative_resource_name + An example is: "organizations/{organization_id}". + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + custom_config (:class:`google.cloud.securitycenter_v1.types.CustomConfig`): + Required. The user specified custom + configuration to test. + + This corresponds to the ``custom_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + resource (:class:`google.cloud.securitycenter_v1.types.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource`): + Required. Resource data to simulate + custom module against. + + This corresponds to the ``resource`` 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.SimulateSecurityHealthAnalyticsCustomModuleResponse: + Response message for simulating a + SecurityHealthAnalyticsCustomModule + against a given resource. + + """ + # 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, custom_config, resource]) + 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.SimulateSecurityHealthAnalyticsCustomModuleRequest( + request + ) + ) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if custom_config is not None: + request.custom_config = custom_config + if resource is not None: + request.resource = resource + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.simulate_security_health_analytics_custom_module, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + async def update_external_system( 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 ce90cfd26e9b..0d642f94cb70 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 @@ -4677,6 +4677,154 @@ def sample_test_iam_permissions(): # Done; return the response. return response + def simulate_security_health_analytics_custom_module( + self, + request: Optional[ + Union[ + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest, + dict, + ] + ] = None, + *, + parent: Optional[str] = None, + custom_config: Optional[ + security_health_analytics_custom_config.CustomConfig + ] = None, + resource: Optional[ + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse: + r"""Simulates a given SecurityHealthAnalyticsCustomModule + and Resource. + + .. 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_simulate_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + resource = securitycenter_v1.SimulatedResource() + resource.resource_type = "resource_type_value" + + request = securitycenter_v1.SimulateSecurityHealthAnalyticsCustomModuleRequest( + parent="parent_value", + resource=resource, + ) + + # Make the request + response = client.simulate_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.securitycenter_v1.types.SimulateSecurityHealthAnalyticsCustomModuleRequest, dict]): + The request object. Request message to simulate a + CustomConfig against a given test + resource. Maximum size of the request is + 4 MB by default. + parent (str): + Required. The relative resource name of the + organization, project, or folder. See: + https://cloud.google.com/apis/design/resource_names#relative_resource_name + An example is: "organizations/{organization_id}". + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + custom_config (google.cloud.securitycenter_v1.types.CustomConfig): + Required. The user specified custom + configuration to test. + + This corresponds to the ``custom_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + resource (google.cloud.securitycenter_v1.types.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource): + Required. Resource data to simulate + custom module against. + + This corresponds to the ``resource`` 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.SimulateSecurityHealthAnalyticsCustomModuleResponse: + Response message for simulating a + SecurityHealthAnalyticsCustomModule + against a given resource. + + """ + # 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, custom_config, resource]) + 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.SimulateSecurityHealthAnalyticsCustomModuleRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest, + ): + request = securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest( + request + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if custom_config is not None: + request.custom_config = custom_config + if resource is not None: + request.resource = resource + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.simulate_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 update_external_system( self, request: Optional[ 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 4ce72c36b456..8291786cbbf6 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 @@ -470,6 +470,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.simulate_security_health_analytics_custom_module: gapic_v1.method.wrap_method( + self.simulate_security_health_analytics_custom_module, + default_timeout=None, + client_info=client_info, + ), self.update_external_system: gapic_v1.method.wrap_method( self.update_external_system, default_timeout=None, @@ -903,6 +908,20 @@ def test_iam_permissions( ]: raise NotImplementedError() + @property + def simulate_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest], + Union[ + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse, + Awaitable[ + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse + ], + ], + ]: + raise NotImplementedError() + @property def update_external_system( 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 d649cccc23f0..3559eb3fc9ce 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 @@ -1239,6 +1239,39 @@ def test_iam_permissions( ) return self._stubs["test_iam_permissions"] + @property + def simulate_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest], + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse, + ]: + r"""Return a callable for the simulate security health + analytics custom module method over gRPC. + + Simulates a given SecurityHealthAnalyticsCustomModule + and Resource. + + Returns: + Callable[[~.SimulateSecurityHealthAnalyticsCustomModuleRequest], + ~.SimulateSecurityHealthAnalyticsCustomModuleResponse]: + 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 "simulate_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "simulate_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/SimulateSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse.deserialize, + ) + return self._stubs["simulate_security_health_analytics_custom_module"] + @property def update_external_system( 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 5b8d3d8ec020..d0834150f3f5 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 @@ -1268,6 +1268,41 @@ def test_iam_permissions( ) return self._stubs["test_iam_permissions"] + @property + def simulate_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[ + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse + ], + ]: + r"""Return a callable for the simulate security health + analytics custom module method over gRPC. + + Simulates a given SecurityHealthAnalyticsCustomModule + and Resource. + + Returns: + Callable[[~.SimulateSecurityHealthAnalyticsCustomModuleRequest], + Awaitable[~.SimulateSecurityHealthAnalyticsCustomModuleResponse]]: + 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 "simulate_security_health_analytics_custom_module" not in self._stubs: + self._stubs[ + "simulate_security_health_analytics_custom_module" + ] = self.grpc_channel.unary_unary( + "/google.cloud.securitycenter.v1.SecurityCenter/SimulateSecurityHealthAnalyticsCustomModule", + request_serializer=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.serialize, + response_deserializer=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse.deserialize, + ) + return self._stubs["simulate_security_health_analytics_custom_module"] + @property def update_external_system( 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 d4a3443a0fc4..67fc2c8c7ca9 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 @@ -354,6 +354,14 @@ def post_set_mute(self, response): logging.log(f"Received response: {response}") return response + def pre_simulate_security_health_analytics_custom_module(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_simulate_security_health_analytics_custom_module(self, response): + logging.log(f"Received response: {response}") + return response + def pre_test_iam_permissions(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -1223,6 +1231,33 @@ def post_set_mute(self, response: finding.Finding) -> finding.Finding: """ return response + def pre_simulate_security_health_analytics_custom_module( + self, + request: securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[ + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest, + Sequence[Tuple[str, str]], + ]: + """Pre-rpc interceptor for simulate_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_simulate_security_health_analytics_custom_module( + self, + response: securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse, + ) -> securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse: + """Post-rpc interceptor for simulate_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_test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest, @@ -5399,6 +5434,133 @@ def __call__( resp = self._interceptor.post_set_mute(resp) return resp + class _SimulateSecurityHealthAnalyticsCustomModule(SecurityCenterRestStub): + def __hash__(self): + return hash("SimulateSecurityHealthAnalyticsCustomModule") + + __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.SimulateSecurityHealthAnalyticsCustomModuleRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse: + r"""Call the simulate security health + analytics custom module method over HTTP. + + Args: + request (~.securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest): + The request object. Request message to simulate a + CustomConfig against a given test + resource. Maximum size of the request is + 4 MB by default. + 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.SimulateSecurityHealthAnalyticsCustomModuleResponse: + Response message for simulating a + SecurityHealthAnalyticsCustomModule + against a given resource. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{parent=organizations/*/securityHealthAnalyticsSettings}/customModules:simulate", + "body": "*", + }, + { + "method": "post", + "uri": "/v1/{parent=folders/*/securityHealthAnalyticsSettings}/customModules:simulate", + "body": "*", + }, + { + "method": "post", + "uri": "/v1/{parent=projects/*/securityHealthAnalyticsSettings}/customModules:simulate", + "body": "*", + }, + ] + ( + request, + metadata, + ) = self._interceptor.pre_simulate_security_health_analytics_custom_module( + request, metadata + ) + pb_request = securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.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 = ( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + pb_resp = securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse.pb( + resp + ) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = ( + self._interceptor.post_simulate_security_health_analytics_custom_module( + resp + ) + ) + return resp + class _TestIamPermissions(SecurityCenterRestStub): def __hash__(self): return hash("TestIamPermissions") @@ -6877,6 +7039,17 @@ def set_mute( # In C++ this would require a dynamic_cast return self._SetMute(self._session, self._host, self._interceptor) # type: ignore + @property + def simulate_security_health_analytics_custom_module( + self, + ) -> Callable[ + [securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest], + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse, + ]: + # 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._SimulateSecurityHealthAnalyticsCustomModule(self._session, self._host, self._interceptor) # type: ignore + @property def test_iam_permissions( 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 454ccb33f8dd..6a5273002aa6 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 @@ -93,6 +93,8 @@ RunAssetDiscoveryRequest, SetFindingStateRequest, SetMuteRequest, + SimulateSecurityHealthAnalyticsCustomModuleRequest, + SimulateSecurityHealthAnalyticsCustomModuleResponse, UpdateBigQueryExportRequest, UpdateExternalSystemRequest, UpdateFindingRequest, @@ -189,6 +191,8 @@ "RunAssetDiscoveryRequest", "SetFindingStateRequest", "SetMuteRequest", + "SimulateSecurityHealthAnalyticsCustomModuleRequest", + "SimulateSecurityHealthAnalyticsCustomModuleResponse", "UpdateBigQueryExportRequest", "UpdateExternalSystemRequest", "UpdateFindingRequest", 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 5a4d2a8a1a6a..3fe51737297d 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 @@ -17,10 +17,13 @@ from typing import MutableMapping, MutableSequence +from google.iam.v1 import policy_pb2 # type: ignore from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore import proto # type: ignore from google.cloud.securitycenter_v1.types import ( @@ -34,6 +37,7 @@ from google.cloud.securitycenter_v1.types import ( organization_settings as gcs_organization_settings, ) +from google.cloud.securitycenter_v1.types import security_health_analytics_custom_config from google.cloud.securitycenter_v1.types import ( security_health_analytics_custom_module as gcs_security_health_analytics_custom_module, ) @@ -88,6 +92,8 @@ "SetFindingStateRequest", "SetMuteRequest", "RunAssetDiscoveryRequest", + "SimulateSecurityHealthAnalyticsCustomModuleRequest", + "SimulateSecurityHealthAnalyticsCustomModuleResponse", "UpdateExternalSystemRequest", "UpdateFindingRequest", "UpdateMuteConfigRequest", @@ -2116,6 +2122,135 @@ class RunAssetDiscoveryRequest(proto.Message): ) +class SimulateSecurityHealthAnalyticsCustomModuleRequest(proto.Message): + r"""Request message to simulate a CustomConfig against a given + test resource. Maximum size of the request is 4 MB by default. + + Attributes: + parent (str): + Required. The relative resource name of the organization, + project, or folder. See: + https://cloud.google.com/apis/design/resource_names#relative_resource_name + An example is: "organizations/{organization_id}". + custom_config (google.cloud.securitycenter_v1.types.CustomConfig): + Required. The user specified custom + configuration to test. + resource (google.cloud.securitycenter_v1.types.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource): + Required. Resource data to simulate custom + module against. + """ + + class SimulatedResource(proto.Message): + r"""Manually constructed resource. If the custom module only evaluates + against the resource data, the iam_policy_data field can be omitted, + and vice versa. + + Attributes: + resource_type (str): + Required. The type of the resource, e.g. + ``compute.googleapis.com/Disk``. + resource_data (google.protobuf.struct_pb2.Struct): + Optional. A representation of the GCP + resource. Should match the GCP resource JSON + format. + iam_policy_data (google.iam.v1.policy_pb2.Policy): + Optional. A representation of the IAM policy. + """ + + resource_type: str = proto.Field( + proto.STRING, + number=1, + ) + resource_data: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=2, + message=struct_pb2.Struct, + ) + iam_policy_data: policy_pb2.Policy = proto.Field( + proto.MESSAGE, + number=3, + message=policy_pb2.Policy, + ) + + parent: 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, + ) + resource: SimulatedResource = proto.Field( + proto.MESSAGE, + number=3, + message=SimulatedResource, + ) + + +class SimulateSecurityHealthAnalyticsCustomModuleResponse(proto.Message): + r"""Response message for simulating a + SecurityHealthAnalyticsCustomModule against a given resource. + + Attributes: + result (google.cloud.securitycenter_v1.types.SimulateSecurityHealthAnalyticsCustomModuleResponse.SimulatedResult): + Result for test case in the corresponding + request. + """ + + class SimulatedResult(proto.Message): + r"""Possible test result. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + finding (google.cloud.securitycenter_v1.types.Finding): + Finding that would be published for the test + case, if a violation is detected. + + This field is a member of `oneof`_ ``result``. + no_violation (google.protobuf.empty_pb2.Empty): + Indicates that the test case does not trigger + any violation. + + This field is a member of `oneof`_ ``result``. + error (google.rpc.status_pb2.Status): + Error encountered during the test. + + This field is a member of `oneof`_ ``result``. + """ + + finding: gcs_finding.Finding = proto.Field( + proto.MESSAGE, + number=1, + oneof="result", + message=gcs_finding.Finding, + ) + no_violation: empty_pb2.Empty = proto.Field( + proto.MESSAGE, + number=2, + oneof="result", + message=empty_pb2.Empty, + ) + error: status_pb2.Status = proto.Field( + proto.MESSAGE, + number=3, + oneof="result", + message=status_pb2.Status, + ) + + result: SimulatedResult = proto.Field( + proto.MESSAGE, + number=1, + message=SimulatedResult, + ) + + class UpdateExternalSystemRequest(proto.Message): r"""Request message for updating a ExternalSystem resource. diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_simulate_security_health_analytics_custom_module_async.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_simulate_security_health_analytics_custom_module_async.py new file mode 100644 index 000000000000..63d75ca93055 --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_simulate_security_health_analytics_custom_module_async.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 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 SimulateSecurityHealthAnalyticsCustomModule +# 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_SimulateSecurityHealthAnalyticsCustomModule_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_simulate_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterAsyncClient() + + # Initialize request argument(s) + resource = securitycenter_v1.SimulatedResource() + resource.resource_type = "resource_type_value" + + request = securitycenter_v1.SimulateSecurityHealthAnalyticsCustomModuleRequest( + parent="parent_value", + resource=resource, + ) + + # Make the request + response = await client.simulate_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_SimulateSecurityHealthAnalyticsCustomModule_async] diff --git a/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_simulate_security_health_analytics_custom_module_sync.py b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_simulate_security_health_analytics_custom_module_sync.py new file mode 100644 index 000000000000..1812c256df5b --- /dev/null +++ b/packages/google-cloud-securitycenter/samples/generated_samples/securitycenter_v1_generated_security_center_simulate_security_health_analytics_custom_module_sync.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 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 SimulateSecurityHealthAnalyticsCustomModule +# 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_SimulateSecurityHealthAnalyticsCustomModule_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_simulate_security_health_analytics_custom_module(): + # Create a client + client = securitycenter_v1.SecurityCenterClient() + + # Initialize request argument(s) + resource = securitycenter_v1.SimulatedResource() + resource.resource_type = "resource_type_value" + + request = securitycenter_v1.SimulateSecurityHealthAnalyticsCustomModuleRequest( + parent="parent_value", + resource=resource, + ) + + # Make the request + response = client.simulate_security_health_analytics_custom_module(request=request) + + # Handle the response + print(response) + +# [END securitycenter_v1_generated_SecurityCenter_SimulateSecurityHealthAnalyticsCustomModule_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 ec678e1a8024..278ec40bb216 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 @@ -5549,6 +5549,183 @@ ], "title": "securitycenter_v1_generated_security_center_set_mute_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient", + "shortName": "SecurityCenterAsyncClient" + }, + "fullName": "google.cloud.securitycenter_v1.SecurityCenterAsyncClient.simulate_security_health_analytics_custom_module", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.SimulateSecurityHealthAnalyticsCustomModule", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "SimulateSecurityHealthAnalyticsCustomModule" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.SimulateSecurityHealthAnalyticsCustomModuleRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "custom_config", + "type": "google.cloud.securitycenter_v1.types.CustomConfig" + }, + { + "name": "resource", + "type": "google.cloud.securitycenter_v1.types.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource" + }, + { + "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.SimulateSecurityHealthAnalyticsCustomModuleResponse", + "shortName": "simulate_security_health_analytics_custom_module" + }, + "description": "Sample for SimulateSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_simulate_security_health_analytics_custom_module_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_SimulateSecurityHealthAnalyticsCustomModule_async", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 49, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 50, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_simulate_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.simulate_security_health_analytics_custom_module", + "method": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter.SimulateSecurityHealthAnalyticsCustomModule", + "service": { + "fullName": "google.cloud.securitycenter.v1.SecurityCenter", + "shortName": "SecurityCenter" + }, + "shortName": "SimulateSecurityHealthAnalyticsCustomModule" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.securitycenter_v1.types.SimulateSecurityHealthAnalyticsCustomModuleRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "custom_config", + "type": "google.cloud.securitycenter_v1.types.CustomConfig" + }, + { + "name": "resource", + "type": "google.cloud.securitycenter_v1.types.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource" + }, + { + "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.SimulateSecurityHealthAnalyticsCustomModuleResponse", + "shortName": "simulate_security_health_analytics_custom_module" + }, + "description": "Sample for SimulateSecurityHealthAnalyticsCustomModule", + "file": "securitycenter_v1_generated_security_center_simulate_security_health_analytics_custom_module_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "securitycenter_v1_generated_SecurityCenter_SimulateSecurityHealthAnalyticsCustomModule_sync", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 49, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 50, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "securitycenter_v1_generated_security_center_simulate_security_health_analytics_custom_module_sync.py" + }, { "canonical": true, "clientMethod": { 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 6fad82510481..0cebe697f3dd 100644 --- a/packages/google-cloud-securitycenter/scripts/fixup_securitycenter_v1_keywords.py +++ b/packages/google-cloud-securitycenter/scripts/fixup_securitycenter_v1_keywords.py @@ -73,6 +73,7 @@ class securitycenterCallTransformer(cst.CSTTransformer): 'set_finding_state': ('name', 'state', 'start_time', ), 'set_iam_policy': ('resource', 'policy', 'update_mask', ), 'set_mute': ('name', 'mute', ), + 'simulate_security_health_analytics_custom_module': ('parent', 'custom_config', 'resource', ), 'test_iam_permissions': ('resource', 'permissions', ), 'update_big_query_export': ('big_query_export', 'update_mask', ), 'update_external_system': ('external_system', '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 739db2643a59..d2d1933ba657 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 @@ -10984,6 +10984,329 @@ async def test_test_iam_permissions_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest, + dict, + ], +) +def test_simulate_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.simulate_security_health_analytics_custom_module), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + response = client.simulate_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.SimulateSecurityHealthAnalyticsCustomModuleRequest() + ) + + # Establish that the response is the type that we expect. + assert isinstance( + response, + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse, + ) + + +def test_simulate_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.simulate_security_health_analytics_custom_module), + "__call__", + ) as call: + client.simulate_security_health_analytics_custom_module() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert ( + args[0] + == securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest() + ) + + +@pytest.mark.asyncio +async def test_simulate_security_health_analytics_custom_module_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest, +): + 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.simulate_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.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + response = await client.simulate_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.SimulateSecurityHealthAnalyticsCustomModuleRequest() + ) + + # Establish that the response is the type that we expect. + assert isinstance( + response, + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse, + ) + + +@pytest.mark.asyncio +async def test_simulate_security_health_analytics_custom_module_async_from_dict(): + await test_simulate_security_health_analytics_custom_module_async(request_type=dict) + + +def test_simulate_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.SimulateSecurityHealthAnalyticsCustomModuleRequest() + ) + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.simulate_security_health_analytics_custom_module), + "__call__", + ) as call: + call.return_value = ( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + client.simulate_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_simulate_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.SimulateSecurityHealthAnalyticsCustomModuleRequest() + ) + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.simulate_security_health_analytics_custom_module), + "__call__", + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + await client.simulate_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_simulate_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.simulate_security_health_analytics_custom_module), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.simulate_security_health_analytics_custom_module( + parent="parent_value", + custom_config=security_health_analytics_custom_config.CustomConfig( + predicate=expr_pb2.Expr(expression="expression_value") + ), + resource=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource( + resource_type="resource_type_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].custom_config + mock_val = security_health_analytics_custom_config.CustomConfig( + predicate=expr_pb2.Expr(expression="expression_value") + ) + assert arg == mock_val + arg = args[0].resource + mock_val = securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource( + resource_type="resource_type_value" + ) + assert arg == mock_val + + +def test_simulate_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.simulate_security_health_analytics_custom_module( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest(), + parent="parent_value", + custom_config=security_health_analytics_custom_config.CustomConfig( + predicate=expr_pb2.Expr(expression="expression_value") + ), + resource=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource( + resource_type="resource_type_value" + ), + ) + + +@pytest.mark.asyncio +async def test_simulate_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.simulate_security_health_analytics_custom_module), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.simulate_security_health_analytics_custom_module( + parent="parent_value", + custom_config=security_health_analytics_custom_config.CustomConfig( + predicate=expr_pb2.Expr(expression="expression_value") + ), + resource=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource( + resource_type="resource_type_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].custom_config + mock_val = security_health_analytics_custom_config.CustomConfig( + predicate=expr_pb2.Expr(expression="expression_value") + ) + assert arg == mock_val + arg = args[0].resource + mock_val = securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource( + resource_type="resource_type_value" + ) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_simulate_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.simulate_security_health_analytics_custom_module( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest(), + parent="parent_value", + custom_config=security_health_analytics_custom_config.CustomConfig( + predicate=expr_pb2.Expr(expression="expression_value") + ), + resource=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource( + resource_type="resource_type_value" + ), + ) + + @pytest.mark.parametrize( "request_type", [ @@ -24793,19 +25116,343 @@ def test_test_iam_permissions_rest_error(): @pytest.mark.parametrize( "request_type", [ - securitycenter_service.UpdateExternalSystemRequest, + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest, dict, ], ) -def test_update_external_system_rest(request_type): +def test_simulate_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 = { - "external_system": { + 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.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse.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.simulate_security_health_analytics_custom_module(request) + + # Establish that the response is the type that we expect. + assert isinstance( + response, + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse, + ) + + +def test_simulate_security_health_analytics_custom_module_rest_required_fields( + request_type=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest, +): + 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() + ).simulate_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() + ).simulate_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 = ( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + # 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 + + # Convert return value to protobuf type + return_value = securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse.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.simulate_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_simulate_security_health_analytics_custom_module_rest_unset_required_fields(): + transport = transports.SecurityCenterRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.simulate_security_health_analytics_custom_module._get_unset_required_fields( + {} + ) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "customConfig", + "resource", + ) + ) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_simulate_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_simulate_security_health_analytics_custom_module", + ) as post, mock.patch.object( + transports.SecurityCenterRestInterceptor, + "pre_simulate_security_health_analytics_custom_module", + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.pb( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest() + ) + 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 = securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse.to_json( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + + request = ( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest() + ) + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = ( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + + client.simulate_security_health_analytics_custom_module( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_simulate_security_health_analytics_custom_module_rest_bad_request( + transport: str = "rest", + request_type=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest, +): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "organizations/sample1/securityHealthAnalyticsSettings"} + 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.simulate_security_health_analytics_custom_module(request) + + +def test_simulate_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 = ( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse() + ) + + # 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", + custom_config=security_health_analytics_custom_config.CustomConfig( + predicate=expr_pb2.Expr(expression="expression_value") + ), + resource=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource( + resource_type="resource_type_value" + ), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleResponse.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.simulate_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:simulate" + % client.transport._host, + args[1], + ) + + +def test_simulate_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.simulate_security_health_analytics_custom_module( + securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest(), + parent="parent_value", + custom_config=security_health_analytics_custom_config.CustomConfig( + predicate=expr_pb2.Expr(expression="expression_value") + ), + resource=securitycenter_service.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource( + resource_type="resource_type_value" + ), + ) + + +def test_simulate_security_health_analytics_custom_module_rest_error(): + client = SecurityCenterClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + securitycenter_service.UpdateExternalSystemRequest, + dict, + ], +) +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 = { + "external_system": { "name": "organizations/sample1/sources/sample2/findings/sample3/externalSystems/sample4" } } @@ -29504,6 +30151,7 @@ def test_security_center_base_transport(): "set_mute", "set_iam_policy", "test_iam_permissions", + "simulate_security_health_analytics_custom_module", "update_external_system", "update_finding", "update_mute_config", @@ -29908,6 +30556,13 @@ def test_security_center_client_transport_session_collision(transport_name): session1 = client1.transport.test_iam_permissions._session session2 = client2.transport.test_iam_permissions._session assert session1 != session2 + session1 = ( + client1.transport.simulate_security_health_analytics_custom_module._session + ) + session2 = ( + client2.transport.simulate_security_health_analytics_custom_module._session + ) + assert session1 != session2 session1 = client1.transport.update_external_system._session session2 = client2.transport.update_external_system._session assert session1 != session2