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]
2218def 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):
4442def 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