1
+ #!/usr/bin/env python
2
+ #
3
+ # Copyright 2024 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # [START securitycenter_regional_endpoint_list_findings]
18
+ def rep_list_finding (parent , endpoint ) -> int :
19
+ """
20
+ lists all findings for a parent
21
+ Args:
22
+ parent: Parent resource for which findings to be listed. Must be in one of the following formats:
23
+ "organizations/{organization_id}/sources/{sources}/locations/{location}"
24
+ "projects/{project_id}/sources/{sources}/locations/{location}"
25
+ "folders/{folder_id}/sources/{sources}/locations/{location}"
26
+ endpoint: Endpoint for this request. For example "securitycenter.googleapis.com", "securitycenter.me-central2.rep.googleapis.com"
27
+ Returns:
28
+ int: return the count of all findings for a source
29
+ """
30
+ from google .cloud import securitycenter_v2 as securitycenter
31
+ from google .api_core .client_options import ClientOptions
32
+ # Override endpoint and create a client.
33
+ options = ClientOptions (api_endpoint = endpoint )
34
+ client = securitycenter .SecurityCenterClient (client_options = options )
35
+
36
+ finding_result_iterator = client .list_findings (request = {"parent" : parent })
37
+ for count , finding_result in enumerate (finding_result_iterator ):
38
+ print (
39
+ "{}: name: {} resource: {}" .format (
40
+ count , finding_result .finding .name , finding_result .finding .resource_name
41
+ )
42
+ )
43
+ return count
44
+
45
+ # [END securitycenter_regional_endpoint_list_findings]
0 commit comments