Skip to content

Commit

Permalink
Updates Could-KMS sample code to use V1 libraries. [(#856)](GoogleClo…
Browse files Browse the repository at this point in the history
  • Loading branch information
philcoakley authored and busunkim96 committed Jun 4, 2020
1 parent 9a168dc commit f83094f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-kms/samples/snippets/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 packages/google-cloud-kms/samples/snippets/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
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

0 comments on commit f83094f

Please sign in to comment.