Skip to content

Commit 91d0799

Browse files
committed
Merge remote-tracking branch 'origin/demosite-app-recaptcha' into demosite-app-recaptcha
2 parents e70dde6 + a6559b3 commit 91d0799

File tree

37 files changed

+467
-370
lines changed

37 files changed

+467
-370
lines changed

.github/workflows/asset.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2023 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+
name: asset
16+
on:
17+
push:
18+
branches:
19+
- main
20+
paths:
21+
- 'asset/**'
22+
- '.github/workflows/asset.yaml'
23+
pull_request:
24+
paths:
25+
- 'asset/**'
26+
- '.github/workflows/asset.yaml'
27+
pull_request_target:
28+
types: [labeled]
29+
paths:
30+
- 'asset/**'
31+
- '.github/workflows/asset.yaml'
32+
schedule:
33+
- cron: '0 0 * * 0'
34+
jobs:
35+
test:
36+
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
37+
runs-on: ubuntu-latest
38+
timeout-minutes: 60
39+
permissions:
40+
contents: 'write'
41+
pull-requests: 'write'
42+
id-token: 'write'
43+
steps:
44+
- uses: actions/[email protected]
45+
with:
46+
ref: ${{github.event.pull_request.head.sha}}
47+
- uses: 'google-github-actions/[email protected]'
48+
with:
49+
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
50+
service_account: '[email protected]'
51+
create_credentials_file: 'true'
52+
access_token_lifetime: 600s
53+
- uses: actions/[email protected]
54+
with:
55+
node-version: 16
56+
- run: npm install
57+
working-directory: asset/snippets
58+
- run: npm test
59+
working-directory: asset/snippets
60+
env:
61+
MOCHA_REPORTER_SUITENAME: asset
62+
MOCHA_REPORTER_OUTPUT: asset_sponge_log.xml
63+
MOCHA_REPORTER: xunit
64+
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
65+
uses: actions/github-script@v6
66+
with:
67+
github-token: ${{ secrets.GITHUB_TOKEN }}
68+
script: |
69+
try {
70+
await github.rest.issues.removeLabel({
71+
name: 'actions:force-run',
72+
owner: 'GoogleCloudPlatform',
73+
repo: 'nodejs-docs-samples',
74+
issue_number: context.payload.pull_request.number
75+
});
76+
} catch (e) {
77+
if (!e.message.includes('Label does not exist')) {
78+
throw e;
79+
}
80+
}
81+
- if: ${{ github.event_name == 'schedule' && always() }}
82+
run: |
83+
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
84+
chmod +x ./flakybot
85+
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}

.github/workflows/media-livestream.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
pull-requests: 'write'
2828
id-token: 'write'
2929
steps:
30-
- uses: actions/checkout@v3.1.0
30+
- uses: actions/checkout@v3.3.0
3131
with:
3232
ref: ${{github.event.pull_request.head.sha}}
3333
- uses: 'google-github-actions/[email protected]'
@@ -36,7 +36,7 @@ jobs:
3636
service_account: '[email protected]'
3737
create_credentials_file: 'true'
3838
access_token_lifetime: 600s
39-
- uses: actions/setup-node@v3.5.1
39+
- uses: actions/setup-node@v3.6.0
4040
with:
4141
node-version: 16
4242
- run: npm install

.github/workflows/media-transcoder.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
pull-requests: 'write'
2828
id-token: 'write'
2929
steps:
30-
- uses: actions/checkout@v3.1.0
30+
- uses: actions/checkout@v3.3.0
3131
with:
3232
ref: ${{github.event.pull_request.head.sha}}
3333
- uses: 'google-github-actions/[email protected]'
@@ -36,7 +36,7 @@ jobs:
3636
service_account: '[email protected]'
3737
create_credentials_file: 'true'
3838
access_token_lifetime: 600s
39-
- uses: actions/setup-node@v3.5.1
39+
- uses: actions/setup-node@v3.6.0
4040
with:
4141
node-version: 16
4242
- run: npm install

