Skip to content
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

migrate code from googleapis/nodejs-containeranalysis #2834

Merged
merged 138 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 135 commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
a67a8b8
added directory structure
murog May 8, 2019
d70d099
npm init
murog May 8, 2019
9f781ff
moved over samples
murog May 8, 2019
397455b
passing tests for create, get, delete note and create occurrence
murog May 9, 2019
4cdd1ef
passing get occurrence test
murog May 14, 2019
7353725
passing delete occurrence
murog May 14, 2019
e27ca26
passing test for occurrences for note, flaky
murog May 14, 2019
1ffccce
passing occurrences for image
murog May 14, 2019
5739d98
samples
JustinBeckwith May 14, 2019
c0aab11
passing get Discovery Info
murog May 14, 2019
12b9c64
passing find vulnerabilities for image
murog May 14, 2019
0483c04
passing high severity vulnerability test
murog May 15, 2019
4cc415f
pass all vulnerabilities for image
murog May 15, 2019
4499e31
failing pubsub
murog May 15, 2019
b1b2e61
passing pubsub tests
murog May 16, 2019
7c665a2
passing polling test
murog May 16, 2019
60e9be6
Merge branch 'master' of https://github.com/googleapis/nodejs-contain…
murog May 16, 2019
0595e4a
updated imageUrl to https://gcr.io/my-project/my-image:123 for more r…
murog May 20, 2019
c1f354e
removed escape slashes from filter strings, not needed
murog May 20, 2019
a17a296
updated description of occurrenceId
murog May 20, 2019
68c04d3
added comment to explain second filter statement, needed for testing
murog May 20, 2019
14ec8e4
explicity state length greater than zero
murog May 20, 2019
1435323
removed system-test, moved tests into test directory
murog May 20, 2019
5de0336
removed async functions from tests without await
murog May 20, 2019
d030bb1
removed unused exec
murog May 20, 2019
3032fb3
removed explicit project id from pub sub
murog May 20, 2019
3af92d1
ran fix
murog May 20, 2019
e9b5ba4
replaced promise/timeout with p-retry
murog May 21, 2019
21be877
changed all samples to be wrapped with an outer main function, added
murog May 21, 2019
3d470ca
added after step to delete occurrences and notes
murog May 21, 2019
d14adb9
updated polling sample and test
murog May 21, 2019
78e7b12
ran fix, dangling errs for symlink and polling
murog May 21, 2019
7dad261
updated comment on occurrenceId
murog May 23, 2019
5d6daa1
fixed typo in discovery test
murog May 23, 2019
c4a6193
grabs projectId from client, update projectId and vars the refer to i…
murog May 23, 2019
d4c6c5c
removed commented code from polling sample
murog May 23, 2019
0c29526
move end region tag to inside main function
murog May 23, 2019
4740ead
removed symlinks from test script, removed commented test from pollin…
murog May 24, 2019
4ea46a7
deleted unused import from pub sub sample
murog May 24, 2019
5c52fb0
changed grafeas to container analysis v1beta1 client
murog May 24, 2019
d9fa96c
fixed typo in client, removed comment
murog May 24, 2019
3eada80
added retry logic to get occurrence test
murog May 28, 2019
3850bca
changed assert match to assert include
murog May 28, 2019
d8d2a52
added create topic logic to fix ci test error
murog May 28, 2019
0fa3c0c
removed regexp from assert include
murog May 28, 2019
3e38ab8
changed tests to include arrow functions
murog May 28, 2019
bf76572
moved containeranalysis and pubsub into prod deps
murog May 28, 2019
970053e
added retry logic for all occs of note, check if topic exists and fix…
murog May 28, 2019
3e3c530
added sample-metadata
murog May 29, 2019
a71693d
fixed occurrence typo
murog May 29, 2019
4d32bdf
added params to sample-metadata usage
murog May 29, 2019
0ee106d
added p-retry to prod deps, updated poll sample
murog May 29, 2019
64bb802
working poll discovery occurrence finished sample
murog May 30, 2019
9d83fdf
updated default value of retries and timeoutSeconds to be more readable
murog May 30, 2019
8a06948
refactor: changes formatting of various statements
yoshi-automation Jun 7, 2019
eee7213
chore: release 1.0.0 (#33)
yoshi-automation Jun 8, 2019
32c8434
fix(deps): update dependency @google-cloud/pubsub to ^0.29.0 (#36)
renovate[bot] Jun 11, 2019
2ac666b
chore: release 1.0.1 (#37)
yoshi-automation Jun 11, 2019
3a04b94
chore: release 1.0.2 (#40)
yoshi-automation Jun 14, 2019
9e8fbfb
chore: release 1.1.0 (#44)
yoshi-automation Jun 18, 2019
3bcdcf9
feat: adds getGrafeasClient() method on ContainerAnalysisClient insta…
bcoe Jun 19, 2019
d8523f7
chore: release 1.2.0 (#47)
yoshi-automation Jun 19, 2019
7ac60e4
chore: update samples to reflect v1 Grafeas API (#48)
daniel-sanche Jun 20, 2019
6c43f69
chore: release 1.2.1 (#50)
yoshi-automation Jun 24, 2019
53eb45d
chore: release 1.2.2 (#52)
yoshi-automation Jun 26, 2019
3f9ca4a
docs(samples): Update Topic ID in PubSub sample (#55)
daniel-sanche Jul 8, 2019
c93f150
chore: release 1.3.0 (#58)
yoshi-automation Jul 15, 2019
0c40854
fix(deps): update dependency @google-cloud/pubsub to ^0.30.0 (#59)
renovate-bot Jul 26, 2019
080b9c3
chore: release 1.3.1 (#61)
yoshi-automation Jul 29, 2019
7982156
chore: release 1.3.2 (#68)
yoshi-automation Aug 3, 2019
9028698
fix(deps): update dependency @google-cloud/pubsub to ^0.31.0 (#71)
renovate-bot Aug 16, 2019
cc8b0cd
chore: release 1.3.3 (#72)
yoshi-automation Aug 16, 2019
f1217d3
fix(deps): update dependency @google-cloud/pubsub to ^0.32.0 (#81)
renovate-bot Sep 11, 2019
3ea94a0
chore: release 1.4.0 (#78)
yoshi-automation Sep 16, 2019
857fdf5
fix(deps): update dependency @google-cloud/pubsub to v1 (#84)
renovate-bot Sep 18, 2019
58ff97c
chore: release 1.5.1 (#97)
release-please[bot] Oct 22, 2019
cecf4d8
chore: add license headers for samples (#106)
JustinBeckwith Nov 14, 2019
63f7978
chore: release 1.6.0 (#110)
release-please[bot] Nov 20, 2019
26721b3
chore: release 1.6.1 (#113)
release-please[bot] Dec 5, 2019
2c6c0fc
refactor: use explicit mocha imports (#119)
JustinBeckwith Dec 30, 2019
1325c16
chore: release 1.7.0 (#115)
release-please[bot] Jan 2, 2020
1d07831
chore(deps): update dependency mocha to v7 (#121)
renovate-bot Jan 6, 2020
5b6c5ac
chore: release 1.7.1 (#131)
release-please[bot] Feb 5, 2020
c9c4f5a
feat: move API to typescript code generation (#135)
xiaozhenliu-gg5 Feb 7, 2020
c84790e
chore: release 1.8.0 (#137)
release-please[bot] Feb 12, 2020
0435060
chore(deps): update dependency uuid to v7
renovate-bot Feb 26, 2020
1205d7b
chore: release 1.9.0 (#144)
release-please[bot] Mar 2, 2020
2324d29
chore: release 1.10.0 (#153)
release-please[bot] Mar 11, 2020
f46a57c
feat!: drop node8 support, support for async iterators (#167)
alexander-fenster Apr 2, 2020
c155555
test: there's a race condition emptying queue (#175)
bcoe Apr 3, 2020
fc5addd
test: retry pubsub test, as it relies on many moving parts (#186)
bcoe Apr 13, 2020
67366bd
test: retry queue deletion (#191)
bcoe Apr 14, 2020
705a62a
build: adopt CI changes and generator formatting (#197)
yoshi-automation Apr 22, 2020
3ad89e6
test: make tests idempotent (#201)
bcoe Apr 23, 2020
1cb4a12
fix(samples): should use effective_severity field (#200)
daniel-sanche Apr 23, 2020
33a2cbe
chore: release 2.0.0 (#170)
release-please[bot] Apr 23, 2020
58d67b6
build: modified export in protos.js
yoshi-automation Apr 28, 2020
536f566
chore(deps): update dependency uuid to v8 (#206)
renovate-bot May 1, 2020
52abee5
fix(deps): update dependency @google-cloud/pubsub to v2 (#215)
renovate-bot May 27, 2020
474d3ec
chore(deps): update dependency mocha to v8 (#222)
renovate-bot Jun 12, 2020
1ed98b2
test: attempt retry on note delete (#224)
JustinBeckwith Jun 12, 2020
fbbd62c
chore: release 2.1.0 (#210)
release-please[bot] Jun 29, 2020
2e9806b
chore: release 2.1.1 (#232)
release-please[bot] Jul 10, 2020
d2c50bf
docs(samples): update sample to illustrate AR style urls
donmccasland Nov 16, 2020
10b6a2d
chore: release 3.0.0 (#264)
release-please[bot] Nov 17, 2020
28e7aaa
chore: release 3.0.1 (#268)
release-please[bot] Dec 2, 2020
c2e9b63
chore: release 3.1.0 (#278)
release-please[bot] Jan 14, 2021
54c211a
build: update gapic-generator-typescript to v1.2.10. (#284)
yoshi-automation Mar 8, 2021
4c26e30
chore: release 3.1.1 (#294)
release-please[bot] Apr 28, 2021
b325b44
chore: release 3.1.2 (#299)
release-please[bot] May 7, 2021
3b2c642
chore: new owl bot post processor docker image (#300)
gcf-owl-bot[bot] May 10, 2021
317e180
chore: release 3.1.3 (#303)
release-please[bot] May 12, 2021
a4e6ec0
chore: release 3.1.4 (#309)
release-please[bot] May 27, 2021
6f2150a
chore: release 3.1.5 (#319)
release-please[bot] Jul 1, 2021
ac31261
chore: release 3.1.6 (#325)
release-please[bot] Jul 1, 2021
0f1df34
chore: release 3.1.7 (#327)
release-please[bot] Jul 21, 2021
ff2b247
chore: release 3.1.8 (#337)
release-please[bot] Aug 17, 2021
391bdf7
chore: release 3.2.0 (#340)
release-please[bot] Aug 23, 2021
3985062
chore: release 3.3.0 (#353)
release-please[bot] Nov 15, 2021
8fdfc6f
chore(main): release 3.4.0 (#389)
release-please[bot] Apr 5, 2022
bd0bbb5
fix: Flaky pubsub test (#394)
wietsevenema Apr 20, 2022
dcb6e93
build!: update library to use Node 12 (#408)
alexander-fenster May 17, 2022
90ba422
chore(main): release 4.0.0 (#407)
release-please[bot] May 26, 2022
018fdd3
fix(deps): update dependency @google-cloud/pubsub to v3 (#410)
renovate-bot Jun 9, 2022
4172a73
chore(main): release 4.1.0 (#416)
release-please[bot] Jun 10, 2022
23739a2
fix(issue-417): adding additional asserts to track flaky error (#421)
pattishin Jun 23, 2022
dcd85d4
chore(main): release 4.2.0 (#422)
release-please[bot] Jul 4, 2022
d00839e
chore(deps): update dependency uuid to v9 (#435)
renovate-bot Sep 8, 2022
10aeaaa
test(samples): disable samples tests for this repository (#440)
alexander-fenster Sep 20, 2022
58e0824
chore(main): release 4.3.0 (#429)
release-please[bot] Sep 22, 2022
2cdca7c
chore(main): release 4.4.0 (#444)
release-please[bot] Oct 17, 2022
8967a8d
chore(main): release 4.4.1 (#449)
release-please[bot] Nov 11, 2022
52c34a0
Merge remote-tracking branch 'migration/main' into nodejs-containeran…
NimJay Nov 11, 2022
db5d54c
Generate container-analysis-snippets.yaml
NimJay Nov 11, 2022
f65d8dc
Change Google Inc. to Google LLC
NimJay Nov 11, 2022
900a677
samples
JustinBeckwith May 14, 2019
78467b0
Merge branch 'main' into nodejs-containeranalysis-migration
Nov 11, 2022
bdcb86a
Merge branch 'main' into nodejs-containeranalysis-migration
NimJay Nov 11, 2022
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
67 changes: 67 additions & 0 deletions .github/workflows/container-analysis-snippets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: container-analysis-snippets
on:
push:
branches:
- main
paths:
- 'container-analysis/snippets/**'
pull_request:
paths:
- 'container-analysis/snippets/**'
pull_request_target:
types: [labeled]
schedule:
- cron: '0 0 * * 0'
jobs:
test:
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: 'write'
pull-requests: 'write'
id-token: 'write'
steps:
- uses: actions/checkout@v3.1.0
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- uses: 'google-github-actions/auth@v0.8.3'
with:
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: 'kokoro-system-test@long-door-651.iam.gserviceaccount.com'
create_credentials_file: 'true'
access_token_lifetime: 600s
- uses: actions/setup-node@v3.5.1
with:
node-version: 16
- run: npm install
working-directory: container-analysis/snippets
- run: npm test
working-directory: container-analysis/snippets
env:
MOCHA_REPORTER_SUITENAME: container_analysis_snippets
MOCHA_REPORTER_OUTPUT: container_analysis_snippets_sponge_log.xml
MOCHA_REPORTER: xunit
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
name: 'actions:force-run',
owner: 'GoogleCloudPlatform',
repo: 'nodejs-docs-samples',
issue_number: context.payload.pull_request.number
});
} catch (e) {
if (!e.message.includes('Label does not exist')) {
throw e;
}
}
- if: ${{ github.event_name == 'schedule'}}
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
1 change: 1 addition & 0 deletions .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"cloud-tasks/tutorial-gcf/function",
"composer",
"composer/functions/composer-storage-trigger",
"container-analysis/snippets",
"containerengine/hello-world",
"datacatalog/cloud-client",
"datalabeling",
Expand Down
3 changes: 3 additions & 0 deletions container-analysis/snippets/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
rules:
no-console: off
68 changes: 68 additions & 0 deletions container-analysis/snippets/createNote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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
//
// https://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';

// sample-metadata:
// title: Create Note
// description: Creates a Note with specified ID
// usage: node createNote.js "project-id" "note-id"
async function main(
projectId = 'your-project-id', // Your GCP Project ID
noteId = 'my-note-id' // Id of the note
) {
// [START containeranalysis_create_note]
/**
* TODO(developer): Uncomment these variables before running the sample
*/
// const projectId = 'your-project-id', // Your GCP Project ID
// const noteId = 'my-note-id' // Id of the note

// Import the library and create a client
const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis');
const client = new ContainerAnalysisClient();

// Construct request
// Associate the Note with a metadata type
// https://cloud.google.com/container-registry/docs/container-analysis#supported_metadata_types
// Here, we use the type "vulnerabiltity"
const formattedParent = client.getGrafeasClient().projectPath(projectId);

// Creates and returns a new Note
const [note] = await client.getGrafeasClient().createNote({
parent: formattedParent,
noteId: noteId,
note: {
vulnerability: {
details: [
{
affectedCpeUri: 'foo.uri',
affectedPackage: 'foo',
affectedVersionStart: {
kind: 'MINIMUM',
},
affectedVersionEnd: {
kind: 'MAXIMUM',
},
},
],
},
},
});

console.log(`Note ${note.name} created.`);
// [END containeranalysis_create_note]
}

main(...process.argv.slice(2));
81 changes: 81 additions & 0 deletions container-analysis/snippets/createOccurrence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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
//
// https://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';

// sample-metadata:
// title: Create Occurrence
// description: Creates an Occurrence of a Note and attaches it as a metadata to an image
// usage: node createOccurrence.js "note-project-id" "note-id" "occurrence-project-id" "image url"
async function main(
noteProjectId = 'your-project-id', // Your GCP Project Id
noteId = 'my-note-id', // Id of the note
occurrenceProjectId = 'your-project-id', // GCP Project Id of Occurrence
// If you are using Google Container Registry
imageUrl = 'https://gcr.io/my-project/my-repo/my-image:123' // Image to attach metadata to
// If you are using Google Artifact Registry
// imageUrl = 'https://LOCATION-docker.pkg.dev/my-project/my-repo/my-image:123' // Image to attach metadata to
) {
// [START containeranalysis_create_occurrence]
/**
* TODO(developer): Uncomment these variables before running the sample
*/
// const noteProjectId = 'your-project-id', // Your GCP Project Id
// const noteId = 'my-note-id', // Id of the note
// const occurrenceProjectId = 'your-project-id', // GCP Project Id of Occurrence
// If you are using Google Container Registry
// const imageUrl = 'https://gcr.io/my-project/my-repo/my-image:123' // Image to attach metadata to
// If you are using Google Artifact Registry
// const imageUrl = 'https://LOCATION-docker.pkg.dev/my-project/my-repo/my-image:123' // Image to attach metadata to

// Import the library and create a client
const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis');
const client = new ContainerAnalysisClient();

// Construct request
const formattedParent = client
.getGrafeasClient()
.projectPath(occurrenceProjectId);
const formattedNote = client
.getGrafeasClient()
.notePath(noteProjectId, noteId);

// Creates and returns a new Occurrence associated with an existing Note
const [occurrence] = await client.getGrafeasClient().createOccurrence({
parent: formattedParent,
occurrence: {
noteName: formattedNote,
resourceUri: imageUrl,
vulnerability: {
packageIssue: [
{
affectedCpeUri: 'foo.uri',
affectedPackage: 'foo',
affectedVersion: {
kind: 'MINIMUM',
},
fixedVersion: {
kind: 'MAXIMUM',
},
},
],
},
},
});
console.log(`Occurrence created ${occurrence.name}.`);
return occurrence;
// [END containeranalysis_create_occurrence]
}

main(...process.argv.slice(2));
45 changes: 45 additions & 0 deletions container-analysis/snippets/deleteNote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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
//
// https://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';

// sample-metadata:
// title: Delete Note
// description: Deletes a specified Note
// usage: node deleteNote.js "project-id" "note-id"
async function main(
projectId = 'your-project-id', // Your GCP Project Id
noteId = 'my-note-id' // Id of the note
) {
// [START containeranalysis_delete_note]
/**
* TODO(developer): Uncomment these variables before running the sample
*/
// const projectId = 'your-project-id', // Your GCP Project Id
// const noteId = 'my-note-id' // Id of the note

// Import the library and create a client
const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis');
const client = new ContainerAnalysisClient();

// Get the full path to the note
const formattedName = client.notePath(projectId, noteId);

// Delete the note
await client.getGrafeasClient().deleteNote({name: formattedName});
console.log(`Note ${formattedName} deleted.`);
// [END containeranalysis_delete_note]
}

main(...process.argv.slice(2));
50 changes: 50 additions & 0 deletions container-analysis/snippets/deleteOccurrence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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
//
// https://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';

// sample-metadata:
// title: Delete Occurrence
// description: Deletes a specified Occurrence
// usage: node deleteOccurrence.js "project-id" "occurrence-id"
async function main(
projectId = 'your-project-id', // Your GCP Project ID
occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence
) {
// [START containeranalysis_delete_occurrence]
/**
* TODO(developer): Uncomment these variables before running the sample
*/
// const projectId = 'your-project-id', // Your GCP Project ID
// const occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence

// Import the library and create a client
const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis');
const client = new ContainerAnalysisClient();

// Get full path to occurrence
const formattedName = client
.getGrafeasClient()
.occurrencePath(projectId, occurrenceId);

// Deletes an existing Occurrence from the server
await client.getGrafeasClient().deleteOccurrence({
name: formattedName,
});

console.log(`Occurrence deleted: ${formattedName}`);
// [END containeranalysis_delete_occurrence]
}

main(...process.argv.slice(2));
61 changes: 61 additions & 0 deletions container-analysis/snippets/getDiscoveryInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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
//
// https://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';

// sample-metadata:
// title: Get Discovery Info
// description: Gets all Discovery Occurrences attached to specified image
// usage: node getDiscoveryInfo.js "project-id" "image-url"
async function main(
projectId = 'your-project-id', // Your GCP Project ID
// If you are using Google Container Registry
imageUrl = 'https://gcr.io/my-project/my-repo/my-image:123' // Image to attach metadata to
// If you are using Google Artifact Registry
// imageUrl = 'https://LOCATION-docker.pkg.dev/my-project/my-repo/my-image:123' // Image to attach metadata to
) {
// [START containeranalysis_discovery_info]
/**
* TODO(developer): Uncomment these variables before running the sample
*/
// const projectId = 'your-project-id', // Your GCP Project ID
// If you are using Google Container Registry
// const imageUrl = 'https://gcr.io/my-project/my-repo/my-image:123' // Image to attach metadata to
// If you are using Google Artifact Registry
// const imageUrl = 'https://LOCATION-docker.pkg.dev/my-project/my-repo/my-image:123' // Image to attach metadata to

// Import the library and create a client
const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis');
const client = new ContainerAnalysisClient();

const formattedParent = client.getGrafeasClient().projectPath(projectId);
// Retrieves and prints the Discovery Occurrence created for a specified image
// The Discovery Occurrence contains information about the initial scan on the image
const [occurrences] = await client.getGrafeasClient().listOccurrences({
parent: formattedParent,
filter: `kind = "DISCOVERY" AND resourceUrl = "${imageUrl}"`,
});

if (occurrences.length > 0) {
console.log(`Discovery Occurrences for ${imageUrl}`);
occurrences.forEach(occurrence => {
console.log(`${occurrence.name}:`);
});
} else {
console.log('No occurrences found.');
}
// [END containeranalysis_discovery_info]
}

main(...process.argv.slice(2));
Loading