Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit 8c988a6

Browse files
feat: Added a new API method UpdateExternalSystem (#256)
.. which enables updating a finding w/ external system metadata. External systems are a child resource under finding, and are housed on the finding itself, and can also be filtered on in Notifications, the ListFindings and GroupFindings API. - [ ] Regenerate this pull request now. PiperOrigin-RevId: 411093163 Source-Link: googleapis/googleapis@be8f988 Source-Link: https://github.com/googleapis/googleapis-gen/commit/186665a0ff6acaf9bf6d5ef0cef663dd828b48a7 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMTg2NjY1YTBmZjZhY2FmOWJmNmQ1ZWYwY2VmNjYzZGQ4MjhiNDhhNyJ9
1 parent 6f3e1b2 commit 8c988a6

File tree

14 files changed

+722
-38
lines changed

14 files changed

+722
-38
lines changed

google/cloud/securitycenter/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323

2424
from google.cloud.securitycenter_v1.types.asset import Asset
25+
from google.cloud.securitycenter_v1.types.external_system import ExternalSystem
2526
from google.cloud.securitycenter_v1.types.finding import Finding
2627
from google.cloud.securitycenter_v1.types.folder import Folder
2728
from google.cloud.securitycenter_v1.types.indicator import Indicator
@@ -122,6 +123,9 @@
122123
SetFindingStateRequest,
123124
)
124125
from google.cloud.securitycenter_v1.types.securitycenter_service import SetMuteRequest
126+
from google.cloud.securitycenter_v1.types.securitycenter_service import (
127+
UpdateExternalSystemRequest,
128+
)
125129
from google.cloud.securitycenter_v1.types.securitycenter_service import (
126130
UpdateFindingRequest,
127131
)
@@ -150,6 +154,7 @@
150154
"SecurityCenterClient",
151155
"SecurityCenterAsyncClient",
152156
"Asset",
157+
"ExternalSystem",
153158
"Finding",
154159
"Folder",
155160
"Indicator",
@@ -190,6 +195,7 @@
190195
"RunAssetDiscoveryRequest",
191196
"SetFindingStateRequest",
192197
"SetMuteRequest",
198+
"UpdateExternalSystemRequest",
193199
"UpdateFindingRequest",
194200
"UpdateMuteConfigRequest",
195201
"UpdateNotificationConfigRequest",

google/cloud/securitycenter_v1/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .services.security_center import SecurityCenterAsyncClient
1919

2020
from .types.asset import Asset
21+
from .types.external_system import ExternalSystem
2122
from .types.finding import Finding
2223
from .types.folder import Folder
2324
from .types.indicator import Indicator
@@ -58,6 +59,7 @@
5859
from .types.securitycenter_service import RunAssetDiscoveryRequest
5960
from .types.securitycenter_service import SetFindingStateRequest
6061
from .types.securitycenter_service import SetMuteRequest
62+
from .types.securitycenter_service import UpdateExternalSystemRequest
6163
from .types.securitycenter_service import UpdateFindingRequest
6264
from .types.securitycenter_service import UpdateMuteConfigRequest
6365
from .types.securitycenter_service import UpdateNotificationConfigRequest
@@ -83,6 +85,7 @@
8385
"Cvssv3",
8486
"DeleteMuteConfigRequest",
8587
"DeleteNotificationConfigRequest",
88+
"ExternalSystem",
8689
"Finding",
8790
"Folder",
8891
"GetMuteConfigRequest",
@@ -118,6 +121,7 @@
118121
"SetFindingStateRequest",
119122
"SetMuteRequest",
120123
"Source",
124+
"UpdateExternalSystemRequest",
121125
"UpdateFindingRequest",
122126
"UpdateMuteConfigRequest",
123127
"UpdateNotificationConfigRequest",

google/cloud/securitycenter_v1/gapic_metadata.json