.github/workflows/media-video-stitcher.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
pull-requests: 'write'
2828
id-token: 'write'
2929
steps:
30-
- uses: actions/checkout@v3.1.0
30+
- uses: actions/checkout@v3.3.0
3131
with:
3232
ref: ${{github.event.pull_request.head.sha}}
3333
- uses: 'google-github-actions/[email protected]'
@@ -36,7 +36,7 @@ jobs:
3636
service_account: '[email protected]'
3737
create_credentials_file: 'true'
3838
access_token_lifetime: 600s
39-
- uses: actions/setup-node@v3.5.1
39+
- uses: actions/setup-node@v3.6.0
4040
with:
4141
node-version: 16
4242
- run: npm install

.github/workflows/retail.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
pull-requests: 'write'
2828
id-token: 'write'
2929
steps:
30-
- uses: actions/checkout@v3.1.0
30+
- uses: actions/checkout@v3.3.0
3131
with:
3232
ref: ${{github.event.pull_request.head.sha}}
3333
- uses: 'google-github-actions/[email protected]'
@@ -36,7 +36,7 @@ jobs:
3636
service_account: '[email protected]'
3737
create_credentials_file: 'true'
3838
access_token_lifetime: 600s
39-
- uses: actions/setup-node@v3.5.1
39+
- uses: actions/setup-node@v3.6.0
4040
with:
4141
node-version: 16
4242
- run: npm install

.github/workflows/storagetransfer.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
pull-requests: 'write'
2828
id-token: 'write'
2929
steps:
30-
- uses: actions/checkout@v3.1.0
30+
- uses: actions/checkout@v3.3.0
3131
with:
3232
ref: ${{github.event.pull_request.head.sha}}
3333
- uses: 'google-github-actions/[email protected]'
@@ -42,7 +42,7 @@ jobs:
4242
secrets: |-
4343
sts_aws_secret:nodejs-docs-samples-tests/nodejs-docs-samples-storagetransfer-aws
4444
sts_azure_secret:nodejs-docs-samples-tests/nodejs-docs-samples-storagetransfer-azure
45-
- uses: actions/setup-node@v3.5.1
45+
- uses: actions/setup-node@v3.6.0
4646
with:
4747
node-version: 16
4848
- run: npm install

.github/workflows/workflows.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"appengine/static-files",
1515
"appengine/storage/flexible",
1616
"appengine/storage/standard",
17+
"asset",
1718
"auth",
1819
"automl",
1920
"appengine/typescript",

CODEOWNERS

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ monitoring/opencensus @GoogleCloudPlatform/nodejs-samples-reviewers
5959
# Data & AI
6060
ai-platform @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6161
automl @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
62-
dialogflow @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
63-
dialogflow-cx @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
64-
document-ai @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6562
cloud-language @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6663
contact-center-insights @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6764
datalabeling @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
65+
dialogflow @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
66+
dialogflow-cx @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6867
document-ai @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6968
mediatranslation @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
7069
notebooks @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers

