8000 Updated dicom samples to remove api keys · dougc333/python-docs-samples@3fa8238 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3fa8238

Browse files
committed
Updated dicom samples to remove api keys
1 parent e47a309 commit 3fa8238

File tree

4 files changed

+12
-61
lines changed

4 files changed

+12
-61
lines changed

healthcare/api-client/dicom/README.rst.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ product:
1616

1717
setup:
1818
- auth
19-
- auth_api_key
2019
- install_deps
2120

2221
samples:

healthcare/api-client/dicom/dicom_stores.py

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
# [START healthcare_get_client]
24-
def get_client(service_account_json, api_key):
24+
def get_client(service_account_json):
2525
"""Returns an authorized API client by discovering the Healthcare API and
2626
creating a service object using the service account credentials JSON."""
2727
api_scopes = ['https://www.googleapis.com/auth/cloud-platform']
@@ -33,8 +33,8 @@ def get_client(service_account_json, api_key):
3333
service_account_json)
3434
scoped_credentials = credentials.with_scopes(api_scopes)
3535

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)
3838

3939
return discovery.build(
4040
service_name,
@@ -48,13 +48,12 @@ def get_client(service_account_json, api_key):
4848
# [START healthcare_create_dicom_store]
4949
def create_dicom_store(
5050
service_account_json,
51-
api_key,
5251
project_id,
5352
cloud_region,
5453
dataset_id,
5554
dicom_store_id):
5655
"""Creates a new DICOM store within the parent dataset."""
57-
client = get_client(service_account_json, api_key)
56+
client = get_client(service_account_json)
5857
dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
5958
project_id, cloud_region, dataset_id)
6059

@@ -76,13 +75,12 @@ def create_dicom_store(
7675
# [START healthcare_delete_dicom_store]
7776
def delete_dicom_store(
7877
service_account_json,
79-
api_key,
8078
project_id,
8179
cloud_region,
8280
dataset_id,
8381
dicom_store_id):
8482
"""Deletes the specified DICOM store."""
85-
client = get_client(service_account_json, api_key)
83+
client = get_client(service_account_json)
8684
dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
8785
project_id, cloud_region, dataset_id)
8886
dicom_store_name = '{}/dicomStores/{}'.format(
@@ -104,13 +102,12 @@ def delete_dicom_store(
104102
# [START healthcare_get_dicom_store]
105103
def get_dicom_store(
106104
service_account_json,
107-
api_key,
108105
project_id,
109106
cloud_region,
110107
dataset_id,
111108
dicom_store_id):
112109
"""Gets the specified DICOM store."""
113-
client = get_client(service_account_json, api_key)
110+
client = get_client(service_account_json)
114111
dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
115112
project_id, cloud_region, dataset_id)
116113
dicom_store_name = '{}/dicomStores/{}'.format(
@@ -133,12 +130,11 @@ def get_dicom_store(
133130
# [START healthcare_list_dicom_stores]
134131
def list_dicom_stores(
135132
service_account_json,
136-
api_key,
137133
project_id,
138134
cloud_region,
139135
dataset_id):
140136
"""Lists the DICOM stores in the given dataset."""
141-
client = get_client(service_account_json, api_key)
137+
client = get_client(service_account_json)
142138
dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
143139
project_id, cloud_region, dataset_id)
144140

@@ -159,14 +155,13 @@ def list_dicom_stores(
159155
# [START healthcare_patch_dicom_store]
160156
def patch_dicom_store(
161157
service_account_json,
162-
api_key,
163158
project_id,
164159
cloud_region,
165160
dataset_id,
166161
dicom_store_id,
167162
pubsub_topic):
168163
"""Updates the DICOM store."""
169-
client = get_client(service_account_json, api_key)
164+
client = get_client(service_account_json)
170165
dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
171166
project_id, cloud_region, dataset_id)
172167
dicom_store_name = '{}/dicomStores/{}'.format(
@@ -198,15 +193,14 @@ def patch_dicom_store(
198193
# [START healthcare_export_dicom_instance]
199194
def export_dicom_instance(
200195
service_account_json,
201-
api_key,
202196
project_id,
203197
cloud_region,
204198
dataset_id,
205199
dicom_store_id,
206200
uri_prefix):
207201
"""Export data to a Google Cloud Storage bucket by copying
208202
it from the DICOM store."""
209-
client = get_client(service_account_json, api_key)
203+
client = get_client(service_account_json)
210204
dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
211205
project_id, cloud_region, dataset_id)
212206
dicom_store_name = '{}/dicomStores/{}'.format(
@@ -234,7 +228,6 @@ def export_dicom_instance(
234228
# [START healthcare_import_dicom_instance]
235229
def import_dicom_instance(
236230
service_account_json,
237-
api_key,
238231
project_id,
239232
cloud_region,
240233
dataset_id,
@@ -243,7 +236,7 @@ def import_dicom_instance(
243236
"""Import data into the DICOM store by copying it from the specified
244237
source.
245238
"""
246-
client = get_client(service_account_json, api_key)
239+
client = get_client(service_account_json)
247240
dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
248241
project_id, cloud_region, dataset_id)
249242
dicom_store_name = '{}/dicomStores/{}'.format(
@@ -273,13 +266,12 @@ def import_dicom_instance(
273266
# [START healthcare_dicom_store_get_iam_policy]
274267
def get_dicom_store_iam_policy(
275268
service_account_json,
276-
api_key,
277269
project_id,
278270
cloud_region,
279271
dataset_id,
280272
dicom_store_id):
281273
"""Gets the IAM policy for the specified dicom store."""
282-
client = get_client(service_account_json, api_key)
274+
client = get_client(service_account_json)
283275
dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
284276
project_id, cloud_region, dataset_id)
285277
dicom_store_name = '{}/dicomStores/{}'.format(
@@ -297,7 +289,6 @@ def get_dicom_store_iam_policy(
297289
# [START healthcare_dicom_store_set_iam_policy]
298290
def set_dicom_store_iam_policy(
299291
service_account_json,
300-
api_key,
301292
project_id,
302293
cloud_region,
303294
dataset_id,
@@ -320,7 +311,7 @@ def set_dicom_store_iam_policy(
320311
A role can be any IAM role, such as 'roles/viewer', 'roles/owner',
321312
or 'roles/editor'
322313
"""
323-
client = get_client(service_account_json, api_key)
314+
client = get_client(service_account_json)
324315
dicom_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
325316
project_id, cloud_region, dataset_id)
326317
dicom_store_name = '{}/dicomStores/{}'.format(
@@ -362,11 +353,6 @@ def parse_command_line_args():
362353
default=os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"),
363354
help='Path to service account JSON file.')
364355

365-
parser.add_argument(
366-
'--api_key',
367-
default=os.environ.get("API_KEY"),
368-
help='Your API key')
369-
370356
parser.add_argument(
371357
'--project_id',
372358
default=os.environ.get("GOOGLE_CLOUD_PROJECT"),
@@ -458,7 +444,6 @@ def run_command(args):
458444
elif args.command == 'create-dicom-store':
459445
create_dicom_store(
460446
args.service_account_json,
461-
args.api_key,
462447
args.project_id,
463448
args.cloud_region,
464449
args.dataset_id,
@@ -467,7 +452,6 @@ def run_command(args):
467452
elif args.command == 'delete-dicom-store':
468453
delete_dicom_store(
469454
args.service_account_json,
470-
args.api_key,
471455
args.project_id,
472456
args.cloud_region,
473457
args.dataset_id,
@@ -476,7 +460,6 @@ def run_command(args):
476460
elif args.command == 'get-dicom-store':
477461
get_dicom_store(
478462
args.service_account_json,
479-
args.api_key,
480463
args.project_id,
481464
args.cloud_region,
482465
args.dataset_id,
@@ -485,15 +468,13 @@ def run_command(args):
485468
elif args.command == 'list-dicom-stores':
486469
list_dicom_stores(
487470
args.service_account_json,
488-
args.api_key,
489471
args.project_id,
490472
args.cloud_region,
491473
args.dataset_id)
492474

493475
elif args.command == 'patch-dicom-store':
494476
patch_dicom_store(
495477
args.service_account_json,
496-
args.api_key,
497478
args.project_id,
498479
args.cloud_region,
499480
args.dataset_id,
@@ -503,7 +484,6 @@ def run_command(args):
503484
elif args.command == 'export-dicom-store':
504485
export_dicom_instance(
505486
args.service_account_json,
506-
args.api_key,
507487
args.project_id,
508488
args.cloud_region,
509489
args.dataset_id,
@@ -513,7 +493,6 @@ def run_command(args):
513493
elif args.command == 'import-dicom-store':
514494
import_dicom_instance(
515495
args.service_account_json,
516-
args.api_key,
517496
args.project_id,
518497
args.cloud_region,
519498
args.dataset_id,
@@ -523,7 +502,6 @@ def run_command(args):
523502
elif args.command == 'get_iam_policy':
524503
get_dicom_store_iam_policy(
525504
args.service_account_json,
526-
args.api_key,
527505
args.project_id,
528506
args.cloud_region,
529507
args.dataset_id,
@@ -532,7 +510,6 @@ def run_command(args):
532510
elif args.command == 'set_iam_policy':
533511
set_dicom_store_iam_policy(
534512
args.service_account_json,
535-
args.api_key,
536513
args.project_id,
537514
args.cloud_region,
538515
args.dataset_id,

0 commit comments

Comments
 (0)
0