Skip to content

Commit

Permalink
Move import statements into tagged regions [(#2219)](GoogleCloudPlatf…
Browse files Browse the repository at this point in the history
…orm/python-docs-samples#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.
  • Loading branch information
engelke authored and busunkim96 committed Jun 4, 2020
1 parent 3dd4699 commit 1dc5d51
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions packages/google-cloud-kms/samples/snippets/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
# See the License for the specific language governing permissions and


from google.cloud import kms_v1
from google.cloud.kms_v1 import enums


# [START kms_create_keyring]
def create_key_ring(project_id, location_id, key_ring_id):
"""Creates a KeyRing in the given location (e.g. global)."""

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1
from google.cloud.kms_v1 import enums

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1
from google.cloud.kms_v1 import enums

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1
from google.cloud.kms_v1 import enums

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

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

from google.cloud import kms_v1

# Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()

Expand Down

0 comments on commit 1dc5d51

Please sign in to comment.