Skip to content
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

Add Healthcare API dataset get/set IAM policy #1371

Merged
merged 4 commits into from
Jun 19, 2019
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
3 changes: 3 additions & 0 deletions healthcare/datasets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Run the following command to install the library dependencies for Node.js:
patchDataset.js <projectId> <cloudRegion> <datasetId> <timeZone> Updates dataset details.
deidentifyDataset.js <projectId> <cloudRegion> <sourceDatasetId> Creates a new dataset containing de-identified data from
<destinationDatasetId> <keeplistTags> the source dataset.
getDatasetIamPolicy.js <projectId> <cloudRegion> <datasetId> Gets the IAM policy for the dataset.
setDatasetIamPolicy.js <projectId> <cloudRegion> <datasetId> <member> Sets the IAM policy for the dataset.
<role>

Options:
--version Show version number [boolean]
Expand Down
56 changes: 56 additions & 0 deletions healthcare/datasets/getDatasetIamPolicy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright 2019, Google, LLC
* Licensed under the Apache License, Version 2.0 (the `License`);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an `AS IS` BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint-disable no-warning-comments */

'use strict';

function main(
projectId = process.env.GCLOUD_PROJECT,
cloudRegion = 'us-central1',
datasetId
) {
// [START healthcare_get_dataset_iam_policy]
const {google} = require('googleapis');
const healthcare = google.healthcare('v1beta1');

async function getDatasetIamPolicy() {
const auth = await google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
google.options({auth});

// TODO(developer): uncomment these lines before running the sample
// const cloudRegion = 'us-central1';
// const projectId = 'adjective-noun-123';
// const datasetId = 'my-dataset';
const resource_ = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
const request = {resource_};

const dataset = await healthcare.projects.locations.datasets.getIamPolicy(
request
);
console.log(
'Got dataset IAM policy:',
JSON.stringify(dataset.data, null, 2)
);
}

getDatasetIamPolicy();
// [END healthcare_get_dataset_iam_policy]
}

// node getDatasetIamPolicy.js <projectId> <cloudRegion> <datasetId>
main(...process.argv.slice(2));
72 changes: 72 additions & 0 deletions healthcare/datasets/setDatasetIamPolicy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright 2019, Google, LLC
* Licensed under the Apache License, Version 2.0 (the `License`);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an `AS IS` BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint-disable no-warning-comments */

'use strict';

function main(
projectId = process.env.GCLOUD_PROJECT,
cloudRegion = 'us-central1',
datasetId,
member,
noerog marked this conversation as resolved.
Show resolved Hide resolved
role
) {
// [START healthcare_set_dataset_iam_policy]
const {google} = require('googleapis');
const healthcare = google.healthcare('v1beta1');

async function setDatasetIamPolicy() {
const auth = await google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
google.options({auth});

// TODO(developer): uncomment these lines before running the sample
// const cloudRegion = 'us-central1';
// const projectId = 'adjective-noun-123';
// const datasetId = 'my-dataset';
// const member = 'user:example@gmail.com';
// const role = 'roles/healthcare.datasetViewer';
const resource_ = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
const request = {
resource_,
resource: {
policy: {
bindings: [
{
members: member,
role: role,
},
],
},
},
};

const dataset = await healthcare.projects.locations.datasets.setIamPolicy(
request
);
console.log(
'Set dataset IAM policy:',
JSON.stringify(dataset.data, null, 2)
);
}

setDatasetIamPolicy();
// [END healthcare_set_dataset_iam_policy]
}

// node setDatasetIamPolicy.js <projectId> <cloudRegion> <datasetId> <member> <role>
main(...process.argv.slice(2));
16 changes: 16 additions & 0 deletions healthcare/datasets/system-test/datasets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ it('should de-identify data in a dataset and write to a new dataset', async () =
);
});

it('should create and get a dataset IAM policy', async () => {
const localMember = 'group:dpebot@google.com';
const localRole = 'roles/viewer';

let output = await tools.runAsync(
`node setDatasetIamPolicy.js ${projectId} ${cloudRegion} ${datasetId} ${localMember} ${localRole}`,
cwd
);
assert.ok(output.includes, 'ETAG');

output = await tools.runAsync(
`node getDatasetIamPolicy.js ${projectId} ${cloudRegion} ${datasetId}`
);
assert.ok(output.includes('dpebot'));
});

it('should delete a dataset', async () => {
const output = await tools.runAsync(
`node deleteDataset.js ${projectId} ${cloudRegion} ${datasetId}`,
Expand Down