appengine/pubsub/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ app.post('/', formBodyParser, async (req, res, next) => {
6363

6464
const data = Buffer.from(req.body.payload);
6565
try {
66-
const messageId = await topic.publish(data);
66+
const messageId = await topic.publishMessage({data});
6767
res.status(200).send(`Message ${messageId} sent.`);
6868
} catch (error) {
6969
next(error);

appengine/pubsub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"dependencies": {
1616
"@google-cloud/pubsub": "^3.0.0",
1717
"express": "^4.17.1",
18-
"google-auth-library": "^7.0.0",
18+
"google-auth-library": "^8.0.0",
1919
"pug": "^3.0.0"
2020
},
2121
"devDependencies": {

asset/snippets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"repository": "googleapis/nodejs-asset",
1313
"private": true,
1414
"scripts": {
15-
"test": "mocha --timeout 600000"
15+
"test": "mocha test --timeout 600000"
1616
},
1717
"dependencies": {
1818
"@google-cloud/asset": "^4.5.0",

asset/snippets/test/asset.test.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright 2023 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+
const {assert} = require('chai');
16+
const {after, before, describe, it} = require('mocha');
17+
const sinon = require('sinon');
18+
const uuid = require('uuid');
19+
20+
const {Storage} = require('@google-cloud/storage');
21+
22+
const cp = require('child_process');
23+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24+
25+
function sleep(ms) {
26+
return new Promise(resolve => setTimeout(resolve, ms));
27+
}
28+
29+
describe('asset sample tests', () => {
30+
let bucket;
31+
let bucketName;
32+
let fileSuffix;
33+
const suffix = uuid.v4();
34+
35+
before(async () => {
36+
const storage = new Storage();
37+
fileSuffix = `${suffix}`;
38+
39+
bucketName = `asset-nodejs-${suffix}`;
40+
bucket = storage.bucket(bucketName);
41+
await bucket.create();
42+
});
43+
44+
after(async () => {
45+
await bucket.delete();
46+
});
47+
48+
const stubConsole = function () {
49+
sinon.stub(console, 'error');
50+
sinon.stub(console, 'log');
51+
};
52+
const restoreConsole = function () {
53+
console.log.restore();
54+
console.error.restore();
55+
};
56+
57+
beforeEach(stubConsole);
58+
afterEach(restoreConsole);
59+
60+
it('should export assets to specified path', async () => {
61+
const dumpFilePath = `gs://${bucketName}/my-assets-${fileSuffix}.txt`;
62+
execSync(`node exportAssets ${dumpFilePath}`);
63+
let waitMs = 4000;
64+
let exists = false;
65+
let file;
66+
for (let retry = 0; retry < 3 && !exists; ++retry) {
67+
await sleep((waitMs *= 2));
68+
file = await bucket.file(`my-assets-${fileSuffix}.txt`);
69+
exists = await file.exists();
70+
}
71+
assert.ok(exists);
72+
await file.delete();
73+
});
74+
75+
it.skip('should export asset relationships to specified path', async () => {
76+
const dumpFilePath = `gs://${bucketName}/my-relationships-${fileSuffix}.txt`;
77+
const contentType = 'RELATIONSHIP';
78+
execSync(`node exportAssets ${dumpFilePath} ${contentType}`);
79+
let waitMs = 4000;
80+
let exists = false;
81+
let file;
82+
for (let retry = 0; retry < 3 && !exists; ++retry) {
83+
await sleep((waitMs *= 2));
84+
file = await bucket.file(`my-relationships-${fileSuffix}.txt`);
85+
exists = await file.exists();
86+
}
87+
assert.ok(exists);
88+
await file.delete();
89+
});
90+
91+
// The assets returned within 'readTimeWindow' frequently do not include
92+
// the newly created bucket:
93+
it('should get assets history successfully', async () => {
94+
const assetName = `//storage.googleapis.com/${bucketName}`;
95+
let waitMs = 1000;
96+
let included = false;
97+
for (let retry = 0; retry < 3 && !included; ++retry) {
98+
await sleep((waitMs *= 2));
99+
const stdout = execSync(
100+
`node getBatchAssetHistory ${assetName} 'RESOURCE'`
101+
);
102+
included = stdout.includes(assetName);
103+
}
104+
assert.ok(included);
105+
});
106+
107+
it('should list assets successfully', async () => {
108+
const assetType = 'storage.googleapis.com/Bucket';
109+
const stdout = execSync(`node listAssets ${assetType} 'RESOURCE'`);
110+
assert.include(stdout, assetType);
111+
});
112+
113+
it.skip('should list asset relationship successfully', async () => {
114+
const assetType = '';
115+
const stdout = execSync(`node listAssets ${assetType} 'RELATIONSHIP'`);
116+
assert.include(stdout, 'relatedAsset');
117+
});
118+
});

0 commit comments

Comments
 (0)