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

Updates Cloud-KMS sample code to use V1 libraries. #856

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion kms/api-client/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run_quickstart():
location = 'global'

# Creates an API client for the KMS API.
kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1')
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')

# The resource name of the location associated with the key rings.
parent = 'projects/{}/locations/{}'.format(project_id, location)
Expand Down
16 changes: 8 additions & 8 deletions kms/api-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_keyring(project_id, location, keyring):
"""Creates a KeyRing in the given location (e.g. global)."""

# Creates an API client for the KMS API.
kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1')
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')

# The resource name of the location associated with the KeyRing.
parent = 'projects/{}/locations/{}'.format(project_id, location)
Expand All @@ -44,7 +44,7 @@ def create_cryptokey(project_id, location, keyring, cryptokey):
"""Creates a CryptoKey within a KeyRing in the given location."""

# Creates an API client for the KMS API.
kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1')
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')

# The resource name of the KeyRing associated with the CryptoKey.
parent = 'projects/{}/locations/{}/keyRings/{}'.format(
Expand All @@ -68,7 +68,7 @@ def encrypt(project_id, location, keyring, cryptokey, plaintext_file_name,
call to decrypt."""

# Creates an API client for the KMS API.
kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1')
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')

# The resource name of the CryptoKey.
name = 'projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}'.format(
Expand Down Expand Up @@ -101,7 +101,7 @@ def decrypt(project_id, location, keyring, cryptokey, encrypted_file_name,
decrpyted_file_name."""

# Creates an API client for the KMS API.
kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1')
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')

# The resource name of the CryptoKey.
name = 'projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}'.format(
Expand Down Expand Up @@ -134,7 +134,7 @@ def disable_cryptokey_version(project_id, location, keyring, cryptokey,
KeyRing."""

# Creates an API client for the KMS API.
kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1')
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')

# Construct the resource name of the CryptoKeyVersion.
name = (
Expand All @@ -160,7 +160,7 @@ def destroy_cryptokey_version(
KeyRing for destruction 24 hours in the future."""

# Creates an API client for the KMS API.
kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1')
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')

# Construct the resource name of the CryptoKeyVersion.
name = (
Expand All @@ -185,7 +185,7 @@ def add_member_to_cryptokey_policy(
(IAM) policy for a given CryptoKey associated with a KeyRing."""

# Creates an API client for the KMS API.
kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1')
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')

# The resource name of the CryptoKey.
parent = 'projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}'.format(
Expand Down Expand Up @@ -225,7 +225,7 @@ def get_keyring_policy(project_id, location, keyring):
and prints out roles and the members assigned to those roles."""

# Creates an API client for the KMS API.
kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1')
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')

# The resource name of the KeyRing.
parent = 'projects/{}/locations/{}/keyRings/{}'.format(
Expand Down
2 changes: 1 addition & 1 deletion kms/api-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_add_member_to_cryptokey_policy(capsys, cloud_config):
.format(MEMBER, ROLE, CRYPTOKEY, KEYRING))
assert expected in out

kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1')
kms_client = googleapiclient.discovery.build('cloudkms', 'v1')
parent = 'projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}'.format(
cloud_config.project, LOCATION, KEYRING, CRYPTOKEY)
cryptokeys = kms_client.projects().locations().keyRings().cryptoKeys()
Expand Down