Skip to content

Commit d0873bf

Browse files
author
Nick Cook
committed
docs: add a REST sample and test for AML AI
1 parent c08518a commit d0873bf

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed

.github/workflows/aml-ai.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2024 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: aml-ai
16+
on:
17+
push:
18+
branches:
19+
- main
20+
paths:
21+
- 'aml-ai/**'
22+
- '.github/workflows/aml-ai.yaml'
23+
pull_request:
24+
types:
25+
- opened
26+
- reopened
27+
- synchronize
28+
- labeled
29+
paths:
30+
- 'aml-ai/**'
31+
- '.github/workflows/aml-ai.yaml'
32+
schedule:
33+
- cron: '0 0 * * 0'
34+
jobs:
35+
test:
36+
# Ref: https://github.com/google-github-actions/auth#usage
37+
permissions:
38+
contents: 'read'
39+
id-token: 'write'
40+
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
41+
uses: ./.github/workflows/test.yaml
42+
with:
43+
name: 'aml-ai'
44+
path: 'aml-ai'
45+
flakybot:
46+
# Ref: https://github.com/google-github-actions/auth#usage
47+
permissions:
48+
contents: 'read'
49+
id-token: 'write'
50+
if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail
51+
uses: ./.github/workflows/flakybot.yaml
52+
needs: [test]

.github/workflows/utils/workflows.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
"aml-ai",
23
"appengine/analytics",
34
"appengine/building-an-app/build",
45
"appengine/building-an-app/update",

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ vision @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-revi
6363

6464
# Self-service
6565
ai-platform @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/text-embedding @GoogleCloudPlatform/cloud-samples-reviewers
66+
aml-ai @GoogleCloudPlatform/aml-ai @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
6667
asset @GoogleCloudPlatform/cloud-asset-analysis-team @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
6768
dlp @GoogleCloudPlatform/googleapis-dlp @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
6869
security-center @GoogleCloudPlatform/gcp-security-command-center @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers

aml-ai/listLocations.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright 2024 Google LLC
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+
16+
'use strict';
17+
18+
const main = (projectId = process.env.GOOGLE_CLOUD_PROJECT) => {
19+
// [START antimoneylaunderingai_list_locations]
20+
// Import google-auth-library for authentication.
21+
const {GoogleAuth} = require('google-auth-library');
22+
23+
const listLocations = async () => {
24+
const auth = new GoogleAuth({
25+
scopes: 'https://www.googleapis.com/auth/cloud-platform',
26+
headers: {'Content-Type': 'application/json; charset=utf-8'},
27+
});
28+
// TODO(developer): uncomment these lines before running the sample
29+
// const projectId = 'my-project-id';
30+
const url = `https://financialservices.googleapis.com/v1/projects/${projectId}/locations`;
31+
const client = await auth.getClient();
32+
const response = await client.request({url, method: 'GET'});
33+
console.log(JSON.stringify(response.data));
34+
};
35+
36+
listLocations();
37+
// [END antimoneylaunderingai_list_locations]
38+
};
39+
40+
// node listLocations.js <projectId>
41+
main(...process.argv.slice(2));

aml-ai/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "nodejs-docs-samples-aml-ai",
3+
"version": "0.0.1",
4+
"private": true,
5+
"license": "Apache-2.0",
6+
"author": "Google LLC",
7+
"repository": "GoogleCloudPlatform/nodejs-docs-samples",
8+
"engines": {
9+
"node": ">=12.0.0"
10+
},
11+
"scripts": {
12+
"test": "c8 mocha -p -j 2 system-test/*.test.js --timeout=60000"
13+
},
14+
"devDependencies": {
15+
"c8": "^10.0.0",
16+
"google-auth-library": "^9.0.0",
17+
"mocha": "^10.0.0"
18+
}
19+
}

aml-ai/system-test/aml-ai.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2024 Google LLC
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+
16+
'use strict';
17+
18+
const assert = require('assert');
19+
const path = require('path');
20+
const cwd = path.join(__dirname, '..');
21+
const {execSync} = require('child_process');
22+
const {it} = require('mocha');
23+
24+
const projectId = process.env.GCLOUD_PROJECT;
25+
const cloudRegion = 'us-central1';
26+
27+
it('should get the AML AI API locations', () => {
28+
const output = execSync(`node listLocations.js ${projectId}`, {cwd});
29+
assert.ok(output.includes(cloudRegion));
30+
});

0 commit comments

Comments
 (0)