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
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,
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:[email protected]';
// 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:[email protected]';
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