Skip to content

Commit eace931

Browse files
authored
Merge branch 'main' into buckets-storage-migration
2 parents 2258efc + 24d8a8a commit eace931

19 files changed

Lines changed: 950 additions & 37 deletions

healthcare/fhir/getFhirResource.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const main = (
2929
auth: new google.auth.GoogleAuth({
3030
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
3131
}),
32+
responseType: 'json',
3233
});
3334

3435
const getFhirResource = async () => {
@@ -42,11 +43,18 @@ const main = (
4243
const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}`;
4344
const request = {name};
4445

45-
const resource =
46-
await healthcare.projects.locations.datasets.fhirStores.fhir.read(
47-
request
46+
try {
47+
const resource =
48+
await healthcare.projects.locations.datasets.fhirStores.fhir.read(
49+
request
50+
);
51+
console.log(`Got ${resourceType} resource:\n`, resource.data);
52+
} catch (error) {
53+
console.error(
54+
`Error getting ${resourceType} resource:`,
55+
error.message || error
4856
);
49-
console.log(`Got ${resourceType} resource:\n`, resource.data);
57+
}
5058
};
5159

5260
getFhirResource();

healthcare/fhir/importFhirResources.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const main = (
2828
auth: new google.auth.GoogleAuth({
2929
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
3030
}),
31+
responseType: 'json',
3132
});
3233
const sleep = ms => {
3334
return new Promise(resolve => setTimeout(resolve, ms));
@@ -50,32 +51,48 @@ const main = (
5051
},
5152
},
5253
};
54+
try {
55+
const operation =
56+
await healthcare.projects.locations.datasets.fhirStores.import(request);
57+
const operationName = operation.data.name;
5358

54-
const operation =
55-
await healthcare.projects.locations.datasets.fhirStores.import(request);
56-
const operationName = operation.data.name;
59+
console.log(`Import operation started: ${operationName}`);
5760

58-
const operationRequest = {name: operationName};
61+
let done = false;
62+
let operationStatus;
63+
let attempts = 0;
5964

60-
// Wait twenty seconds for the LRO to finish.
61-
await sleep(20000);
65+
while (!done && attempts < 100) {
66+
console.log('Waiting for import operation to complete...');
67+
attempts++;
68+
await sleep(5000); // Wait 5 seconds between polls
6269

63-
// Check the LRO's status
64-
const operationStatus =
65-
await healthcare.projects.locations.datasets.operations.get(
66-
operationRequest
67-
);
70+
operationStatus =
71+
await healthcare.projects.locations.datasets.operations.get({
72+
name: operationName,
73+
});
6874

69-
const success = operationStatus.data.metadata.counter.success;
75+
done = operationStatus.data.done;
76+
}
7077

71-
if (typeof success !== 'undefined') {
72-
console.log(
73-
`Import FHIR resources succeeded. ${success} resources imported.`
74-
);
75-
} else {
76-
console.log(
77-
'Imported FHIR resources failed. Details available in Cloud Logging at the following URL:\n',
78-
operationStatus.data.metadata.logsUrl
78+
if (operationStatus.data.error) {
79+
console.error(
80+
'Import FHIR resources failed:',
81+
operationStatus.data.error
82+
);
83+
} else if (done) {
84+
const successCount =
85+
operationStatus.data.metadata?.counter?.success || 0;
86+
console.log(
87+
`Import FHIR resources succeeded. ${successCount} resources imported.`
88+
);
89+
} else {
90+
console.error('Import operation timed out in the sample.');
91+
}
92+
} catch (error) {
93+
console.error(
94+
'An error occurred during the import process:',
95+
error.message || error
7996
);
8097
}
8198
};

healthcare/fhir/listFhirStores.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const main = (
2626
auth: new google.auth.GoogleAuth({
2727
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
2828
}),
29+
responseType: 'json',
2930
});
3031

3132
const listFhirStores = async () => {
@@ -36,9 +37,13 @@ const main = (
3637
const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
3738
const request = {parent};
3839

39-
const fhirStores =
40-
await healthcare.projects.locations.datasets.fhirStores.list(request);
41-
console.log(JSON.stringify(fhirStores.data));
40+
try {
41+
const fhirStores =
42+
await healthcare.projects.locations.datasets.fhirStores.list(request);
43+
console.log(JSON.stringify(fhirStores.data));
44+
} catch (error) {
45+
console.error('Error listing FHIR stores:', error.message || error);
46+
}
4247
};
4348

4449
listFhirStores();

healthcare/fhir/updateFhirResource.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const main = (
3030
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
3131
}),
3232
headers: {'Content-Type': 'application/fhir+json'},
33+
responseType: 'json',
3334
});
3435

3536
const updateFhirResource = async () => {
@@ -47,11 +48,18 @@ const main = (
4748
const body = {resourceType: resourceType, id: resourceId, active: true};
4849
const request = {name, requestBody: body};
4950

50-
const resource =
51-
await healthcare.projects.locations.datasets.fhirStores.fhir.update(
52-
request
51+
try {
52+
const resource =
53+
await healthcare.projects.locations.datasets.fhirStores.fhir.update(
54+
request
55+
);
56+
console.log(`Updated ${resourceType} resource:\n`, resource.data);
57+
} catch (error) {
58+
console.error(
59+
`Error updating ${resourceType} resource:`,
60+
error.message || error
5361
);
54-
console.log(`Updated ${resourceType} resource:\n`, resource.data);
62+
}
5563
};
5664

5765
updateFhirResource();

recaptcha_enterprise/demosite/app/controllers/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Label = {
3232
// Parse config file and read available reCAPTCHA actions. All reCAPTCHA actions registered in the client
3333
// should be mapped in the config file. This will be used to verify if the token obtained during assessment
3434
// corresponds to the claimed action.
35-
const propertiesReader = require('properties-reader');
35+
const {propertiesReader} = require('properties-reader');
3636
const PROPERTIES = propertiesReader('config.properties');
3737

3838
const context = {

recaptcha_enterprise/demosite/app/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"license": "Apache-2.0",
66
"author": "Google Inc.",
77
"scripts": {
8+
"start": "node index.js",
89
"test": "echo \"Error: no test specified\" && exit 1"
910
},
1011
"engines": {
@@ -16,10 +17,10 @@
1617
"url": "https://github.com/googleapis/google-cloud-node.git"
1718
},
1819
"dependencies": {
19-
"@google-cloud/recaptcha-enterprise": "^5.5.0",
20-
"body-parser": "^1.20.0",
21-
"express": "^4.18.1",
20+
"@google-cloud/recaptcha-enterprise": "^6.4.0",
21+
"body-parser": "^2.2.2",
22+
"express": "^5.2.1",
2223
"mustache-express": "^1.3.2",
23-
"properties-reader": "^2.2.0"
24+
"properties-reader": "^3.0.1"
2425
}
25-
}
26+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* This application demonstrates how to perform basic operations on bucket and
19+
* file Access Control Lists with the Google Cloud Storage API.
20+
*
21+
* For more information, see the README.md under /storage and the documentation
22+
* at https://cloud.google.com/storage/docs.
23+
*/
24+
25+
function main(bucketName = 'my-bucket', userEmail = 'jdobry@google.com') {
26+
// [START storage_add_bucket_default_owner]
27+
/**
28+
* TODO(developer): Uncomment the following lines before running the sample.
29+
*/
30+
// The ID of your GCS bucket
31+
// const bucketName = 'your-unique-bucket-name';
32+
33+
// The email address of the user to add
34+
// const userEmail = 'user-email-to-add';
35+
36+
// Imports the Google Cloud client library
37+
const {Storage} = require('@google-cloud/storage');
38+
39+
// Creates a client
40+
const storage = new Storage();
41+
42+
async function addBucketDefaultOwner() {
43+
try {
44+
// Makes the user an owner in the default ACL of the bucket. You can use
45+
// addAllUsers(), addDomain(), addProject(), addGroup(), and
46+
// addAllAuthenticatedUsers() to grant access to different types of entities.
47+
// You can also use "readers" and "writers" to grant different roles.
48+
await storage.bucket(bucketName).acl.default.owners.addUser(userEmail);
49+
50+
console.log(
51+
`Added user ${userEmail} as an owner on bucket ${bucketName}.`
52+
);
53+
} catch (error) {
54+
console.error(
55+
'Error executing add bucket default owner ACL:',
56+
error.message || error
57+
);
58+
}
59+
}
60+
61+
addBucketDefaultOwner();
62+
// [END storage_add_bucket_default_owner]
63+
}
64+
main(...process.argv.slice(2));

storage/addBucketOwnerAcl.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* This application demonstrates how to perform basic operations on bucket and
19+
* file Access Control Lists with the Google Cloud Storage API.
20+
*
21+
* For more information, see the README.md under /storage and the documentation
22+
* at https://cloud.google.com/storage/docs.
23+
*/
24+
25+
function main(bucketName = 'my-bucket', userEmail = 'jdobry@google.com') {
26+
// [START storage_add_bucket_owner]
27+
/**
28+
* TODO(developer): Uncomment the following lines before running the sample.
29+
*/
30+
// The ID of your GCS bucket
31+
// const bucketName = 'your-unique-bucket-name';
32+
33+
// The email address of the user to add
34+
// const userEmail = 'user-email-to-add';
35+
36+
// Imports the Google Cloud client library
37+
const {Storage} = require('@google-cloud/storage');
38+
39+
// Creates a client
40+
const storage = new Storage();
41+
42+
async function addBucketOwner() {
43+
try {
44+
// Makes the user an owner of the bucket. You can use addAllUsers(),
45+
// addDomain(), addProject(), addGroup(), and addAllAuthenticatedUsers()
46+
// to grant access to different types of entities. You can also use "readers"
47+
// and "writers" to grant different roles.
48+
await storage.bucket(bucketName).acl.owners.addUser(userEmail);
49+
50+
console.log(
51+
`Added user ${userEmail} as an owner on bucket ${bucketName}.`
52+
);
53+
} catch (error) {
54+
console.error(
55+
'Error executing add bucket owner ACL:',
56+
error.message || error
57+
);
58+
}
59+
}
60+
61+
addBucketOwner();
62+
// [END storage_add_bucket_owner]
63+
}
64+
main(...process.argv.slice(2));

storage/addFileOwnerAcl.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* This application demonstrates how to perform basic operations on bucket and
19+
* file Access Control Lists with the Google Cloud Storage API.
20+
*
21+
* For more information, see the README.md under /storage and the documentation
22+
* at https://cloud.google.com/storage/docs.
23+
*/
24+
25+
function main(
26+
bucketName = 'my-bucket',
27+
fileName = 'test.txt',
28+
userEmail = 'jdobry@google.com'
29+
) {
30+
// [START storage_add_file_owner]
31+
/**
32+
* TODO(developer): Uncomment the following lines before running the sample.
33+
*/
34+
// The ID of your GCS bucket
35+
// const bucketName = 'your-unique-bucket-name';
36+
37+
// The name of the file to access
38+
// const fileName = 'file.txt';
39+
40+
// The email address of the user to add
41+
// const userEmail = 'user-email-to-add';
42+
43+
// Imports the Google Cloud client library
44+
const {Storage} = require('@google-cloud/storage');
45+
46+
// Creates a client
47+
const storage = new Storage();
48+
49+
async function addFileOwner() {
50+
try {
51+
await storage
52+
.bucket(bucketName)
53+
.file(fileName)
54+
.acl.owners.addUser(userEmail);
55+
56+
console.log(`Added user ${userEmail} as an owner on file ${fileName}.`);
57+
} catch (error) {
58+
console.error(
59+
'Error executing add file owner ACL:',
60+
error.message || error
61+
);
62+
}
63+
}
64+
65+
addFileOwner();
66+
// [END storage_add_file_owner]
67+
}
68+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)