From ca2522aaf1e3d250178be2fd7117ca537e9a7ad8 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Thu, 16 Feb 2017 17:07:45 -0800 Subject: [PATCH] Remove usage of GoogleCredentials [(#810)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/810) --- samples/snippets/quickstart.py | 4 ++-- samples/snippets/snippets.py | 18 +++++++++--------- samples/snippets/snippets_test.py | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/samples/snippets/quickstart.py b/samples/snippets/quickstart.py index 4e94a669..f4e4c7be 100644 --- a/samples/snippets/quickstart.py +++ b/samples/snippets/quickstart.py @@ -17,7 +17,7 @@ def run_quickstart(): # [START kms_quickstart] # Imports the Google APIs client library - from googleapiclient import discovery + import googleapiclient.discovery # Your Google Cloud Platform project ID project_id = 'YOUR_PROJECT_ID' @@ -26,7 +26,7 @@ def run_quickstart(): location = 'global' # Creates an API client for the KMS API. - kms_client = discovery.build('cloudkms', 'v1beta1') + kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1') # The resource name of the location associated with the key rings. parent = 'projects/{}/locations/{}'.format(project_id, location) diff --git a/samples/snippets/snippets.py b/samples/snippets/snippets.py index 9469b939..1c0a5292 100644 --- a/samples/snippets/snippets.py +++ b/samples/snippets/snippets.py @@ -17,7 +17,7 @@ import base64 import io -from googleapiclient import discovery +import googleapiclient.discovery # [START kms_create_keyring] @@ -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 = discovery.build('cloudkms', 'v1beta1') + kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1') # The resource name of the location associated with the KeyRing. parent = 'projects/{}/locations/{}'.format(project_id, location) @@ -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 = discovery.build('cloudkms', 'v1beta1') + kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1') # The resource name of the KeyRing associated with the CryptoKey. parent = 'projects/{}/locations/{}/keyRings/{}'.format( @@ -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 = discovery.build('cloudkms', 'v1beta1') + kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1') # The resource name of the CryptoKey. name = 'projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}'.format( @@ -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 = discovery.build('cloudkms', 'v1beta1') + kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1') # The resource name of the CryptoKey. name = 'projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}'.format( @@ -134,7 +134,7 @@ def disable_cryptokey_version(project_id, location, keyring, cryptokey, KeyRing.""" # Creates an API client for the KMS API. - kms_client = discovery.build('cloudkms', 'v1beta1') + kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1') # Construct the resource name of the CryptoKeyVersion. name = ( @@ -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 = discovery.build('cloudkms', 'v1beta1') + kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1') # Construct the resource name of the CryptoKeyVersion. name = ( @@ -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 = discovery.build('cloudkms', 'v1beta1') + kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1') # The resource name of the CryptoKey. parent = 'projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}'.format( @@ -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 = discovery.build('cloudkms', 'v1beta1') + kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1') # The resource name of the KeyRing. parent = 'projects/{}/locations/{}/keyRings/{}'.format( diff --git a/samples/snippets/snippets_test.py b/samples/snippets/snippets_test.py index 2ea0b12c..dc532bce 100644 --- a/samples/snippets/snippets_test.py +++ b/samples/snippets/snippets_test.py @@ -16,7 +16,7 @@ import random import string -from googleapiclient import discovery +import googleapiclient.discovery import snippets @@ -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 = discovery.build('cloudkms', 'v1beta1') + kms_client = googleapiclient.discovery.build('cloudkms', 'v1beta1') parent = 'projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}'.format( cloud_config.project, LOCATION, KEYRING, CRYPTOKEY) cryptokeys = kms_client.projects().locations().keyRings().cryptoKeys()