14
14
# See the License for the specific language governing permissions and
15
15
16
16
17
- from google .cloud import kms_v1
18
- from google .cloud .kms_v1 import enums
19
-
20
-
21
17
# [START kms_create_keyring]
22
18
def create_key_ring (project_id , location_id , key_ring_id ):
23
19
"""Creates a KeyRing in the given location (e.g. global)."""
24
20
21
+ from google .cloud import kms_v1
22
+
25
23
# Creates an API client for the KMS API.
26
24
client = kms_v1 .KeyManagementServiceClient ()
27
25
@@ -44,6 +42,9 @@ def create_key_ring(project_id, location_id, key_ring_id):
44
42
def create_crypto_key (project_id , location_id , key_ring_id , crypto_key_id ):
45
43
"""Creates a CryptoKey within a KeyRing in the given location."""
46
44
45
+ from google .cloud import kms_v1
46
+ from google .cloud .kms_v1 import enums
47
+
47
48
# Creates an API client for the KMS API.
48
49
client = kms_v1 .KeyManagementServiceClient ()
49
50
@@ -67,6 +68,8 @@ def encrypt_symmetric(project_id, location_id, key_ring_id, crypto_key_id,
67
68
plaintext ):
68
69
"""Encrypts input plaintext data using the provided symmetric CryptoKey."""
69
70
71
+ from google .cloud import kms_v1
72
+
70
73
# Creates an API client for the KMS API.
71
74
client = kms_v1 .KeyManagementServiceClient ()
72
75
@@ -85,6 +88,8 @@ def decrypt_symmetric(project_id, location_id, key_ring_id, crypto_key_id,
85
88
ciphertext ):
86
89
"""Decrypts input ciphertext using the provided symmetric CryptoKey."""
87
90
91
+ from google .cloud import kms_v1
92
+
88
93
# Creates an API client for the KMS API.
89
94
client = kms_v1 .KeyManagementServiceClient ()
90
95
@@ -103,6 +108,9 @@ def disable_crypto_key_version(project_id, location_id, key_ring_id,
103
108
"""Disables a CryptoKeyVersion associated with a given CryptoKey and
104
109
KeyRing."""
105
110
111
+ from google .cloud import kms_v1
112
+ from google .cloud .kms_v1 import enums
113
+
106
114
# Creates an API client for the KMS API.
107
115
client = kms_v1 .KeyManagementServiceClient ()
108
116
@@ -128,6 +136,9 @@ def enable_crypto_key_version(project_id, location_id, key_ring_id,
128
136
"""Enables a CryptoKeyVersion associated with a given CryptoKey and
129
137
KeyRing."""
130
138
139
+ from google .cloud import kms_v1
140
+ from google .cloud .kms_v1 import enums
141
+
131
142
# Creates an API client for the KMS API.
132
143
client = kms_v1 .KeyManagementServiceClient ()
133
144
@@ -153,6 +164,8 @@ def destroy_crypto_key_version(
153
164
"""Schedules a CryptoKeyVersion associated with a given CryptoKey and
154
165
KeyRing for destruction 24 hours in the future."""
155
166
167
+ from google .cloud import kms_v1
168
+
156
169
# Creates an API client for the KMS API.
157
170
client = kms_v1 .KeyManagementServiceClient ()
158
171
@@ -174,6 +187,8 @@ def restore_crypto_key_version(
174
187
project_id , location_id , key_ring_id , crypto_key_id , version_id ):
175
188
"""Restores a CryptoKeyVersion that is scheduled for destruction."""
176
189
190
+ from google .cloud import kms_v1
191
+
177
192
# Creates an API client for the KMS API.
178
193
client = kms_v1 .KeyManagementServiceClient ()
179
194
@@ -198,6 +213,8 @@ def add_member_to_crypto_key_policy(
198
213
"""Adds a member with a given role to the Identity and Access Management
199
214
(IAM) policy for a given CryptoKey associated with a KeyRing."""
200
215
216
+ from google .cloud import kms_v1
217
+
201
218
# Creates an API client for the KMS API.
202
219
client = kms_v1 .KeyManagementServiceClient ()
203
220
@@ -227,6 +244,8 @@ def add_member_to_key_ring_policy(
227
244
"""Adds a member with a given role to the Identity and Access Management
228
245
(IAM) policy for a given KeyRing."""
229
246
247
+ from google .cloud import kms_v1
248
+
230
249
# Creates an API client for the KMS API.
231
250
client = kms_v1 .KeyManagementServiceClient ()
232
251
@@ -257,6 +276,8 @@ def remove_member_from_crypto_key_policy(
257
276
"""Removes a member with a given role from the Identity and Access
258
277
Management (IAM) policy for a given CryptoKey associated with a KeyRing."""
259
278
279
+ from google .cloud import kms_v1
280
+
260
281
# Creates an API client for the KMS API.
261
282
client = kms_v1 .KeyManagementServiceClient ()
262
283
@@ -285,6 +306,8 @@ def remove_member_from_key_ring_policy(project_id, location_id, key_ring_id,
285
306
"""Removes a member with a given role from the Identity and Access
286
307
Management (IAM) policy for a given KeyRing."""
287
308
309
+ from google .cloud import kms_v1
310
+
288
311
# Creates an API client for the KMS API.
289
312
client = kms_v1 .KeyManagementServiceClient ()
290
313
@@ -312,6 +335,8 @@ def get_key_ring_policy(project_id, location_id, key_ring_id):
312
335
"""Gets the Identity and Access Management (IAM) policy for a given KeyRing
313
336
and prints out roles and the members assigned to those roles."""
314
337
338
+ from google .cloud import kms_v1
339
+
315
340
# Creates an API client for the KMS API.
316
341
client = kms_v1 .KeyManagementServiceClient ()
317
342
@@ -334,6 +359,8 @@ def get_crypto_key_policy(project_id, location_id, key_ring_id, crypto_key_id):
334
359
"""Gets the Identity and Access Management (IAM) policy for a given KeyRing
335
360
and prints out roles and the members assigned to those roles."""
336
361
362
+ from google .cloud import kms_v1
363
+
337
364
# Creates an API client for the KMS API.
338
365
client = kms_v1 .KeyManagementServiceClient ()
339
366
0 commit comments