Skip to content

Commit 5db0862

Browse files
authored
feat(securitycenter): add sample for creating client with regional endpoint (GoogleCloudPlatform#12671)
* feat(securitycenter): add sample for creating client with regional endpoint * address feedback * simplify sample; fix linter errors
1 parent 927dd9d commit 5db0862

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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"

0 commit comments

Comments
 (0)