+10
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@
130130
"test_iam_permissions"
131131
]
132132
},
133+
"UpdateExternalSystem": {
134+
"methods": [
135+
"update_external_system"
136+
]
137+
},
133138
"UpdateFinding": {
134139
"methods": [
135140
"update_finding"
@@ -285,6 +290,11 @@
285290
"test_iam_permissions"
286291
]
287292
},
293+
"UpdateExternalSystem": {
294+
"methods": [
295+
"update_external_system"
296+
]
297+
},
288298
"UpdateFinding": {
289299
"methods": [
290300
"update_finding"

google/cloud/securitycenter_v1/services/security_center/async_client.py

+90
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from google.api_core import operation # type: ignore
3535
from google.api_core import operation_async # type: ignore
3636
from google.cloud.securitycenter_v1.services.security_center import pagers
37+
from google.cloud.securitycenter_v1.types import external_system as gcs_external_system
3738
from google.cloud.securitycenter_v1.types import finding
3839
from google.cloud.securitycenter_v1.types import finding as gcs_finding
3940
from google.cloud.securitycenter_v1.types import indicator
@@ -74,6 +75,10 @@ class SecurityCenterAsyncClient:
7475

7576
asset_path = staticmethod(SecurityCenterClient.asset_path)
7677
parse_asset_path = staticmethod(SecurityCenterClient.parse_asset_path)
78+
external_system_path = staticmethod(SecurityCenterClient.external_system_path)
79+
parse_external_system_path = staticmethod(
80+
SecurityCenterClient.parse_external_system_path
81+
)
7782
finding_path = staticmethod(SecurityCenterClient.finding_path)
7883
parse_finding_path = staticmethod(SecurityCenterClient.parse_finding_path)
7984
mute_config_path = staticmethod(SecurityCenterClient.mute_config_path)
@@ -2406,6 +2411,91 @@ async def test_iam_permissions(
24062411
# Done; return the response.
24072412
return response
24082413

2414+
async def update_external_system(
2415+
self,
2416+
request: Union[securitycenter_service.UpdateExternalSystemRequest, dict] = None,
2417+
*,
2418+
external_system: gcs_external_system.ExternalSystem = None,
2419+
update_mask: field_mask_pb2.FieldMask = None,
2420+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
2421+
timeout: float = None,
2422+
metadata: Sequence[Tuple[str, str]] = (),
2423+
) -> gcs_external_system.ExternalSystem:
2424+
r"""Updates external system. This is for a given finding.
2425+
2426+
Args:
2427+
request (Union[google.cloud.securitycenter_v1.types.UpdateExternalSystemRequest, dict]):
2428+
The request object. Request message for updating a
2429+
ExternalSystem resource.
2430+
external_system (:class:`google.cloud.securitycenter_v1.types.ExternalSystem`):
2431+
Required. The external system
2432+
resource to update.
2433+
2434+
This corresponds to the ``external_system`` field
2435+
on the ``request`` instance; if ``request`` is provided, this
2436+
should not be set.
2437+
update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`):
2438+
The FieldMask to use when updating
2439+
the external system resource.
2440+
If empty all mutable fields will be
2441+
updated.
2442+
2443+
This corresponds to the ``update_mask`` field
2444+
on the ``request`` instance; if ``request`` is provided, this
2445+
should not be set.
2446+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
2447+
should be retried.
2448+
timeout (float): The timeout for this request.
2449+
metadata (Sequence[Tuple[str, str]]): Strings which should be
2450+
sent along with the request as metadata.
2451+
2452+
Returns:
2453+
google.cloud.securitycenter_v1.types.ExternalSystem:
2454+
Representation of third party
2455+
SIEM/SOAR fields within SCC.
2456+
2457+
"""
2458+
# Create or coerce a protobuf request object.
2459+
# Sanity check: If we got a request object, we should *not* have
2460+
# gotten any keyword arguments that map to the request.
2461+
has_flattened_params = any([external_system, update_mask])
2462+
if request is not None and has_flattened_params:
2463+
raise ValueError(
2464+
"If the `request` argument is set, then none of "
2465+
"the individual field arguments should be set."
2466+
)
2467+
2468+
request = securitycenter_service.UpdateExternalSystemRequest(request)
2469+
2470+
# If we have keyword arguments corresponding to fields on the
2471+
# request, apply these.
2472+
if external_system is not None:
2473+
request.external_system = external_system
2474+
if update_mask is not None:
2475+
request.update_mask = update_mask
2476+
2477+
# Wrap the RPC method; this adds retry and timeout information,
2478+
# and friendly error handling.
2479+
rpc = gapic_v1.method_async.wrap_method(
2480+
self._client._transport.update_external_system,
2481+
default_timeout=None,
2482+
client_info=DEFAULT_CLIENT_INFO,
2483+
)
2484+
2485+
# Certain fields should be provided within the metadata header;
2486+
# add these here.
2487+
metadata = tuple(metadata) + (
2488+
gapic_v1.routing_header.to_grpc_metadata(
2489+
(("external_system.name", request.external_system.name),)
2490+
),
2491+
)
2492+
2493+
# Send the request.
2494+
response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
2495+
2496+
# Done; return the response.
2497+
return response
2498+
24092499
async def update_finding(
24102500
self,
24112501
request: Union[securitycenter_service.UpdateFindingRequest, dict] = None,

google/cloud/securitycenter_v1/services/security_center/client.py

+107
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from google.api_core import operation # type: ignore
3838
from google.api_core import operation_async # type: ignore
3939
from google.cloud.securitycenter_v1.services.security_center import pagers
40+
from google.cloud.securitycenter_v1.types import external_system as gcs_external_system
4041
from google.cloud.securitycenter_v1.types import finding
4142
from google.cloud.securitycenter_v1.types import finding as gcs_finding
4243
from google.cloud.securitycenter_v1.types import indicator
@@ -200,6 +201,27 @@ def parse_asset_path(path: str) -> Dict[str, str]:
200201
)
201202
return m.groupdict() if m else {}
202203

204+
@staticmethod
205+
def external_system_path(
206+
organization: str, source: str, finding: str, externalsystem: str,
207+
) -> str:
208+
"""Returns a fully-qualified external_system string."""
209+
return "organizations/{organization}/sources/{source}/findings/{finding}/externalSystems/{externalsystem}".format(
210+
organization=organization,
211+
source=source,
212+
finding=finding,
213+
externalsystem=externalsystem,
214+
)
215+
216+
@staticmethod
217+
def parse_external_system_path(path: str) -> Dict[str, str]:
218+
"""Parses a external_system path into its component segments."""
219+
m = re.match(
220+
r"^organizations/(?P<organization>.+?)/sources/(?P<source>.+?)/findings/(?P<finding>.+?)/externalSystems/(?P<externalsystem>.+?)$",
221+
path,
222+
)
223+
return m.groupdict() if m else {}
224+
203225
@staticmethod
204226
def finding_path(organization: str, source: str, finding: str,) -> str:
205227
"""Returns a fully-qualified finding string."""
@@ -2584,6 +2606,91 @@ def test_iam_permissions(
25842606
# Done; return the response.
25852607
return response
25862608

2609+
def update_external_system(
2610+
self,
2611+
request: Union[securitycenter_service.UpdateExternalSystemRequest, dict] = None,
2612+
*,
2613+
external_system: gcs_external_system.ExternalSystem = None,
2614+
update_mask: field_mask_pb2.FieldMask = None,
2615+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
2616+
timeout: float = None,
2617+
metadata: Sequence[Tuple[str, str]] = (),
2618+
) -> gcs_external_system.ExternalSystem:
2619+
r"""Updates external system. This is for a given finding.
2620+
2621+
Args:
2622+
request (Union[google.cloud.securitycenter_v1.types.UpdateExternalSystemRequest, dict]):
2623+
The request object. Request message for updating a
2624+
ExternalSystem resource.
2625+
external_system (google.cloud.securitycenter_v1.types.ExternalSystem):
2626+
Required. The external system
2627+
resource to update.
2628+
2629+
This corresponds to the ``external_system`` field
2630+
on the ``request`` instance; if ``request`` is provided, this
2631+
should not be set.
2632+
update_mask (google.protobuf.field_mask_pb2.FieldMask):
2633+
The FieldMask to use when updating
2634+
the external system resource.
2635+
If empty all mutable fields will be
2636+
updated.
2637+
2638+
This corresponds to the ``update_mask`` field
2639+
on the ``request`` instance; if ``request`` is provided, this
2640+
should not be set.
2641+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
2642+
should be retried.
2643+
timeout (float): The timeout for this request.
2644+
metadata (Sequence[Tuple[str, str]]): Strings which should be
2645+
sent along with the request as metadata.
2646+
2647+
Returns:
2648+
google.cloud.securitycenter_v1.types.ExternalSystem:
2649+
Representation of third party
2650+
SIEM/SOAR fields within SCC.
2651+
2652+
"""
2653+
# Create or coerce a protobuf request object.
2654+
# Sanity check: If we got a request object, we should *not* have
2655+
# gotten any keyword arguments that map to the request.
2656+
has_flattened_params = any([external_system, update_mask])
2657+
if request is not None and has_flattened_params:
2658+
raise ValueError(
2659+
"If the `request` argument is set, then none of "
2660+
"the individual field arguments should be set."
2661+
)
2662+
2663+
# Minor optimization to avoid making a copy if the user passes
2664+
# in a securitycenter_service.UpdateExternalSystemRequest.
2665+
# There's no risk of modifying the input as we've already verified
2666+
# there are no flattened fields.
2667+
if not isinstance(request, securitycenter_service.UpdateExternalSystemRequest):
2668+
request = securitycenter_service.UpdateExternalSystemRequest(request)
2669+
# If we have keyword arguments corresponding to fields on the
2670+
# request, apply these.
2671+
if external_system is not None:
2672+
request.external_system = external_system
2673+
if update_mask is not None:
2674+
request.update_mask = update_mask
2675+
2676+
# Wrap the RPC method; this adds retry and timeout information,
2677+
# and friendly error handling.
2678+
rpc = self._transport._wrapped_methods[self._transport.update_external_system]
2679+
2680+
# Certain fields should be provided within the metadata header;
2681+
# add these here.
2682+
metadata = tuple(metadata) + (
2683+
gapic_v1.routing_header.to_grpc_metadata(
2684+
(("external_system.name", request.external_system.name),)
2685+
),
2686+
)
2687+
2688+
# Send the request.
2689+
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
2690+
2691+
# Done; return the response.
2692+
return response
2693+
25872694
def update_finding(
25882695
self,
25892696
request: Union[securitycenter_service.UpdateFindingRequest, dict] = None,

google/cloud/securitycenter_v1/services/security_center/transports/base.py

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from google.auth import credentials as ga_credentials # type: ignore
2727
from google.oauth2 import service_account # type: ignore
2828

29+
from google.cloud.securitycenter_v1.types import external_system as gcs_external_system
2930
from google.cloud.securitycenter_v1.types import finding
3031
from google.cloud.securitycenter_v1.types import finding as gcs_finding
3132
from google.cloud.securitycenter_v1.types import mute_config
@@ -349,6 +350,11 @@ def _prep_wrapped_messages(self, client_info):
349350
default_timeout=60.0,
350351
client_info=client_info,
351352
),
353+
self.update_external_system: gapic_v1.method.wrap_method(
354+
self.update_external_system,
355+
default_timeout=None,
356+
client_info=client_info,
357+
),
352358
self.update_finding: gapic_v1.method.wrap_method(
353359
self.update_finding, default_timeout=60.0, client_info=client_info,
354360
),
@@ -638,6 +644,18 @@ def test_iam_permissions(
638644
]:
639645
raise NotImplementedError()
640646

647+
@property
648+
def update_external_system(
649+
self,
650+
) -> Callable[
651+
[securitycenter_service.UpdateExternalSystemRequest],
652+
Union[
653+
gcs_external_system.ExternalSystem,
654+
Awaitable[gcs_external_system.ExternalSystem],
655+
],
656+
]:
657+
raise NotImplementedError()
658+
641659
@property
642660
def update_finding(
643661
self,

0 commit comments

Comments
 (0)