Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit57740e4

Browse files
Mattix23gcf-owl-bot[bot]parthea
authored
docs: revise create table cmek sample (#1452)
* docs: revise create table cmek sample* 🦉 Updates from OwlBot post-processorSeehttps://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.mdCo-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent14ae1f2 commit57740e4

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

‎docs/snippets.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def test_create_table_cmek(client, to_delete):
168168
dataset=bigquery.Dataset(dataset_ref)
169169
client.create_dataset(dataset)
170170
to_delete.append(dataset)
171-
171+
# TODO(Mattix23): When sample is updated in cloud.google.com, delete this one.
172172
# [START bigquery_create_table_cmek]
173173
# from google.cloud import bigquery
174174
# client = bigquery.Client()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2022 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+
16+
defcreate_table_cmek(table_id:str,kms_key_name:str)->None:
17+
orig_table_id=table_id
18+
orig_key_name=kms_key_name
19+
# [START bigquery_create_table_cmek]
20+
fromgoogle.cloudimportbigquery
21+
22+
client=bigquery.Client()
23+
24+
# TODO(dev): Change table_id to the full name of the table you want to create.
25+
table_id="your-project.your_dataset.your_table_name"
26+
27+
# Set the encryption key to use for the table.
28+
# TODO: Replace this key with a key you have created in Cloud KMS.
29+
kms_key_name="projects/your-project/locations/us/keyRings/test/cryptoKeys/test"
30+
31+
# [END bigquery_create_table_cmek]
32+
33+
table_id=orig_table_id
34+
kms_key_name=orig_key_name
35+
36+
# [START bigquery_create_table_cmek]
37+
table=bigquery.Table(table_id)
38+
table.encryption_configuration=bigquery.EncryptionConfiguration(
39+
kms_key_name=kms_key_name
40+
)
41+
table=client.create_table(table)# API request
42+
43+
print(f"Created{table_id}.")
44+
print(f"Key:{table.encryption_configuration.kms_key_name}.")
45+
46+
# [END bigquery_create_table_cmek]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2022 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+
importtyping
16+
17+
importcreate_table_cmek
18+
19+
iftyping.TYPE_CHECKING:
20+
importpytest
21+
22+
23+
deftest_create_table(
24+
capsys:"pytest.CaptureFixture[str]",
25+
random_table_id:str,
26+
)->None:
27+
28+
kms_key_name= (
29+
"projects/cloud-samples-tests/locations/us/keyRings/test/cryptoKeys/test"
30+
)
31+
32+
create_table_cmek.create_table_cmek(random_table_id,kms_key_name)
33+
34+
out,_=capsys.readouterr()
35+
assert"Created"inout
36+
assertrandom_table_idinout
37+
assertkms_key_nameinout

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp