-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New healthcare #2089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New healthcare #2089
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
623ce7c
dicom_stores tests pass (when discovery_url is active)
engelke 52ce620
Get/Set IAM policies for fhir_stores
engelke c8b6a23
Updated test
engelke 43f13b6
IAM operations on fhir_stores complete
engelke 1055a41
IAM policy get/set for hl7v2 stores
engelke 032ff93
IAM get/set for dicom stores
engelke 8978635
IAM get/set policy for datasets
engelke 72a4255
Added list_resource_history
engelke 673e0f4
Added get_resource_history
engelke ba514e0
Added delete_resource_purge
engelke 2396490
Added conditional_update_resource
engelke fa79fb9
Added conditional_delete_resource
engelke 980357c
Added conditional_patch_resource
engelke ec7b731
Added fhir resource import and export
engelke 11c5315
Added execute_bundle
engelke 14136bb
Dicomweb search instances
engelke 2d70b36
Cleaning up FHIR resources
engelke 87834b6
All dicom tests running and passing
engelke ec7b6c0
No longer skipping datasets tests
engelke a18101e
All fhir tests running and passing
engelke bdb04c6
All hl7v2 tests running and passing
engelke e274bf5
Fix lint issues
engelke ccd8ce2
More lint issues
engelke 724f254
Removed trailing whitespace.
engelke 9085f06
Fixing lint errors
engelke 3a9a350
Fixed API version
engelke 565e02f
A new lint error appears
engelke 7c6472b
Lint
engelke 2c1c3f6
Merge branch 'master' into new_healthcare
gguuss 767d17c
Fixed API version
engelke 11dcd7a
Merge branch 'new_healthcare' of github.com:GoogleCloudPlatform/pytho…
engelke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,9 @@ def get_client(service_account_json, api_key): | |
service_account_json) | ||
scoped_credentials = credentials.with_scopes(api_scopes) | ||
|
||
discovery_url = '{}?labels=CHC_ALPHA&version={}&key={}'.format( | ||
discovery_url = '{}?labels=CHC_BETA&version={}&key={}'.format( | ||
discovery_api, api_version, api_key) | ||
|
||
return discovery.build( | ||
service_name, | ||
api_version, | ||
|
@@ -237,6 +237,80 @@ def deidentify_dataset( | |
# [END healthcare_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) | ||
dataset_name = 'projects/{}/locations/{}/datasets/{}'.format( | ||
project_id, cloud_region, dataset_id) | ||
|
||
request = client.projects().locations().datasets().getIamPolicy( | ||
resource=dataset_name) | ||
response = request.execute() | ||
|
||
print('etag: {}'.format(response.get('name'))) | ||
return response | ||
# [END healthcare_dataset_get_iam_policy] | ||
|
||
|
||
# [START healthcare_dataset_set_iam_policy] | ||
def set_dataset_iam_policy( | ||
service_account_json, | ||
api_key, | ||
project_id, | ||
cloud_region, | ||
dataset_id, | ||
member, | ||
role, | ||
etag = None): | ||
"""Sets the IAM policy for the specified dataset. | ||
|
||
A single member will be assigned a single role. A member can be any of: | ||
|
||
- allUsers, that is, anyone | ||
- allAuthenticatedUsers, anyone authenticated with a Google account | ||
- user:email, as in 'user:[email protected]' | ||
- group:email, as in 'group:[email protected]' | ||
- domain:domainname, as in 'domain:example.com' | ||
- serviceAccount:email, | ||
as in 'serviceAccount:[email protected]' | ||
|
||
A role can be any IAM role, such as 'roles/viewer', 'roles/owner', | ||
or 'roles/editor' | ||
""" | ||
client = get_client(service_account_json, api_key) | ||
dataset_name = 'projects/{}/locations/{}/datasets/{}'.format( | ||
project_id, cloud_region, dataset_id) | ||
|
||
policy = { | ||
"bindings": [ | ||
{ | ||
"role": role, | ||
"members": [ | ||
member | ||
] | ||
} | ||
] | ||
} | ||
|
||
if etag is not None: | ||
policy['etag'] = etag | ||
|
||
request = client.projects().locations().datasets().setIamPolicy( | ||
resource=dataset_name, body={'policy': policy}) | ||
response = request.execute() | ||
|
||
print('etag: {}'.format(response.get('name'))) | ||
print('bindings: {}'.format(response.get('bindings'))) | ||
return response | ||
# [END healthcare_dataset_set_iam_policy] | ||
|
||
|
||
def parse_command_line_args(): | ||
"""Parses command line arguments.""" | ||
|
||
|
@@ -286,13 +360,26 @@ def parse_command_line_args(): | |
help='The data to keeplist, for example "PatientID" ' | ||
'or "StudyInstanceUID"') | ||
|
||
parser.add_argument( | ||
'--member', | ||
default=None, | ||
help='Member to add to IAM policy (e.g. "domain:example.com")') | ||
|
||
parser.add_argument( | ||
'--role', | ||
default=None, | ||
help='IAM Role to give to member (e.g. "roles/viewer")') | ||
|
||
|
||
command = parser.add_subparsers(dest='command') | ||
|
||
command.add_parser('create-dataset', help=create_dataset.__doc__) | ||
command.add_parser('delete-dataset', help=delete_dataset.__doc__) | ||
command.add_parser('get-dataset', help=get_dataset.__doc__) | ||
command.add_parser('list-datasets', help=list_datasets.__doc__) | ||
command.add_parser('patch-dataset', help=patch_dataset.__doc__) | ||
command.add_parser('get_iam_policy', help=get_dataset_iam_policy.__doc__) | ||
command.add_parser('set_iam_policy', help=set_dataset_iam_policy.__doc__) | ||
|
||
command.add_parser('deidentify-dataset', help=deidentify_dataset.__doc__) | ||
|
||
|
@@ -356,6 +443,24 @@ def run_command(args): | |
args.destination_dataset_id, | ||
args.keeplist_tags) | ||
|
||
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, | ||
args.member, | ||
args.role) | ||
|
||
|
||
def main(): | ||
args = parse_command_line_args() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ | |
time_zone = 'UTC' | ||
|
||
|
||
@pytest.mark.skip(reason='disable until API whitelisted / enabled') | ||
def test_CRUD_dataset(capsys): | ||
datasets.create_dataset( | ||
service_account_json, | ||
|
@@ -57,7 +56,6 @@ def test_CRUD_dataset(capsys): | |
assert 'Deleted dataset' in out | ||
|
||
|
||
@pytest.mark.skip(reason='disable until API whitelisted / enabled') | ||
def test_patch_dataset(capsys): | ||
datasets.create_dataset( | ||
service_account_json, | ||
|
@@ -84,7 +82,6 @@ def test_patch_dataset(capsys): | |
assert 'UTC' in out | ||
|
||
|
||
@pytest.mark.skip(reason='disable until API whitelisted / enabled') | ||
def test_deidentify_dataset(capsys): | ||
datasets.create_dataset( | ||
service_account_json, | ||
|
@@ -116,3 +113,44 @@ def test_deidentify_dataset(capsys): | |
|
||
# Check that de-identify worked | ||
assert 'De-identified data written to' in out | ||
|
||
|
||
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, | ||
'serviceAccount:[email protected]', | ||
'roles/viewer') | ||
|
||
# Clean up | ||
datasets.delete_dataset( | ||
service_account_json, | ||
api_key, | ||
project_id, | ||
cloud_region, | ||
dataset_id) | ||
|
||
out, _ = capsys.readouterr() | ||
|
||
assert 'etag' in get_response | ||
assert 'bindings' in set_response | ||
assert len(set_response['bindings']) == 1 | ||
assert 'python-docs-samples-tests' in str(set_response['bindings']) | ||
assert 'roles/viewer' in str(set_response['bindings']) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit. trailing whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just fixed the two lint errors. I'll remove the trailing whitespace ASAP.