21
21
22
22
23
23
# [START healthcare_get_client]
24
- def get_client (service_account_json , api_key ):
24
+ def get_client (service_account_json ):
25
25
"""Returns an authorized API client by discovering the Healthcare API and
26
26
creating a service object using the service account credentials JSON."""
27
27
api_scopes = ['https://www.googleapis.com/auth/cloud-platform' ]
@@ -33,8 +33,8 @@ def get_client(service_account_json, api_key):
33
33
service_account_json )
34
34
scoped_credentials = credentials .with_scopes (api_scopes )
35
35
36
- discovery_url = '{}?labels=CHC_BETA&version={}&key={} ' .format (
37
- discovery_api , api_version , api_key )
36
+ discovery_url = '{}?labels=CHC_BETA&version={}' .format (
37
+ discovery_api , api_version )
38
38
39
39
return discovery .build (
40
40
service_name ,
@@ -47,12 +47,11 @@ def get_client(service_account_json, api_key):
47
47
# [START healthcare_create_dataset]
48
48
def create_dataset (
49
49
service_account_json ,
50
- api_key ,
51
50
project_id ,
52
51
cloud_region ,
53
52
dataset_id ):
54
53
"""Creates a dataset."""
55
- client = get_client (service_account_json , api_key )
54
+ client = get_client (service_account_json )
56
55
dataset_parent = 'projects/{}/locations/{}' .format (
57
56
project_id , cloud_region )
58
57
@@ -74,12 +73,11 @@ def create_dataset(
74
73
# [START healthcare_delete_dataset]
75
74
def delete_dataset (
76
75
service_account_json ,
77
- api_key ,
78
76
project_id ,
79
77
cloud_region ,
80
78
dataset_id ):
81
79
"""Deletes a dataset."""
82
- client = get_client (service_account_json , api_key )
80
+ client = get_client (service_account_json )
83
81
dataset_name = 'projects/{}/locations/{}/datasets/{}' .format (
84
82
project_id , cloud_region , dataset_id )
85
83
@@ -99,12 +97,11 @@ def delete_dataset(
99
97
# [START healthcare_get_dataset]
100
98
def get_dataset (
101
99
service_account_json ,
102
- api_key ,
103
100
project_id ,
104
101
cloud_region ,
105
102
dataset_id ):
106
103
"""Gets any metadata associated with a dataset."""
107
- client = get_client (service_account_json , api_key )
104
+ client = get_client (service_account_json )
108
105
dataset_name = 'projects/{}/locations/{}/datasets/{}' .format (
109
106
project_id , cloud_region , dataset_id )
110
107
@@ -119,9 +116,9 @@ def get_dataset(
119
116
120
117
121
118
# [START healthcare_list_datasets]
122
- def list_datasets (service_account_json , api_key , project_id , cloud_region ):
119
+ def list_datasets (service_account_json , project_id , cloud_region ):
123
120
"""Lists the datasets in the project."""
124
- client = get_client (service_account_json , api_key )
121
+ client = get_client (service_account_json )
125
122
dataset_parent = 'projects/{}/locations/{}' .format (
126
123
project_id , cloud_region )
127
124
@@ -141,13 +138,12 @@ def list_datasets(service_account_json, api_key, project_id, cloud_region):
141
138
# [START healthcare_patch_dataset]
142
139
def patch_dataset (
143
140
service_account_json ,
144
- api_key ,
145
141
project_id ,
146
142
cloud_region ,
147
143
dataset_id ,
148
144
time_zone ):
149
145
"""Updates dataset metadata."""
150
- client = get_client (service_account_json , api_key )
146
+ client = get_client (service_account_json )
151
147
dataset_parent = 'projects/{}/locations/{}' .format (
152
148
project_id , cloud_region )
153
149
dataset_name = '{}/datasets/{}' .format (dataset_parent , dataset_id )
@@ -176,7 +172,6 @@ def patch_dataset(
176
172
# [START healthcare_deidentify_dataset]
177
173
def deidentify_dataset (
178
174
service_account_json ,
179
- api_key ,
180
175
project_id ,
181
176
cloud_region ,
182
177
dataset_id ,
@@ -185,7 +180,7 @@ def deidentify_dataset(
185
180
"""Creates a new dataset containing de-identified data
186
181
from the source dataset.
187
182
"""
188
- client = get_client (service_account_json , api_key )
183
+ client = get_client (service_account_json )
189
184
source_dataset = 'projects/{}/locations/{}/datasets/{}' .format (
190
185
project_id , cloud_region , dataset_id )
191
186
destination_dataset = 'projects/{}/locations/{}/datasets/{}' .format (
@@ -240,12 +235,11 @@ def deidentify_dataset(
240
235
# [START healthcare_dataset_get_iam_policy]
241
236
def get_dataset_iam_policy (
242
237
service_account_json ,
243
- api_key ,
244
238
project_id ,
245
239
cloud_region ,
246
240
dataset_id ):
247
241
"""Gets the IAM policy for the specified dataset."""
248
- client = get_client (service_account_json , api_key )
242
+ client = get_client (service_account_json )
249
243
dataset_name = 'projects/{}/locations/{}/datasets/{}' .format (
250
244
project_id , cloud_region , dataset_id )
251
245
@@ -261,7 +255,6 @@ def get_dataset_iam_policy(
261
255
# [START healthcare_dataset_set_iam_policy]
262
256
def set_dataset_iam_policy (
263
257
service_account_json ,
264
- api_key ,
265
258
project_id ,
266
259
cloud_region ,
267
260
dataset_id ,
@@ -283,7 +276,7 @@ def set_dataset_iam_policy(
283
276
A role can be any IAM role, such as 'roles/viewer', 'roles/owner',
284
277
or 'roles/editor'
285
278
"""
286
- client = get_client (service_account_json , api_key )
279
+ client = get_client (service_account_json )
287
280
dataset_name = 'projects/{}/locations/{}/datasets/{}' .format (
288
281
project_id , cloud_region , dataset_id )
289
282
@@ -323,11 +316,6 @@ def parse_command_line_args():
323
316
default = os .environ .get ("GOOGLE_APPLICATION_CREDENTIALS" ),
324
317
help = 'Path to service account JSON file.' )
325
318
326
- parser .add_argument (
327
- '--api_key' ,
328
- default = os .environ .get ("API_KEY" ),
329
- help = 'Your API key.' )
330
-
331
319
parser .add_argument (
332
320
'--project_id' ,
333
321
default = os .environ .get ("GOOGLE_CLOUD_PROJECT" ),
@@ -395,38 +383,33 @@ def run_command(args):
395
383
elif args .command == 'create-dataset' :
396
384
create_dataset (
397
385
args .service_account_json ,
398
- args .api_key ,
399
386
args .project_id ,
400
387
args .cloud_region ,
401
388
args .dataset_id )
402
389
403
390
elif args .command == 'delete-dataset' :
404
391
delete_dataset (
405
392
args .service_account_json ,
406
- args .api_key ,
407
393
args .project_id ,
408
394
args .cloud_region ,
409
395
args .dataset_id )
410
396
411
397
elif args .command == 'get-dataset' :
412
398
get_dataset (
413
399
args .service_account_json ,
414
- args .api_key ,
415
400
args .project_id ,
416
401
args .cloud_region ,
417
402
args .dataset_id )
418
403
419
404
elif args .command == 'list-datasets' :
420
405
list_datasets (
421
406
args .service_account_json ,
422
- args .api_key ,
423
407
args .project_id ,
424
408
args .cloud_region )
425
409
426
410
elif args .command == 'patch-dataset' :
427
411
patch_dataset (
428
412
args .service_account_json ,
429
- args .api_key ,
430
413
args .project_id ,
431
414
args .cloud_region ,
432
415
args .dataset_id ,
@@ -435,7 +418,6 @@ def run_command(args):
435
418
elif args .command == 'deidentify-dataset' :
436
419
deidentify_dataset (
437
420
args .service_account_json ,
438
- args .api_key ,
439
421
args .project_id ,
440
422
args .cloud_region ,
441
423
args .dataset_id ,
@@ -445,15 +427,13 @@ def run_command(args):
445
427
elif args .command == 'get_iam_policy' :
446
428
get_dataset_iam_policy (
447
429
args .service_account_json ,
448
- args .api_key ,
449
430
args .project_id ,
450
431
args .cloud_region ,
451
432
args .dataset_id )
452
433
453
434
elif args .command == 'set_iam_policy' :
454
435
set_dataset_iam_policy (
455
436
args .service_account_json ,
456
- args .api_key ,
457
437
args .project_id ,
458
438
args .cloud_region ,
459
439
args .dataset_id ,
0 commit comments