Skip to content
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
1 change: 0 additions & 1 deletion healthcare/api-client/datasets/README.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ product:

setup:
- auth
- auth_api_key
- install_deps

samples:
Expand Down
44 changes: 12 additions & 32 deletions healthcare/api-client/datasets/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -395,38 +383,33 @@ 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)

elif args.command == 'delete-dataset':
delete_dataset(
args.service_account_json,
args.api_key,
args.project_id,
args.cloud_region,
args.dataset_id)

elif args.command == 'get-dataset':
get_dataset(
args.service_account_json,
args.api_key,
args.project_id,
args.cloud_region,
args.dataset_id)

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,
Expand All @@ -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,
Expand All @@ -445,15 +427,13 @@ 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)

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,
Expand Down
21 changes: 5 additions & 16 deletions healthcare/api-client/datasets/datasets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand All @@ -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()

Expand All @@ -58,22 +56,20 @@ 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,
time_zone)

# 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()

Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion healthcare/api-client/dicom/README.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ product:

setup:
- auth
- auth_api_key
- install_deps

samples:
Expand Down
Loading