File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
securitycenter/snippets_v2 Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ # Copyright 2024 Google LLC
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # https://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ """Examples of working with clients for Security Command Center."""
16+ # [START securitycenter_set_client_endpoint_v2]
17+ from google .cloud import securitycenter_v2
18+
19+
20+ def create_client_with_endpoint (api_endpoint ) -> securitycenter_v2 .SecurityCenterClient :
21+ """
22+ Creates a Security Command Center client for a regional endpoint.
23+ Args:
24+ api_endpoint: the regional endpoint's hostname, like 'securitycenter.REGION.rep.googleapis.com'
25+ Returns:
26+ Dict: Returns clients with the default and regional endpoints; each key is a hostname
27+ """
28+ regional_client = securitycenter_v2 .SecurityCenterClient (
29+ client_options = {"api_endpoint" : api_endpoint }
30+ )
31+ print ("Regional client initiated with endpoint: {}" .format (regional_client .api_endpoint ))
32+ return regional_client
33+ # [END securitycenter_set_client_endpoint_v2]
Original file line number Diff line number Diff line change 1+ # Copyright 2024 Google LLC
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # https://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+ import snippets_create_client_v2
15+
16+
17+ def test_create_client_with_endpoint ():
18+ client = snippets_create_client_v2 .create_client_with_endpoint (
19+ "securitycenter.me-central2.rep.googleapis.com" )
20+ assert client .api_endpoint == "securitycenter.me-central2.rep.googleapis.com"
You can’t perform that action at this time.
0 commit comments