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

Appearance settings

Commit 951ac8e

Browse filesBrowse files
authored
Move import statements into tagged regions (GoogleCloudPlatform#2219)
* Move import statements into tagged regions So they will show up in context on web pages. * Flake8 didn't like needless enums imports I have to admit, it's right. It's clearer now.
1 parent 769049b commit 951ac8e
Copy full SHA for 951ac8e

File tree

Expand file treeCollapse file tree

1 file changed

+31
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+31
-4
lines changed

‎kms/api-client/snippets.py

Copy file name to clipboardExpand all lines: kms/api-client/snippets.py
+31-4Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
# See the License for the specific language governing permissions and
1515

1616

17-
from google.cloud import kms_v1
18-
from google.cloud.kms_v1 import enums
19-
20-
2117
# [START kms_create_keyring]
2218
def create_key_ring(project_id, location_id, key_ring_id):
2319
"""Creates a KeyRing in the given location (e.g. global)."""
2420

21+
from google.cloud import kms_v1
22+
2523
# Creates an API client for the KMS API.
2624
client = kms_v1.KeyManagementServiceClient()
2725

@@ -44,6 +42,9 @@ def create_key_ring(project_id, location_id, key_ring_id):
4442
def create_crypto_key(project_id, location_id, key_ring_id, crypto_key_id):
4543
"""Creates a CryptoKey within a KeyRing in the given location."""
4644

45+
from google.cloud import kms_v1
46+
from google.cloud.kms_v1 import enums
47+
4748
# Creates an API client for the KMS API.
4849
client = kms_v1.KeyManagementServiceClient()
4950

@@ -67,6 +68,8 @@ def encrypt_symmetric(project_id, location_id, key_ring_id, crypto_key_id,
6768
plaintext):
6869
"""Encrypts input plaintext data using the provided symmetric CryptoKey."""
6970

71+
from google.cloud import kms_v1
72+
7073
# Creates an API client for the KMS API.
7174
client = kms_v1.KeyManagementServiceClient()
7275

@@ -85,6 +88,8 @@ def decrypt_symmetric(project_id, location_id, key_ring_id, crypto_key_id,
8588
ciphertext):
8689
"""Decrypts input ciphertext using the provided symmetric CryptoKey."""
8790

91+
from google.cloud import kms_v1
92+
8893
# Creates an API client for the KMS API.
8994
client = kms_v1.KeyManagementServiceClient()
9095

@@ -103,6 +108,9 @@ def disable_crypto_key_version(project_id, location_id, key_ring_id,
103108
"""Disables a CryptoKeyVersion associated with a given CryptoKey and
104109
KeyRing."""
105110

111+
from google.cloud import kms_v1
112+
from google.cloud.kms_v1 import enums
113+
106114
# Creates an API client for the KMS API.
107115
client = kms_v1.KeyManagementServiceClient()
108116

@@ -128,6 +136,9 @@ def enable_crypto_key_version(project_id, location_id, key_ring_id,
128136
"""Enables a CryptoKeyVersion associated with a given CryptoKey and
129137
KeyRing."""
130138

139+
from google.cloud import kms_v1
140+
from google.cloud.kms_v1 import enums
141+
131142
# Creates an API client for the KMS API.
132143
client = kms_v1.KeyManagementServiceClient()
133144

@@ -153,6 +164,8 @@ def destroy_crypto_key_version(
153164
"""Schedules a CryptoKeyVersion associated with a given CryptoKey and
154165
KeyRing for destruction 24 hours in the future."""
155166

167+
from google.cloud import kms_v1
168+
156169
# Creates an API client for the KMS API.
157170
client = kms_v1.KeyManagementServiceClient()
158171

@@ -174,6 +187,8 @@ def restore_crypto_key_version(
174187
project_id, location_id, key_ring_id, crypto_key_id, version_id):
175188
"""Restores a CryptoKeyVersion that is scheduled for destruction."""
176189

190+
from google.cloud import kms_v1
191+
177192
# Creates an API client for the KMS API.
178193
client = kms_v1.KeyManagementServiceClient()
179194

@@ -198,6 +213,8 @@ def add_member_to_crypto_key_policy(
198213
"""Adds a member with a given role to the Identity and Access Management
199214
(IAM) policy for a given CryptoKey associated with a KeyRing."""
200215

216+
from google.cloud import kms_v1
217+
201218
# Creates an API client for the KMS API.
202219
client = kms_v1.KeyManagementServiceClient()
203220

@@ -227,6 +244,8 @@ def add_member_to_key_ring_policy(
227244
"""Adds a member with a given role to the Identity and Access Management
228245
(IAM) policy for a given KeyRing."""
229246

247+
from google.cloud import kms_v1
248+
230249
# Creates an API client for the KMS API.
231250
client = kms_v1.KeyManagementServiceClient()
232251

@@ -257,6 +276,8 @@ def remove_member_from_crypto_key_policy(
257276
"""Removes a member with a given role from the Identity and Access
258277
Management (IAM) policy for a given CryptoKey associated with a KeyRing."""
259278

279+
from google.cloud import kms_v1
280+
260281
# Creates an API client for the KMS API.
261282
client = kms_v1.KeyManagementServiceClient()
262283

@@ -285,6 +306,8 @@ def remove_member_from_key_ring_policy(project_id, location_id, key_ring_id,
285306
"""Removes a member with a given role from the Identity and Access
286307
Management (IAM) policy for a given KeyRing."""
287308

309+
from google.cloud import kms_v1
310+
288311
# Creates an API client for the KMS API.
289312
client = kms_v1.KeyManagementServiceClient()
290313

@@ -312,6 +335,8 @@ def get_key_ring_policy(project_id, location_id, key_ring_id):
312335
"""Gets the Identity and Access Management (IAM) policy for a given KeyRing
313336
and prints out roles and the members assigned to those roles."""
314337

338+
from google.cloud import kms_v1
339+
315340
# Creates an API client for the KMS API.
316341
client = kms_v1.KeyManagementServiceClient()
317342

@@ -334,6 +359,8 @@ def get_crypto_key_policy(project_id, location_id, key_ring_id, crypto_key_id):
334359
"""Gets the Identity and Access Management (IAM) policy for a given KeyRing
335360
and prints out roles and the members assigned to those roles."""
336361

362+
from google.cloud import kms_v1
363+
337364
# Creates an API client for the KMS API.
338365
client = kms_v1.KeyManagementServiceClient()
339366

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.