-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add a REST sample and test for AML AI #3809
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
Changes from 5 commits
d0873bf
0ca1215
0cc6c9e
d399ab3
100207c
6d85a88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Copyright 2024 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. | ||
|
|
||
| name: aml-ai | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'aml-ai/**' | ||
| - '.github/workflows/aml-ai.yaml' | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| - labeled | ||
| paths: | ||
| - 'aml-ai/**' | ||
| - '.github/workflows/aml-ai.yaml' | ||
| schedule: | ||
| - cron: '0 0 * * 0' | ||
| jobs: | ||
| test: | ||
| # Ref: https://github.com/google-github-actions/auth#usage | ||
| permissions: | ||
| contents: 'read' | ||
| id-token: 'write' | ||
| if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' | ||
| uses: ./.github/workflows/test.yaml | ||
| with: | ||
| name: 'aml-ai' | ||
| path: 'aml-ai' | ||
| flakybot: | ||
| # Ref: https://github.com/google-github-actions/auth#usage | ||
| permissions: | ||
| contents: 'read' | ||
| id-token: 'write' | ||
| if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| uses: ./.github/workflows/flakybot.yaml | ||
| needs: [test] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| [ | ||
| "aml-ai", | ||
| "appengine/analytics", | ||
| "appengine/building-an-app/build", | ||
| "appengine/building-an-app/update", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||||
| /** | ||||||||
| * Copyright 2024 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. | ||||||||
| */ | ||||||||
|
|
||||||||
| 'use strict'; | ||||||||
|
|
||||||||
| const main = async () => { | ||||||||
| // [START antimoneylaunderingai_list_locations] | ||||||||
| // Import google-auth-library for authentication. | ||||||||
| const {GoogleAuth} = require('google-auth-library'); | ||||||||
|
|
||||||||
| const listLocations = async () => { | ||||||||
| const auth = new GoogleAuth({ | ||||||||
| scopes: 'https://www.googleapis.com/auth/cloud-platform', | ||||||||
| headers: {'Content-Type': 'application/json; charset=utf-8'}, | ||||||||
| }); | ||||||||
| // TODO(developer): update the project ID as needed | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TODO should be more specific about how the developer should update the project ID. Is it via an environment variable? Should it be hardcoded? Provide an example.
Suggested change
|
||||||||
| const projectId = process.env.GOOGLE_CLOUD_PROJECT; | ||||||||
| const url = `https://financialservices.googleapis.com/v1/projects/${projectId}/locations`; | ||||||||
| const client = await auth.getClient(); | ||||||||
irataxy marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| let response; | ||||||||
| try { | ||||||||
| response = await client.request({url, method: 'GET'}); | ||||||||
| } catch (err) { | ||||||||
| throw new Error(`API request failed: ${err}`); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of just logging the error message, consider including the original error object (
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
| console.log(JSON.stringify(response.data)); | ||||||||
| }; | ||||||||
|
|
||||||||
| return await listLocations(); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||
| // [END antimoneylaunderingai_list_locations] | ||||||||
| }; | ||||||||
|
|
||||||||
| // node listLocations.js | ||||||||
| main().catch(err => { | ||||||||
| console.error(err); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed this so mocha's reporter prints the reason for the failure. The current mocha test reporter filters out
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cl/674939991 is merged, waiting on API enablement now.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @irataxy The API was enabled (internal: cl/676595619). Looks like a few conflicts must be resolved to get this merged, however. Do you have bandwidth to follow up, or would you like to convert this to a draft or close it for now?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Converted to draft for now
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @irataxy The PR to enable the financialservices api was merged. I'm going to take this out of draft mode and rerun tests to confirm.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||
| process.exitCode = 1; | ||||||||
| }); | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "nodejs-docs-samples-aml-ai", | ||
| "version": "0.0.1", | ||
| "private": true, | ||
| "license": "Apache-2.0", | ||
| "author": "Google LLC", | ||
| "repository": "GoogleCloudPlatform/nodejs-docs-samples", | ||
| "engines": { | ||
| "node": ">=12.0.0" | ||
| }, | ||
| "scripts": { | ||
| "test": "c8 mocha -p -j 2 system-test/*.test.js --timeout=60000" | ||
| }, | ||
| "devDependencies": { | ||
| "c8": "^10.0.0", | ||
| "google-auth-library": "^9.0.0", | ||
| "mocha": "^10.0.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||
| /** | ||||||||
| * Copyright 2024 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. | ||||||||
| */ | ||||||||
|
|
||||||||
| 'use strict'; | ||||||||
|
|
||||||||
| const assert = require('assert'); | ||||||||
| const path = require('path'); | ||||||||
| const cwd = path.join(__dirname, '..'); | ||||||||
| const {execSync} = require('child_process'); | ||||||||
| const {it} = require('mocha'); | ||||||||
|
|
||||||||
| const cloudRegion = 'us-central1'; | ||||||||
|
|
||||||||
| it('should get the AML AI API locations', () => { | ||||||||
| const output = execSync('node listLocations.js', {cwd}); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good practice to assert on the full response or specific fields within the response data, rather than just checking if a string is included. This makes the test more robust and less prone to false positives. Also, consider using
Suggested change
|
||||||||
| assert.ok(output.includes(cloudRegion)); | ||||||||
| }); | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment explaining the purpose of the
actions:force-runlabel and when it should be used.