From e47a3091a68c5477b84c6555832705b244bd231f Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Fri, 26 Apr 2019 14:56:11 -0700 Subject: [PATCH 1/4] Updated datasets samples to remove api keys --- healthcare/api-client/datasets/README.rst.in | 1 - healthcare/api-client/datasets/datasets.py | 44 +++++-------------- .../api-client/datasets/datasets_test.py | 21 +++------ 3 files changed, 17 insertions(+), 49 deletions(-) diff --git a/healthcare/api-client/datasets/README.rst.in b/healthcare/api-client/datasets/README.rst.in index 20c008aee8a..f8a0666d1df 100644 --- a/healthcare/api-client/datasets/README.rst.in +++ b/healthcare/api-client/datasets/README.rst.in @@ -16,7 +16,6 @@ product: setup: - auth -- auth_api_key - install_deps samples: diff --git a/healthcare/api-client/datasets/datasets.py b/healthcare/api-client/datasets/datasets.py index 6b109b7c5dc..f53dc3a8de9 100644 --- a/healthcare/api-client/datasets/datasets.py +++ b/healthcare/api-client/datasets/datasets.py @@ -21,7 +21,7 @@ # [START healthcare_get_client] -def get_client(service_account_json, api_key): +def get_client(service_account_json): """Returns an authorized API client by discovering the Healthcare API and creating a service object using the service account credentials JSON.""" api_scopes = ['https://www.googleapis.com/auth/cloud-platform'] @@ -33,8 +33,8 @@ def get_client(service_account_json, api_key): service_account_json) scoped_credentials = credentials.with_scopes(api_scopes) - discovery_url = '{}?labels=CHC_BETA&version={}&key={}'.format( - discovery_api, api_version, api_key) + discovery_url = '{}?labels=CHC_BETA&version={}'.format( + discovery_api, api_version) return discovery.build( service_name, @@ -47,12 +47,11 @@ def get_client(service_account_json, api_key): # [START healthcare_create_dataset] def create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id): """Creates a dataset.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dataset_parent = 'projects/{}/locations/{}'.format( project_id, cloud_region) @@ -74,12 +73,11 @@ def create_dataset( # [START healthcare_delete_dataset] def delete_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id): """Deletes a dataset.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dataset_name = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) @@ -99,12 +97,11 @@ def delete_dataset( # [START healthcare_get_dataset] def get_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id): """Gets any metadata associated with a dataset.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dataset_name = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) @@ -119,9 +116,9 @@ def get_dataset( # [START healthcare_list_datasets] -def list_datasets(service_account_json, api_key, project_id, cloud_region): +def list_datasets(service_account_json, project_id, cloud_region): """Lists the datasets in the project.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dataset_parent = 'projects/{}/locations/{}'.format( project_id, cloud_region) @@ -141,13 +138,12 @@ def list_datasets(service_account_json, api_key, project_id, cloud_region): # [START healthcare_patch_dataset] def patch_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id, time_zone): """Updates dataset metadata.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dataset_parent = 'projects/{}/locations/{}'.format( project_id, cloud_region) dataset_name = '{}/datasets/{}'.format(dataset_parent, dataset_id) @@ -176,7 +172,6 @@ def patch_dataset( # [START healthcare_deidentify_dataset] def deidentify_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -185,7 +180,7 @@ def deidentify_dataset( """Creates a new dataset containing de-identified data from the source dataset. """ - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) source_dataset = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) destination_dataset = 'projects/{}/locations/{}/datasets/{}'.format( @@ -240,12 +235,11 @@ def deidentify_dataset( # [START healthcare_dataset_get_iam_policy] def get_dataset_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id): """Gets the IAM policy for the specified dataset.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dataset_name = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) @@ -261,7 +255,6 @@ def get_dataset_iam_policy( # [START healthcare_dataset_set_iam_policy] def set_dataset_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -283,7 +276,7 @@ def set_dataset_iam_policy( A role can be any IAM role, such as 'roles/viewer', 'roles/owner', or 'roles/editor' """ - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dataset_name = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) @@ -323,11 +316,6 @@ def parse_command_line_args(): default=os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"), help='Path to service account JSON file.') - parser.add_argument( - '--api_key', - default=os.environ.get("API_KEY"), - help='Your API key.') - parser.add_argument( '--project_id', default=os.environ.get("GOOGLE_CLOUD_PROJECT"), @@ -395,7 +383,6 @@ def run_command(args): elif args.command == 'create-dataset': create_dataset( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id) @@ -403,7 +390,6 @@ def run_command(args): elif args.command == 'delete-dataset': delete_dataset( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id) @@ -411,7 +397,6 @@ def run_command(args): elif args.command == 'get-dataset': get_dataset( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id) @@ -419,14 +404,12 @@ def run_command(args): elif args.command == 'list-datasets': list_datasets( args.service_account_json, - args.api_key, args.project_id, args.cloud_region) elif args.command == 'patch-dataset': patch_dataset( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -435,7 +418,6 @@ def run_command(args): elif args.command == 'deidentify-dataset': deidentify_dataset( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -445,7 +427,6 @@ def run_command(args): elif args.command == 'get_iam_policy': get_dataset_iam_policy( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id) @@ -453,7 +434,6 @@ def run_command(args): elif args.command == 'set_iam_policy': set_dataset_iam_policy( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, diff --git a/healthcare/api-client/datasets/datasets_test.py b/healthcare/api-client/datasets/datasets_test.py index 1eeb981a523..b832ef52f61 100644 --- a/healthcare/api-client/datasets/datasets_test.py +++ b/healthcare/api-client/datasets/datasets_test.py @@ -18,7 +18,6 @@ import datasets cloud_region = 'us-central1' -api_key = os.environ['API_KEY'] project_id = os.environ['GOOGLE_CLOUD_PROJECT'] service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS'] @@ -31,20 +30,19 @@ def test_CRUD_dataset(capsys): datasets.create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) datasets.get_dataset( - service_account_json, api_key, project_id, cloud_region, dataset_id) + service_account_json, project_id, cloud_region, dataset_id) datasets.list_datasets( - service_account_json, api_key, project_id, cloud_region) + service_account_json, project_id, cloud_region) # Test and also clean up datasets.delete_dataset( - service_account_json, api_key, project_id, cloud_region, dataset_id) + service_account_json, project_id, cloud_region, dataset_id) out, _ = capsys.readouterr() @@ -58,14 +56,12 @@ def test_CRUD_dataset(capsys): def test_patch_dataset(capsys): datasets.create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) datasets.patch_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -73,7 +69,7 @@ def test_patch_dataset(capsys): # Clean up datasets.delete_dataset( - service_account_json, api_key, project_id, cloud_region, dataset_id) + service_account_json, project_id, cloud_region, dataset_id) out, _ = capsys.readouterr() @@ -84,14 +80,12 @@ def test_patch_dataset(capsys): def test_deidentify_dataset(capsys): datasets.create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) datasets.deidentify_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -100,10 +94,9 @@ def test_deidentify_dataset(capsys): # Clean up datasets.delete_dataset( - service_account_json, api_key, project_id, cloud_region, dataset_id) + service_account_json, project_id, cloud_region, dataset_id) datasets.delete_dataset( service_account_json, - api_key, project_id, cloud_region, destination_dataset_id) @@ -117,21 +110,18 @@ def test_deidentify_dataset(capsys): def test_get_set_dataset_iam_policy(capsys): datasets.create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) get_response = datasets.get_dataset_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id) set_response = datasets.set_dataset_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -141,7 +131,6 @@ def test_get_set_dataset_iam_policy(capsys): # Clean up datasets.delete_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) From 3fa8238ebd97605e8f26b167b70ce4dacdbbed68 Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Fri, 26 Apr 2019 15:02:04 -0700 Subject: [PATCH 2/4] Updated dicom samples to remove api keys --- healthcare/api-client/dicom/README.rst.in | 1 - healthcare/api-client/dicom/dicom_stores.py | 47 +++++-------------- .../api-client/dicom/dicom_stores_test.py | 20 -------- healthcare/api-client/dicom/dicomweb_test.py | 5 -- 4 files changed, 12 insertions(+), 61 deletions(-) diff --git a/healthcare/api-client/dicom/README.rst.in b/healthcare/api-client/dicom/README.rst.in index c11fdb12dfc..58d9153c3fc 100644 --- a/healthcare/api-client/dicom/README.rst.in +++ b/healthcare/api-client/dicom/README.rst.in @@ -16,7 +16,6 @@ product: setup: - auth -- auth_api_key - install_deps samples: diff --git a/healthcare/api-client/dicom/dicom_stores.py b/healthcare/api-client/dicom/dicom_stores.py index 7bb4f8d42e2..c2aa979c597 100644 --- a/healthcare/api-client/dicom/dicom_stores.py +++ b/healthcare/api-client/dicom/dicom_stores.py @@ -21,7 +21,7 @@ # [START healthcare_get_client] -def get_client(service_account_json, api_key): +def get_client(service_account_json): """Returns an authorized API client by discovering the Healthcare API and creating a service object using the service account credentials JSON.""" api_scopes = ['https://www.googleapis.com/auth/cloud-platform'] @@ -33,8 +33,8 @@ def get_client(service_account_json, api_key): service_account_json) scoped_credentials = credentials.with_scopes(api_scopes) - discovery_url = '{}?labels=CHC_BETA&version={}&key={}'.format( - discovery_api, api_version, api_key) + discovery_url = '{}?labels=CHC_BETA&version={}'.format( + discovery_api, api_version) return discovery.build( service_name, @@ -48,13 +48,12 @@ def get_client(service_account_json, api_key): # [START healthcare_create_dicom_store] def create_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, dicom_store_id): """Creates a new DICOM store within the parent dataset.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) @@ -76,13 +75,12 @@ def create_dicom_store( # [START healthcare_delete_dicom_store] def delete_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, dicom_store_id): """Deletes the specified DICOM store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) dicom_store_name = '{}/dicomStores/{}'.format( @@ -104,13 +102,12 @@ def delete_dicom_store( # [START healthcare_get_dicom_store] def get_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, dicom_store_id): """Gets the specified DICOM store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) dicom_store_name = '{}/dicomStores/{}'.format( @@ -133,12 +130,11 @@ def get_dicom_store( # [START healthcare_list_dicom_stores] def list_dicom_stores( service_account_json, - api_key, project_id, cloud_region, dataset_id): """Lists the DICOM stores in the given dataset.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) @@ -159,14 +155,13 @@ def list_dicom_stores( # [START healthcare_patch_dicom_store] def patch_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, dicom_store_id, pubsub_topic): """Updates the DICOM store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) dicom_store_name = '{}/dicomStores/{}'.format( @@ -198,7 +193,6 @@ def patch_dicom_store( # [START healthcare_export_dicom_instance] def export_dicom_instance( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -206,7 +200,7 @@ def export_dicom_instance( uri_prefix): """Export data to a Google Cloud Storage bucket by copying it from the DICOM store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) dicom_store_name = '{}/dicomStores/{}'.format( @@ -234,7 +228,6 @@ def export_dicom_instance( # [START healthcare_import_dicom_instance] def import_dicom_instance( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -243,7 +236,7 @@ def import_dicom_instance( """Import data into the DICOM store by copying it from the specified source. """ - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) dicom_store_name = '{}/dicomStores/{}'.format( @@ -273,13 +266,12 @@ def import_dicom_instance( # [START healthcare_dicom_store_get_iam_policy] def get_dicom_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, dicom_store_id): """Gets the IAM policy for the specified dicom store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) dicom_store_name = '{}/dicomStores/{}'.format( @@ -297,7 +289,6 @@ def get_dicom_store_iam_policy( # [START healthcare_dicom_store_set_iam_policy] def set_dicom_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -320,7 +311,7 @@ def set_dicom_store_iam_policy( A role can be any IAM role, such as 'roles/viewer', 'roles/owner', or 'roles/editor' """ - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) dicom_store_name = '{}/dicomStores/{}'.format( @@ -362,11 +353,6 @@ def parse_command_line_args(): default=os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"), help='Path to service account JSON file.') - parser.add_argument( - '--api_key', - default=os.environ.get("API_KEY"), - help='Your API key') - parser.add_argument( '--project_id', default=os.environ.get("GOOGLE_CLOUD_PROJECT"), @@ -458,7 +444,6 @@ def run_command(args): elif args.command == 'create-dicom-store': create_dicom_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -467,7 +452,6 @@ def run_command(args): elif args.command == 'delete-dicom-store': delete_dicom_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -476,7 +460,6 @@ def run_command(args): elif args.command == 'get-dicom-store': get_dicom_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -485,7 +468,6 @@ def run_command(args): elif args.command == 'list-dicom-stores': list_dicom_stores( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id) @@ -493,7 +475,6 @@ def run_command(args): elif args.command == 'patch-dicom-store': patch_dicom_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -503,7 +484,6 @@ def run_command(args): elif args.command == 'export-dicom-store': export_dicom_instance( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -513,7 +493,6 @@ def run_command(args): elif args.command == 'import-dicom-store': import_dicom_instance( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -523,7 +502,6 @@ def run_command(args): elif args.command == 'get_iam_policy': get_dicom_store_iam_policy( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -532,7 +510,6 @@ def run_command(args): elif args.command == 'set_iam_policy': set_dicom_store_iam_policy( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, diff --git a/healthcare/api-client/dicom/dicom_stores_test.py b/healthcare/api-client/dicom/dicom_stores_test.py index 42d232b2aa4..856a2986692 100644 --- a/healthcare/api-client/dicom/dicom_stores_test.py +++ b/healthcare/api-client/dicom/dicom_stores_test.py @@ -23,7 +23,6 @@ import dicom_stores cloud_region = 'us-central1' -api_key = os.environ['API_KEY'] project_id = os.environ['GOOGLE_CLOUD_PROJECT'] service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS'] @@ -42,7 +41,6 @@ def test_dataset(): dataset = datasets.create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -52,7 +50,6 @@ def test_dataset(): # Clean up datasets.delete_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -61,7 +58,6 @@ def test_dataset(): def test_CRUD_dicom_store(test_dataset, capsys): dicom_stores.create_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -69,7 +65,6 @@ def test_CRUD_dicom_store(test_dataset, capsys): dicom_stores.get_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -77,14 +72,12 @@ def test_CRUD_dicom_store(test_dataset, capsys): dicom_stores.list_dicom_stores( service_account_json, - api_key, project_id, cloud_region, dataset_id) dicom_stores.delete_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -102,7 +95,6 @@ def test_CRUD_dicom_store(test_dataset, capsys): def test_patch_dicom_store(test_dataset, capsys): dicom_stores.create_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -110,7 +102,6 @@ def test_patch_dicom_store(test_dataset, capsys): dicom_stores.patch_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -120,7 +111,6 @@ def test_patch_dicom_store(test_dataset, capsys): # Clean up dicom_stores.delete_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -134,7 +124,6 @@ def test_patch_dicom_store(test_dataset, capsys): def test_import_dicom_instance(test_dataset, capsys): dicom_stores.create_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -142,7 +131,6 @@ def test_import_dicom_instance(test_dataset, capsys): dicom_stores.import_dicom_instance( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -152,7 +140,6 @@ def test_import_dicom_instance(test_dataset, capsys): # Clean up dicom_stores.delete_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -166,7 +153,6 @@ def test_import_dicom_instance(test_dataset, capsys): def test_export_dicom_instance(test_dataset, capsys): dicom_stores.create_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -174,7 +160,6 @@ def test_export_dicom_instance(test_dataset, capsys): dicom_stores.export_dicom_instance( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -184,7 +169,6 @@ def test_export_dicom_instance(test_dataset, capsys): # Clean up dicom_stores.delete_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -198,7 +182,6 @@ def test_export_dicom_instance(test_dataset, capsys): def test_get_set_dicom_store_iam_policy(test_dataset, capsys): dicom_stores.create_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -206,7 +189,6 @@ def test_get_set_dicom_store_iam_policy(test_dataset, capsys): get_response = dicom_stores.get_dicom_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -214,7 +196,6 @@ def test_get_set_dicom_store_iam_policy(test_dataset, capsys): set_response = dicom_stores.set_dicom_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -225,7 +206,6 @@ def test_get_set_dicom_store_iam_policy(test_dataset, capsys): # Clean up dicom_stores.delete_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, diff --git a/healthcare/api-client/dicom/dicomweb_test.py b/healthcare/api-client/dicom/dicomweb_test.py index 0a936387cb9..a3bb6489a73 100644 --- a/healthcare/api-client/dicom/dicomweb_test.py +++ b/healthcare/api-client/dicom/dicomweb_test.py @@ -24,7 +24,6 @@ import dicomweb cloud_region = 'us-central1' -api_key = os.environ['API_KEY'] base_url = 'https://healthcare.googleapis.com/v1beta1' project_id = os.environ['GOOGLE_CLOUD_PROJECT'] service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS'] @@ -44,7 +43,6 @@ def test_dataset(): dataset = datasets.create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -54,7 +52,6 @@ def test_dataset(): # Clean up datasets.delete_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -64,7 +61,6 @@ def test_dataset(): def test_dicom_store(): dicom_store = dicom_stores.create_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -75,7 +71,6 @@ def test_dicom_store(): # Clean up dicom_stores.delete_dicom_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, From 8431b8b290804dc519c9700aeae22ea5cbc9c950 Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Fri, 26 Apr 2019 15:05:34 -0700 Subject: [PATCH 3/4] Updated fhir samples to remove api keys --- healthcare/api-client/fhir/README.rst.in | 1 - .../api-client/fhir/fhir_resources_test.py | 5 --- healthcare/api-client/fhir/fhir_stores.py | 45 +++++-------------- .../api-client/fhir/fhir_stores_test.py | 20 --------- 4 files changed, 11 insertions(+), 60 deletions(-) diff --git a/healthcare/api-client/fhir/README.rst.in b/healthcare/api-client/fhir/README.rst.in index 8bdf368125c..cf756a4be8e 100644 --- a/healthcare/api-client/fhir/README.rst.in +++ b/healthcare/api-client/fhir/README.rst.in @@ -16,7 +16,6 @@ product: setup: - auth -- auth_api_key - install_deps samples: diff --git a/healthcare/api-client/fhir/fhir_resources_test.py b/healthcare/api-client/fhir/fhir_resources_test.py index 4ac3c874091..e18afce74bb 100644 --- a/healthcare/api-client/fhir/fhir_resources_test.py +++ b/healthcare/api-client/fhir/fhir_resources_test.py @@ -24,7 +24,6 @@ import fhir_resources cloud_region = 'us-central1' -api_key = os.environ['API_KEY'] base_url = 'https://healthcare.googleapis.com/v1beta1' project_id = os.environ['GOOGLE_CLOUD_PROJECT'] service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS'] @@ -38,7 +37,6 @@ def test_dataset(): dataset = datasets.create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -48,7 +46,6 @@ def test_dataset(): # Clean up datasets.delete_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -58,7 +55,6 @@ def test_dataset(): def test_fhir_store(): fhir_store = fhir_stores.create_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -68,7 +64,6 @@ def test_fhir_store(): fhir_stores.delete_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, diff --git a/healthcare/api-client/fhir/fhir_stores.py b/healthcare/api-client/fhir/fhir_stores.py index 3624b37b053..2caf2582da2 100644 --- a/healthcare/api-client/fhir/fhir_stores.py +++ b/healthcare/api-client/fhir/fhir_stores.py @@ -21,7 +21,7 @@ # [START healthcare_get_client] -def get_client(service_account_json, api_key): +def get_client(service_account_json): """Returns an authorized API client by discovering the Healthcare API and creating a service object using the service account credentials JSON.""" api_scopes = ['https://www.googleapis.com/auth/cloud-platform'] @@ -34,7 +34,7 @@ def get_client(service_account_json, api_key): scoped_credentials = credentials.with_scopes(api_scopes) discovery_url = '{}?labels=CHC_BETA&version={}&key={}'.format( - discovery_api, api_version, api_key) + discovery_api, api_version) return discovery.build( service_name, @@ -47,13 +47,12 @@ def get_client(service_account_json, api_key): # [START healthcare_create_fhir_store] def create_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, fhir_store_id): """Creates a new FHIR store within the parent dataset.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) @@ -75,13 +74,12 @@ def create_fhir_store( # [START healthcare_delete_fhir_store] def delete_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, fhir_store_id): """Deletes the specified FHIR store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) fhir_store_name = '{}/fhirStores/{}'.format( @@ -103,13 +101,12 @@ def delete_fhir_store( # [START healthcare_get_fhir_store] def get_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, fhir_store_id): """Gets the specified FHIR store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) fhir_store_name = '{}/fhirStores/{}'.format( @@ -136,12 +133,11 @@ def get_fhir_store( # [START healthcare_list_fhir_stores] def list_fhir_stores( service_account_json, - api_key, project_id, cloud_region, dataset_id): """Lists the FHIR stores in the given dataset.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) @@ -166,14 +162,13 @@ def list_fhir_stores( # [START healthcare_patch_fhir_store] def patch_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, fhir_store_id, pubsub_topic): """Updates the FHIR store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) fhir_store_name = '{}/fhirStores/{}'.format( @@ -205,7 +200,6 @@ def patch_fhir_store( # [START healthcare_export_fhir_store_gcs] def export_fhir_store_gcs( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -213,7 +207,7 @@ def export_fhir_store_gcs( gcs_uri): """Export resources to a Google Cloud Storage bucket by copying them from the FHIR store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) fhir_store_name = '{}/fhirStores/{}'.format( @@ -241,7 +235,6 @@ def export_fhir_store_gcs( # [START healthcare_import_fhir_store] def import_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -250,7 +243,7 @@ def import_fhir_store( """Import resources into the FHIR store by copying them from the specified source. """ - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) fhir_store_name = '{}/fhirStores/{}'.format( @@ -281,13 +274,12 @@ def import_fhir_store( # [START healthcare_get_iam_policy] def get_fhir_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, fhir_store_id): """Gets the IAM policy for the specified FHIR store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) fhir_store_name = '{}/fhirStores/{}'.format( @@ -305,7 +297,6 @@ def get_fhir_store_iam_policy( # [START healthcare_set_iam_policy] def set_fhir_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -328,7 +319,7 @@ def set_fhir_store_iam_policy( A role can be any IAM role, such as 'roles/viewer', 'roles/owner', or 'roles/editor' """ - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) fhir_store_name = '{}/fhirStores/{}'.format( @@ -370,11 +361,6 @@ def parse_command_line_args(): default=os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"), help='Path to service account JSON file.') - parser.add_argument( - '--api_key', - default=os.environ.get("API_KEY"), - help='Your API key.') - parser.add_argument( '--project_id', default=os.environ.get("GOOGLE_CLOUD_PROJECT"), @@ -451,7 +437,6 @@ def run_command(args): elif args.command == 'create-fhir-store': create_fhir_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -460,7 +445,6 @@ def run_command(args): elif args.command == 'delete-fhir-store': delete_fhir_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -469,7 +453,6 @@ def run_command(args): elif args.command == 'get-fhir-store': get_fhir_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -478,7 +461,6 @@ def run_command(args): elif args.command == 'list-fhir-stores': list_fhir_stores( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id) @@ -486,7 +468,6 @@ def run_command(args): elif args.command == 'patch-fhir-store': patch_fhir_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -496,7 +477,6 @@ def run_command(args): elif args.command == 'export-fhir-store-gcs': export_fhir_store_gcs( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -506,7 +486,6 @@ def run_command(args): elif args.command == 'import-fhir-store': import_fhir_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -516,7 +495,6 @@ def run_command(args): elif args.command == 'get_iam_policy': get_fhir_store_iam_policy( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -525,7 +503,6 @@ def run_command(args): elif args.command == 'set_iam_policy': set_fhir_store_iam_policy( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, diff --git a/healthcare/api-client/fhir/fhir_stores_test.py b/healthcare/api-client/fhir/fhir_stores_test.py index f23307e9068..a8aae5e7fc9 100644 --- a/healthcare/api-client/fhir/fhir_stores_test.py +++ b/healthcare/api-client/fhir/fhir_stores_test.py @@ -25,7 +25,6 @@ import fhir_stores cloud_region = 'us-central1' -api_key = os.environ['API_KEY'] project_id = os.environ['GOOGLE_CLOUD_PROJECT'] service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS'] @@ -44,7 +43,6 @@ def test_dataset(): dataset = datasets.create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -54,7 +52,6 @@ def test_dataset(): # Clean up datasets.delete_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -63,7 +60,6 @@ def test_dataset(): def test_CRUD_fhir_store(test_dataset, capsys): fhir_stores.create_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -71,7 +67,6 @@ def test_CRUD_fhir_store(test_dataset, capsys): fhir_stores.get_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -79,14 +74,12 @@ def test_CRUD_fhir_store(test_dataset, capsys): fhir_stores.list_fhir_stores( service_account_json, - api_key, project_id, cloud_region, dataset_id) fhir_stores.delete_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -104,7 +97,6 @@ def test_CRUD_fhir_store(test_dataset, capsys): def test_patch_fhir_store(test_dataset, capsys): fhir_stores.create_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -112,7 +104,6 @@ def test_patch_fhir_store(test_dataset, capsys): fhir_stores.patch_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -122,7 +113,6 @@ def test_patch_fhir_store(test_dataset, capsys): # Clean up fhir_stores.delete_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -136,7 +126,6 @@ def test_patch_fhir_store(test_dataset, capsys): def test_import_fhir_store_gcs(test_dataset, capsys): fhir_stores.create_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -151,7 +140,6 @@ def test_import_fhir_store_gcs(test_dataset, capsys): time.sleep(5) # Give new blob time to propagate fhir_stores.import_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -163,7 +151,6 @@ def test_import_fhir_store_gcs(test_dataset, capsys): fhir_stores.delete_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -177,7 +164,6 @@ def test_import_fhir_store_gcs(test_dataset, capsys): def test_export_fhir_store_gcs(test_dataset, capsys): fhir_stores.create_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -185,7 +171,6 @@ def test_export_fhir_store_gcs(test_dataset, capsys): fhir_stores.export_fhir_store_gcs( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -195,7 +180,6 @@ def test_export_fhir_store_gcs(test_dataset, capsys): # Clean up fhir_stores.delete_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -209,7 +193,6 @@ def test_export_fhir_store_gcs(test_dataset, capsys): def test_get_set_fhir_store_iam_policy(test_dataset, capsys): fhir_stores.create_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -217,7 +200,6 @@ def test_get_set_fhir_store_iam_policy(test_dataset, capsys): get_response = fhir_stores.get_fhir_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -225,7 +207,6 @@ def test_get_set_fhir_store_iam_policy(test_dataset, capsys): set_response = fhir_stores.set_fhir_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -236,7 +217,6 @@ def test_get_set_fhir_store_iam_policy(test_dataset, capsys): # Clean up fhir_stores.delete_fhir_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, From cfdcd60a597f86dc1b656b461897edf6b269c6b7 Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Fri, 26 Apr 2019 15:36:16 -0700 Subject: [PATCH 4/4] Updated all samples to remove api keys --- healthcare/api-client/fhir/fhir_stores.py | 16 ++---- .../api-client/fhir/fhir_stores_test.py | 4 +- healthcare/api-client/hl7v2/README.rst.in | 1 - healthcare/api-client/hl7v2/hl7v2_messages.py | 35 ++++-------- .../api-client/hl7v2/hl7v2_messages_test.py | 17 ------ healthcare/api-client/hl7v2/hl7v2_stores.py | 54 ++++++------------- .../api-client/hl7v2/hl7v2_stores_test.py | 18 +------ 7 files changed, 31 insertions(+), 114 deletions(-) diff --git a/healthcare/api-client/fhir/fhir_stores.py b/healthcare/api-client/fhir/fhir_stores.py index 2caf2582da2..25ec8aa337b 100644 --- a/healthcare/api-client/fhir/fhir_stores.py +++ b/healthcare/api-client/fhir/fhir_stores.py @@ -33,7 +33,7 @@ def get_client(service_account_json): service_account_json) scoped_credentials = credentials.with_scopes(api_scopes) - discovery_url = '{}?labels=CHC_BETA&version={}&key={}'.format( + discovery_url = '{}?labels=CHC_BETA&version={}'.format( discovery_api, api_version) return discovery.build( @@ -165,8 +165,7 @@ def patch_fhir_store( project_id, cloud_region, dataset_id, - fhir_store_id, - pubsub_topic): + fhir_store_id): """Updates the FHIR store.""" client = get_client(service_account_json) fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( @@ -175,11 +174,7 @@ def patch_fhir_store( fhir_store_parent, fhir_store_id) patch = { - 'notificationConfig': { - 'pubsubTopic': 'projects/{}/locations/{}/topics/{}'.format( - project_id, - cloud_region, - pubsub_topic)}} + 'notificationConfig': None} request = client.projects().locations().datasets().fhirStores().patch( name=fhir_store_name, updateMask='notificationConfig', body=patch) @@ -187,9 +182,8 @@ def patch_fhir_store( try: response = request.execute() print( - 'Patched FHIR store {} with Cloud Pub/Sub topic: {}'.format( - fhir_store_id, - pubsub_topic)) + 'Patched FHIR store {} with Cloud Pub/Sub topic: None'.format( + fhir_store_id)) return response except HttpError as e: print('Error, FHIR store not patched: {}'.format(e)) diff --git a/healthcare/api-client/fhir/fhir_stores_test.py b/healthcare/api-client/fhir/fhir_stores_test.py index a8aae5e7fc9..f2fbda0a920 100644 --- a/healthcare/api-client/fhir/fhir_stores_test.py +++ b/healthcare/api-client/fhir/fhir_stores_test.py @@ -30,7 +30,6 @@ dataset_id = 'test_dataset_{}'.format(int(time.time())) fhir_store_id = 'test_fhir_store-{}'.format(int(time.time())) -pubsub_topic = 'test_pubsub_topic-{}'.format(int(time.time())) gcs_uri = os.environ['CLOUD_STORAGE_BUCKET'] RESOURCES = os.path.join(os.path.dirname(__file__), 'resources') @@ -107,8 +106,7 @@ def test_patch_fhir_store(test_dataset, capsys): project_id, cloud_region, dataset_id, - fhir_store_id, - pubsub_topic) + fhir_store_id) # Clean up fhir_stores.delete_fhir_store( diff --git a/healthcare/api-client/hl7v2/README.rst.in b/healthcare/api-client/hl7v2/README.rst.in index 655532ecca0..dc8dc117cf6 100644 --- a/healthcare/api-client/hl7v2/README.rst.in +++ b/healthcare/api-client/hl7v2/README.rst.in @@ -16,7 +16,6 @@ product: setup: - auth -- auth_api_key - install_deps samples: diff --git a/healthcare/api-client/hl7v2/hl7v2_messages.py b/healthcare/api-client/hl7v2/hl7v2_messages.py index a40b92e2823..603edf3c302 100644 --- a/healthcare/api-client/hl7v2/hl7v2_messages.py +++ b/healthcare/api-client/hl7v2/hl7v2_messages.py @@ -22,7 +22,7 @@ # [START healthcare_get_client] -def get_client(service_account_json, api_key): +def get_client(service_account_json): """Returns an authorized API client by discovering the Healthcare API and creating a service object using the service account credentials JSON.""" api_scopes = ['https://www.googleapis.com/auth/cloud-platform'] @@ -34,8 +34,8 @@ def get_client(service_account_json, api_key): service_account_json) scoped_credentials = credentials.with_scopes(api_scopes) - discovery_url = '{}?labels=CHC_BETA&version={}&key={}'.format( - discovery_api, api_version, api_key) + discovery_url = '{}?labels=CHC_BETA&version={}'.format( + discovery_api, api_version) return discovery.build( service_name, @@ -48,7 +48,6 @@ def get_client(service_account_json, api_key): # [START healthcare_create_hl7v2_message] def create_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -57,7 +56,7 @@ def create_hl7v2_message( """Creates an HL7v2 message and sends a notification to the Cloud Pub/Sub topic. """ - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_parent = 'projects/{}/locations/{}'.format(project_id, cloud_region) hl7v2_store_name = '{}/datasets/{}/hl7V2Stores/{}'.format( hl7v2_parent, dataset_id, hl7v2_store_id) @@ -81,14 +80,13 @@ def create_hl7v2_message( # [START healthcare_delete_hl7v2_message] def delete_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id): """Deletes an HL7v2 message.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_parent = 'projects/{}/locations/{}'.format(project_id, cloud_region) hl7v2_message = '{}/datasets/{}/hl7V2Stores/{}/messages/{}'.format( hl7v2_parent, dataset_id, hl7v2_store_id, hl7v2_message_id) @@ -109,14 +107,13 @@ def delete_hl7v2_message( # [START healthcare_get_hl7v2_message] def get_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id): """Gets an HL7v2 message.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_parent = 'projects/{}/locations/{}'.format(project_id, cloud_region) hl7v2_message_name = '{}/datasets/{}/hl7V2Stores/{}/messages/{}'.format( hl7v2_parent, dataset_id, hl7v2_store_id, hl7v2_message_id) @@ -145,7 +142,6 @@ def get_hl7v2_message( # [START healthcare_ingest_hl7v2_message] def ingest_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -155,7 +151,7 @@ def ingest_hl7v2_message( to the Cloud Pub/Sub topic. Return is an HL7v2 ACK message if the message was successfully stored. """ - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_parent = 'projects/{}/locations/{}'.format(project_id, cloud_region) hl7v2_store_name = '{}/datasets/{}/hl7V2Stores/{}'.format( hl7v2_parent, dataset_id, hl7v2_store_id) @@ -180,7 +176,6 @@ def ingest_hl7v2_message( # [START healthcare_list_hl7v2_messages] def list_hl7v2_messages( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -188,7 +183,7 @@ def list_hl7v2_messages( """Lists all the messages in the given HL7v2 store with support for filtering. """ - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_messages_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) hl7v2_message_path = '{}/hl7V2Stores/{}'.format( @@ -207,7 +202,6 @@ def list_hl7v2_messages( # [START healthcare_patch_hl7v2_message] def patch_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -216,7 +210,7 @@ def patch_hl7v2_message( label_key, label_value): """Updates the message.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_message_parent = 'projects/{}/locations/{}'.format( project_id, cloud_region, dataset_id, hl7v2_store_id) hl7v2_message_name = '{}/datasets/{}/hl7V2Stores/{}/messages/{}'.format( @@ -257,11 +251,6 @@ def parse_command_line_args(): default=os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"), help='Path to service account JSON file.') - parser.add_argument( - '--api_key', - default=os.environ.get("API_KEY"), - help='Your API key.') - parser.add_argument( '--project_id', default=os.environ.get("GOOGLE_CLOUD_PROJECT"), @@ -335,7 +324,6 @@ def run_command(args): elif args.command == 'create-hl7v2-message': create_hl7v2_message( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -345,7 +333,6 @@ def run_command(args): elif args.command == 'delete-hl7v2-message': delete_hl7v2_message( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -355,7 +342,6 @@ def run_command(args): elif args.command == 'get-hl7v2-message': get_hl7v2_message( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -365,7 +351,6 @@ def run_command(args): elif args.command == 'ingest-hl7v2-message': ingest_hl7v2_message( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -375,7 +360,6 @@ def run_command(args): elif args.command == 'list-hl7v2-messages': list_hl7v2_messages( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -384,7 +368,6 @@ def run_command(args): elif args.command == 'patch-hl7v2-message': patch_hl7v2_message( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, diff --git a/healthcare/api-client/hl7v2/hl7v2_messages_test.py b/healthcare/api-client/hl7v2/hl7v2_messages_test.py index 505a96816af..efc3c3cbd05 100644 --- a/healthcare/api-client/hl7v2/hl7v2_messages_test.py +++ b/healthcare/api-client/hl7v2/hl7v2_messages_test.py @@ -25,7 +25,6 @@ import hl7v2_messages cloud_region = 'us-central1' -api_key = os.environ['API_KEY'] project_id = os.environ['GOOGLE_CLOUD_PROJECT'] service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS'] @@ -40,7 +39,6 @@ def test_dataset(): dataset = datasets.create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -50,7 +48,6 @@ def test_dataset(): # Clean up datasets.delete_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -60,7 +57,6 @@ def test_dataset(): def test_hl7v2_store(): hl7v2_store = hl7v2_stores.create_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -70,7 +66,6 @@ def test_hl7v2_store(): hl7v2_stores.delete_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -80,7 +75,6 @@ def test_hl7v2_store(): def test_CRUD_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.create_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -89,7 +83,6 @@ def test_CRUD_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -100,7 +93,6 @@ def test_CRUD_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.get_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -109,7 +101,6 @@ def test_CRUD_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.delete_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -127,7 +118,6 @@ def test_CRUD_hl7v2_message(test_dataset, test_hl7v2_store, capsys): def test_ingest_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.ingest_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -136,7 +126,6 @@ def test_ingest_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -147,7 +136,6 @@ def test_ingest_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.get_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -156,7 +144,6 @@ def test_ingest_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.delete_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -174,7 +161,6 @@ def test_ingest_hl7v2_message(test_dataset, test_hl7v2_store, capsys): def test_patch_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.create_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -183,7 +169,6 @@ def test_patch_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -194,7 +179,6 @@ def test_patch_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.patch_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -205,7 +189,6 @@ def test_patch_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.delete_hl7v2_message( service_account_json, - api_key, project_id, cloud_region, dataset_id, diff --git a/healthcare/api-client/hl7v2/hl7v2_stores.py b/healthcare/api-client/hl7v2/hl7v2_stores.py index aa34f36f617..9bdb7a0e28a 100644 --- a/healthcare/api-client/hl7v2/hl7v2_stores.py +++ b/healthcare/api-client/hl7v2/hl7v2_stores.py @@ -21,7 +21,7 @@ # [START healthcare_get_client] -def get_client(service_account_json, api_key): +def get_client(service_account_json): """Returns an authorized API client by discovering the Healthcare API and creating a service object using the service account credentials JSON.""" api_scopes = ['https://www.googleapis.com/auth/cloud-platform'] @@ -33,8 +33,8 @@ def get_client(service_account_json, api_key): service_account_json) scoped_credentials = credentials.with_scopes(api_scopes) - discovery_url = '{}?labels=CHC_BETA&version={}&key={}'.format( - discovery_api, api_version, api_key) + discovery_url = '{}?labels=CHC_BETA&version={}'.format( + discovery_api, api_version) return discovery.build( service_name, @@ -47,13 +47,12 @@ def get_client(service_account_json, api_key): # [START healthcare_create_hl7v2_store] def create_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, hl7v2_store_id): """Creates a new HL7v2 store within the parent dataset.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) @@ -75,13 +74,12 @@ def create_hl7v2_store( # [START healthcare_delete_hl7v2_store] def delete_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, hl7v2_store_id): """Deletes the specified HL7v2 store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) hl7v2_store_name = '{}/hl7V2Stores/{}'.format( @@ -103,13 +101,12 @@ def delete_hl7v2_store( # [START healthcare_get_hl7v2_store] def get_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, hl7v2_store_id): """Gets the specified HL7v2 store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) hl7v2_store_name = '{}/hl7V2Stores/{}'.format( @@ -132,12 +129,11 @@ def get_hl7v2_store( # [START healthcare_list_hl7v2_stores] def list_hl7v2_stores( service_account_json, - api_key, project_id, cloud_region, dataset_id): """Lists the HL7v2 stores in the given dataset.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) @@ -158,25 +154,20 @@ def list_hl7v2_stores( # [START healthcare_patch_hl7v2_store] def patch_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, - hl7v2_store_id, - pubsub_topic): + hl7v2_store_id): """Updates the HL7v2 store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) hl7v2_store_name = '{}/hl7V2Stores/{}'.format( hl7v2_store_parent, hl7v2_store_id) patch = { - 'notificationConfig': { - 'pubsubTopic': 'projects/{}/locations/{}/topics/{}'.format( - project_id, - cloud_region, - pubsub_topic)}} + 'notificationConfig': None + } request = client.projects().locations().datasets().hl7V2Stores().patch( name=hl7v2_store_name, updateMask='notificationConfig', body=patch) @@ -184,9 +175,8 @@ def patch_hl7v2_store( try: response = request.execute() print( - 'Patched HL7v2 store {} with Cloud Pub/Sub topic: {}'.format( - hl7v2_store_id, - pubsub_topic)) + 'Patched HL7v2 store {} with Cloud Pub/Sub topic: None'.format( + hl7v2_store_id)) return response except HttpError as e: print('Error, HL7v2 store not patched: {}'.format(e)) @@ -197,13 +187,12 @@ def patch_hl7v2_store( # [START healthcare_hl7v2_store_get_iam_policy] def get_hl7v2_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, hl7v2_store_id): """Gets the IAM policy for the specified hl7v2 store.""" - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) hl7v2_store_name = '{}/hl7V2Stores/{}'.format( @@ -221,7 +210,6 @@ def get_hl7v2_store_iam_policy( # [START healthcare_hl7v2_store_set_iam_policy] def set_hl7v2_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -244,7 +232,7 @@ def set_hl7v2_store_iam_policy( A role can be any IAM role, such as 'roles/viewer', 'roles/owner', or 'roles/editor' """ - client = get_client(service_account_json, api_key) + client = get_client(service_account_json) hl7v2_store_parent = 'projects/{}/locations/{}/datasets/{}'.format( project_id, cloud_region, dataset_id) hl7v2_store_name = '{}/hl7V2Stores/{}'.format( @@ -286,11 +274,6 @@ def parse_command_line_args(): default=os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"), help='Path to service account JSON file.') - parser.add_argument( - '--api_key', - default=os.environ.get("API_KEY"), - help='Your API key.') - parser.add_argument( '--project_id', default=os.environ.get("GOOGLE_CLOUD_PROJECT"), @@ -354,7 +337,6 @@ def run_command(args): elif args.command == 'create-hl7v2-store': create_hl7v2_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -363,7 +345,6 @@ def run_command(args): elif args.command == 'delete-hl7v2-store': delete_hl7v2_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -372,7 +353,6 @@ def run_command(args): elif args.command == 'get-hl7v2-store': get_hl7v2_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -381,7 +361,6 @@ def run_command(args): elif args.command == 'list-hl7v2-stores': list_hl7v2_stores( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id) @@ -389,7 +368,6 @@ def run_command(args): elif args.command == 'patch-hl7v2-store': patch_hl7v2_store( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -399,7 +377,6 @@ def run_command(args): elif args.command == 'get_hl7v2_store_iam_policy': get_hl7v2_store_iam_policy( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, @@ -408,7 +385,6 @@ def run_command(args): elif args.command == 'set_hl7v2_store_iam_policy': set_hl7v2_store_iam_policy( args.service_account_json, - args.api_key, args.project_id, args.cloud_region, args.dataset_id, diff --git a/healthcare/api-client/hl7v2/hl7v2_stores_test.py b/healthcare/api-client/hl7v2/hl7v2_stores_test.py index ab59ae1aa7b..c8295d21d0a 100644 --- a/healthcare/api-client/hl7v2/hl7v2_stores_test.py +++ b/healthcare/api-client/hl7v2/hl7v2_stores_test.py @@ -23,20 +23,17 @@ import hl7v2_stores cloud_region = 'us-central1' -api_key = os.environ['API_KEY'] project_id = os.environ['GOOGLE_CLOUD_PROJECT'] service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS'] dataset_id = 'test_dataset_{}'.format(int(time.time())) hl7v2_store_id = 'test_hl7v2_store-{}'.format(int(time.time())) -pubsub_topic = 'test_pubsub_topic-{}'.format(int(time.time())) @pytest.fixture(scope='module') def test_dataset(): dataset = datasets.create_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -46,7 +43,6 @@ def test_dataset(): # Clean up datasets.delete_dataset( service_account_json, - api_key, project_id, cloud_region, dataset_id) @@ -55,7 +51,6 @@ def test_dataset(): def test_CRUD_hl7v2_store(test_dataset, capsys): hl7v2_stores.create_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -63,7 +58,6 @@ def test_CRUD_hl7v2_store(test_dataset, capsys): hl7v2_stores.get_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -71,14 +65,12 @@ def test_CRUD_hl7v2_store(test_dataset, capsys): hl7v2_stores.list_hl7v2_stores( service_account_json, - api_key, project_id, cloud_region, dataset_id) hl7v2_stores.delete_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -96,7 +88,6 @@ def test_CRUD_hl7v2_store(test_dataset, capsys): def test_patch_hl7v2_store(test_dataset, capsys): hl7v2_stores.create_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -104,17 +95,14 @@ def test_patch_hl7v2_store(test_dataset, capsys): hl7v2_stores.patch_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, - hl7v2_store_id, - pubsub_topic) + hl7v2_store_id) # Clean up hl7v2_stores.delete_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -128,7 +116,6 @@ def test_patch_hl7v2_store(test_dataset, capsys): def test_get_set_hl7v2_store_iam_policy(test_dataset, capsys): hl7v2_stores.create_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -136,7 +123,6 @@ def test_get_set_hl7v2_store_iam_policy(test_dataset, capsys): get_response = hl7v2_stores.get_hl7v2_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -144,7 +130,6 @@ def test_get_set_hl7v2_store_iam_policy(test_dataset, capsys): set_response = hl7v2_stores.set_hl7v2_store_iam_policy( service_account_json, - api_key, project_id, cloud_region, dataset_id, @@ -155,7 +140,6 @@ def test_get_set_hl7v2_store_iam_policy(test_dataset, capsys): # Clean up hl7v2_stores.delete_hl7v2_store( service_account_json, - api_key, project_id, cloud_region, dataset_id,