Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move import statements into tagged regions #2219

Merged
merged 2 commits into from
Jun 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions kms/api-client/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