From a67a8b84db9308eb7788c3a5e9a325eff10db97c Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 7 May 2019 19:17:13 -0700 Subject: [PATCH 001/131] added directory structure --- container-analysis/snippets/system-test/.eslintrc.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 container-analysis/snippets/system-test/.eslintrc.yml diff --git a/container-analysis/snippets/system-test/.eslintrc.yml b/container-analysis/snippets/system-test/.eslintrc.yml new file mode 100644 index 00000000000..6db2a46c535 --- /dev/null +++ b/container-analysis/snippets/system-test/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +env: + mocha: true From d70d099c1734a6b16b521514634c3adb5a283be7 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 7 May 2019 19:22:23 -0700 Subject: [PATCH 002/131] npm init --- container-analysis/snippets/package.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 container-analysis/snippets/package.json diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json new file mode 100644 index 00000000000..1a896861ece --- /dev/null +++ b/container-analysis/snippets/package.json @@ -0,0 +1,14 @@ +{ + "name": "nodejs-containeranalysis-samples", + "private": true, + "license": "Apache-2.0", + "author": "Google Inc.", + "repository": "googleapis/nodejs-containeranalysis", + "files": [ + "*.js" + ], + "engines": { + "node": ">=8" + } +} + From 9f781ffdd8211f1ff7716c93c8f47b669b4ec883 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 7 May 2019 19:24:58 -0700 Subject: [PATCH 003/131] moved over samples --- container-analysis/snippets/createNote.js | 37 +++++++++++++++++++ .../snippets/createOccurence.js | 29 +++++++++++++++ container-analysis/snippets/deleteNote.js | 21 +++++++++++ .../snippets/deleteOccurrence.js | 13 +++++++ .../snippets/getDiscoveryInfo.js | 14 +++++++ container-analysis/snippets/getNote.js | 22 +++++++++++ container-analysis/snippets/getOccurrence.js | 13 +++++++ .../snippets/highVulnerabilitiesForImage.js | 13 +++++++ .../snippets/occurrencesForImage.js | 15 ++++++++ .../snippets/occurrencesForNote.js | 15 ++++++++ container-analysis/snippets/package.json | 3 +- .../pollDiscoveryOccurrenceFinished.js | 14 +++++++ container-analysis/snippets/pubSub.js | 13 +++++++ .../vulnerabilityOccurencesForImage.js | 13 +++++++ 14 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 container-analysis/snippets/createNote.js create mode 100644 container-analysis/snippets/createOccurence.js create mode 100644 container-analysis/snippets/deleteNote.js create mode 100644 container-analysis/snippets/deleteOccurrence.js create mode 100644 container-analysis/snippets/getDiscoveryInfo.js create mode 100644 container-analysis/snippets/getNote.js create mode 100644 container-analysis/snippets/getOccurrence.js create mode 100644 container-analysis/snippets/highVulnerabilitiesForImage.js create mode 100644 container-analysis/snippets/occurrencesForImage.js create mode 100644 container-analysis/snippets/occurrencesForNote.js create mode 100644 container-analysis/snippets/pollDiscoveryOccurrenceFinished.js create mode 100644 container-analysis/snippets/pubSub.js create mode 100644 container-analysis/snippets/vulnerabilityOccurencesForImage.js diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js new file mode 100644 index 00000000000..6d3631f74a4 --- /dev/null +++ b/container-analysis/snippets/createNote.js @@ -0,0 +1,37 @@ +// [START containeranalysis_create_note] +// Creates and returns a new Note +const createNote = async ( + projectId = 'your-project-id', // Your GCP Project ID + noteId = 'my-note-id', // Id of the note +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); + + // 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 "attestation" + const formattedParent = client.projectPath(projectId); + + const [note] = await client.createNote({ + parent: formattedParent, + noteId: noteId, + note: { + noteKind: 'ATTESTATION', + attestationAuthority: { + hint: { + humanReadableName: 'my-authority' + } + } + } + }); + + console.log(`Note ${note.name} created.`); + +}; +// [END containeranalysis_create_note] + + +const args = process.argv.slice(2); +createNote(...args).catch(console.error); \ No newline at end of file diff --git a/container-analysis/snippets/createOccurence.js b/container-analysis/snippets/createOccurence.js new file mode 100644 index 00000000000..8526c480874 --- /dev/null +++ b/container-analysis/snippets/createOccurence.js @@ -0,0 +1,29 @@ +// [START containeranalysis_create_occurrence] +// Creates and returns a new Occurrence associated with an existing Note +const createOccurence = async( + noteProjectId = 'your-project-id', // Your GCP Project Id + noteId = 'my-note-id', // Id of the note + occurenceProjectId = 'your-project-id', // GCP Project Id of Occurence + imageUrl = 'my-url.io/project/image' // Image to attach metadata to +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); + + // Construct request + const formattedParent = client.projectPath(occurenceProjectId); + const formattedNote = client.notePath(noteProjectId, noteId); + + // Attach the occurence to the associated image url + const [occ] = await client.createOccurrence({ + parent: formattedParent, + occurrence: { + noteName: formattedNote, + } + }); + +}; +// [END containeranalysis_create_occurrence] + +const args = process.argv.slice(2); +createOccurence(...args).catch(console.error); \ No newline at end of file diff --git a/container-analysis/snippets/deleteNote.js b/container-analysis/snippets/deleteNote.js new file mode 100644 index 00000000000..ef7e68b5313 --- /dev/null +++ b/container-analysis/snippets/deleteNote.js @@ -0,0 +1,21 @@ +// [START containeranalysis_delete_note] +// Deletes an existing Note from the server +const deleteNote = async( + projectId = 'your-project-id', // Your GCP Project Id + noteId = 'my-note-id', // Id of the note +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); + + // Get the full path to the note + const formattedName = client.notePath(projectId, noteId); + + // Delete the note + const response = await client.deleteNote({name: formattedName}); + console.log(`Note ${formattedName} deleted.`); +}; +// [END containeranalysis_delete_note] + +const args = process.argv.slice(2); +deleteNote(...args).catch(console.error); \ No newline at end of file diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js new file mode 100644 index 00000000000..f34a8088d7b --- /dev/null +++ b/container-analysis/snippets/deleteOccurrence.js @@ -0,0 +1,13 @@ +// [START containeranalysis_delete_occurrence] +// Deletes an existing Occurrence from the server +const deleteOccurrence = async ( + +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); +}; +// [END containeranalysis_delete_occurrence] + +const args = process.argv.slice(2); +deleteOccurrence() \ No newline at end of file diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js new file mode 100644 index 00000000000..108e4330d0d --- /dev/null +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -0,0 +1,14 @@ +// [START containeranalysis_discovery_info] +// Retrieves and prints the Discovery Occurrence created for a specified image +// The Discovery Occurrence contains information about the initial scan on the image +const getDiscoveryInfo = async ( + +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); +}; +// [END containeranalysis_discovery_info] + +const args = process.argv.slice(2); +getDiscoveryInfo(...args).catch(console.error) \ No newline at end of file diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js new file mode 100644 index 00000000000..fa2b9b4f783 --- /dev/null +++ b/container-analysis/snippets/getNote.js @@ -0,0 +1,22 @@ +// [START containeranalysis_get_note] +// Retrieves and prints a specified Note from the server +const getNote = async ( + projectId = 'your-project-id', // Your GCP Project ID + noteId = 'my-note-id', // Id of the not +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient() + + // Get the full path to the note + const formattedName = client.notePath(projectId, noteId); + // Get the note + const [note] = await client.getNote({name: formattedName}); + + console.log(`Note name: ${note.name}`); + +}; +// [END containeranalysis_get_note] + +const args = process.argv.slice(2); +getNote(...args).catch(console.error) diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js new file mode 100644 index 00000000000..8e5329384bf --- /dev/null +++ b/container-analysis/snippets/getOccurrence.js @@ -0,0 +1,13 @@ +// [START containeranalysis_get_occurrence] +// Retrieves and prints a specified Occurrence from the server +const getOccurrence = async( + +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); +}; +// [END containeranalysis_get_occurrence] + +const args = process.argv.slice(2); +getOccurrence(...args).catch(console.error) \ No newline at end of file diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js new file mode 100644 index 00000000000..41df5d06452 --- /dev/null +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -0,0 +1,13 @@ +// [START containeranalysis_filter_vulnerability_occurrences] +// Retrieve a list of vulnerability occurrences with a severity level of 'HIGH' or greater +const highVulnerabilitiesForImage = async( + +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); +}; +// [END containeranalysis_filter_vulnerability_occurrences] + +const args = process.argv.slice(2); +highVulnerabilitiesForImage(...args).catch(console.error); diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js new file mode 100644 index 00000000000..37aeae3b95f --- /dev/null +++ b/container-analysis/snippets/occurrencesForImage.js @@ -0,0 +1,15 @@ +// [START containeranalysis_occurrences_for_image] +// Retrieves all the Occurrences associated with a specified image +// Here, all Occurrences are simply printed and counted +const occurrencesForImage = async( + +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); +}; +// [END containeranalysis_occurrences_for_image] + +const args = process.argv.slice(2); +occurrencesForImage(...args).catch(console.error); + diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js new file mode 100644 index 00000000000..753cf3abd59 --- /dev/null +++ b/container-analysis/snippets/occurrencesForNote.js @@ -0,0 +1,15 @@ +// [START containeranalysis_occurrences_for_note] +// Retrieves all the Occurrences associated with a specified Note +// Here, all Occurrences are printed and counted +const occurrencesForNote = async( + +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); + +}; +// [END containeranalysis_occurrences_for_note] + +const args = process.argv.slice(2); +occurrencesForNote(...args).catch(console.error); \ No newline at end of file diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 1a896861ece..1f35d5b3a80 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -8,7 +8,6 @@ "*.js" ], "engines": { - "node": ">=8" + "node": ">=8" } } - diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js new file mode 100644 index 00000000000..6c9f702cdba --- /dev/null +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -0,0 +1,14 @@ +// [START containeranalysis_poll_discovery_occurrence_finished]i +// Repeatedly query the Container Analysis API for the latest discovery occurrence until it is +// either in a terminal state, or the timeout value has been exceeded +const pollDiscoveryOccurrenceFinished = async ( + +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); +}; +// [END containeranalysis_poll_discovery_occurrence_finished] + +const args = process.argv.slice(2); +pollDiscoveryOccurrenceFinished(...args).catch(console.error); \ No newline at end of file diff --git a/container-analysis/snippets/pubSub.js b/container-analysis/snippets/pubSub.js new file mode 100644 index 00000000000..2b50528f4be --- /dev/null +++ b/container-analysis/snippets/pubSub.js @@ -0,0 +1,13 @@ +// [START containeranalysis_pubsub] +// Handle incoming Occurrences using a Cloud Pub/Sub subscription +const pubSub = async( + +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); +}; +// [END containeranalysis_pubsub] + +const args = process.argv.slice(2); +pubSub(...args).catch(console.error); diff --git a/container-analysis/snippets/vulnerabilityOccurencesForImage.js b/container-analysis/snippets/vulnerabilityOccurencesForImage.js new file mode 100644 index 00000000000..d8093d45844 --- /dev/null +++ b/container-analysis/snippets/vulnerabilityOccurencesForImage.js @@ -0,0 +1,13 @@ +// [START containeranalysis_vulnerability_occurrences_for_image] +// Retrieve a list of vulnerability occurrences assoviated with a resource +const vulnerabilityOccurrencesForImage = async( + +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); +}; +// [END containeranalysis_vulnerability_occurrences_for_image] + +const args = process.argv.slice(2); +vulnerabilityOccurrencesForImage(...args).catch(console.error); From 397455ba014a57d4f2387219b43d9341797ce49b Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Wed, 8 May 2019 17:23:39 -0700 Subject: [PATCH 004/131] passing tests for create, get, delete note and create occurrence --- container-analysis/snippets/createNote.js | 11 +- ...createOccurence.js => createOccurrence.js} | 8 +- container-analysis/snippets/package.json | 8 + .../system-test/containerAnalysis.test.js | 142 ++++++++++++++++++ 4 files changed, 160 insertions(+), 9 deletions(-) rename container-analysis/snippets/{createOccurence.js => createOccurrence.js} (80%) create mode 100644 container-analysis/snippets/system-test/containerAnalysis.test.js diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index 6d3631f74a4..abc1fb6a978 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -1,9 +1,9 @@ // [START containeranalysis_create_note] // Creates and returns a new Note -const createNote = async ( +async function createNote( projectId = 'your-project-id', // Your GCP Project ID noteId = 'my-note-id', // Id of the note -) => { +) { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); @@ -18,12 +18,7 @@ const createNote = async ( parent: formattedParent, noteId: noteId, note: { - noteKind: 'ATTESTATION', - attestationAuthority: { - hint: { - humanReadableName: 'my-authority' - } - } + vulnerability: {} } }); diff --git a/container-analysis/snippets/createOccurence.js b/container-analysis/snippets/createOccurrence.js similarity index 80% rename from container-analysis/snippets/createOccurence.js rename to container-analysis/snippets/createOccurrence.js index 8526c480874..09c4f1a4d85 100644 --- a/container-analysis/snippets/createOccurence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -15,13 +15,19 @@ const createOccurence = async( const formattedNote = client.notePath(noteProjectId, noteId); // Attach the occurence to the associated image url - const [occ] = await client.createOccurrence({ + const [occurrence] = await client.createOccurrence({ parent: formattedParent, occurrence: { noteName: formattedNote, + vulnerability: {}, + resource: { + uri: imageUrl + } } }); + console.log(`Occurrence created for image ${occurrence.resource.uri}.`); + }; // [END containeranalysis_create_occurrence] diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 1f35d5b3a80..56fef32dab6 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -9,5 +9,13 @@ ], "engines": { "node": ">=8" + }, + "scripts": { + "test": "mocha --preserve-symlinks system-test/**.test.js" + }, + "devDependencies": { + "chai": "^4.2.0", + "mocha": "^6.1.4", + "uuid": "^3.3.2" } } diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js new file mode 100644 index 00000000000..d2e336a44e9 --- /dev/null +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -0,0 +1,142 @@ +const { assert } = require('chai'); +const cp = require('child_process'); +const uuid = require(`uuid`); + +const execSync = cmd => cp.execSync(cmd, { encoding: 'utf-8' }); + +const projectId = process.env.GCLOUD_PROJECT; +const noteId = `test-note-${uuid.v4()}`; +const formattedNoteName = `projects/${projectId}/notes/${noteId}` +const formattedOccName = `projects/${projectId}/occurences` +const resourceUrl = `gcr.io/project/image`; + + +describe('Note tests', async function () { + it('should create a note', async function () { + const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); + assert.match( + output, + new RegExp(`Note ${formattedNoteName} created.`) + ); + }); + + + it('should get note', async function () { + const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); + assert.match( + output, + new RegExp(`Note name: ${formattedNoteName}`) + ); + }); + + it('should create occurrence', async function() { + const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"`); + assert.match( + output, + new RegExp(`Occurrence created for image ${resourceUrl}.`) + ) + }); + + it('should delete note', async function() { + const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); + assert.match( + output, + new RegExp(`Note ${formattedNoteName} deleted.`) + ); + }); + +}); + +// describe('Occurrence tests', async function() { +// it('should create occurrence', async function() { +// const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}"`); +// assert.match( +// output, +// new RegExp(`Occurrence created.`) +// ) +// }); +// // TODO: finalize inputs +// it('should get occurrence', async function() { +// const output = execSync(`node getOccurrence.js`); +// assert.match( +// output, +// new RegExp(`Occurrence name: `) +// ) +// }); +// // TODO: +// it('should delete occurrence', async function() { +// const output = execSync(`node deleteOccurrence.js`); +// assert.match( +// output, +// new RegExp(`Occurrence deleted.`) +// ) +// }); +// // TODO: +// it('should get occurences for note', async function() { +// const output = execSync(`node occurrencesForNote.js`); +// assert.match(output, /Occurrences:/); +// }); +// }); +// // TODO: +// describe('image queries', async function() { +// it('should get occurrences for image', async function() { +// const output = execSync(`node occurrencesForImage.js`); +// assert.match( +// output, +// new RegExp(``) +// ); +// }); + +// it('should get high vulnerabilities for image', async function() { +// const output = execSync(`node highVulnerabilitiesForImage`); +// assert.match( +// output, +// new RegExp(``) +// ); +// }); + +// it('should get all vulnerabilites for image', async function() { +// const output = execSync(`node vulnerabilityOccurrencesForImage`); +// assert.match( +// output, +// new RegExp(``) +// ); +// }); + +// it('should get discovery info for image', async function() { +// const output = execSync(`node getDiscoveryInfo`); +// assert.match( +// output, +// new RegExp(``) +// ); +// }); +// }); +// // TODO: +// describe('polling', async function() { +// it('should poll api until timeout', async function() { +// const output = execSync(`node pollDiscoveryOccurrenceFinished.js`); +// assert.match( +// output, +// new RegExp(``) +// ); +// }); + +// it('should successfully poll latest discovery occurrence', async function() { +// const output = execSync(`node pollDiscoveryOccurrenceFinished.js`); +// assert.match( +// output, +// new RegExp(``) +// ); +// }); + +// }); +// // TODO: +// describe('pubsub', async function() { +// it('should get accurate count of occurrences from pubsub topic', async function() { +// const output = execSync(`node pubSub.js`); +// assert.match( +// output, +// new RegExp(``) +// ); +// }); +// }); From 4cdd1ef9ffc8d1c9ba23af4f55cdb827a9b23b2a Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 13 May 2019 20:40:39 -0700 Subject: [PATCH 005/131] passing get occurrence test --- .../snippets/createOccurrence.js | 5 ++- container-analysis/snippets/getOccurrence.js | 14 ++++++++- .../system-test/containerAnalysis.test.js | 31 +++++++++++++------ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index 09c4f1a4d85..28c8305b154 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -25,9 +25,8 @@ const createOccurence = async( } } }); - - console.log(`Occurrence created for image ${occurrence.resource.uri}.`); - + console.log(`Occurrence created ${occurrence.name}.`); + return occurrence; }; // [END containeranalysis_create_occurrence] diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index 8e5329384bf..514885a939e 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -1,11 +1,23 @@ // [START containeranalysis_get_occurrence] // Retrieves and prints a specified Occurrence from the server const getOccurrence = async( - + projectId = 'your-project-id', // Your GCP Project ID + occurrenceId = 'my-occurrence', // Your Occurrence name ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); + + // Get full path to occurrence + const formattedName = client.occurrencePath(projectId, occurrenceId) + + // Get occurrence + const [occurrence] = await client.getOccurrence({ + name: formattedName + }); + + console.log(`Occurrence name: ${occurrence.name}`) + }; // [END containeranalysis_get_occurrence] diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index d2e336a44e9..864b219403d 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -7,7 +7,6 @@ const execSync = cmd => cp.execSync(cmd, { encoding: 'utf-8' }); const projectId = process.env.GCLOUD_PROJECT; const noteId = `test-note-${uuid.v4()}`; const formattedNoteName = `projects/${projectId}/notes/${noteId}` -const formattedOccName = `projects/${projectId}/occurences` const resourceUrl = `gcr.io/project/image`; @@ -33,7 +32,27 @@ describe('Note tests', async function () { const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"`); assert.match( output, - new RegExp(`Occurrence created for image ${resourceUrl}.`) + new RegExp(`Occurrence created`) + ) + + }); + + it('should get occurrence', async function() { + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); + const formattedParent = client.projectPath(projectId); + const [occurrences] = await client.listOccurrences({ + parent: formattedParent + }); + assert(occurrences.length > 0); + + const occurrence = occurrences[0]; + const occurrenceId = occurrence.name.split("/")[3]; + + const output = execSync(`node getOccurrence.js "${projectId}" "${occurrenceId}"`); + assert.match( + output, + new RegExp(`Occurrence name: ${occurrence.name}`) ) }); @@ -56,13 +75,7 @@ describe('Note tests', async function () { // ) // }); // // TODO: finalize inputs -// it('should get occurrence', async function() { -// const output = execSync(`node getOccurrence.js`); -// assert.match( -// output, -// new RegExp(`Occurrence name: `) -// ) -// }); + // // TODO: // it('should delete occurrence', async function() { // const output = execSync(`node deleteOccurrence.js`); From 7353725ca6d0176379e79f8ce0ef39f0ec932333 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 13 May 2019 21:39:37 -0700 Subject: [PATCH 006/131] passing delete occurrence --- .../snippets/deleteOccurrence.js | 19 +++++++++++--- container-analysis/snippets/getOccurrence.js | 2 +- .../system-test/containerAnalysis.test.js | 26 +++++++++++++++---- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index f34a8088d7b..586f3254877 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -1,13 +1,24 @@ // [START containeranalysis_delete_occurrence] // Deletes an existing Occurrence from the server -const deleteOccurrence = async ( - -) => { +async function deleteOccurrence( + projectId = 'your-project-id', // Your GCP Project ID + occurrenceId = 'my-occurrence', // Your Occurrence name +) { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); + + // Get full path to occurrence + const formattedName = client.occurrencePath(projectId, occurrenceId); + + const result = await client.deleteOccurrence({ + name: formattedName + }); + + console.log(`Occurrence deleted: ${formattedName}`); + }; // [END containeranalysis_delete_occurrence] const args = process.argv.slice(2); -deleteOccurrence() \ No newline at end of file +deleteOccurrence(...args).catch(console.error); \ No newline at end of file diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index 514885a939e..9a4df9327e4 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -2,7 +2,7 @@ // Retrieves and prints a specified Occurrence from the server const getOccurrence = async( projectId = 'your-project-id', // Your GCP Project ID - occurrenceId = 'my-occurrence', // Your Occurrence name + occurrenceId = 'my-occurrence' // Your Occurrence name ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index 864b219403d..a4cfbf4f730 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -2,11 +2,15 @@ const { assert } = require('chai'); const cp = require('child_process'); const uuid = require(`uuid`); +const grafeas = require('@google-cloud/grafeas'); +const client = new grafeas.v1.GrafeasClient(); + const execSync = cmd => cp.execSync(cmd, { encoding: 'utf-8' }); const projectId = process.env.GCLOUD_PROJECT; +const formattedParent = `projects/${projectId}`; const noteId = `test-note-${uuid.v4()}`; -const formattedNoteName = `projects/${projectId}/notes/${noteId}` +const formattedNoteName = `projects/${projectId}/notes/${noteId}`; const resourceUrl = `gcr.io/project/image`; @@ -38,9 +42,6 @@ describe('Note tests', async function () { }); it('should get occurrence', async function() { - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); - const formattedParent = client.projectPath(projectId); const [occurrences] = await client.listOccurrences({ parent: formattedParent }); @@ -53,8 +54,23 @@ describe('Note tests', async function () { assert.match( output, new RegExp(`Occurrence name: ${occurrence.name}`) - ) + ); }); + // TODO: + it('should delete occurrence', async function() { + const [occurrences] = await client.listOccurrences({ + parent: formattedParent + }); + assert(occurrences.length > 0); + const occurrence = occurrences[0]; + const occurrenceId = occurrence.name.split("/")[3]; + + const output = execSync(`node deleteOccurrence.js "${projectId}" "${occurrenceId}"`); + assert.match( + output, + new RegExp(`Occurrence deleted.`) + ); + }) it('should delete note', async function() { const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); From e27ca26c3298dada25c64e0cd7a2789cb0237f69 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 13 May 2019 22:17:09 -0700 Subject: [PATCH 007/131] passing test for occurrences for note, flaky --- container-analysis/snippets/getNote.js | 2 +- .../snippets/occurrencesForNote.js | 21 +++++++++++++++- .../system-test/containerAnalysis.test.js | 24 ++++++++++++------- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js index fa2b9b4f783..c2eec3a890b 100644 --- a/container-analysis/snippets/getNote.js +++ b/container-analysis/snippets/getNote.js @@ -2,7 +2,7 @@ // Retrieves and prints a specified Note from the server const getNote = async ( projectId = 'your-project-id', // Your GCP Project ID - noteId = 'my-note-id', // Id of the not + noteId = 'my-note-id', // Id of the note ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index 753cf3abd59..7a093ce6d0e 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -2,12 +2,31 @@ // Retrieves all the Occurrences associated with a specified Note // Here, all Occurrences are printed and counted const occurrencesForNote = async( - + projectId = 'your-project-id', // Your GCP Project ID + noteId = 'my-note-id', // Id of the note ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); + // Get path to Note + const formattedNote = client.notePath(projectId, noteId); + + // Get occurrences + const [occurrences] = await client.listNoteOccurrences({ + name: formattedNote + }); + if (occurrences.length) { + console.log('Occurrences:'); + occurrences.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) + }); + } else { + console.log('No occurrences found.'); + } + + }; // [END containeranalysis_occurrences_for_note] diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index a4cfbf4f730..37006dac2c7 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -23,7 +23,6 @@ describe('Note tests', async function () { ); }); - it('should get note', async function () { const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); assert.match( @@ -32,7 +31,7 @@ describe('Note tests', async function () { ); }); - it('should create occurrence', async function() { + it('should create occurrence', async function () { const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"`); assert.match( output, @@ -41,7 +40,7 @@ describe('Note tests', async function () { }); - it('should get occurrence', async function() { + it('should get occurrence', async function () { const [occurrences] = await client.listOccurrences({ parent: formattedParent }); @@ -56,23 +55,30 @@ describe('Note tests', async function () { new RegExp(`Occurrence name: ${occurrence.name}`) ); }); - // TODO: - it('should delete occurrence', async function() { + + // TODO: + it('should get occurences for note', async function () { + const output = execSync(`node occurrencesForNote.js "${projectId}" "${noteId}"`); + assert.match(output, /Occurrences:/); + }) + + it('should delete occurrence', async function () { const [occurrences] = await client.listOccurrences({ parent: formattedParent }); assert(occurrences.length > 0); const occurrence = occurrences[0]; - const occurrenceId = occurrence.name.split("/")[3]; - + const occurrenceId = occurrence.name.split("/")[3]; + const output = execSync(`node deleteOccurrence.js "${projectId}" "${occurrenceId}"`); assert.match( output, new RegExp(`Occurrence deleted.`) ); - }) + }); + ; - it('should delete note', async function() { + it('should delete note', async function () { const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); assert.match( output, From 1ffccce5901a59277444c6d31a9d58d097af3273 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 14 May 2019 13:14:09 -0700 Subject: [PATCH 008/131] passing occurrences for image --- .../snippets/getDiscoveryInfo.js | 18 +++++++++++++++ .../snippets/highVulnerabilitiesForImage.js | 20 ++++++++++++++++- .../snippets/occurrencesForImage.js | 22 +++++++++++++++++-- .../system-test/containerAnalysis.test.js | 10 ++++++++- .../vulnerabilityOccurencesForImage.js | 18 +++++++++++++++ 5 files changed, 84 insertions(+), 4 deletions(-) diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 108e4330d0d..dbcdb5b1976 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -7,6 +7,24 @@ const getDiscoveryInfo = async ( // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); + + const formattedParent = client.projectPath(projectId); + + const [occurences] = await client.listOccurrences({ + parent: formattedParent, + // TODO: filter throws invalid argument + filter: `resourceUrl` + }); + + if (occurrences.length) { + console.log('Occurrences:'); + occurrences.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) + }); + } else { + console.log('No occurrences found.'); + } }; // [END containeranalysis_discovery_info] diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 41df5d06452..20866f59127 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -1,11 +1,29 @@ // [START containeranalysis_filter_vulnerability_occurrences] // Retrieve a list of vulnerability occurrences with a severity level of 'HIGH' or greater -const highVulnerabilitiesForImage = async( +const highVulnerabilitiesForImage = async ( ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); + + const formattedParent = client.projectPath(projectId); + + const [occurences] = await client.listOccurrences({ + parent: formattedParent, + // TODO: filter throws invalid argument + filter: `resourceUrl` + }); + + if (occurrences.length) { + console.log('Occurrences:'); + occurrences.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) + }); + } else { + console.log('No occurrences found.'); + } }; // [END containeranalysis_filter_vulnerability_occurrences] diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index 37aeae3b95f..eeefbb546ca 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -1,12 +1,30 @@ // [START containeranalysis_occurrences_for_image] // Retrieves all the Occurrences associated with a specified image // Here, all Occurrences are simply printed and counted -const occurrencesForImage = async( - +const occurrencesForImage = async ( + projectId = 'your-project-id', // Your GCP Project ID + imageUrl = 'my-url.io/project/image' // Image to attach metadata to ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); + + const formattedParent = client.projectPath(projectId); + + const [occurrences] = await client.listOccurrences({ + parent: formattedParent, + filter: `resourceUrl = \"${imageUrl}\"` + }); + + if (occurrences.length) { + console.log(`Occurrences for ${imageUrl}`); + occurrences.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) + }); + } else { + console.log('No occurrences found.'); + } }; // [END containeranalysis_occurrences_for_image] diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index 37006dac2c7..f1a77a48709 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -60,7 +60,15 @@ describe('Note tests', async function () { it('should get occurences for note', async function () { const output = execSync(`node occurrencesForNote.js "${projectId}" "${noteId}"`); assert.match(output, /Occurrences:/); - }) + }); + + it('should get occurrences for image', async function() { + const output = execSync(`node occurrencesForImage.js "${projectId}" "${resourceUrl}"`); + assert.match( + output, + new RegExp(`Occurrences for ${resourceUrl}`) + ); + }); it('should delete occurrence', async function () { const [occurrences] = await client.listOccurrences({ diff --git a/container-analysis/snippets/vulnerabilityOccurencesForImage.js b/container-analysis/snippets/vulnerabilityOccurencesForImage.js index d8093d45844..577d6e4c957 100644 --- a/container-analysis/snippets/vulnerabilityOccurencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurencesForImage.js @@ -6,6 +6,24 @@ const vulnerabilityOccurrencesForImage = async( // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); + + const formattedParent = client.projectPath(projectId); + + const [occurences] = await client.listOccurrences({ + parent: formattedParent, + // TODO: filter throws invalid argument + filter: `resourceUrl` + }); + + if (occurrences.length) { + console.log('Occurrences:'); + occurrences.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) + }); + } else { + console.log('No occurrences found.'); + } }; // [END containeranalysis_vulnerability_occurrences_for_image] From 5739d986253b13a05a514d2a88f9f81d7970a13f Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Tue, 14 May 2019 14:29:27 -0700 Subject: [PATCH 009/131] samples --- container-analysis/snippets/.eslintrc.yml | 3 +++ container-analysis/snippets/package.json | 23 ++++++++++++++++ container-analysis/snippets/quickstart.js | 24 +++++++++++++++++ .../snippets/test/.eslintrc.yml | 6 +++++ container-analysis/snippets/test/tests.js | 27 +++++++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 container-analysis/snippets/.eslintrc.yml create mode 100644 container-analysis/snippets/package.json create mode 100644 container-analysis/snippets/quickstart.js create mode 100644 container-analysis/snippets/test/.eslintrc.yml create mode 100644 container-analysis/snippets/test/tests.js diff --git a/container-analysis/snippets/.eslintrc.yml b/container-analysis/snippets/.eslintrc.yml new file mode 100644 index 00000000000..282535f55f6 --- /dev/null +++ b/container-analysis/snippets/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +rules: + no-console: off diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json new file mode 100644 index 00000000000..515f7884b6e --- /dev/null +++ b/container-analysis/snippets/package.json @@ -0,0 +1,23 @@ +{ + "name": "nodejs-containeranalysis-samples", + "private": true, + "license": "Apache-2.0", + "author": "Google Inc.", + "repository": "googleapis/nodejs-containeranalysis", + "files": [ + "*.js" + ], + "engines": { + "node": ">=10" + }, + "scripts": { + "test": "mocha" + }, + "dependencies": { + "@google-cloud/containeranalysis": "^0.1.0" + }, + "devDependencies": { + "chai": "^4.2.0", + "mocha": "^6.0.0" + } +} diff --git a/container-analysis/snippets/quickstart.js b/container-analysis/snippets/quickstart.js new file mode 100644 index 00000000000..47df69fc213 --- /dev/null +++ b/container-analysis/snippets/quickstart.js @@ -0,0 +1,24 @@ +// 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'; + +// [START containeranalysis_quickstart] +async function quickstart() { + // Imports the @google-cloud/containeranalysis client library + const client = require('@google-cloud/containeranalysis'); + console.log(client); +} +quickstart(); +// [END containeranalysis_quickstart] diff --git a/container-analysis/snippets/test/.eslintrc.yml b/container-analysis/snippets/test/.eslintrc.yml new file mode 100644 index 00000000000..3c1b1649787 --- /dev/null +++ b/container-analysis/snippets/test/.eslintrc.yml @@ -0,0 +1,6 @@ +--- +rules: + node/no-unpublished-require: off + no-empty: off +env: + mocha: true diff --git a/container-analysis/snippets/test/tests.js b/container-analysis/snippets/test/tests.js new file mode 100644 index 00000000000..2d84838090f --- /dev/null +++ b/container-analysis/snippets/test/tests.js @@ -0,0 +1,27 @@ +// Copyright 2018 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'; + +const {assert} = require('chai'); +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +describe('container analysis sample tests', () => { + it('should run the quickstart', async () => { + const output = execSync('node quickstart.js'); + assert.isNotEmpty(output); + }); +}); From c0aab112ef2e43369d67569aaa3da30aeffb13e3 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 14 May 2019 15:14:32 -0700 Subject: [PATCH 010/131] passing get Discovery Info --- .../snippets/getDiscoveryInfo.js | 10 ++--- .../system-test/containerAnalysis.test.js | 38 ++++++++++++++++++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index dbcdb5b1976..85f3fe26f0d 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -2,7 +2,8 @@ // Retrieves and prints the Discovery Occurrence created for a specified image // The Discovery Occurrence contains information about the initial scan on the image const getDiscoveryInfo = async ( - + projectId = 'your-project-id', // Your GCP Project ID + imageUrl = 'my-url.io/project/image' // Image to attach metadata to ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); @@ -10,14 +11,13 @@ const getDiscoveryInfo = async ( const formattedParent = client.projectPath(projectId); - const [occurences] = await client.listOccurrences({ + const [occurrences] = await client.listOccurrences({ parent: formattedParent, - // TODO: filter throws invalid argument - filter: `resourceUrl` + filter: `kind = \"DISCOVERY\" AND resourceUrl = \"${imageUrl}\"` }); if (occurrences.length) { - console.log('Occurrences:'); + console.log(`Discovery Occurrences for ${imageUrl}`); occurrences.forEach(occurrence => { console.log(`${occurrence.name}:`); console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index f1a77a48709..9d960b3f648 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -56,7 +56,6 @@ describe('Note tests', async function () { ); }); - // TODO: it('should get occurences for note', async function () { const output = execSync(`node occurrencesForNote.js "${projectId}" "${noteId}"`); assert.match(output, /Occurrences:/); @@ -70,6 +69,43 @@ describe('Note tests', async function () { ); }); + // TODO: + it('should get discovery info for image', async function() { + // TODO: create discovery note and occurrence + const discoveryNoteRequest = { + parent: formattedParent, + noteId: `${noteId}-discovery`, + note: { + discovery: {} + } + }; + + const [discoveryNote] = await client.createNote(discoveryNoteRequest); + + const occurrenceRequest = { + parent: formattedParent, + occurrence: { + noteName: `${formattedNoteName}-discovery`, + discovered: { + discovered: { + analysis_status: 'FINISHED_SUCCESS' + }, + }, + resource: { + uri: resourceUrl + } + } + } + + const [discoveryOccurrence] = await client.createOccurrence(occurrenceRequest) + + const output = execSync(`node getDiscoveryInfo "${projectId}" "${resourceUrl}"`); + assert.match( + output, + new RegExp(`Discovery Occurrences for ${resourceUrl}`) + ); + }); + it('should delete occurrence', async function () { const [occurrences] = await client.listOccurrences({ parent: formattedParent From 12b9c644d5fa437556cd1473d59df6e05ec23320 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 14 May 2019 16:12:40 -0700 Subject: [PATCH 011/131] passing find vulnerabilities for image --- .../snippets/highVulnerabilitiesForImage.js | 10 +++++----- .../snippets/system-test/containerAnalysis.test.js | 11 +++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 20866f59127..a4549681111 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -1,7 +1,8 @@ // [START containeranalysis_filter_vulnerability_occurrences] // Retrieve a list of vulnerability occurrences with a severity level of 'HIGH' or greater const highVulnerabilitiesForImage = async ( - + projectId = 'your-project-id', // Your GCP Project ID + imageUrl = 'my-url.io/project/image' // Image to attach metadata to ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); @@ -9,14 +10,13 @@ const highVulnerabilitiesForImage = async ( const formattedParent = client.projectPath(projectId); - const [occurences] = await client.listOccurrences({ + const [occurrences] = await client.listOccurrences({ parent: formattedParent, - // TODO: filter throws invalid argument - filter: `resourceUrl` + filter: `kind = \"VULNERABILITY\" AND resourceUrl = \"${imageUrl}\"` }); if (occurrences.length) { - console.log('Occurrences:'); + console.log(`High Severity Vulnerabilities for ${imageUrl}`); occurrences.forEach(occurrence => { console.log(`${occurrence.name}:`); console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index 9d960b3f648..f514b4ecc14 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -40,6 +40,7 @@ describe('Note tests', async function () { }); + // TODO: sometimes fails, should try again if no images are found it('should get occurrence', async function () { const [occurrences] = await client.listOccurrences({ parent: formattedParent @@ -69,9 +70,7 @@ describe('Note tests', async function () { ); }); - // TODO: it('should get discovery info for image', async function() { - // TODO: create discovery note and occurrence const discoveryNoteRequest = { parent: formattedParent, noteId: `${noteId}-discovery`, @@ -106,6 +105,14 @@ describe('Note tests', async function () { ); }); + it('should get high vulnerabilities for image', async function() { + const output = execSync(`node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"`); + assert.match( + output, + new RegExp(`High Severity Vulnerabilities for ${resourceUrl}`) + ); + }); + it('should delete occurrence', async function () { const [occurrences] = await client.listOccurrences({ parent: formattedParent From 0483c040af969a62970beab2ae5edb6458e895eb Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Wed, 15 May 2019 11:01:00 -0700 Subject: [PATCH 012/131] passing high severity vulnerability test --- .../snippets/highVulnerabilitiesForImage.js | 2 ++ .../system-test/containerAnalysis.test.js | 32 ++++++++++++++++++- .../vulnerabilityOccurencesForImage.js | 13 ++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index a4549681111..b868d01b47f 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -18,8 +18,10 @@ const highVulnerabilitiesForImage = async ( if (occurrences.length) { console.log(`High Severity Vulnerabilities for ${imageUrl}`); occurrences.forEach(occurrence => { + if (occurrence.vulnerability.severity == 'HIGH' || occurrence.vulnerability.severity == 'CRITICAL') { console.log(`${occurrence.name}:`); console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) + } }); } else { console.log('No occurrences found.'); diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index f514b4ecc14..5d899fa68e6 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -106,7 +106,37 @@ describe('Note tests', async function () { }); it('should get high vulnerabilities for image', async function() { + const criticalNoteReq= { + parent: formattedParent, + noteId: `${noteId}-critical`, + note: { + vulnerability: { + severity: 'CRITICAL' + } + } + } + + const [criticalNote] = await client.createNote(criticalNoteReq); + + const criticalOccurrenceReq = { + parent: formattedParent, + occurrence: { + noteName: `${formattedNoteName}-critical`, + vulnerability: { + vulnerability: { + severity: 'CRITICAL' + } + }, + resource: { + uri: resourceUrl + } + } + } + + const [criticalOccurrence] = await client.createOccurrence(criticalOccurrenceReq); + const output = execSync(`node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"`); + assert.match( output, new RegExp(`High Severity Vulnerabilities for ${resourceUrl}`) @@ -180,7 +210,7 @@ describe('Note tests', async function () { // new RegExp(``) // ); // }); - +// // TODO: what is difference between "all" and "high severity" // it('should get all vulnerabilites for image', async function() { // const output = execSync(`node vulnerabilityOccurrencesForImage`); // assert.match( diff --git a/container-analysis/snippets/vulnerabilityOccurencesForImage.js b/container-analysis/snippets/vulnerabilityOccurencesForImage.js index 577d6e4c957..866f50c6b67 100644 --- a/container-analysis/snippets/vulnerabilityOccurencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurencesForImage.js @@ -1,7 +1,8 @@ // [START containeranalysis_vulnerability_occurrences_for_image] // Retrieve a list of vulnerability occurrences assoviated with a resource -const vulnerabilityOccurrencesForImage = async( - +const vulnerabilityOccurrencesForImage = async ( + projectId = 'your-project-id', // Your GCP Project ID + imageUrl = 'my-url.io/project/image' // Image to attach metadata to ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); @@ -9,14 +10,13 @@ const vulnerabilityOccurrencesForImage = async( const formattedParent = client.projectPath(projectId); - const [occurences] = await client.listOccurrences({ + const [occurrences] = await client.listOccurrences({ parent: formattedParent, - // TODO: filter throws invalid argument - filter: `resourceUrl` + filter: `kind = \"VULNERABILITY\" AND resourceUrl = \"${imageUrl}\"` }); if (occurrences.length) { - console.log('Occurrences:'); + console.log(`High Severity Vulnerabilities for ${imageUrl}`); occurrences.forEach(occurrence => { console.log(`${occurrence.name}:`); console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) @@ -25,6 +25,7 @@ const vulnerabilityOccurrencesForImage = async( console.log('No occurrences found.'); } }; +}; // [END containeranalysis_vulnerability_occurrences_for_image] const args = process.argv.slice(2); From 4cc415f3e347bb576885a6f2e344c17a76de6b31 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Wed, 15 May 2019 11:06:14 -0700 Subject: [PATCH 013/131] pass all vulnerabilities for image --- .../system-test/containerAnalysis.test.js | 34 +++++-------------- ...js => vulnerabilityOccurrencesForImage.js} | 3 +- 2 files changed, 10 insertions(+), 27 deletions(-) rename container-analysis/snippets/{vulnerabilityOccurencesForImage.js => vulnerabilityOccurrencesForImage.js} (94%) diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index 5d899fa68e6..95c5095e055 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -105,7 +105,7 @@ describe('Note tests', async function () { ); }); - it('should get high vulnerabilities for image', async function() { + it('should get high severity vulnerabilities for image', async function() { const criticalNoteReq= { parent: formattedParent, noteId: `${noteId}-critical`, @@ -143,6 +143,14 @@ describe('Note tests', async function () { ); }); + it('should get all vulnerabilites for image', async function() { + const output = execSync(`node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"`); + assert.match( + output, + new RegExp(`All Vulnerabilities for ${resourceUrl}`) + ); + }); + it('should delete occurrence', async function () { const [occurrences] = await client.listOccurrences({ parent: formattedParent @@ -169,30 +177,6 @@ describe('Note tests', async function () { }); -// describe('Occurrence tests', async function() { -// it('should create occurrence', async function() { -// const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}"`); -// assert.match( -// output, -// new RegExp(`Occurrence created.`) -// ) -// }); -// // TODO: finalize inputs - -// // TODO: -// it('should delete occurrence', async function() { -// const output = execSync(`node deleteOccurrence.js`); -// assert.match( -// output, -// new RegExp(`Occurrence deleted.`) -// ) -// }); -// // TODO: -// it('should get occurences for note', async function() { -// const output = execSync(`node occurrencesForNote.js`); -// assert.match(output, /Occurrences:/); -// }); -// }); // // TODO: // describe('image queries', async function() { // it('should get occurrences for image', async function() { diff --git a/container-analysis/snippets/vulnerabilityOccurencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js similarity index 94% rename from container-analysis/snippets/vulnerabilityOccurencesForImage.js rename to container-analysis/snippets/vulnerabilityOccurrencesForImage.js index 866f50c6b67..7f7acad36c4 100644 --- a/container-analysis/snippets/vulnerabilityOccurencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -16,7 +16,7 @@ const vulnerabilityOccurrencesForImage = async ( }); if (occurrences.length) { - console.log(`High Severity Vulnerabilities for ${imageUrl}`); + console.log(`All Vulnerabilities for ${imageUrl}`); occurrences.forEach(occurrence => { console.log(`${occurrence.name}:`); console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) @@ -25,7 +25,6 @@ const vulnerabilityOccurrencesForImage = async ( console.log('No occurrences found.'); } }; -}; // [END containeranalysis_vulnerability_occurrences_for_image] const args = process.argv.slice(2); From 4499e31a8f843ba6612e19c8f24b32f3fc3bf7e9 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Wed, 15 May 2019 15:57:13 -0700 Subject: [PATCH 014/131] failing pubsub --- .../snippets/occurrencePubSub.js | 15 + container-analysis/snippets/pubSub.js | 13 - .../system-test/containerAnalysis.test.js | 371 +++++++++--------- 3 files changed, 207 insertions(+), 192 deletions(-) create mode 100644 container-analysis/snippets/occurrencePubSub.js delete mode 100644 container-analysis/snippets/pubSub.js diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js new file mode 100644 index 00000000000..160accb2906 --- /dev/null +++ b/container-analysis/snippets/occurrencePubSub.js @@ -0,0 +1,15 @@ +// [START containeranalysis_pubsub] +// Handle incoming Occurrences using a Cloud Pub/Sub subscription +const occurrencePubSub = async( + projectId = 'your-project-id', // Your GCP Project ID + subscriptionId = 'my-sub-id', // A user-specified identifier for the new subscription + timeoutSeconds = 'timeout-in-seconds', // The number of seconds to listen for the new Pub/Sub messages +) => { + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); +}; +// [END containeranalysis_pubsub] + +const args = process.argv.slice(2); +occurrencePubSub(...args).catch(console.error); diff --git a/container-analysis/snippets/pubSub.js b/container-analysis/snippets/pubSub.js deleted file mode 100644 index 2b50528f4be..00000000000 --- a/container-analysis/snippets/pubSub.js +++ /dev/null @@ -1,13 +0,0 @@ -// [START containeranalysis_pubsub] -// Handle incoming Occurrences using a Cloud Pub/Sub subscription -const pubSub = async( - -) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); -}; -// [END containeranalysis_pubsub] - -const args = process.argv.slice(2); -pubSub(...args).catch(console.error); diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index 95c5095e055..a94d80f9a0d 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -6,218 +6,189 @@ const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); const execSync = cmd => cp.execSync(cmd, { encoding: 'utf-8' }); +const exec = cmd => cp.exec(cmd, {encoding: 'utf-8'}) const projectId = process.env.GCLOUD_PROJECT; const formattedParent = `projects/${projectId}`; -const noteId = `test-note-${uuid.v4()}`; +const uuidVal = uuid.v4(); +const noteId = `test-note-${uuidVal}`; const formattedNoteName = `projects/${projectId}/notes/${noteId}`; const resourceUrl = `gcr.io/project/image`; +const subscriptionId = `occurrence-subscription-${uuidVal}`; +const timeoutSeconds = 5; +const tryLimit = 10; -describe('Note tests', async function () { - it('should create a note', async function () { - const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); - assert.match( - output, - new RegExp(`Note ${formattedNoteName} created.`) - ); - }); - - it('should get note', async function () { - const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); - assert.match( - output, - new RegExp(`Note name: ${formattedNoteName}`) - ); - }); - it('should create occurrence', async function () { - const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"`); - assert.match( - output, - new RegExp(`Occurrence created`) - ) - - }); - - // TODO: sometimes fails, should try again if no images are found - it('should get occurrence', async function () { - const [occurrences] = await client.listOccurrences({ - parent: formattedParent - }); - assert(occurrences.length > 0); - - const occurrence = occurrences[0]; - const occurrenceId = occurrence.name.split("/")[3]; - - const output = execSync(`node getOccurrence.js "${projectId}" "${occurrenceId}"`); - assert.match( - output, - new RegExp(`Occurrence name: ${occurrence.name}`) - ); - }); - - it('should get occurences for note', async function () { - const output = execSync(`node occurrencesForNote.js "${projectId}" "${noteId}"`); - assert.match(output, /Occurrences:/); - }); - - it('should get occurrences for image', async function() { - const output = execSync(`node occurrencesForImage.js "${projectId}" "${resourceUrl}"`); - assert.match( - output, - new RegExp(`Occurrences for ${resourceUrl}`) - ); - }); - - it('should get discovery info for image', async function() { - const discoveryNoteRequest = { - parent: formattedParent, - noteId: `${noteId}-discovery`, - note: { - discovery: {} - } - }; +// describe('Note tests', async function () { +// it('should create a note', async function () { +// const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); +// assert.match( +// output, +// new RegExp(`Note ${formattedNoteName} created.`) +// ); +// }); - const [discoveryNote] = await client.createNote(discoveryNoteRequest); +// it('should get note', async function () { +// const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); +// assert.match( +// output, +// new RegExp(`Note name: ${formattedNoteName}`) +// ); +// }); - const occurrenceRequest = { - parent: formattedParent, - occurrence: { - noteName: `${formattedNoteName}-discovery`, - discovered: { - discovered: { - analysis_status: 'FINISHED_SUCCESS' - }, - }, - resource: { - uri: resourceUrl - } - } - } +// it('should create occurrence', async function () { +// const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"`); +// assert.match( +// output, +// new RegExp(`Occurrence created`) +// ) - const [discoveryOccurrence] = await client.createOccurrence(occurrenceRequest) +// }); - const output = execSync(`node getDiscoveryInfo "${projectId}" "${resourceUrl}"`); - assert.match( - output, - new RegExp(`Discovery Occurrences for ${resourceUrl}`) - ); - }); +// // TODO: sometimes fails, should try again if no images are found +// it('should get occurrence', async function () { +// const [occurrences] = await client.listOccurrences({ +// parent: formattedParent +// }); +// assert(occurrences.length > 0); - it('should get high severity vulnerabilities for image', async function() { - const criticalNoteReq= { - parent: formattedParent, - noteId: `${noteId}-critical`, - note: { - vulnerability: { - severity: 'CRITICAL' - } - } - } +// const occurrence = occurrences[0]; +// const occurrenceId = occurrence.name.split("/")[3]; +// const output = execSync(`node getOccurrence.js "${projectId}" "${occurrenceId}"`); +// assert.match( +// output, +// new RegExp(`Occurrence name: ${occurrence.name}`) +// ); +// }); - const [criticalNote] = await client.createNote(criticalNoteReq); +// it('should get occurences for note', async function () { +// const output = execSync(`node occurrencesForNote.js "${projectId}" "${noteId}"`); +// assert.match(output, /Occurrences:/); +// }); - const criticalOccurrenceReq = { - parent: formattedParent, - occurrence: { - noteName: `${formattedNoteName}-critical`, - vulnerability: { - vulnerability: { - severity: 'CRITICAL' - } - }, - resource: { - uri: resourceUrl - } - } - } +// it('should get occurrences for image', async function() { +// const output = execSync(`node occurrencesForImage.js "${projectId}" "${resourceUrl}"`); +// assert.match( +// output, +// new RegExp(`Occurrences for ${resourceUrl}`) +// ); +// }); - const [criticalOccurrence] = await client.createOccurrence(criticalOccurrenceReq); +// it('should get discovery info for image', async function() { +// const discoveryNoteRequest = { +// parent: formattedParent, +// noteId: `${noteId}-discovery`, +// note: { +// discovery: {} +// } +// }; + +// const [discoveryNote] = await client.createNote(discoveryNoteRequest); + +// const occurrenceRequest = { +// parent: formattedParent, +// occurrence: { +// noteName: `${formattedNoteName}-discovery`, +// discovered: { +// discovered: { +// analysis_status: 'FINISHED_SUCCESS' +// }, +// }, +// resource: { +// uri: resourceUrl +// } +// } +// } + +// const [discoveryOccurrence] = await client.createOccurrence(occurrenceRequest) + +// const output = execSync(`node getDiscoveryInfo "${projectId}" "${resourceUrl}"`); +// assert.match( +// output, +// new RegExp(`Discovery Occurrences for ${resourceUrl}`) +// ); +// }); - const output = execSync(`node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"`); +// it('should get high severity vulnerabilities for image', async function() { +// const criticalNoteReq= { +// parent: formattedParent, +// noteId: `${noteId}-critical`, +// note: { +// vulnerability: { +// severity: 'CRITICAL' +// } +// } +// } + +// const [criticalNote] = await client.createNote(criticalNoteReq); + +// const criticalOccurrenceReq = { +// parent: formattedParent, +// occurrence: { +// noteName: `${formattedNoteName}-critical`, +// vulnerability: { +// vulnerability: { +// severity: 'CRITICAL' +// } +// }, +// resource: { +// uri: resourceUrl +// } +// } +// } + +// const [criticalOccurrence] = await client.createOccurrence(criticalOccurrenceReq); + +// const output = execSync(`node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"`); - assert.match( - output, - new RegExp(`High Severity Vulnerabilities for ${resourceUrl}`) - ); - }); - - it('should get all vulnerabilites for image', async function() { - const output = execSync(`node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"`); - assert.match( - output, - new RegExp(`All Vulnerabilities for ${resourceUrl}`) - ); - }); - - it('should delete occurrence', async function () { - const [occurrences] = await client.listOccurrences({ - parent: formattedParent - }); - assert(occurrences.length > 0); - const occurrence = occurrences[0]; - const occurrenceId = occurrence.name.split("/")[3]; - - const output = execSync(`node deleteOccurrence.js "${projectId}" "${occurrenceId}"`); - assert.match( - output, - new RegExp(`Occurrence deleted.`) - ); - }); - ; - - it('should delete note', async function () { - const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); - assert.match( - output, - new RegExp(`Note ${formattedNoteName} deleted.`) - ); - }); - -}); - -// // TODO: -// describe('image queries', async function() { -// it('should get occurrences for image', async function() { -// const output = execSync(`node occurrencesForImage.js`); // assert.match( // output, -// new RegExp(``) +// new RegExp(`High Severity Vulnerabilities for ${resourceUrl}`) // ); // }); -// it('should get high vulnerabilities for image', async function() { -// const output = execSync(`node highVulnerabilitiesForImage`); +// it('should get all vulnerabilites for image', async function() { +// const output = execSync(`node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"`); // assert.match( // output, -// new RegExp(``) +// new RegExp(`All Vulnerabilities for ${resourceUrl}`) // ); // }); -// // TODO: what is difference between "all" and "high severity" -// it('should get all vulnerabilites for image', async function() { -// const output = execSync(`node vulnerabilityOccurrencesForImage`); + +// it('should delete occurrence', async function () { +// const [occurrences] = await client.listOccurrences({ +// parent: formattedParent +// }); +// assert(occurrences.length > 0); +// const occurrence = occurrences[0]; +// const occurrenceId = occurrence.name.split("/")[3]; + +// const output = execSync(`node deleteOccurrence.js "${projectId}" "${occurrenceId}"`); // assert.match( // output, -// new RegExp(``) +// new RegExp(`Occurrence deleted.`) // ); // }); +// ; -// it('should get discovery info for image', async function() { -// const output = execSync(`node getDiscoveryInfo`); +// it('should delete note', async function () { +// const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); // assert.match( // output, -// new RegExp(``) +// new RegExp(`Note ${formattedNoteName} deleted.`) // ); // }); + // }); + // // TODO: // describe('polling', async function() { // it('should poll api until timeout', async function() { // const output = execSync(`node pollDiscoveryOccurrenceFinished.js`); // assert.match( // output, -// new RegExp(``) +// new RegExp(`Timeout reached, no discovery occurrences found.`) // ); // }); @@ -225,18 +196,60 @@ describe('Note tests', async function () { // const output = execSync(`node pollDiscoveryOccurrenceFinished.js`); // assert.match( // output, -// new RegExp(``) +// new RegExp(`Latest discovery occurrence: `) // ); // }); // }); // // TODO: -// describe('pubsub', async function() { -// it('should get accurate count of occurrences from pubsub topic', async function() { -// const output = execSync(`node pubSub.js`); -// assert.match( -// output, -// new RegExp(``) -// ); -// }); -// }); +describe('pubsub', async function() { + before(async function() { + const pubSubNoteReq = { + parent: formattedParent, + noteId: `${noteId}-pubsub`, + note: { + vulnerability: {} + } + } + const [pubSubNote] = await client.createNote(pubSubNoteReq); + }); + after(async function() { + const result = await client.deleteNote({name: `${formattedNoteName}-pubsub`}); + }); + it('should get accurate count of occurrences from pubsub topic', async function() { + const expectedNum = 3; + const pubSubOccurrenceReq= { + parent: formattedParent, + occurrence: { + noteName: `${formattedNoteName}-pubsub`, + vulnerability: { + vulnerability: {} + }, + resource: { + uri: resourceUrl + } + } + } + + // run async + const initial = execSync(`node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"`); + + assert.match( + initial, + new RegExp(`Polled 0 occurrences`) + ); + // create test occurrences + for(i=0; i < expectedNum; i++) { + const [pubSubOccurrence] = await client.createOccurrence(pubSubOccurrenceReq); + const pubSubOccurrenceId = pubSubOccurrence.name.split("/")[3]; + const result = await client.deleteOccurrence({name: pubSubOccurrence.name}); + } + const output = execSync(`node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"`); + + // make sure pubsub number matches + assert.match( + output, + new RegExp(`Polled ${expectedNum} occurrences `) + ); + }); +}); From b1b2e6109b194a9e0789b8ae55f6c24de31d1d9b Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Thu, 16 May 2019 12:34:33 -0700 Subject: [PATCH 015/131] passing pubsub tests --- .../snippets/occurrencePubSub.js | 21 +- container-analysis/snippets/package.json | 3 +- .../system-test/containerAnalysis.test.js | 318 +++++++++--------- 3 files changed, 185 insertions(+), 157 deletions(-) diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index 160accb2906..82944d251c7 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -2,12 +2,31 @@ // Handle incoming Occurrences using a Cloud Pub/Sub subscription const occurrencePubSub = async( projectId = 'your-project-id', // Your GCP Project ID - subscriptionId = 'my-sub-id', // A user-specified identifier for the new subscription + subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic timeoutSeconds = 'timeout-in-seconds', // The number of seconds to listen for the new Pub/Sub messages ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); + + // Import the pubsub library and create a client, topic and subscription + const {PubSub} = require('@google-cloud/pubsub'); + const pubsub = new PubSub({projectId}); + const subscription = pubsub.subscription(subscriptionId); + + let count = 0 + const messageHandler = message => { + count ++; + message.ack(); + }; + + // Listen for new messages until timeout is hit + subscription.on(`message`, messageHandler); + + setTimeout(() => { + subscription.removeListener(`message`, messageHandler); + console.log(`Polled ${count} occurrences`); + }, timeoutSeconds * 1000); }; // [END containeranalysis_pubsub] diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 56fef32dab6..8fa703e9f00 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -11,9 +11,10 @@ "node": ">=8" }, "scripts": { - "test": "mocha --preserve-symlinks system-test/**.test.js" + "test": "mocha --preserve-symlinks --timeout 100000 system-test/**.test.js" }, "devDependencies": { + "@google-cloud/pubsub": "^0.28.1", "chai": "^4.2.0", "mocha": "^6.1.4", "uuid": "^3.3.2" diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index a94d80f9a0d..39fc16cf387 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -18,169 +18,172 @@ const subscriptionId = `occurrence-subscription-${uuidVal}`; const timeoutSeconds = 5; const tryLimit = 10; +const {PubSub} = require('@google-cloud/pubsub'); +const pubsub = new PubSub({projectId}); +const topicName = 'container-analysis-occurrences-v1beta1'; +const topic = pubsub.topic(topicName); + +describe('Note tests', async function () { + it('should create a note', async function () { + const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); + assert.match( + output, + new RegExp(`Note ${formattedNoteName} created.`) + ); + }); + it('should get note', async function () { + const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); + assert.match( + output, + new RegExp(`Note name: ${formattedNoteName}`) + ); + }); -// describe('Note tests', async function () { -// it('should create a note', async function () { -// const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); -// assert.match( -// output, -// new RegExp(`Note ${formattedNoteName} created.`) -// ); -// }); + it('should create occurrence', async function () { + const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"`); + assert.match( + output, + new RegExp(`Occurrence created`) + ) -// it('should get note', async function () { -// const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); -// assert.match( -// output, -// new RegExp(`Note name: ${formattedNoteName}`) -// ); -// }); + }); -// it('should create occurrence', async function () { -// const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"`); -// assert.match( -// output, -// new RegExp(`Occurrence created`) -// ) + // TODO: sometimes fails, should try again if no images are found + it('should get occurrence', async function () { + const [occurrences] = await client.listOccurrences({ + parent: formattedParent + }); + assert(occurrences.length > 0); -// }); + const occurrence = occurrences[0]; + const occurrenceId = occurrence.name.split("/")[3]; + const output = execSync(`node getOccurrence.js "${projectId}" "${occurrenceId}"`); + assert.match( + output, + new RegExp(`Occurrence name: ${occurrence.name}`) + ); + }); -// // TODO: sometimes fails, should try again if no images are found -// it('should get occurrence', async function () { -// const [occurrences] = await client.listOccurrences({ -// parent: formattedParent -// }); -// assert(occurrences.length > 0); + it('should get occurences for note', async function () { + const output = execSync(`node occurrencesForNote.js "${projectId}" "${noteId}"`); + assert.match(output, /Occurrences:/); + }); -// const occurrence = occurrences[0]; -// const occurrenceId = occurrence.name.split("/")[3]; -// const output = execSync(`node getOccurrence.js "${projectId}" "${occurrenceId}"`); -// assert.match( -// output, -// new RegExp(`Occurrence name: ${occurrence.name}`) -// ); -// }); + it('should get occurrences for image', async function() { + const output = execSync(`node occurrencesForImage.js "${projectId}" "${resourceUrl}"`); + assert.match( + output, + new RegExp(`Occurrences for ${resourceUrl}`) + ); + }); -// it('should get occurences for note', async function () { -// const output = execSync(`node occurrencesForNote.js "${projectId}" "${noteId}"`); -// assert.match(output, /Occurrences:/); -// }); + it('should get discovery info for image', async function() { + const discoveryNoteRequest = { + parent: formattedParent, + noteId: `${noteId}-discovery`, + note: { + discovery: {} + } + }; -// it('should get occurrences for image', async function() { -// const output = execSync(`node occurrencesForImage.js "${projectId}" "${resourceUrl}"`); -// assert.match( -// output, -// new RegExp(`Occurrences for ${resourceUrl}`) -// ); -// }); + const [discoveryNote] = await client.createNote(discoveryNoteRequest); -// it('should get discovery info for image', async function() { -// const discoveryNoteRequest = { -// parent: formattedParent, -// noteId: `${noteId}-discovery`, -// note: { -// discovery: {} -// } -// }; - -// const [discoveryNote] = await client.createNote(discoveryNoteRequest); - -// const occurrenceRequest = { -// parent: formattedParent, -// occurrence: { -// noteName: `${formattedNoteName}-discovery`, -// discovered: { -// discovered: { -// analysis_status: 'FINISHED_SUCCESS' -// }, -// }, -// resource: { -// uri: resourceUrl -// } -// } -// } - -// const [discoveryOccurrence] = await client.createOccurrence(occurrenceRequest) - -// const output = execSync(`node getDiscoveryInfo "${projectId}" "${resourceUrl}"`); -// assert.match( -// output, -// new RegExp(`Discovery Occurrences for ${resourceUrl}`) -// ); -// }); + const occurrenceRequest = { + parent: formattedParent, + occurrence: { + noteName: `${formattedNoteName}-discovery`, + discovered: { + discovered: { + analysis_status: 'FINISHED_SUCCESS' + }, + }, + resource: { + uri: resourceUrl + } + } + } + + const [discoveryOccurrence] = await client.createOccurrence(occurrenceRequest) -// it('should get high severity vulnerabilities for image', async function() { -// const criticalNoteReq= { -// parent: formattedParent, -// noteId: `${noteId}-critical`, -// note: { -// vulnerability: { -// severity: 'CRITICAL' -// } -// } -// } - -// const [criticalNote] = await client.createNote(criticalNoteReq); - -// const criticalOccurrenceReq = { -// parent: formattedParent, -// occurrence: { -// noteName: `${formattedNoteName}-critical`, -// vulnerability: { -// vulnerability: { -// severity: 'CRITICAL' -// } -// }, -// resource: { -// uri: resourceUrl -// } -// } -// } - -// const [criticalOccurrence] = await client.createOccurrence(criticalOccurrenceReq); - -// const output = execSync(`node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"`); + const output = execSync(`node getDiscoveryInfo "${projectId}" "${resourceUrl}"`); + assert.match( + output, + new RegExp(`Discovery Occurrences for ${resourceUrl}`) + ); + }); + + it('should get high severity vulnerabilities for image', async function() { + const criticalNoteReq= { + parent: formattedParent, + noteId: `${noteId}-critical`, + note: { + vulnerability: { + severity: 'CRITICAL' + } + } + } + + const [criticalNote] = await client.createNote(criticalNoteReq); + + const criticalOccurrenceReq = { + parent: formattedParent, + occurrence: { + noteName: `${formattedNoteName}-critical`, + vulnerability: { + vulnerability: { + severity: 'CRITICAL' + } + }, + resource: { + uri: resourceUrl + } + } + } + + const [criticalOccurrence] = await client.createOccurrence(criticalOccurrenceReq); + + const output = execSync(`node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"`); -// assert.match( -// output, -// new RegExp(`High Severity Vulnerabilities for ${resourceUrl}`) -// ); -// }); + assert.match( + output, + new RegExp(`High Severity Vulnerabilities for ${resourceUrl}`) + ); + }); -// it('should get all vulnerabilites for image', async function() { -// const output = execSync(`node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"`); -// assert.match( -// output, -// new RegExp(`All Vulnerabilities for ${resourceUrl}`) -// ); -// }); + it('should get all vulnerabilites for image', async function() { + const output = execSync(`node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"`); + assert.match( + output, + new RegExp(`All Vulnerabilities for ${resourceUrl}`) + ); + }); -// it('should delete occurrence', async function () { -// const [occurrences] = await client.listOccurrences({ -// parent: formattedParent -// }); -// assert(occurrences.length > 0); -// const occurrence = occurrences[0]; -// const occurrenceId = occurrence.name.split("/")[3]; + it('should delete occurrence', async function () { + const [occurrences] = await client.listOccurrences({ + parent: formattedParent + }); + assert(occurrences.length > 0); + const occurrence = occurrences[0]; + const occurrenceId = occurrence.name.split("/")[3]; -// const output = execSync(`node deleteOccurrence.js "${projectId}" "${occurrenceId}"`); -// assert.match( -// output, -// new RegExp(`Occurrence deleted.`) -// ); -// }); -// ; + const output = execSync(`node deleteOccurrence.js "${projectId}" "${occurrenceId}"`); + assert.match( + output, + new RegExp(`Occurrence deleted.`) + ); + }); + ; -// it('should delete note', async function () { -// const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); -// assert.match( -// output, -// new RegExp(`Note ${formattedNoteName} deleted.`) -// ); -// }); + it('should delete note', async function () { + const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); + assert.match( + output, + new RegExp(`Note ${formattedNoteName} deleted.`) + ); + }); -// }); +}); // // TODO: // describe('polling', async function() { @@ -203,7 +206,8 @@ const tryLimit = 10; // }); // // TODO: describe('pubsub', async function() { - before(async function() { + beforeEach(async function() { + const [subscription] = await topic.createSubscription(subscriptionId); const pubSubNoteReq = { parent: formattedParent, noteId: `${noteId}-pubsub`, @@ -212,9 +216,11 @@ describe('pubsub', async function() { } } const [pubSubNote] = await client.createNote(pubSubNoteReq); + }); - after(async function() { - const result = await client.deleteNote({name: `${formattedNoteName}-pubsub`}); + afterEach(async function() { + await client.deleteNote({name: `${formattedNoteName}-pubsub`}); + await pubsub.subscription(subscriptionId).delete(); }); it('should get accurate count of occurrences from pubsub topic', async function() { const expectedNum = 3; @@ -230,26 +236,28 @@ describe('pubsub', async function() { } } } - - // run async + // empty subscription const initial = execSync(`node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"`); + // make sure empty + const empty = execSync(`node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"`); + assert.match( - initial, + empty, new RegExp(`Polled 0 occurrences`) ); // create test occurrences for(i=0; i < expectedNum; i++) { const [pubSubOccurrence] = await client.createOccurrence(pubSubOccurrenceReq); - const pubSubOccurrenceId = pubSubOccurrence.name.split("/")[3]; - const result = await client.deleteOccurrence({name: pubSubOccurrence.name}); + // const pubSubOccurrenceId = pubSubOccurrence.name.split("/")[3]; + await client.deleteOccurrence({name: pubSubOccurrence.name}); } const output = execSync(`node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"`); // make sure pubsub number matches assert.match( output, - new RegExp(`Polled ${expectedNum} occurrences `) + new RegExp(`Polled ${expectedNum} occurrences`) ); }); }); From 7c665a27a5829ac529c915f42eed9595bc7a69e9 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Thu, 16 May 2019 15:24:17 -0700 Subject: [PATCH 016/131] passing polling test --- .../pollDiscoveryOccurrenceFinished.js | 44 ++++++++++++++++++- .../system-test/containerAnalysis.test.js | 41 ++++++++--------- 2 files changed, 63 insertions(+), 22 deletions(-) diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 6c9f702cdba..9b38929ab3a 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -1,12 +1,52 @@ -// [START containeranalysis_poll_discovery_occurrence_finished]i +// [START containeranalysis_poll_discovery_occurrence_finished] // Repeatedly query the Container Analysis API for the latest discovery occurrence until it is // either in a terminal state, or the timeout value has been exceeded const pollDiscoveryOccurrenceFinished = async ( - + projectId = 'your-project-id', // Your GCP Project ID + imageUrl = 'my-url.io/project/image', // Image to attach metadata to + timeoutSeconds = 'timeout-in-seconds', // The number of seconds to listen for the new Pub/Sub messages ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); + + const formattedParent = client.projectPath(projectId); + + let filter = `resourceUrl=\"${imageUrl}\" AND noteProjectId=\"goog-analysis\" AND noteId=\"PACKAGE_VULNERABILITY\"`; + // [END containeranalysis_poll_discovery_occurrence_finished] + filter = `kind = \"DISCOVERY\" AND resourceUrl = \"${imageUrl}\"`; + // [START containeranalysis_poll_discovery_occurrence_finished] + + const pollDiscoveryOccurrence = () => { + return new Promise(async(resolve, reject) => { + setTimeout(() =>{ + reject('Timeout while retrieving discovery occurrence.'); + }, timeoutSeconds * 1000); + let found = false; + while (found == false) { + let [discoveryOccurrences] = await client.listOccurrences({ + parent: formattedParent, + filter: filter + }) + if (discoveryOccurrences.length > 0) { + found = true; + clearTimeout(); + resolve(discoveryOccurrences); + } + } + }); + } + pollDiscoveryOccurrence().then(result => { + console.log(`Polled Discovery Occurrences for ${imageUrl}`); + result.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) + }); + + }).catch(err => { + console.log(err); + }); + }; // [END containeranalysis_poll_discovery_occurrence_finished] diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/system-test/containerAnalysis.test.js index 39fc16cf387..1c41ea4721d 100644 --- a/container-analysis/snippets/system-test/containerAnalysis.test.js +++ b/container-analysis/snippets/system-test/containerAnalysis.test.js @@ -14,6 +14,7 @@ const uuidVal = uuid.v4(); const noteId = `test-note-${uuidVal}`; const formattedNoteName = `projects/${projectId}/notes/${noteId}`; const resourceUrl = `gcr.io/project/image`; +const urlWithoutOccurrences = `gcr.io/project/nooccurrences`; const subscriptionId = `occurrence-subscription-${uuidVal}`; const timeoutSeconds = 5; const tryLimit = 10; @@ -185,26 +186,26 @@ describe('Note tests', async function () { }); -// // TODO: -// describe('polling', async function() { -// it('should poll api until timeout', async function() { -// const output = execSync(`node pollDiscoveryOccurrenceFinished.js`); -// assert.match( -// output, -// new RegExp(`Timeout reached, no discovery occurrences found.`) -// ); -// }); - -// it('should successfully poll latest discovery occurrence', async function() { -// const output = execSync(`node pollDiscoveryOccurrenceFinished.js`); -// assert.match( -// output, -// new RegExp(`Latest discovery occurrence: `) -// ); -// }); - -// }); -// // TODO: +// TODO: +describe('polling', async function() { + // it('should poll api until timeout', async function() { + // const output = execSync(`node pollDiscoveryOccurrenceFinished.js "${projectId}" "${urlWithoutOccurrences}" "${timeoutSeconds}"`); + // assert.match( + // output, + // new RegExp(`'Timeout while retrieving discovery occurrence.`) + // ); + // }); + + it('should successfully poll latest discovery occurrence', async function() { + const output = execSync(`node pollDiscoveryOccurrenceFinished.js "${projectId}" "${resourceUrl}" "${timeoutSeconds}"`); + assert.match( + output, + new RegExp(`Polled Discovery Occurrences for ${resourceUrl}`) + ); + }); + +}); +// TODO: describe('pubsub', async function() { beforeEach(async function() { const [subscription] = await topic.createSubscription(subscriptionId); From 0595e4a85d2d90ae259bc9369c74e69ee2852ca6 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 09:35:27 -0700 Subject: [PATCH 017/131] updated imageUrl to https://gcr.io/my-project/my-image:123 for more realistic use case --- container-analysis/snippets/createOccurrence.js | 2 +- container-analysis/snippets/getDiscoveryInfo.js | 2 +- container-analysis/snippets/highVulnerabilitiesForImage.js | 2 +- container-analysis/snippets/occurrencesForImage.js | 2 +- container-analysis/snippets/pollDiscoveryOccurrenceFinished.js | 2 +- container-analysis/snippets/vulnerabilityOccurrencesForImage.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index 28c8305b154..b34766c315d 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -4,7 +4,7 @@ const createOccurence = async( noteProjectId = 'your-project-id', // Your GCP Project Id noteId = 'my-note-id', // Id of the note occurenceProjectId = 'your-project-id', // GCP Project Id of Occurence - imageUrl = 'my-url.io/project/image' // Image to attach metadata to + imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 85f3fe26f0d..0df620060e9 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -3,7 +3,7 @@ // The Discovery Occurrence contains information about the initial scan on the image const getDiscoveryInfo = async ( projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'my-url.io/project/image' // Image to attach metadata to + imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index b868d01b47f..2a7988e0b0c 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -2,7 +2,7 @@ // Retrieve a list of vulnerability occurrences with a severity level of 'HIGH' or greater const highVulnerabilitiesForImage = async ( projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'my-url.io/project/image' // Image to attach metadata to + imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index eeefbb546ca..6e22ad16948 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -3,7 +3,7 @@ // Here, all Occurrences are simply printed and counted const occurrencesForImage = async ( projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'my-url.io/project/image' // Image to attach metadata to + imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 9b38929ab3a..a31d1d0b2e4 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -3,7 +3,7 @@ // either in a terminal state, or the timeout value has been exceeded const pollDiscoveryOccurrenceFinished = async ( projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'my-url.io/project/image', // Image to attach metadata to + imageUrl = 'https://gcr.io/my-project/my-image:123', // Image to attach metadata to timeoutSeconds = 'timeout-in-seconds', // The number of seconds to listen for the new Pub/Sub messages ) => { // Import the library and create a client diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index 7f7acad36c4..5e48b2b97c4 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -2,7 +2,7 @@ // Retrieve a list of vulnerability occurrences assoviated with a resource const vulnerabilityOccurrencesForImage = async ( projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'my-url.io/project/image' // Image to attach metadata to + imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); From c1f354e9ebf0a78bdfedb58db41bbc7006235830 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 09:41:37 -0700 Subject: [PATCH 018/131] removed escape slashes from filter strings, not needed --- container-analysis/snippets/getDiscoveryInfo.js | 2 +- container-analysis/snippets/highVulnerabilitiesForImage.js | 2 +- container-analysis/snippets/occurrencesForImage.js | 2 +- container-analysis/snippets/vulnerabilityOccurrencesForImage.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 0df620060e9..69ff443f3f6 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -13,7 +13,7 @@ const getDiscoveryInfo = async ( const [occurrences] = await client.listOccurrences({ parent: formattedParent, - filter: `kind = \"DISCOVERY\" AND resourceUrl = \"${imageUrl}\"` + filter: `kind = "DISCOVERY" AND resourceUrl = "${imageUrl}"` }); if (occurrences.length) { diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 2a7988e0b0c..0719bec3593 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -12,7 +12,7 @@ const highVulnerabilitiesForImage = async ( const [occurrences] = await client.listOccurrences({ parent: formattedParent, - filter: `kind = \"VULNERABILITY\" AND resourceUrl = \"${imageUrl}\"` + filter: `kind = "VULNERABILITY" AND resourceUrl = "${imageUrl}"` }); if (occurrences.length) { diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index 6e22ad16948..e97aee95dee 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -13,7 +13,7 @@ const occurrencesForImage = async ( const [occurrences] = await client.listOccurrences({ parent: formattedParent, - filter: `resourceUrl = \"${imageUrl}\"` + filter: `resourceUrl = "${imageUrl}"` }); if (occurrences.length) { diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index 5e48b2b97c4..e4b3798c3cf 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -12,7 +12,7 @@ const vulnerabilityOccurrencesForImage = async ( const [occurrences] = await client.listOccurrences({ parent: formattedParent, - filter: `kind = \"VULNERABILITY\" AND resourceUrl = \"${imageUrl}\"` + filter: `kind = "VULNERABILITY" AND resourceUrl = "${imageUrl}"` }); if (occurrences.length) { From a17a296a4dc4495868a5f1bb859fe78839800842 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 09:42:54 -0700 Subject: [PATCH 019/131] updated description of occurrenceId --- container-analysis/snippets/getOccurrence.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index 9a4df9327e4..df5aa498a12 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -2,7 +2,7 @@ // Retrieves and prints a specified Occurrence from the server const getOccurrence = async( projectId = 'your-project-id', // Your GCP Project ID - occurrenceId = 'my-occurrence' // Your Occurrence name + occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence ) => { // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); From 68c04d33538327084470767f40e5020cce80328e Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 10:23:32 -0700 Subject: [PATCH 020/131] added comment to explain second filter statement, needed for testing --- container-analysis/snippets/pollDiscoveryOccurrenceFinished.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index a31d1d0b2e4..a298730aa47 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -14,6 +14,8 @@ const pollDiscoveryOccurrenceFinished = async ( let filter = `resourceUrl=\"${imageUrl}\" AND noteProjectId=\"goog-analysis\" AND noteId=\"PACKAGE_VULNERABILITY\"`; // [END containeranalysis_poll_discovery_occurrence_finished] + // The above filter isn't testable, since it looks for occurrences in a locked down project + // Fall back to a more permissive filter for testing filter = `kind = \"DISCOVERY\" AND resourceUrl = \"${imageUrl}\"`; // [START containeranalysis_poll_discovery_occurrence_finished] From 14ec8e40a59ac3fbc251b5f08ee198050e4178be Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 10:31:10 -0700 Subject: [PATCH 021/131] explicity state length greater than zero --- container-analysis/snippets/getDiscoveryInfo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 69ff443f3f6..9c589acdf43 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -16,7 +16,7 @@ const getDiscoveryInfo = async ( filter: `kind = "DISCOVERY" AND resourceUrl = "${imageUrl}"` }); - if (occurrences.length) { + if (occurrences.length > 0) { console.log(`Discovery Occurrences for ${imageUrl}`); occurrences.forEach(occurrence => { console.log(`${occurrence.name}:`); From 14353232c4ce15f43b154936a8209987d379db98 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 11:14:29 -0700 Subject: [PATCH 022/131] removed system-test, moved tests into test directory --- container-analysis/snippets/package.json | 2 +- container-analysis/snippets/system-test/.eslintrc.yml | 3 --- .../snippets/{system-test => test}/containerAnalysis.test.js | 0 3 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 container-analysis/snippets/system-test/.eslintrc.yml rename container-analysis/snippets/{system-test => test}/containerAnalysis.test.js (100%) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index e755d045909..3946dc89627 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -11,7 +11,7 @@ "node": ">=10" }, "scripts": { - "test": "mocha --preserve-symlinks --timeout 100000 system-test/**.test.js" + "test": "mocha --preserve-symlinks --timeout 100000 test/**.test.js" }, "devDependencies": { "@google-cloud/pubsub": "^0.28.1", diff --git a/container-analysis/snippets/system-test/.eslintrc.yml b/container-analysis/snippets/system-test/.eslintrc.yml deleted file mode 100644 index 6db2a46c535..00000000000 --- a/container-analysis/snippets/system-test/.eslintrc.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -env: - mocha: true diff --git a/container-analysis/snippets/system-test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js similarity index 100% rename from container-analysis/snippets/system-test/containerAnalysis.test.js rename to container-analysis/snippets/test/containerAnalysis.test.js From 5de03365957b1001ff09e95c1d0f1b80fd38883c Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 14:16:43 -0700 Subject: [PATCH 023/131] removed async functions from tests without await --- .../snippets/test/containerAnalysis.test.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 1c41ea4721d..a834291debb 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -24,8 +24,8 @@ const pubsub = new PubSub({projectId}); const topicName = 'container-analysis-occurrences-v1beta1'; const topic = pubsub.topic(topicName); -describe('Note tests', async function () { - it('should create a note', async function () { +describe('Note tests', function () { + it('should create a note', function () { const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); assert.match( output, @@ -33,7 +33,7 @@ describe('Note tests', async function () { ); }); - it('should get note', async function () { + it('should get note', function () { const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); assert.match( output, @@ -41,7 +41,7 @@ describe('Note tests', async function () { ); }); - it('should create occurrence', async function () { + it('should create occurrence', function () { const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"`); assert.match( output, @@ -66,12 +66,12 @@ describe('Note tests', async function () { ); }); - it('should get occurences for note', async function () { + it('should get occurences for note', function () { const output = execSync(`node occurrencesForNote.js "${projectId}" "${noteId}"`); assert.match(output, /Occurrences:/); }); - it('should get occurrences for image', async function() { + it('should get occurrences for image', function() { const output = execSync(`node occurrencesForImage.js "${projectId}" "${resourceUrl}"`); assert.match( output, @@ -152,7 +152,7 @@ describe('Note tests', async function () { ); }); - it('should get all vulnerabilites for image', async function() { + it('should get all vulnerabilites for image', function() { const output = execSync(`node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"`); assert.match( output, @@ -160,7 +160,7 @@ describe('Note tests', async function () { ); }); - it('should delete occurrence', async function () { + it('should delete occurrence', async function() { const [occurrences] = await client.listOccurrences({ parent: formattedParent }); @@ -176,7 +176,7 @@ describe('Note tests', async function () { }); ; - it('should delete note', async function () { + it('should delete note', function () { const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); assert.match( output, @@ -187,8 +187,8 @@ describe('Note tests', async function () { }); // TODO: -describe('polling', async function() { - // it('should poll api until timeout', async function() { +describe('polling', function() { + // it('should poll api until timeout', function() { // const output = execSync(`node pollDiscoveryOccurrenceFinished.js "${projectId}" "${urlWithoutOccurrences}" "${timeoutSeconds}"`); // assert.match( // output, @@ -196,7 +196,7 @@ describe('polling', async function() { // ); // }); - it('should successfully poll latest discovery occurrence', async function() { + it('should successfully poll latest discovery occurrence', function() { const output = execSync(`node pollDiscoveryOccurrenceFinished.js "${projectId}" "${resourceUrl}" "${timeoutSeconds}"`); assert.match( output, @@ -206,7 +206,7 @@ describe('polling', async function() { }); // TODO: -describe('pubsub', async function() { +describe('pubsub', function() { beforeEach(async function() { const [subscription] = await topic.createSubscription(subscriptionId); const pubSubNoteReq = { From d030bb1948acc48f92a7cf85f14457126734b51e Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 14:22:30 -0700 Subject: [PATCH 024/131] removed unused exec --- container-analysis/snippets/test/containerAnalysis.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index a834291debb..0ca995bd63e 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -6,7 +6,6 @@ const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); const execSync = cmd => cp.execSync(cmd, { encoding: 'utf-8' }); -const exec = cmd => cp.exec(cmd, {encoding: 'utf-8'}) const projectId = process.env.GCLOUD_PROJECT; const formattedParent = `projects/${projectId}`; From 3032fb35ea46b9285af2a93dcde0125594d50ef6 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 14:37:47 -0700 Subject: [PATCH 025/131] removed explicit project id from pub sub --- container-analysis/snippets/test/containerAnalysis.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 0ca995bd63e..6bdb7e5dd2b 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -19,7 +19,7 @@ const timeoutSeconds = 5; const tryLimit = 10; const {PubSub} = require('@google-cloud/pubsub'); -const pubsub = new PubSub({projectId}); +const pubsub = new PubSub(); const topicName = 'container-analysis-occurrences-v1beta1'; const topic = pubsub.topic(topicName); From 3af92d1d63c11f99126eee0b619acf936096372a Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 14:44:11 -0700 Subject: [PATCH 026/131] ran fix --- container-analysis/snippets/createNote.js | 42 +- .../snippets/createOccurrence.js | 52 +- container-analysis/snippets/deleteNote.js | 24 +- .../snippets/deleteOccurrence.js | 27 +- .../snippets/getDiscoveryInfo.js | 42 +- container-analysis/snippets/getNote.js | 23 +- container-analysis/snippets/getOccurrence.js | 29 +- .../snippets/highVulnerabilitiesForImage.js | 47 +- .../snippets/occurrencePubSub.js | 46 +- .../snippets/occurrencesForImage.js | 41 +- .../snippets/occurrencesForNote.js | 46 +- .../pollDiscoveryOccurrenceFinished.js | 86 ++-- .../snippets/test/containerAnalysis.test.js | 456 +++++++++--------- .../vulnerabilityOccurrencesForImage.js | 40 +- 14 files changed, 501 insertions(+), 500 deletions(-) diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index abc1fb6a978..239547859e0 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -1,32 +1,30 @@ // [START containeranalysis_create_note] // Creates and returns a new Note async function createNote( - projectId = 'your-project-id', // Your GCP Project ID - noteId = 'my-note-id', // Id of the note + projectId = 'your-project-id', // Your GCP Project ID + noteId = 'my-note-id' // Id of the note ) { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - // 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 "attestation" - const formattedParent = client.projectPath(projectId); + // 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 "attestation" + const formattedParent = client.projectPath(projectId); - const [note] = await client.createNote({ - parent: formattedParent, - noteId: noteId, - note: { - vulnerability: {} - } - }); + const [note] = await client.createNote({ + parent: formattedParent, + noteId: noteId, + note: { + vulnerability: {}, + }, + }); - console.log(`Note ${note.name} created.`); - -}; + console.log(`Note ${note.name} created.`); +} // [END containeranalysis_create_note] - const args = process.argv.slice(2); -createNote(...args).catch(console.error); \ No newline at end of file +createNote(...args).catch(console.error); diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index b34766c315d..08c34ee9448 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -1,34 +1,34 @@ // [START containeranalysis_create_occurrence] // Creates and returns a new Occurrence associated with an existing Note -const createOccurence = async( - noteProjectId = 'your-project-id', // Your GCP Project Id - noteId = 'my-note-id', // Id of the note - occurenceProjectId = 'your-project-id', // GCP Project Id of Occurence - imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to +const createOccurence = async ( + noteProjectId = 'your-project-id', // Your GCP Project Id + noteId = 'my-note-id', // Id of the note + occurenceProjectId = 'your-project-id', // GCP Project Id of Occurence + imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); - - // Construct request - const formattedParent = client.projectPath(occurenceProjectId); - const formattedNote = client.notePath(noteProjectId, noteId); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - // Attach the occurence to the associated image url - const [occurrence] = await client.createOccurrence({ - parent: formattedParent, - occurrence: { - noteName: formattedNote, - vulnerability: {}, - resource: { - uri: imageUrl - } - } - }); - console.log(`Occurrence created ${occurrence.name}.`); - return occurrence; + // Construct request + const formattedParent = client.projectPath(occurenceProjectId); + const formattedNote = client.notePath(noteProjectId, noteId); + + // Attach the occurence to the associated image url + const [occurrence] = await client.createOccurrence({ + parent: formattedParent, + occurrence: { + noteName: formattedNote, + vulnerability: {}, + resource: { + uri: imageUrl, + }, + }, + }); + console.log(`Occurrence created ${occurrence.name}.`); + return occurrence; }; // [END containeranalysis_create_occurrence] const args = process.argv.slice(2); -createOccurence(...args).catch(console.error); \ No newline at end of file +createOccurence(...args).catch(console.error); diff --git a/container-analysis/snippets/deleteNote.js b/container-analysis/snippets/deleteNote.js index ef7e68b5313..6c80921520f 100644 --- a/container-analysis/snippets/deleteNote.js +++ b/container-analysis/snippets/deleteNote.js @@ -1,21 +1,21 @@ // [START containeranalysis_delete_note] // Deletes an existing Note from the server -const deleteNote = async( - projectId = 'your-project-id', // Your GCP Project Id - noteId = 'my-note-id', // Id of the note +const deleteNote = async ( + projectId = 'your-project-id', // Your GCP Project Id + noteId = 'my-note-id' // Id of the note ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - // Get the full path to the note - const formattedName = client.notePath(projectId, noteId); + // Get the full path to the note + const formattedName = client.notePath(projectId, noteId); - // Delete the note - const response = await client.deleteNote({name: formattedName}); - console.log(`Note ${formattedName} deleted.`); + // Delete the note + const response = await client.deleteNote({name: formattedName}); + console.log(`Note ${formattedName} deleted.`); }; // [END containeranalysis_delete_note] const args = process.argv.slice(2); -deleteNote(...args).catch(console.error); \ No newline at end of file +deleteNote(...args).catch(console.error); diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index 586f3254877..5b3257891ad 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -1,24 +1,23 @@ // [START containeranalysis_delete_occurrence] // Deletes an existing Occurrence from the server async function deleteOccurrence( - projectId = 'your-project-id', // Your GCP Project ID - occurrenceId = 'my-occurrence', // Your Occurrence name + projectId = 'your-project-id', // Your GCP Project ID + occurrenceId = 'my-occurrence' // Your Occurrence name ) { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - // Get full path to occurrence - const formattedName = client.occurrencePath(projectId, occurrenceId); + // Get full path to occurrence + const formattedName = client.occurrencePath(projectId, occurrenceId); - const result = await client.deleteOccurrence({ - name: formattedName - }); + const result = await client.deleteOccurrence({ + name: formattedName, + }); - console.log(`Occurrence deleted: ${formattedName}`); - -}; + console.log(`Occurrence deleted: ${formattedName}`); +} // [END containeranalysis_delete_occurrence] const args = process.argv.slice(2); -deleteOccurrence(...args).catch(console.error); \ No newline at end of file +deleteOccurrence(...args).catch(console.error); diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 9c589acdf43..2c5755d900d 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -2,31 +2,33 @@ // Retrieves and prints the Discovery Occurrence created for a specified image // The Discovery Occurrence contains information about the initial scan on the image const getDiscoveryInfo = async ( - projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + projectId = 'your-project-id', // Your GCP Project ID + imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - const formattedParent = client.projectPath(projectId); + const formattedParent = client.projectPath(projectId); - const [occurrences] = await client.listOccurrences({ - parent: formattedParent, - filter: `kind = "DISCOVERY" AND resourceUrl = "${imageUrl}"` - }); + const [occurrences] = await client.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}:`); - console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) - }); - } else { - console.log('No occurrences found.'); - } + if (occurrences.length > 0) { + console.log(`Discovery Occurrences for ${imageUrl}`); + occurrences.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log( + ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` + ); + }); + } else { + console.log('No occurrences found.'); + } }; // [END containeranalysis_discovery_info] const args = process.argv.slice(2); -getDiscoveryInfo(...args).catch(console.error) \ No newline at end of file +getDiscoveryInfo(...args).catch(console.error); diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js index c2eec3a890b..edfbbf38ff7 100644 --- a/container-analysis/snippets/getNote.js +++ b/container-analysis/snippets/getNote.js @@ -1,22 +1,21 @@ // [START containeranalysis_get_note] // Retrieves and prints a specified Note from the server const getNote = async ( - projectId = 'your-project-id', // Your GCP Project ID - noteId = 'my-note-id', // Id of the note + projectId = 'your-project-id', // Your GCP Project ID + noteId = 'my-note-id' // Id of the note ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient() + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - // Get the full path to the note - const formattedName = client.notePath(projectId, noteId); - // Get the note - const [note] = await client.getNote({name: formattedName}); - - console.log(`Note name: ${note.name}`); + // Get the full path to the note + const formattedName = client.notePath(projectId, noteId); + // Get the note + const [note] = await client.getNote({name: formattedName}); + console.log(`Note name: ${note.name}`); }; // [END containeranalysis_get_note] const args = process.argv.slice(2); -getNote(...args).catch(console.error) +getNote(...args).catch(console.error); diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index df5aa498a12..b6e2f427cbd 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -1,25 +1,24 @@ // [START containeranalysis_get_occurrence] // Retrieves and prints a specified Occurrence from the server -const getOccurrence = async( - projectId = 'your-project-id', // Your GCP Project ID - occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence +const getOccurrence = async ( + projectId = 'your-project-id', // Your GCP Project ID + occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - // Get full path to occurrence - const formattedName = client.occurrencePath(projectId, occurrenceId) + // Get full path to occurrence + const formattedName = client.occurrencePath(projectId, occurrenceId); - // Get occurrence - const [occurrence] = await client.getOccurrence({ - name: formattedName - }); - - console.log(`Occurrence name: ${occurrence.name}`) + // Get occurrence + const [occurrence] = await client.getOccurrence({ + name: formattedName, + }); + console.log(`Occurrence name: ${occurrence.name}`); }; // [END containeranalysis_get_occurrence] const args = process.argv.slice(2); -getOccurrence(...args).catch(console.error) \ No newline at end of file +getOccurrence(...args).catch(console.error); diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 0719bec3593..1c869708db8 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -1,31 +1,36 @@ // [START containeranalysis_filter_vulnerability_occurrences] // Retrieve a list of vulnerability occurrences with a severity level of 'HIGH' or greater const highVulnerabilitiesForImage = async ( - projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + projectId = 'your-project-id', // Your GCP Project ID + imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - const formattedParent = client.projectPath(projectId); + const formattedParent = client.projectPath(projectId); - const [occurrences] = await client.listOccurrences({ - parent: formattedParent, - filter: `kind = "VULNERABILITY" AND resourceUrl = "${imageUrl}"` - }); + const [occurrences] = await client.listOccurrences({ + parent: formattedParent, + filter: `kind = "VULNERABILITY" AND resourceUrl = "${imageUrl}"`, + }); - if (occurrences.length) { - console.log(`High Severity Vulnerabilities for ${imageUrl}`); - occurrences.forEach(occurrence => { - if (occurrence.vulnerability.severity == 'HIGH' || occurrence.vulnerability.severity == 'CRITICAL') { - console.log(`${occurrence.name}:`); - console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) - } - }); - } else { - console.log('No occurrences found.'); - } + if (occurrences.length) { + console.log(`High Severity Vulnerabilities for ${imageUrl}`); + occurrences.forEach(occurrence => { + if ( + occurrence.vulnerability.severity == 'HIGH' || + occurrence.vulnerability.severity == 'CRITICAL' + ) { + console.log(`${occurrence.name}:`); + console.log( + ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` + ); + } + }); + } else { + console.log('No occurrences found.'); + } }; // [END containeranalysis_filter_vulnerability_occurrences] diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index 82944d251c7..2bc068444a8 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -1,32 +1,32 @@ // [START containeranalysis_pubsub] // Handle incoming Occurrences using a Cloud Pub/Sub subscription -const occurrencePubSub = async( - projectId = 'your-project-id', // Your GCP Project ID - subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic - timeoutSeconds = 'timeout-in-seconds', // The number of seconds to listen for the new Pub/Sub messages +const occurrencePubSub = async ( + projectId = 'your-project-id', // Your GCP Project ID + subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic + timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub messages ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); - - // Import the pubsub library and create a client, topic and subscription - const {PubSub} = require('@google-cloud/pubsub'); - const pubsub = new PubSub({projectId}); - const subscription = pubsub.subscription(subscriptionId); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - let count = 0 - const messageHandler = message => { - count ++; - message.ack(); - }; + // Import the pubsub library and create a client, topic and subscription + const {PubSub} = require('@google-cloud/pubsub'); + const pubsub = new PubSub({projectId}); + const subscription = pubsub.subscription(subscriptionId); - // Listen for new messages until timeout is hit - subscription.on(`message`, messageHandler); + let count = 0; + const messageHandler = message => { + count++; + message.ack(); + }; - setTimeout(() => { - subscription.removeListener(`message`, messageHandler); - console.log(`Polled ${count} occurrences`); - }, timeoutSeconds * 1000); + // Listen for new messages until timeout is hit + subscription.on(`message`, messageHandler); + + setTimeout(() => { + subscription.removeListener(`message`, messageHandler); + console.log(`Polled ${count} occurrences`); + }, timeoutSeconds * 1000); }; // [END containeranalysis_pubsub] diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index e97aee95dee..06871d105e9 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -2,32 +2,33 @@ // Retrieves all the Occurrences associated with a specified image // Here, all Occurrences are simply printed and counted const occurrencesForImage = async ( - projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + projectId = 'your-project-id', // Your GCP Project ID + imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - const formattedParent = client.projectPath(projectId); + const formattedParent = client.projectPath(projectId); - const [occurrences] = await client.listOccurrences({ - parent: formattedParent, - filter: `resourceUrl = "${imageUrl}"` - }); + const [occurrences] = await client.listOccurrences({ + parent: formattedParent, + filter: `resourceUrl = "${imageUrl}"`, + }); - if (occurrences.length) { - console.log(`Occurrences for ${imageUrl}`); - occurrences.forEach(occurrence => { - console.log(`${occurrence.name}:`); - console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) - }); - } else { - console.log('No occurrences found.'); - } + if (occurrences.length) { + console.log(`Occurrences for ${imageUrl}`); + occurrences.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log( + ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` + ); + }); + } else { + console.log('No occurrences found.'); + } }; // [END containeranalysis_occurrences_for_image] const args = process.argv.slice(2); occurrencesForImage(...args).catch(console.error); - diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index 7a093ce6d0e..d1236c43434 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -1,34 +1,34 @@ // [START containeranalysis_occurrences_for_note] // Retrieves all the Occurrences associated with a specified Note // Here, all Occurrences are printed and counted -const occurrencesForNote = async( - projectId = 'your-project-id', // Your GCP Project ID - noteId = 'my-note-id', // Id of the note +const occurrencesForNote = async ( + projectId = 'your-project-id', // Your GCP Project ID + noteId = 'my-note-id' // Id of the note ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - // Get path to Note - const formattedNote = client.notePath(projectId, noteId); + // Get path to Note + const formattedNote = client.notePath(projectId, noteId); - // Get occurrences - const [occurrences] = await client.listNoteOccurrences({ - name: formattedNote + // Get occurrences + const [occurrences] = await client.listNoteOccurrences({ + name: formattedNote, + }); + if (occurrences.length) { + console.log('Occurrences:'); + occurrences.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log( + ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` + ); }); - if (occurrences.length) { - console.log('Occurrences:'); - occurrences.forEach(occurrence => { - console.log(`${occurrence.name}:`); - console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) - }); - } else { - console.log('No occurrences found.'); - } - - + } else { + console.log('No occurrences found.'); + } }; // [END containeranalysis_occurrences_for_note] const args = process.argv.slice(2); -occurrencesForNote(...args).catch(console.error); \ No newline at end of file +occurrencesForNote(...args).catch(console.error); diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index a298730aa47..e5d5bcf4c39 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -2,55 +2,57 @@ // Repeatedly query the Container Analysis API for the latest discovery occurrence until it is // either in a terminal state, or the timeout value has been exceeded const pollDiscoveryOccurrenceFinished = async ( - projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'https://gcr.io/my-project/my-image:123', // Image to attach metadata to - timeoutSeconds = 'timeout-in-seconds', // The number of seconds to listen for the new Pub/Sub messages + projectId = 'your-project-id', // Your GCP Project ID + imageUrl = 'https://gcr.io/my-project/my-image:123', // Image to attach metadata to + timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub messages ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - const formattedParent = client.projectPath(projectId); + const formattedParent = client.projectPath(projectId); - let filter = `resourceUrl=\"${imageUrl}\" AND noteProjectId=\"goog-analysis\" AND noteId=\"PACKAGE_VULNERABILITY\"`; - // [END containeranalysis_poll_discovery_occurrence_finished] - // The above filter isn't testable, since it looks for occurrences in a locked down project - // Fall back to a more permissive filter for testing - filter = `kind = \"DISCOVERY\" AND resourceUrl = \"${imageUrl}\"`; - // [START containeranalysis_poll_discovery_occurrence_finished] + let filter = `resourceUrl=\"${imageUrl}\" AND noteProjectId=\"goog-analysis\" AND noteId=\"PACKAGE_VULNERABILITY\"`; + // [END containeranalysis_poll_discovery_occurrence_finished] + // The above filter isn't testable, since it looks for occurrences in a locked down project + // Fall back to a more permissive filter for testing + filter = `kind = \"DISCOVERY\" AND resourceUrl = \"${imageUrl}\"`; + // [START containeranalysis_poll_discovery_occurrence_finished] - const pollDiscoveryOccurrence = () => { - return new Promise(async(resolve, reject) => { - setTimeout(() =>{ - reject('Timeout while retrieving discovery occurrence.'); - }, timeoutSeconds * 1000); - let found = false; - while (found == false) { - let [discoveryOccurrences] = await client.listOccurrences({ - parent: formattedParent, - filter: filter - }) - if (discoveryOccurrences.length > 0) { - found = true; - clearTimeout(); - resolve(discoveryOccurrences); - } - } + const pollDiscoveryOccurrence = () => { + return new Promise(async (resolve, reject) => { + setTimeout(() => { + reject('Timeout while retrieving discovery occurrence.'); + }, timeoutSeconds * 1000); + let found = false; + while (found == false) { + const [discoveryOccurrences] = await client.listOccurrences({ + parent: formattedParent, + filter: filter, }); - } - pollDiscoveryOccurrence().then(result => { - console.log(`Polled Discovery Occurrences for ${imageUrl}`); - result.forEach(occurrence => { - console.log(`${occurrence.name}:`); - console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) - }); - - }).catch(err => { - console.log(err); + if (discoveryOccurrences.length > 0) { + found = true; + clearTimeout(); + resolve(discoveryOccurrences); + } + } + }); + }; + pollDiscoveryOccurrence() + .then(result => { + console.log(`Polled Discovery Occurrences for ${imageUrl}`); + result.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log( + ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` + ); + }); + }) + .catch(err => { + console.log(err); }); - }; // [END containeranalysis_poll_discovery_occurrence_finished] const args = process.argv.slice(2); -pollDiscoveryOccurrenceFinished(...args).catch(console.error); \ No newline at end of file +pollDiscoveryOccurrenceFinished(...args).catch(console.error); diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 6bdb7e5dd2b..700f7916bab 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -1,11 +1,11 @@ -const { assert } = require('chai'); +const {assert} = require('chai'); const cp = require('child_process'); const uuid = require(`uuid`); const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); -const execSync = cmd => cp.execSync(cmd, { encoding: 'utf-8' }); +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.GCLOUD_PROJECT; const formattedParent = `projects/${projectId}`; @@ -23,241 +23,235 @@ const pubsub = new PubSub(); const topicName = 'container-analysis-occurrences-v1beta1'; const topic = pubsub.topic(topicName); -describe('Note tests', function () { - it('should create a note', function () { - const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); - assert.match( - output, - new RegExp(`Note ${formattedNoteName} created.`) - ); +describe('Note tests', function() { + it('should create a note', function() { + const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); + assert.match(output, new RegExp(`Note ${formattedNoteName} created.`)); + }); + + it('should get note', function() { + const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); + assert.match(output, new RegExp(`Note name: ${formattedNoteName}`)); + }); + + it('should create occurrence', function() { + const output = execSync( + `node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"` + ); + assert.match(output, new RegExp(`Occurrence created`)); + }); + + // TODO: sometimes fails, should try again if no images are found + it('should get occurrence', async function() { + const [occurrences] = await client.listOccurrences({ + parent: formattedParent, }); - - it('should get note', function () { - const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); - assert.match( - output, - new RegExp(`Note name: ${formattedNoteName}`) - ); - }); - - it('should create occurrence', function () { - const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"`); - assert.match( - output, - new RegExp(`Occurrence created`) - ) - - }); - - // TODO: sometimes fails, should try again if no images are found - it('should get occurrence', async function () { - const [occurrences] = await client.listOccurrences({ - parent: formattedParent - }); - assert(occurrences.length > 0); - - const occurrence = occurrences[0]; - const occurrenceId = occurrence.name.split("/")[3]; - const output = execSync(`node getOccurrence.js "${projectId}" "${occurrenceId}"`); - assert.match( - output, - new RegExp(`Occurrence name: ${occurrence.name}`) - ); - }); - - it('should get occurences for note', function () { - const output = execSync(`node occurrencesForNote.js "${projectId}" "${noteId}"`); - assert.match(output, /Occurrences:/); - }); - - it('should get occurrences for image', function() { - const output = execSync(`node occurrencesForImage.js "${projectId}" "${resourceUrl}"`); - assert.match( - output, - new RegExp(`Occurrences for ${resourceUrl}`) - ); + assert(occurrences.length > 0); + + const occurrence = occurrences[0]; + const occurrenceId = occurrence.name.split('/')[3]; + const output = execSync( + `node getOccurrence.js "${projectId}" "${occurrenceId}"` + ); + assert.match(output, new RegExp(`Occurrence name: ${occurrence.name}`)); + }); + + it('should get occurences for note', function() { + const output = execSync( + `node occurrencesForNote.js "${projectId}" "${noteId}"` + ); + assert.match(output, /Occurrences:/); + }); + + it('should get occurrences for image', function() { + const output = execSync( + `node occurrencesForImage.js "${projectId}" "${resourceUrl}"` + ); + assert.match(output, new RegExp(`Occurrences for ${resourceUrl}`)); + }); + + it('should get discovery info for image', async function() { + const discoveryNoteRequest = { + parent: formattedParent, + noteId: `${noteId}-discovery`, + note: { + discovery: {}, + }, + }; + + const [discoveryNote] = await client.createNote(discoveryNoteRequest); + + const occurrenceRequest = { + parent: formattedParent, + occurrence: { + noteName: `${formattedNoteName}-discovery`, + discovered: { + discovered: { + analysis_status: 'FINISHED_SUCCESS', + }, + }, + resource: { + uri: resourceUrl, + }, + }, + }; + + const [discoveryOccurrence] = await client.createOccurrence( + occurrenceRequest + ); + + const output = execSync( + `node getDiscoveryInfo "${projectId}" "${resourceUrl}"` + ); + assert.match( + output, + new RegExp(`Discovery Occurrences for ${resourceUrl}`) + ); + }); + + it('should get high severity vulnerabilities for image', async function() { + const criticalNoteReq = { + parent: formattedParent, + noteId: `${noteId}-critical`, + note: { + vulnerability: { + severity: 'CRITICAL', + }, + }, + }; + + const [criticalNote] = await client.createNote(criticalNoteReq); + + const criticalOccurrenceReq = { + parent: formattedParent, + occurrence: { + noteName: `${formattedNoteName}-critical`, + vulnerability: { + vulnerability: { + severity: 'CRITICAL', + }, + }, + resource: { + uri: resourceUrl, + }, + }, + }; + + const [criticalOccurrence] = await client.createOccurrence( + criticalOccurrenceReq + ); + + const output = execSync( + `node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"` + ); + + assert.match( + output, + new RegExp(`High Severity Vulnerabilities for ${resourceUrl}`) + ); + }); + + it('should get all vulnerabilites for image', function() { + const output = execSync( + `node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"` + ); + assert.match(output, new RegExp(`All Vulnerabilities for ${resourceUrl}`)); + }); + + it('should delete occurrence', async function() { + const [occurrences] = await client.listOccurrences({ + parent: formattedParent, }); - - it('should get discovery info for image', async function() { - const discoveryNoteRequest = { - parent: formattedParent, - noteId: `${noteId}-discovery`, - note: { - discovery: {} - } - }; - - const [discoveryNote] = await client.createNote(discoveryNoteRequest); - - const occurrenceRequest = { - parent: formattedParent, - occurrence: { - noteName: `${formattedNoteName}-discovery`, - discovered: { - discovered: { - analysis_status: 'FINISHED_SUCCESS' - }, - }, - resource: { - uri: resourceUrl - } - } - } - - const [discoveryOccurrence] = await client.createOccurrence(occurrenceRequest) - - const output = execSync(`node getDiscoveryInfo "${projectId}" "${resourceUrl}"`); - assert.match( - output, - new RegExp(`Discovery Occurrences for ${resourceUrl}`) - ); - }); - - it('should get high severity vulnerabilities for image', async function() { - const criticalNoteReq= { - parent: formattedParent, - noteId: `${noteId}-critical`, - note: { - vulnerability: { - severity: 'CRITICAL' - } - } - } - - const [criticalNote] = await client.createNote(criticalNoteReq); - - const criticalOccurrenceReq = { - parent: formattedParent, - occurrence: { - noteName: `${formattedNoteName}-critical`, - vulnerability: { - vulnerability: { - severity: 'CRITICAL' - } - }, - resource: { - uri: resourceUrl - } - } - } - - const [criticalOccurrence] = await client.createOccurrence(criticalOccurrenceReq); - - const output = execSync(`node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"`); - - assert.match( - output, - new RegExp(`High Severity Vulnerabilities for ${resourceUrl}`) - ); - }); - - it('should get all vulnerabilites for image', function() { - const output = execSync(`node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"`); - assert.match( - output, - new RegExp(`All Vulnerabilities for ${resourceUrl}`) - ); - }); - - it('should delete occurrence', async function() { - const [occurrences] = await client.listOccurrences({ - parent: formattedParent - }); - assert(occurrences.length > 0); - const occurrence = occurrences[0]; - const occurrenceId = occurrence.name.split("/")[3]; - - const output = execSync(`node deleteOccurrence.js "${projectId}" "${occurrenceId}"`); - assert.match( - output, - new RegExp(`Occurrence deleted.`) - ); - }); - ; - - it('should delete note', function () { - const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); - assert.match( - output, - new RegExp(`Note ${formattedNoteName} deleted.`) - ); - }); - + assert(occurrences.length > 0); + const occurrence = occurrences[0]; + const occurrenceId = occurrence.name.split('/')[3]; + + const output = execSync( + `node deleteOccurrence.js "${projectId}" "${occurrenceId}"` + ); + assert.match(output, new RegExp(`Occurrence deleted.`)); + }); + it('should delete note', function() { + const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); + assert.match(output, new RegExp(`Note ${formattedNoteName} deleted.`)); + }); }); // TODO: describe('polling', function() { - // it('should poll api until timeout', function() { - // const output = execSync(`node pollDiscoveryOccurrenceFinished.js "${projectId}" "${urlWithoutOccurrences}" "${timeoutSeconds}"`); - // assert.match( - // output, - // new RegExp(`'Timeout while retrieving discovery occurrence.`) - // ); - // }); - - it('should successfully poll latest discovery occurrence', function() { - const output = execSync(`node pollDiscoveryOccurrenceFinished.js "${projectId}" "${resourceUrl}" "${timeoutSeconds}"`); - assert.match( - output, - new RegExp(`Polled Discovery Occurrences for ${resourceUrl}`) - ); - }); - + // it('should poll api until timeout', function() { + // const output = execSync(`node pollDiscoveryOccurrenceFinished.js "${projectId}" "${urlWithoutOccurrences}" "${timeoutSeconds}"`); + // assert.match( + // output, + // new RegExp(`'Timeout while retrieving discovery occurrence.`) + // ); + // }); + + it('should successfully poll latest discovery occurrence', function() { + const output = execSync( + `node pollDiscoveryOccurrenceFinished.js "${projectId}" "${resourceUrl}" "${timeoutSeconds}"` + ); + assert.match( + output, + new RegExp(`Polled Discovery Occurrences for ${resourceUrl}`) + ); + }); }); -// TODO: +// TODO: describe('pubsub', function() { - beforeEach(async function() { - const [subscription] = await topic.createSubscription(subscriptionId); - const pubSubNoteReq = { - parent: formattedParent, - noteId: `${noteId}-pubsub`, - note: { - vulnerability: {} - } - } - const [pubSubNote] = await client.createNote(pubSubNoteReq); - - }); - afterEach(async function() { - await client.deleteNote({name: `${formattedNoteName}-pubsub`}); - await pubsub.subscription(subscriptionId).delete(); - }); - it('should get accurate count of occurrences from pubsub topic', async function() { - const expectedNum = 3; - const pubSubOccurrenceReq= { - parent: formattedParent, - occurrence: { - noteName: `${formattedNoteName}-pubsub`, - vulnerability: { - vulnerability: {} - }, - resource: { - uri: resourceUrl - } - } - } - // empty subscription - const initial = execSync(`node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"`); - - // make sure empty - const empty = execSync(`node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"`); - - assert.match( - empty, - new RegExp(`Polled 0 occurrences`) - ); - // create test occurrences - for(i=0; i < expectedNum; i++) { - const [pubSubOccurrence] = await client.createOccurrence(pubSubOccurrenceReq); - // const pubSubOccurrenceId = pubSubOccurrence.name.split("/")[3]; - await client.deleteOccurrence({name: pubSubOccurrence.name}); - } - const output = execSync(`node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"`); - - // make sure pubsub number matches - assert.match( - output, - new RegExp(`Polled ${expectedNum} occurrences`) - ); - }); + beforeEach(async function() { + const [subscription] = await topic.createSubscription(subscriptionId); + const pubSubNoteReq = { + parent: formattedParent, + noteId: `${noteId}-pubsub`, + note: { + vulnerability: {}, + }, + }; + const [pubSubNote] = await client.createNote(pubSubNoteReq); + }); + afterEach(async function() { + await client.deleteNote({name: `${formattedNoteName}-pubsub`}); + await pubsub.subscription(subscriptionId).delete(); + }); + it('should get accurate count of occurrences from pubsub topic', async function() { + const expectedNum = 3; + const pubSubOccurrenceReq = { + parent: formattedParent, + occurrence: { + noteName: `${formattedNoteName}-pubsub`, + vulnerability: { + vulnerability: {}, + }, + resource: { + uri: resourceUrl, + }, + }, + }; + // empty subscription + const initial = execSync( + `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` + ); + + // make sure empty + const empty = execSync( + `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` + ); + + assert.match(empty, new RegExp(`Polled 0 occurrences`)); + // create test occurrences + for (i = 0; i < expectedNum; i++) { + const [pubSubOccurrence] = await client.createOccurrence( + pubSubOccurrenceReq + ); + // const pubSubOccurrenceId = pubSubOccurrence.name.split("/")[3]; + await client.deleteOccurrence({name: pubSubOccurrence.name}); + } + const output = execSync( + `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` + ); + + // make sure pubsub number matches + assert.match(output, new RegExp(`Polled ${expectedNum} occurrences`)); + }); }); diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index e4b3798c3cf..aa1af63d9fe 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -1,29 +1,31 @@ // [START containeranalysis_vulnerability_occurrences_for_image] // Retrieve a list of vulnerability occurrences assoviated with a resource const vulnerabilityOccurrencesForImage = async ( - projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + projectId = 'your-project-id', // Your GCP Project ID + imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) => { - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + // Import the library and create a client + const grafeas = require('@google-cloud/grafeas'); + const client = new grafeas.v1.GrafeasClient(); - const formattedParent = client.projectPath(projectId); + const formattedParent = client.projectPath(projectId); - const [occurrences] = await client.listOccurrences({ - parent: formattedParent, - filter: `kind = "VULNERABILITY" AND resourceUrl = "${imageUrl}"` - }); + const [occurrences] = await client.listOccurrences({ + parent: formattedParent, + filter: `kind = "VULNERABILITY" AND resourceUrl = "${imageUrl}"`, + }); - if (occurrences.length) { - console.log(`All Vulnerabilities for ${imageUrl}`); - occurrences.forEach(occurrence => { - console.log(`${occurrence.name}:`); - console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`) - }); - } else { - console.log('No occurrences found.'); - } + if (occurrences.length) { + console.log(`All Vulnerabilities for ${imageUrl}`); + occurrences.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log( + ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` + ); + }); + } else { + console.log('No occurrences found.'); + } }; // [END containeranalysis_vulnerability_occurrences_for_image] From e9b5ba405faa4ff334a5e15f4aba1f552324b7d7 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Mon, 20 May 2019 17:31:24 -0700 Subject: [PATCH 027/131] replaced promise/timeout with p-retry --- container-analysis/snippets/package.json | 1 + .../pollDiscoveryOccurrenceFinished.js | 56 ++++++++----------- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 3946dc89627..5b4da20812c 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -17,6 +17,7 @@ "@google-cloud/pubsub": "^0.28.1", "chai": "^4.2.0", "mocha": "^6.1.4", + "p-retry": "^4.1.0", "uuid": "^3.3.2" } } diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index e5d5bcf4c39..9227e5b73bc 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -12,45 +12,35 @@ const pollDiscoveryOccurrenceFinished = async ( const formattedParent = client.projectPath(projectId); - let filter = `resourceUrl=\"${imageUrl}\" AND noteProjectId=\"goog-analysis\" AND noteId=\"PACKAGE_VULNERABILITY\"`; + let filter = `resourceUrl="${imageUrl}" AND noteProjectId="goog-analysis" AND noteId="PACKAGE_VULNERABILITY"`; // [END containeranalysis_poll_discovery_occurrence_finished] // The above filter isn't testable, since it looks for occurrences in a locked down project // Fall back to a more permissive filter for testing - filter = `kind = \"DISCOVERY\" AND resourceUrl = \"${imageUrl}\"`; + filter = `kind = "DISCOVERY" AND resourceUrl = "${imageUrl}"`; // [START containeranalysis_poll_discovery_occurrence_finished] - const pollDiscoveryOccurrence = () => { - return new Promise(async (resolve, reject) => { - setTimeout(() => { - reject('Timeout while retrieving discovery occurrence.'); - }, timeoutSeconds * 1000); - let found = false; - while (found == false) { - const [discoveryOccurrences] = await client.listOccurrences({ - parent: formattedParent, - filter: filter, - }); - if (discoveryOccurrences.length > 0) { - found = true; - clearTimeout(); - resolve(discoveryOccurrences); - } - } - }); - }; - pollDiscoveryOccurrence() - .then(result => { - console.log(`Polled Discovery Occurrences for ${imageUrl}`); - result.forEach(occurrence => { - console.log(`${occurrence.name}:`); - console.log( - ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` - ); + const pRetry = require('p-retry'); + const discoveryOccurrences = await pRetry( + async () => { + const [occurrences] = await client.listOccurrences({ + parent: formattedParent, + filter: filter, }); - }) - .catch(err => { - console.log(err); - }); + if (occurrences.length < 0) { + throw new Error('No occurrences found for ' + imageUrl); + } + return occurrences; + }, + { + retries: 5, + } + ); + + console.log(`Polled Discovery Occurrences for ${imageUrl}`); + discoveryOccurrences.forEach(occurrence => { + console.log(`${occurrence.name}:`); + console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`); + }); }; // [END containeranalysis_poll_discovery_occurrence_finished] From 21be8775a9b3b28591a175c26591614e1ebba0dd Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 21 May 2019 10:56:39 -0700 Subject: [PATCH 028/131] changed all samples to be wrapped with an outer main function, added params as comments for user --- container-analysis/snippets/createNote.js | 17 +++++++++----- .../snippets/createOccurrence.js | 22 +++++++++++------- container-analysis/snippets/deleteNote.js | 19 +++++++++------ .../snippets/deleteOccurrence.js | 17 +++++++++----- .../snippets/getDiscoveryInfo.js | 22 ++++++++++-------- container-analysis/snippets/getNote.js | 20 +++++++++------- container-analysis/snippets/getOccurrence.js | 19 +++++++++------ .../snippets/highVulnerabilitiesForImage.js | 23 +++++++++++-------- .../snippets/occurrencePubSub.js | 20 ++++++++++------ .../snippets/occurrencesForImage.js | 20 +++++++++------- .../snippets/occurrencesForNote.js | 21 +++++++++-------- .../pollDiscoveryOccurrenceFinished.js | 22 +++++++++++------- .../vulnerabilityOccurrencesForImage.js | 19 +++++++++------ 13 files changed, 162 insertions(+), 99 deletions(-) diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index 239547859e0..edbbcf99832 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -1,9 +1,14 @@ -// [START containeranalysis_create_note] -// Creates and returns a new Note -async function createNote( +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 grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); @@ -11,9 +16,10 @@ async function createNote( // 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 "attestation" + // Here, we use the type "vulnerabiltity" const formattedParent = client.projectPath(projectId); + // Creates and returns a new Note const [note] = await client.createNote({ parent: formattedParent, noteId: noteId, @@ -26,5 +32,4 @@ async function createNote( } // [END containeranalysis_create_note] -const args = process.argv.slice(2); -createNote(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index 08c34ee9448..52190d349b9 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -1,11 +1,18 @@ -// [START containeranalysis_create_occurrence] -// Creates and returns a new Occurrence associated with an existing Note -const createOccurence = async ( +async function main( noteProjectId = 'your-project-id', // Your GCP Project Id noteId = 'my-note-id', // Id of the note occurenceProjectId = 'your-project-id', // GCP Project Id of Occurence imageUrl = 'https://gcr.io/my-project/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 occurenceProjectId = 'your-project-id', // GCP Project Id of Occurence + // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); @@ -14,7 +21,7 @@ const createOccurence = async ( const formattedParent = client.projectPath(occurenceProjectId); const formattedNote = client.notePath(noteProjectId, noteId); - // Attach the occurence to the associated image url + // Creates and returns a new Occurrence associated with an existing Note const [occurrence] = await client.createOccurrence({ parent: formattedParent, occurrence: { @@ -27,8 +34,7 @@ const createOccurence = async ( }); console.log(`Occurrence created ${occurrence.name}.`); return occurrence; -}; +} // [END containeranalysis_create_occurrence] -const args = process.argv.slice(2); -createOccurence(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/deleteNote.js b/container-analysis/snippets/deleteNote.js index 6c80921520f..22a9f5474a0 100644 --- a/container-analysis/snippets/deleteNote.js +++ b/container-analysis/snippets/deleteNote.js @@ -1,9 +1,15 @@ -// [START containeranalysis_delete_note] // Deletes an existing Note from the server -const deleteNote = async ( +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 grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); @@ -12,10 +18,9 @@ const deleteNote = async ( const formattedName = client.notePath(projectId, noteId); // Delete the note - const response = await client.deleteNote({name: formattedName}); + await client.deleteNote({name: formattedName}); console.log(`Note ${formattedName} deleted.`); -}; +} // [END containeranalysis_delete_note] -const args = process.argv.slice(2); -deleteNote(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index 5b3257891ad..155b59edae6 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -1,9 +1,14 @@ -// [START containeranalysis_delete_occurrence] -// Deletes an existing Occurrence from the server -async function deleteOccurrence( +async function main( projectId = 'your-project-id', // Your GCP Project ID occurrenceId = 'my-occurrence' // Your Occurrence name ) { + // [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' // Your Occurrence name + // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); @@ -11,7 +16,8 @@ async function deleteOccurrence( // Get full path to occurrence const formattedName = client.occurrencePath(projectId, occurrenceId); - const result = await client.deleteOccurrence({ + // Deletes an existing Occurrence from the server + await client.deleteOccurrence({ name: formattedName, }); @@ -19,5 +25,4 @@ async function deleteOccurrence( } // [END containeranalysis_delete_occurrence] -const args = process.argv.slice(2); -deleteOccurrence(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 2c5755d900d..b57636923ff 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -1,16 +1,21 @@ -// [START containeranalysis_discovery_info] -// Retrieves and prints the Discovery Occurrence created for a specified image -// The Discovery Occurrence contains information about the initial scan on the image -const getDiscoveryInfo = async ( +async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/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 + // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); const formattedParent = client.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.listOccurrences({ parent: formattedParent, filter: `kind = "DISCOVERY" AND resourceUrl = "${imageUrl}"`, @@ -27,8 +32,7 @@ const getDiscoveryInfo = async ( } else { console.log('No occurrences found.'); } -}; +} // [END containeranalysis_discovery_info] -const args = process.argv.slice(2); -getDiscoveryInfo(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js index edfbbf38ff7..3d65cd5a889 100644 --- a/container-analysis/snippets/getNote.js +++ b/container-analysis/snippets/getNote.js @@ -1,21 +1,25 @@ -// [START containeranalysis_get_note] -// Retrieves and prints a specified Note from the server -const getNote = async ( +async function main( projectId = 'your-project-id', // Your GCP Project ID noteId = 'my-note-id' // Id of the note -) => { +) { + // [START containeranalysis_get_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 grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); // Get the full path to the note const formattedName = client.notePath(projectId, noteId); - // Get the note + // Retrieve the specified note const [note] = await client.getNote({name: formattedName}); console.log(`Note name: ${note.name}`); -}; +} // [END containeranalysis_get_note] -const args = process.argv.slice(2); -getNote(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index b6e2f427cbd..49610cc639f 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -1,9 +1,15 @@ -// [START containeranalysis_get_occurrence] // Retrieves and prints a specified Occurrence from the server -const getOccurrence = async ( +async function main( projectId = 'your-project-id', // Your GCP Project ID occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence -) => { +) { + // [START containeranalysis_get_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 grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); @@ -11,14 +17,13 @@ const getOccurrence = async ( // Get full path to occurrence const formattedName = client.occurrencePath(projectId, occurrenceId); - // Get occurrence + // Retrieves the specified occurrence const [occurrence] = await client.getOccurrence({ name: formattedName, }); console.log(`Occurrence name: ${occurrence.name}`); -}; +} // [END containeranalysis_get_occurrence] -const args = process.argv.slice(2); -getOccurrence(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 1c869708db8..5f0ef79efee 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -1,15 +1,21 @@ -// [START containeranalysis_filter_vulnerability_occurrences] -// Retrieve a list of vulnerability occurrences with a severity level of 'HIGH' or greater -const highVulnerabilitiesForImage = async ( +async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to -) => { +) { + // [START containeranalysis_filter_vulnerability_occurrences] + /** + * TODO(developer): Uncomment these variables before running the sample + */ + // const projectId = 'your-project-id', // Your GCP Project ID + // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); const formattedParent = client.projectPath(projectId); + // Retrieve a list of vulnerability occurrences with a severity level of 'HIGH' or greater const [occurrences] = await client.listOccurrences({ parent: formattedParent, filter: `kind = "VULNERABILITY" AND resourceUrl = "${imageUrl}"`, @@ -19,8 +25,8 @@ const highVulnerabilitiesForImage = async ( console.log(`High Severity Vulnerabilities for ${imageUrl}`); occurrences.forEach(occurrence => { if ( - occurrence.vulnerability.severity == 'HIGH' || - occurrence.vulnerability.severity == 'CRITICAL' + occurrence.vulnerability.severity === 'HIGH' || + occurrence.vulnerability.severity === 'CRITICAL' ) { console.log(`${occurrence.name}:`); console.log( @@ -31,8 +37,7 @@ const highVulnerabilitiesForImage = async ( } else { console.log('No occurrences found.'); } -}; +} // [END containeranalysis_filter_vulnerability_occurrences] -const args = process.argv.slice(2); -highVulnerabilitiesForImage(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index 2bc068444a8..661430ecb36 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -1,10 +1,16 @@ -// [START containeranalysis_pubsub] -// Handle incoming Occurrences using a Cloud Pub/Sub subscription -const occurrencePubSub = async ( +async function main( projectId = 'your-project-id', // Your GCP Project ID subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub messages -) => { +) { + // [START containeranalysis_pubsub] + /** + * TODO(developer): Uncomment these variables before running the sample + */ + // const projectId = 'your-project-id', // Your GCP Project ID + // const subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic + // const timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub Messages + // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); @@ -14,6 +20,7 @@ const occurrencePubSub = async ( const pubsub = new PubSub({projectId}); const subscription = pubsub.subscription(subscriptionId); + // Handle incoming Occurrences using a Cloud Pub/Sub subscription let count = 0; const messageHandler = message => { count++; @@ -27,8 +34,7 @@ const occurrencePubSub = async ( subscription.removeListener(`message`, messageHandler); console.log(`Polled ${count} occurrences`); }, timeoutSeconds * 1000); -}; +} // [END containeranalysis_pubsub] -const args = process.argv.slice(2); -occurrencePubSub(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index 06871d105e9..1fe746aa75e 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -1,16 +1,21 @@ -// [START containeranalysis_occurrences_for_image] -// Retrieves all the Occurrences associated with a specified image -// Here, all Occurrences are simply printed and counted -const occurrencesForImage = async ( +async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to -) => { +) { + // [START containeranalysis_occurrences_for_image] + /** + * TODO(developer): Uncomment these variables before running the sample + */ + // const projectId = 'your-project-id', // Your GCP Project ID + // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); const formattedParent = client.projectPath(projectId); + // Retrieves all the Occurrences associated with a specified image const [occurrences] = await client.listOccurrences({ parent: formattedParent, filter: `resourceUrl = "${imageUrl}"`, @@ -27,8 +32,7 @@ const occurrencesForImage = async ( } else { console.log('No occurrences found.'); } -}; +} // [END containeranalysis_occurrences_for_image] -const args = process.argv.slice(2); -occurrencesForImage(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index d1236c43434..0345f5b0db3 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -1,10 +1,14 @@ -// [START containeranalysis_occurrences_for_note] -// Retrieves all the Occurrences associated with a specified Note -// Here, all Occurrences are printed and counted -const occurrencesForNote = async ( +async function main( projectId = 'your-project-id', // Your GCP Project ID noteId = 'my-note-id' // Id of the note -) => { +) { + // [START containeranalysis_occurrences_for_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 grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); @@ -12,7 +16,7 @@ const occurrencesForNote = async ( // Get path to Note const formattedNote = client.notePath(projectId, noteId); - // Get occurrences + // Retrieves all the Occurrences associated with a specified Note const [occurrences] = await client.listNoteOccurrences({ name: formattedNote, }); @@ -27,8 +31,7 @@ const occurrencesForNote = async ( } else { console.log('No occurrences found.'); } -}; +} // [END containeranalysis_occurrences_for_note] -const args = process.argv.slice(2); -occurrencesForNote(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 9227e5b73bc..57b14fb44c4 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -1,11 +1,16 @@ -// [START containeranalysis_poll_discovery_occurrence_finished] -// Repeatedly query the Container Analysis API for the latest discovery occurrence until it is -// either in a terminal state, or the timeout value has been exceeded -const pollDiscoveryOccurrenceFinished = async ( +async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123', // Image to attach metadata to timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub messages -) => { +) { + // [START containeranalysis_poll_discovery_occurrence_finished] + /** + * TODO(developer): Uncomment these variables before running the sample + */ + // const projectId = 'your-project-id', // Your GCP Project ID + // const imageUrl = 'https://gcr.io/my-project/my-image:123', // Image to attach metadata to + // const timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub messages + // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); @@ -19,6 +24,8 @@ const pollDiscoveryOccurrenceFinished = async ( filter = `kind = "DISCOVERY" AND resourceUrl = "${imageUrl}"`; // [START containeranalysis_poll_discovery_occurrence_finished] + // Repeatedly query the Container Analysis API for the latest discovery occurrence until it is + // either in a terminal state, or the timeout value has been exceeded const pRetry = require('p-retry'); const discoveryOccurrences = await pRetry( async () => { @@ -41,8 +48,7 @@ const pollDiscoveryOccurrenceFinished = async ( console.log(`${occurrence.name}:`); console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`); }); -}; +} // [END containeranalysis_poll_discovery_occurrence_finished] -const args = process.argv.slice(2); -pollDiscoveryOccurrenceFinished(...args).catch(console.error); +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index aa1af63d9fe..9b4937942db 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -1,15 +1,21 @@ -// [START containeranalysis_vulnerability_occurrences_for_image] -// Retrieve a list of vulnerability occurrences assoviated with a resource -const vulnerabilityOccurrencesForImage = async ( +async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to -) => { +) { + // [START containeranalysis_vulnerability_occurrences_for_image] + /** + * TODO(developer): Uncomment these variables before running the sample + */ + // const projectId = 'your-project-id', // Your GCP Project ID + // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); const client = new grafeas.v1.GrafeasClient(); const formattedParent = client.projectPath(projectId); + // Retrieve a list of vulnerability occurrences assoviated with a resource const [occurrences] = await client.listOccurrences({ parent: formattedParent, filter: `kind = "VULNERABILITY" AND resourceUrl = "${imageUrl}"`, @@ -26,8 +32,7 @@ const vulnerabilityOccurrencesForImage = async ( } else { console.log('No occurrences found.'); } -}; +} // [END containeranalysis_vulnerability_occurrences_for_image] -const args = process.argv.slice(2); -vulnerabilityOccurrencesForImage(...args).catch(console.error); +main(...process.argv.slice(2)); From 3d470caa3b2b509fd62916c7cd1764ca947d294a Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 21 May 2019 14:54:46 -0700 Subject: [PATCH 029/131] added after step to delete occurrences and notes --- .../snippets/test/containerAnalysis.test.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 700f7916bab..a5d06539224 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -24,6 +24,26 @@ const topicName = 'container-analysis-occurrences-v1beta1'; const topic = pubsub.topic(topicName); describe('Note tests', function() { + after(async function() { + const [allOccurrences] = await client.listOccurrences({ + parent: formattedParent, + filter: `resourceUrl = "${resourceUrl}"`, + }); + + allOccurrences.forEach(async occurrence => { + await client.deleteOccurrence({name: occurrence.name}); + console.log(`deleted occurrence ${occurrence.name}`); + }); + + const [allNotes] = await client.listNotes({ + parent: formattedParent, + }); + + allNotes.forEach(async note => { + await client.deleteNote({name: note.name}); + console.log(`deleted note ${note.name}`); + }); + }); it('should create a note', function() { const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); assert.match(output, new RegExp(`Note ${formattedNoteName} created.`)); From d14adb9e6d5a8b47182bcf917f7f445c4985bbee Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 21 May 2019 14:55:44 -0700 Subject: [PATCH 030/131] updated polling sample and test --- .../pollDiscoveryOccurrenceFinished.js | 38 ++++++++++++--- .../snippets/test/containerAnalysis.test.js | 47 ++++++++++++++++++- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 57b14fb44c4..7260770bf9a 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -27,7 +27,7 @@ async function main( // Repeatedly query the Container Analysis API for the latest discovery occurrence until it is // either in a terminal state, or the timeout value has been exceeded const pRetry = require('p-retry'); - const discoveryOccurrences = await pRetry( + const discoveryOccurrence = await pRetry( async () => { const [occurrences] = await client.listOccurrences({ parent: formattedParent, @@ -36,7 +36,7 @@ async function main( if (occurrences.length < 0) { throw new Error('No occurrences found for ' + imageUrl); } - return occurrences; + return occurrences[0]; }, { retries: 5, @@ -44,10 +44,36 @@ async function main( ); console.log(`Polled Discovery Occurrences for ${imageUrl}`); - discoveryOccurrences.forEach(occurrence => { - console.log(`${occurrence.name}:`); - console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`); - }); + // Wait for discovery occurrence to enter a terminal state + const finishedOccurrence = await pRetry( + async () => { + let status = 'PENDING'; + const [updated] = await client.getOccurrence({ + name: discoveryOccurrence.name, + }); + status = updated.discovered.discovered.analysisStatus; + if ( + status !== 'FINISHED_SUCCESS' && + status !== 'FINISHED_FAILED' && + status !== 'FINISHED_UNSUPPORTED' + ) { + throw new Error('Timeout while retrieving discovery occurrence'); + } + return updated; + }, + { + retries: 5, + } + ); + console.log( + `Found discovery occurrence ${finishedOccurrence.name}. Status: ${ + finishedOccurrence.discovered.discovered.analysisStatus + }` + ); + // discoveryOccurrences.forEach(occurrence => { + // console.log(`${occurrence.name}:`); + // console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`); + // }); } // [END containeranalysis_poll_discovery_occurrence_finished] diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index a5d06539224..352bdbe21d8 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -107,7 +107,8 @@ describe('Note tests', function() { noteName: `${formattedNoteName}-discovery`, discovered: { discovered: { - analysis_status: 'FINISHED_SUCCESS', + analysisStatus: 'FINISHED_SUCCESS', + }, }, }, resource: { @@ -198,7 +199,49 @@ describe('Note tests', function() { }); // TODO: -describe('polling', function() { +xdescribe('polling', function() { + before(async function() { + const discoveryNoteRequest = { + parent: formattedParent, + noteId: `${noteId}-discovery-polling`, + note: { + discovery: { + continuousAnalysis: 'INACTIVE', + }, + }, + }; + + const [discoveryNote] = await client.createNote(discoveryNoteRequest); + + const occurrenceRequest = { + parent: formattedParent, + occurrence: { + noteName: `${formattedNoteName}-discovery-polling`, + discovered: { + discovered: { + analysisStatus: 'FINISHED_SUCCESS', + }, + }, + }, + resource: { + uri: resourceUrl, + }, + }; + + const [discoveryOccurrence] = await client.createOccurrence( + occurrenceRequest + ); + }); + + after(async function() { + const [discoveryOccurrences] = await client.listNoteOccurrences({ + name: `${formattedNoteName}-discovery-polling`, + }); + discoveryOccurrences.forEach(async occurrence => { + await client.deleteOccurrence({name: occurrence.name}); + }); + await client.deleteNote({name: `${formattedNoteName}-discovery-polling`}); + }); // it('should poll api until timeout', function() { // const output = execSync(`node pollDiscoveryOccurrenceFinished.js "${projectId}" "${urlWithoutOccurrences}" "${timeoutSeconds}"`); // assert.match( From 78e7b126a0e1e3c2719b899e2e22feaaa4175225 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 21 May 2019 15:07:44 -0700 Subject: [PATCH 031/131] ran fix, dangling errs for symlink and polling --- .../snippets/test/containerAnalysis.test.js | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 352bdbe21d8..14ddada799c 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -13,10 +13,8 @@ const uuidVal = uuid.v4(); const noteId = `test-note-${uuidVal}`; const formattedNoteName = `projects/${projectId}/notes/${noteId}`; const resourceUrl = `gcr.io/project/image`; -const urlWithoutOccurrences = `gcr.io/project/nooccurrences`; const subscriptionId = `occurrence-subscription-${uuidVal}`; const timeoutSeconds = 5; -const tryLimit = 10; const {PubSub} = require('@google-cloud/pubsub'); const pubsub = new PubSub(); @@ -99,7 +97,7 @@ describe('Note tests', function() { }, }; - const [discoveryNote] = await client.createNote(discoveryNoteRequest); + await client.createNote(discoveryNoteRequest); const occurrenceRequest = { parent: formattedParent, @@ -107,19 +105,16 @@ describe('Note tests', function() { noteName: `${formattedNoteName}-discovery`, discovered: { discovered: { - analysisStatus: 'FINISHED_SUCCESS', - }, + analysisStatus: 'FINISHED_SUCCESS', }, }, - resource: { - uri: resourceUrl, - }, + }, + resource: { + uri: resourceUrl, }, }; - const [discoveryOccurrence] = await client.createOccurrence( - occurrenceRequest - ); + await client.createOccurrence(occurrenceRequest); const output = execSync( `node getDiscoveryInfo "${projectId}" "${resourceUrl}"` @@ -141,7 +136,7 @@ describe('Note tests', function() { }, }; - const [criticalNote] = await client.createNote(criticalNoteReq); + await client.createNote(criticalNoteReq); const criticalOccurrenceReq = { parent: formattedParent, @@ -158,9 +153,7 @@ describe('Note tests', function() { }, }; - const [criticalOccurrence] = await client.createOccurrence( - criticalOccurrenceReq - ); + await client.createOccurrence(criticalOccurrenceReq); const output = execSync( `node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"` @@ -211,7 +204,7 @@ xdescribe('polling', function() { }, }; - const [discoveryNote] = await client.createNote(discoveryNoteRequest); + await client.createNote(discoveryNoteRequest); const occurrenceRequest = { parent: formattedParent, @@ -228,9 +221,7 @@ xdescribe('polling', function() { }, }; - const [discoveryOccurrence] = await client.createOccurrence( - occurrenceRequest - ); + await client.createOccurrence(occurrenceRequest); }); after(async function() { @@ -260,10 +251,10 @@ xdescribe('polling', function() { ); }); }); -// TODO: + describe('pubsub', function() { beforeEach(async function() { - const [subscription] = await topic.createSubscription(subscriptionId); + await topic.createSubscription(subscriptionId); const pubSubNoteReq = { parent: formattedParent, noteId: `${noteId}-pubsub`, @@ -271,7 +262,7 @@ describe('pubsub', function() { vulnerability: {}, }, }; - const [pubSubNote] = await client.createNote(pubSubNoteReq); + await client.createNote(pubSubNoteReq); }); afterEach(async function() { await client.deleteNote({name: `${formattedNoteName}-pubsub`}); @@ -292,7 +283,7 @@ describe('pubsub', function() { }, }; // empty subscription - const initial = execSync( + execSync( `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` ); @@ -303,7 +294,7 @@ describe('pubsub', function() { assert.match(empty, new RegExp(`Polled 0 occurrences`)); // create test occurrences - for (i = 0; i < expectedNum; i++) { + for (let i = 0; i < expectedNum; i++) { const [pubSubOccurrence] = await client.createOccurrence( pubSubOccurrenceReq ); From 7dad261010d2919023e17aaebdddd8ba21817282 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Thu, 23 May 2019 13:54:51 -0700 Subject: [PATCH 032/131] updated comment on occurrenceId --- container-analysis/snippets/deleteOccurrence.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index 155b59edae6..162df32692b 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -1,13 +1,13 @@ async function main( projectId = 'your-project-id', // Your GCP Project ID - occurrenceId = 'my-occurrence' // Your Occurrence name + 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' // Your Occurrence name + // const occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence // Import the library and create a client const grafeas = require('@google-cloud/grafeas'); From 5d6daa19b53dd7deb3e7560dd621b0ecc8a52069 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Thu, 23 May 2019 14:16:24 -0700 Subject: [PATCH 033/131] fixed typo in discovery test --- container-analysis/snippets/test/containerAnalysis.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 14ddada799c..14ac227f720 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -108,9 +108,9 @@ describe('Note tests', function() { analysisStatus: 'FINISHED_SUCCESS', }, }, - }, - resource: { - uri: resourceUrl, + resource: { + uri: resourceUrl, + }, }, }; From c4a61937ad5a91d687ba5b20b1f4203d23476229 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Thu, 23 May 2019 14:31:21 -0700 Subject: [PATCH 034/131] grabs projectId from client, update projectId and vars the refer to it in before hooks, added uuid to test resourceUrl --- .../snippets/test/containerAnalysis.test.js | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 14ac227f720..13e7fff8cd5 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -7,12 +7,9 @@ const client = new grafeas.v1.GrafeasClient(); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const projectId = process.env.GCLOUD_PROJECT; -const formattedParent = `projects/${projectId}`; const uuidVal = uuid.v4(); const noteId = `test-note-${uuidVal}`; -const formattedNoteName = `projects/${projectId}/notes/${noteId}`; -const resourceUrl = `gcr.io/project/image`; +const resourceUrl = `gcr.io/test-project/test-image-${uuidVal}`; const subscriptionId = `occurrence-subscription-${uuidVal}`; const timeoutSeconds = 5; @@ -21,7 +18,17 @@ const pubsub = new PubSub(); const topicName = 'container-analysis-occurrences-v1beta1'; const topic = pubsub.topic(topicName); +let projectId; +let formattedParent; +let formattedNoteName; + describe('Note tests', function() { + before(async function() { + // define projectId and related vars + projectId = await client.getProjectId(); + formattedParent = `projects/${projectId}`; + formattedNoteName = `projects/${projectId}/notes/${noteId}`; + }); after(async function() { const [allOccurrences] = await client.listOccurrences({ parent: formattedParent, @@ -194,6 +201,11 @@ describe('Note tests', function() { // TODO: xdescribe('polling', function() { before(async function() { + // define project id and related vars + projectId = await client.getProjectId(); + formattedParent = `projects/${projectId}`; + formattedNoteName = `projects/${projectId}/notes/${noteId}`; + const discoveryNoteRequest = { parent: formattedParent, noteId: `${noteId}-discovery-polling`, @@ -253,6 +265,13 @@ xdescribe('polling', function() { }); describe('pubsub', function() { + before(async function() { + // define project id and related vars + projectId = await client.getProjectId(); + formattedParent = `projects/${projectId}`; + formattedNoteName = `projects/${projectId}/notes/${noteId}`; + }); + beforeEach(async function() { await topic.createSubscription(subscriptionId); const pubSubNoteReq = { @@ -264,10 +283,12 @@ describe('pubsub', function() { }; await client.createNote(pubSubNoteReq); }); + afterEach(async function() { await client.deleteNote({name: `${formattedNoteName}-pubsub`}); await pubsub.subscription(subscriptionId).delete(); }); + it('should get accurate count of occurrences from pubsub topic', async function() { const expectedNum = 3; const pubSubOccurrenceReq = { @@ -282,6 +303,7 @@ describe('pubsub', function() { }, }, }; + // empty subscription execSync( `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` From d4c6c5c992dbe63e8ad5685bff9f5ab42d691d66 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Thu, 23 May 2019 14:45:15 -0700 Subject: [PATCH 035/131] removed commented code from polling sample --- .../snippets/pollDiscoveryOccurrenceFinished.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 7260770bf9a..6a67b7ea59f 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -70,10 +70,6 @@ async function main( finishedOccurrence.discovered.discovered.analysisStatus }` ); - // discoveryOccurrences.forEach(occurrence => { - // console.log(`${occurrence.name}:`); - // console.log(` Created: ${new Date(occurrence.createTime.seconds * 1000)}`); - // }); } // [END containeranalysis_poll_discovery_occurrence_finished] From 0c29526fb461aaccfb1d7a254baef8ba8500d9d2 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Thu, 23 May 2019 14:48:46 -0700 Subject: [PATCH 036/131] move end region tag to inside main function --- container-analysis/snippets/createNote.js | 2 +- container-analysis/snippets/createOccurrence.js | 2 +- container-analysis/snippets/deleteNote.js | 2 +- container-analysis/snippets/deleteOccurrence.js | 2 +- container-analysis/snippets/getDiscoveryInfo.js | 2 +- container-analysis/snippets/getNote.js | 2 +- container-analysis/snippets/getOccurrence.js | 2 +- container-analysis/snippets/highVulnerabilitiesForImage.js | 2 +- container-analysis/snippets/occurrencePubSub.js | 2 +- container-analysis/snippets/occurrencesForImage.js | 2 +- container-analysis/snippets/occurrencesForNote.js | 2 +- container-analysis/snippets/vulnerabilityOccurrencesForImage.js | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index edbbcf99832..6e038774e32 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -29,7 +29,7 @@ async function main( }); console.log(`Note ${note.name} created.`); + // [END containeranalysis_create_note] } -// [END containeranalysis_create_note] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index 52190d349b9..7cb7fbb902a 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -34,7 +34,7 @@ async function main( }); console.log(`Occurrence created ${occurrence.name}.`); return occurrence; + // [END containeranalysis_create_occurrence] } -// [END containeranalysis_create_occurrence] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/deleteNote.js b/container-analysis/snippets/deleteNote.js index 22a9f5474a0..5da7ab5372c 100644 --- a/container-analysis/snippets/deleteNote.js +++ b/container-analysis/snippets/deleteNote.js @@ -20,7 +20,7 @@ async function main( // Delete the note await client.deleteNote({name: formattedName}); console.log(`Note ${formattedName} deleted.`); + // [END containeranalysis_delete_note] } -// [END containeranalysis_delete_note] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index 162df32692b..4ecb8aac04a 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -22,7 +22,7 @@ async function main( }); console.log(`Occurrence deleted: ${formattedName}`); + // [END containeranalysis_delete_occurrence] } -// [END containeranalysis_delete_occurrence] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index b57636923ff..362439abfa1 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -32,7 +32,7 @@ async function main( } else { console.log('No occurrences found.'); } + // [END containeranalysis_discovery_info] } -// [END containeranalysis_discovery_info] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js index 3d65cd5a889..ff44945f1c8 100644 --- a/container-analysis/snippets/getNote.js +++ b/container-analysis/snippets/getNote.js @@ -19,7 +19,7 @@ async function main( const [note] = await client.getNote({name: formattedName}); console.log(`Note name: ${note.name}`); + // [END containeranalysis_get_note] } -// [END containeranalysis_get_note] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index 49610cc639f..af5b3bb503a 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -23,7 +23,7 @@ async function main( }); console.log(`Occurrence name: ${occurrence.name}`); + // [END containeranalysis_get_occurrence] } -// [END containeranalysis_get_occurrence] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 5f0ef79efee..73096dbe45b 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -37,7 +37,7 @@ async function main( } else { console.log('No occurrences found.'); } + // [END containeranalysis_filter_vulnerability_occurrences] } -// [END containeranalysis_filter_vulnerability_occurrences] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index 661430ecb36..a23b1d21878 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -34,7 +34,7 @@ async function main( subscription.removeListener(`message`, messageHandler); console.log(`Polled ${count} occurrences`); }, timeoutSeconds * 1000); + // [END containeranalysis_pubsub] } -// [END containeranalysis_pubsub] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index 1fe746aa75e..57d786f2bf9 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -32,7 +32,7 @@ async function main( } else { console.log('No occurrences found.'); } + // [END containeranalysis_occurrences_for_image] } -// [END containeranalysis_occurrences_for_image] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index 0345f5b0db3..60cf0524b50 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -31,7 +31,7 @@ async function main( } else { console.log('No occurrences found.'); } + // [END containeranalysis_occurrences_for_note] } -// [END containeranalysis_occurrences_for_note] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index 9b4937942db..55c97f9a5ec 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -32,7 +32,7 @@ async function main( } else { console.log('No occurrences found.'); } + // [END containeranalysis_vulnerability_occurrences_for_image] } -// [END containeranalysis_vulnerability_occurrences_for_image] main(...process.argv.slice(2)); From 4740ead758417ec91bfa309038884c8104400b6a Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Fri, 24 May 2019 09:53:29 -0700 Subject: [PATCH 037/131] removed symlinks from test script, removed commented test from polling block --- container-analysis/snippets/package.json | 2 +- .../snippets/test/containerAnalysis.test.js | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 5b4da20812c..8844ac424cf 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -11,7 +11,7 @@ "node": ">=10" }, "scripts": { - "test": "mocha --preserve-symlinks --timeout 100000 test/**.test.js" + "test": "mocha --timeout 100000 test/**.test.js" }, "devDependencies": { "@google-cloud/pubsub": "^0.28.1", diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 13e7fff8cd5..acbece67c71 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -198,7 +198,7 @@ describe('Note tests', function() { }); }); -// TODO: +// TODO: complete polling sample xdescribe('polling', function() { before(async function() { // define project id and related vars @@ -245,13 +245,6 @@ xdescribe('polling', function() { }); await client.deleteNote({name: `${formattedNoteName}-discovery-polling`}); }); - // it('should poll api until timeout', function() { - // const output = execSync(`node pollDiscoveryOccurrenceFinished.js "${projectId}" "${urlWithoutOccurrences}" "${timeoutSeconds}"`); - // assert.match( - // output, - // new RegExp(`'Timeout while retrieving discovery occurrence.`) - // ); - // }); it('should successfully poll latest discovery occurrence', function() { const output = execSync( From 4ea46a77c02711b809288a02dd5cc83b31936cb8 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Fri, 24 May 2019 10:36:22 -0700 Subject: [PATCH 038/131] deleted unused import from pub sub sample --- container-analysis/snippets/occurrencePubSub.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index a23b1d21878..0dc43818d72 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -11,10 +11,6 @@ async function main( // const subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic // const timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub Messages - // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); - // Import the pubsub library and create a client, topic and subscription const {PubSub} = require('@google-cloud/pubsub'); const pubsub = new PubSub({projectId}); From 5c52fb02e64552529e7c6e83aebb4d6a21ebad44 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Fri, 24 May 2019 10:39:30 -0700 Subject: [PATCH 039/131] changed grafeas to container analysis v1beta1 client --- container-analysis/snippets/createNote.js | 4 ++-- container-analysis/snippets/createOccurrence.js | 4 ++-- container-analysis/snippets/deleteNote.js | 4 ++-- container-analysis/snippets/deleteOccurrence.js | 4 ++-- container-analysis/snippets/getDiscoveryInfo.js | 4 ++-- container-analysis/snippets/getNote.js | 4 ++-- container-analysis/snippets/getOccurrence.js | 4 ++-- container-analysis/snippets/highVulnerabilitiesForImage.js | 4 ++-- container-analysis/snippets/occurrencesForImage.js | 4 ++-- container-analysis/snippets/occurrencesForNote.js | 4 ++-- .../snippets/pollDiscoveryOccurrenceFinished.js | 4 ++-- container-analysis/snippets/test/containerAnalysis.test.js | 4 ++-- .../snippets/vulnerabilityOccurrencesForImage.js | 4 ++-- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index 6e038774e32..b0057d2ebd3 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -10,8 +10,8 @@ async function main( // const noteId = 'my-note-id' // Id of the note // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); // Construct request // Associate the Note with a metadata type diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index 7cb7fbb902a..411b5ce967f 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -14,8 +14,8 @@ async function main( // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); // Construct request const formattedParent = client.projectPath(occurenceProjectId); diff --git a/container-analysis/snippets/deleteNote.js b/container-analysis/snippets/deleteNote.js index 5da7ab5372c..245eaa40dde 100644 --- a/container-analysis/snippets/deleteNote.js +++ b/container-analysis/snippets/deleteNote.js @@ -11,8 +11,8 @@ async function main( // const noteId = 'my-note-id' // Id of the note // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); // Get the full path to the note const formattedName = client.notePath(projectId, noteId); diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index 4ecb8aac04a..c492a0f0af8 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -10,8 +10,8 @@ async function main( // const occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); // Get full path to occurrence const formattedName = client.occurrencePath(projectId, occurrenceId); diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 362439abfa1..f8b02464f6d 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -10,8 +10,8 @@ async function main( // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); const formattedParent = client.projectPath(projectId); // Retrieves and prints the Discovery Occurrence created for a specified image diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js index ff44945f1c8..365f3494fd6 100644 --- a/container-analysis/snippets/getNote.js +++ b/container-analysis/snippets/getNote.js @@ -10,8 +10,8 @@ async function main( // const noteId = 'my-note-id' // Id of the note // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); // Get the full path to the note const formattedName = client.notePath(projectId, noteId); diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index af5b3bb503a..a3c0c7bcfa9 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -11,8 +11,8 @@ async function main( // const occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); // Get full path to occurrence const formattedName = client.occurrencePath(projectId, occurrenceId); diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 73096dbe45b..29d25163bee 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -10,8 +10,8 @@ async function main( // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); const formattedParent = client.projectPath(projectId); diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index 57d786f2bf9..db30c353954 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -10,8 +10,8 @@ async function main( // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); const formattedParent = client.projectPath(projectId); diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index 60cf0524b50..a853a66574b 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -10,8 +10,8 @@ async function main( // const noteId = 'my-note-id' // Id of the note // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); // Get path to Note const formattedNote = client.notePath(projectId, noteId); diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 6a67b7ea59f..d20e682604b 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -12,8 +12,8 @@ async function main( // const timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub messages // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); const formattedParent = client.projectPath(projectId); diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index acbece67c71..3d144a605fd 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -2,8 +2,8 @@ const {assert} = require('chai'); const cp = require('child_process'); const uuid = require(`uuid`); -const grafeas = require('@google-cloud/grafeas'); -const client = new grafeas.v1.GrafeasClient(); +const containerAnalysis = require('@google-cloud/containeranalysis'); +const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index 55c97f9a5ec..267fce8372f 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -10,8 +10,8 @@ async function main( // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client - const grafeas = require('@google-cloud/grafeas'); - const client = new grafeas.v1.GrafeasClient(); + const containerAnalysis = require('@google-cloud/containeranalysis'); + const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); const formattedParent = client.projectPath(projectId); From d9fa96cf5e44613f31c401569e0b4229681debf3 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Fri, 24 May 2019 10:51:19 -0700 Subject: [PATCH 040/131] fixed typo in client, removed comment --- container-analysis/snippets/createNote.js | 2 +- container-analysis/snippets/createOccurrence.js | 2 +- container-analysis/snippets/deleteNote.js | 2 +- container-analysis/snippets/deleteOccurrence.js | 2 +- container-analysis/snippets/getDiscoveryInfo.js | 2 +- container-analysis/snippets/getNote.js | 2 +- container-analysis/snippets/getOccurrence.js | 2 +- container-analysis/snippets/highVulnerabilitiesForImage.js | 2 +- container-analysis/snippets/occurrencesForImage.js | 2 +- container-analysis/snippets/occurrencesForNote.js | 2 +- container-analysis/snippets/pollDiscoveryOccurrenceFinished.js | 2 +- container-analysis/snippets/test/containerAnalysis.test.js | 3 +-- .../snippets/vulnerabilityOccurrencesForImage.js | 2 +- 13 files changed, 13 insertions(+), 14 deletions(-) diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index b0057d2ebd3..9ad6839c3ca 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -11,7 +11,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); // Construct request // Associate the Note with a metadata type diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index 411b5ce967f..6bca0ee3d25 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -15,7 +15,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); // Construct request const formattedParent = client.projectPath(occurenceProjectId); diff --git a/container-analysis/snippets/deleteNote.js b/container-analysis/snippets/deleteNote.js index 245eaa40dde..24f6622bd9c 100644 --- a/container-analysis/snippets/deleteNote.js +++ b/container-analysis/snippets/deleteNote.js @@ -12,7 +12,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); // Get the full path to the note const formattedName = client.notePath(projectId, noteId); diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index c492a0f0af8..f20c997dc1c 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -11,7 +11,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); // Get full path to occurrence const formattedName = client.occurrencePath(projectId, occurrenceId); diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index f8b02464f6d..ae1e545c3a1 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -11,7 +11,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); const formattedParent = client.projectPath(projectId); // Retrieves and prints the Discovery Occurrence created for a specified image diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js index 365f3494fd6..823cf32154b 100644 --- a/container-analysis/snippets/getNote.js +++ b/container-analysis/snippets/getNote.js @@ -11,7 +11,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); // Get the full path to the note const formattedName = client.notePath(projectId, noteId); diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index a3c0c7bcfa9..eb9e0efa22f 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -12,7 +12,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); // Get full path to occurrence const formattedName = client.occurrencePath(projectId, occurrenceId); diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 29d25163bee..02461763844 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -11,7 +11,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); const formattedParent = client.projectPath(projectId); diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index db30c353954..c1db8154a2f 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -11,7 +11,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); const formattedParent = client.projectPath(projectId); diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index a853a66574b..b38fa2d1008 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -11,7 +11,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); // Get path to Note const formattedNote = client.notePath(projectId, noteId); diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index d20e682604b..052e72f080d 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -13,7 +13,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); const formattedParent = client.projectPath(projectId); diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 3d144a605fd..a4d731ed18e 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -3,7 +3,7 @@ const cp = require('child_process'); const uuid = require(`uuid`); const containerAnalysis = require('@google-cloud/containeranalysis'); -const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); +const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); @@ -313,7 +313,6 @@ describe('pubsub', function() { const [pubSubOccurrence] = await client.createOccurrence( pubSubOccurrenceReq ); - // const pubSubOccurrenceId = pubSubOccurrence.name.split("/")[3]; await client.deleteOccurrence({name: pubSubOccurrence.name}); } const output = execSync( diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index 267fce8372f..aca7ce9454f 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -11,7 +11,7 @@ async function main( // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.ContainerAnalysisV1Beta1Client(); + const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); const formattedParent = client.projectPath(projectId); From 3eada80ad5ddbebed0f3e41d77c59e96b026ecc8 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 28 May 2019 11:48:48 -0700 Subject: [PATCH 041/131] added retry logic to get occurrence test --- .../snippets/test/containerAnalysis.test.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index a4d731ed18e..8adbe92697d 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -12,6 +12,7 @@ const noteId = `test-note-${uuidVal}`; const resourceUrl = `gcr.io/test-project/test-image-${uuidVal}`; const subscriptionId = `occurrence-subscription-${uuidVal}`; const timeoutSeconds = 5; +const retries = 5; const {PubSub} = require('@google-cloud/pubsub'); const pubsub = new PubSub(); @@ -66,7 +67,6 @@ describe('Note tests', function() { assert.match(output, new RegExp(`Occurrence created`)); }); - // TODO: sometimes fails, should try again if no images are found it('should get occurrence', async function() { const [occurrences] = await client.listOccurrences({ parent: formattedParent, @@ -75,9 +75,16 @@ describe('Note tests', function() { const occurrence = occurrences[0]; const occurrenceId = occurrence.name.split('/')[3]; - const output = execSync( - `node getOccurrence.js "${projectId}" "${occurrenceId}"` - ); + let output; + for (let i = 0; i < retries; i++) { + output = execSync( + `node getOccurrence.js "${projectId}" "${occurrenceId}"` + ); + if (output.includes('Occurrence name:')) { + break; + } + } + assert.match(output, new RegExp(`Occurrence name: ${occurrence.name}`)); }); From 3850bca0d22eeaf575496152b1dc3aca0c872891 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 28 May 2019 11:55:55 -0700 Subject: [PATCH 042/131] changed assert match to assert include --- .../snippets/test/containerAnalysis.test.js | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 8adbe92697d..af0859af97b 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -52,19 +52,19 @@ describe('Note tests', function() { }); it('should create a note', function() { const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); - assert.match(output, new RegExp(`Note ${formattedNoteName} created.`)); + assert.include(output, new RegExp(`Note ${formattedNoteName} created.`)); }); it('should get note', function() { const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); - assert.match(output, new RegExp(`Note name: ${formattedNoteName}`)); + assert.include(output, new RegExp(`Note name: ${formattedNoteName}`)); }); it('should create occurrence', function() { const output = execSync( `node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"` ); - assert.match(output, new RegExp(`Occurrence created`)); + assert.include(output, new RegExp(`Occurrence created`)); }); it('should get occurrence', async function() { @@ -85,21 +85,21 @@ describe('Note tests', function() { } } - assert.match(output, new RegExp(`Occurrence name: ${occurrence.name}`)); + assert.include(output, new RegExp(`Occurrence name: ${occurrence.name}`)); }); it('should get occurences for note', function() { const output = execSync( `node occurrencesForNote.js "${projectId}" "${noteId}"` ); - assert.match(output, /Occurrences:/); + assert.include(output, /Occurrences:/); }); it('should get occurrences for image', function() { const output = execSync( `node occurrencesForImage.js "${projectId}" "${resourceUrl}"` ); - assert.match(output, new RegExp(`Occurrences for ${resourceUrl}`)); + assert.include(output, new RegExp(`Occurrences for ${resourceUrl}`)); }); it('should get discovery info for image', async function() { @@ -133,7 +133,7 @@ describe('Note tests', function() { const output = execSync( `node getDiscoveryInfo "${projectId}" "${resourceUrl}"` ); - assert.match( + assert.include( output, new RegExp(`Discovery Occurrences for ${resourceUrl}`) ); @@ -173,7 +173,7 @@ describe('Note tests', function() { `node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"` ); - assert.match( + assert.include( output, new RegExp(`High Severity Vulnerabilities for ${resourceUrl}`) ); @@ -183,7 +183,7 @@ describe('Note tests', function() { const output = execSync( `node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"` ); - assert.match(output, new RegExp(`All Vulnerabilities for ${resourceUrl}`)); + assert.include(output, new RegExp(`All Vulnerabilities for ${resourceUrl}`)); }); it('should delete occurrence', async function() { @@ -197,14 +197,15 @@ describe('Note tests', function() { const output = execSync( `node deleteOccurrence.js "${projectId}" "${occurrenceId}"` ); - assert.match(output, new RegExp(`Occurrence deleted.`)); + assert.include(output, new RegExp(`Occurrence deleted.`)); }); it('should delete note', function() { const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); - assert.match(output, new RegExp(`Note ${formattedNoteName} deleted.`)); + assert.include(output, new RegExp(`Note ${formattedNoteName} deleted.`)); }); }); +// eslint-disable-next-line no-warning-comments // TODO: complete polling sample xdescribe('polling', function() { before(async function() { @@ -257,7 +258,7 @@ xdescribe('polling', function() { const output = execSync( `node pollDiscoveryOccurrenceFinished.js "${projectId}" "${resourceUrl}" "${timeoutSeconds}"` ); - assert.match( + assert.include( output, new RegExp(`Polled Discovery Occurrences for ${resourceUrl}`) ); @@ -314,7 +315,7 @@ describe('pubsub', function() { `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` ); - assert.match(empty, new RegExp(`Polled 0 occurrences`)); + assert.include(empty, new RegExp(`Polled 0 occurrences`)); // create test occurrences for (let i = 0; i < expectedNum; i++) { const [pubSubOccurrence] = await client.createOccurrence( @@ -327,6 +328,6 @@ describe('pubsub', function() { ); // make sure pubsub number matches - assert.match(output, new RegExp(`Polled ${expectedNum} occurrences`)); + assert.include(output, new RegExp(`Polled ${expectedNum} occurrences`)); }); }); From d8d2a5254d3982dea9a68b5d60fb5684c1ace717 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 28 May 2019 12:59:40 -0700 Subject: [PATCH 043/131] added create topic logic to fix ci test error --- container-analysis/snippets/test/containerAnalysis.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index af0859af97b..77a088613b7 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -17,7 +17,7 @@ const retries = 5; const {PubSub} = require('@google-cloud/pubsub'); const pubsub = new PubSub(); const topicName = 'container-analysis-occurrences-v1beta1'; -const topic = pubsub.topic(topicName); +let topic; let projectId; let formattedParent; @@ -271,6 +271,8 @@ describe('pubsub', function() { projectId = await client.getProjectId(); formattedParent = `projects/${projectId}`; formattedNoteName = `projects/${projectId}/notes/${noteId}`; + await pubsub.createTopic(topicName); + topic = pubsub.topic(topicName); }); beforeEach(async function() { From 0fa3c0c765dba9dd637413ed3f9024ea591b431b Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 28 May 2019 15:20:27 -0700 Subject: [PATCH 044/131] removed regexp from assert include --- .../snippets/test/containerAnalysis.test.js | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 77a088613b7..71deb71276a 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -52,19 +52,19 @@ describe('Note tests', function() { }); it('should create a note', function() { const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); - assert.include(output, new RegExp(`Note ${formattedNoteName} created.`)); + assert.include(output, `Note ${formattedNoteName} created.`); }); it('should get note', function() { const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); - assert.include(output, new RegExp(`Note name: ${formattedNoteName}`)); + assert.include(output, `Note name: ${formattedNoteName}`); }); it('should create occurrence', function() { const output = execSync( `node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"` ); - assert.include(output, new RegExp(`Occurrence created`)); + assert.include(output, `Occurrence created`); }); it('should get occurrence', async function() { @@ -85,21 +85,21 @@ describe('Note tests', function() { } } - assert.include(output, new RegExp(`Occurrence name: ${occurrence.name}`)); + assert.include(output, `Occurrence name: ${occurrence.name}`); }); it('should get occurences for note', function() { const output = execSync( `node occurrencesForNote.js "${projectId}" "${noteId}"` ); - assert.include(output, /Occurrences:/); + assert.include(output, 'Occurrences:'); }); it('should get occurrences for image', function() { const output = execSync( `node occurrencesForImage.js "${projectId}" "${resourceUrl}"` ); - assert.include(output, new RegExp(`Occurrences for ${resourceUrl}`)); + assert.include(output, `Occurrences for ${resourceUrl}`); }); it('should get discovery info for image', async function() { @@ -133,10 +133,7 @@ describe('Note tests', function() { const output = execSync( `node getDiscoveryInfo "${projectId}" "${resourceUrl}"` ); - assert.include( - output, - new RegExp(`Discovery Occurrences for ${resourceUrl}`) - ); + assert.include(output, `Discovery Occurrences for ${resourceUrl}`); }); it('should get high severity vulnerabilities for image', async function() { @@ -173,17 +170,14 @@ describe('Note tests', function() { `node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"` ); - assert.include( - output, - new RegExp(`High Severity Vulnerabilities for ${resourceUrl}`) - ); + assert.include(output, `High Severity Vulnerabilities for ${resourceUrl}`); }); it('should get all vulnerabilites for image', function() { const output = execSync( `node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"` ); - assert.include(output, new RegExp(`All Vulnerabilities for ${resourceUrl}`)); + assert.include(output, `All Vulnerabilities for ${resourceUrl}`); }); it('should delete occurrence', async function() { @@ -197,11 +191,11 @@ describe('Note tests', function() { const output = execSync( `node deleteOccurrence.js "${projectId}" "${occurrenceId}"` ); - assert.include(output, new RegExp(`Occurrence deleted.`)); + assert.include(output, `Occurrence deleted.`); }); it('should delete note', function() { const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); - assert.include(output, new RegExp(`Note ${formattedNoteName} deleted.`)); + assert.include(output, `Note ${formattedNoteName} deleted.`); }); }); @@ -258,10 +252,7 @@ xdescribe('polling', function() { const output = execSync( `node pollDiscoveryOccurrenceFinished.js "${projectId}" "${resourceUrl}" "${timeoutSeconds}"` ); - assert.include( - output, - new RegExp(`Polled Discovery Occurrences for ${resourceUrl}`) - ); + assert.include(output, `Polled Discovery Occurrences for ${resourceUrl}`); }); }); @@ -317,7 +308,7 @@ describe('pubsub', function() { `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` ); - assert.include(empty, new RegExp(`Polled 0 occurrences`)); + assert.include(empty, `Polled 0 occurrences`); // create test occurrences for (let i = 0; i < expectedNum; i++) { const [pubSubOccurrence] = await client.createOccurrence( @@ -330,6 +321,6 @@ describe('pubsub', function() { ); // make sure pubsub number matches - assert.include(output, new RegExp(`Polled ${expectedNum} occurrences`)); + assert.include(output, `Polled ${expectedNum} occurrences`); }); }); From 3e38ab81a63cc006f190d150d2877b838d9f51cd Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 28 May 2019 15:28:41 -0700 Subject: [PATCH 045/131] changed tests to include arrow functions --- .../snippets/test/containerAnalysis.test.js | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 71deb71276a..a1cfd185616 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -23,14 +23,14 @@ let projectId; let formattedParent; let formattedNoteName; -describe('Note tests', function() { - before(async function() { +describe('Note tests', () => { + before(async () => { // define projectId and related vars projectId = await client.getProjectId(); formattedParent = `projects/${projectId}`; formattedNoteName = `projects/${projectId}/notes/${noteId}`; }); - after(async function() { + after(async () => { const [allOccurrences] = await client.listOccurrences({ parent: formattedParent, filter: `resourceUrl = "${resourceUrl}"`, @@ -50,24 +50,24 @@ describe('Note tests', function() { console.log(`deleted note ${note.name}`); }); }); - it('should create a note', function() { + it('should create a note', () => { const output = execSync(`node createNote.js "${projectId}" "${noteId}"`); assert.include(output, `Note ${formattedNoteName} created.`); }); - it('should get note', function() { + it('should get note', () => { const output = execSync(`node getNote.js "${projectId}" "${noteId}"`); assert.include(output, `Note name: ${formattedNoteName}`); }); - it('should create occurrence', function() { + it('should create occurrence', () => { const output = execSync( `node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"` ); assert.include(output, `Occurrence created`); }); - it('should get occurrence', async function() { + it('should get occurrence', async () => { const [occurrences] = await client.listOccurrences({ parent: formattedParent, }); @@ -88,21 +88,21 @@ describe('Note tests', function() { assert.include(output, `Occurrence name: ${occurrence.name}`); }); - it('should get occurences for note', function() { + it('should get occurences for note', () => { const output = execSync( `node occurrencesForNote.js "${projectId}" "${noteId}"` ); assert.include(output, 'Occurrences:'); }); - it('should get occurrences for image', function() { + it('should get occurrences for image', () => { const output = execSync( `node occurrencesForImage.js "${projectId}" "${resourceUrl}"` ); assert.include(output, `Occurrences for ${resourceUrl}`); }); - it('should get discovery info for image', async function() { + it('should get discovery info for image', async () => { const discoveryNoteRequest = { parent: formattedParent, noteId: `${noteId}-discovery`, @@ -136,7 +136,7 @@ describe('Note tests', function() { assert.include(output, `Discovery Occurrences for ${resourceUrl}`); }); - it('should get high severity vulnerabilities for image', async function() { + it('should get high severity vulnerabilities for image', async () => { const criticalNoteReq = { parent: formattedParent, noteId: `${noteId}-critical`, @@ -173,14 +173,14 @@ describe('Note tests', function() { assert.include(output, `High Severity Vulnerabilities for ${resourceUrl}`); }); - it('should get all vulnerabilites for image', function() { + it('should get all vulnerabilites for image', () => { const output = execSync( `node vulnerabilityOccurrencesForImage "${projectId}" "${resourceUrl}"` ); assert.include(output, `All Vulnerabilities for ${resourceUrl}`); }); - it('should delete occurrence', async function() { + it('should delete occurrence', async () => { const [occurrences] = await client.listOccurrences({ parent: formattedParent, }); @@ -193,7 +193,7 @@ describe('Note tests', function() { ); assert.include(output, `Occurrence deleted.`); }); - it('should delete note', function() { + it('should delete note', () => { const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); assert.include(output, `Note ${formattedNoteName} deleted.`); }); @@ -201,8 +201,8 @@ describe('Note tests', function() { // eslint-disable-next-line no-warning-comments // TODO: complete polling sample -xdescribe('polling', function() { - before(async function() { +xdescribe('polling', () => { + before(async () => { // define project id and related vars projectId = await client.getProjectId(); formattedParent = `projects/${projectId}`; @@ -238,7 +238,7 @@ xdescribe('polling', function() { await client.createOccurrence(occurrenceRequest); }); - after(async function() { + after(async () => { const [discoveryOccurrences] = await client.listNoteOccurrences({ name: `${formattedNoteName}-discovery-polling`, }); @@ -248,7 +248,7 @@ xdescribe('polling', function() { await client.deleteNote({name: `${formattedNoteName}-discovery-polling`}); }); - it('should successfully poll latest discovery occurrence', function() { + it('should successfully poll latest discovery occurrence', () => { const output = execSync( `node pollDiscoveryOccurrenceFinished.js "${projectId}" "${resourceUrl}" "${timeoutSeconds}"` ); @@ -256,8 +256,8 @@ xdescribe('polling', function() { }); }); -describe('pubsub', function() { - before(async function() { +describe('pubsub', () => { + before(async () => { // define project id and related vars projectId = await client.getProjectId(); formattedParent = `projects/${projectId}`; @@ -266,7 +266,7 @@ describe('pubsub', function() { topic = pubsub.topic(topicName); }); - beforeEach(async function() { + beforeEach(async () => { await topic.createSubscription(subscriptionId); const pubSubNoteReq = { parent: formattedParent, @@ -278,12 +278,12 @@ describe('pubsub', function() { await client.createNote(pubSubNoteReq); }); - afterEach(async function() { + afterEach(async () => { await client.deleteNote({name: `${formattedNoteName}-pubsub`}); await pubsub.subscription(subscriptionId).delete(); }); - it('should get accurate count of occurrences from pubsub topic', async function() { + it('should get accurate count of occurrences from pubsub topic', async () => { const expectedNum = 3; const pubSubOccurrenceReq = { parent: formattedParent, From bf765725e005ab64ab3b9757774f4d52696c1ce0 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 28 May 2019 15:56:09 -0700 Subject: [PATCH 046/131] moved containeranalysis and pubsub into prod deps --- container-analysis/snippets/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 8844ac424cf..7736231f955 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -13,8 +13,11 @@ "scripts": { "test": "mocha --timeout 100000 test/**.test.js" }, + "dependencies": { + "@google-cloud/containeranalysis": "^0.1.0", + "@google-cloud/pubsub": "^0.28.1" + }, "devDependencies": { - "@google-cloud/pubsub": "^0.28.1", "chai": "^4.2.0", "mocha": "^6.1.4", "p-retry": "^4.1.0", From 970053efefd39ea1c38f4e2eac6542dd4f77ce04 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 28 May 2019 16:27:48 -0700 Subject: [PATCH 047/131] added retry logic for all occs of note, check if topic exists and fixed typo on delete occ test --- .../snippets/test/containerAnalysis.test.js | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index a1cfd185616..03507f45b9b 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -89,9 +89,15 @@ describe('Note tests', () => { }); it('should get occurences for note', () => { - const output = execSync( - `node occurrencesForNote.js "${projectId}" "${noteId}"` - ); + let output; + for (let i = 0; i < retries; i++) { + output = execSync( + `node occurrencesForNote.js "${projectId}" "${noteId}"` + ); + if (!output.includes('No occurrences found.')) { + break; + } + } assert.include(output, 'Occurrences:'); }); @@ -191,7 +197,7 @@ describe('Note tests', () => { const output = execSync( `node deleteOccurrence.js "${projectId}" "${occurrenceId}"` ); - assert.include(output, `Occurrence deleted.`); + assert.include(output, `Occurrence deleted:`); }); it('should delete note', () => { const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); @@ -262,8 +268,12 @@ describe('pubsub', () => { projectId = await client.getProjectId(); formattedParent = `projects/${projectId}`; formattedNoteName = `projects/${projectId}/notes/${noteId}`; - await pubsub.createTopic(topicName); - topic = pubsub.topic(topicName); + try { + topic = pubsub.topic(topicName); + } catch (err) { + await pubsub.createTopic(topicName); + topic = pubsub.topic(topicName); + } }); beforeEach(async () => { From 3e3c5300d6d2bb0f187f6d5185985f1e577c1ced Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 28 May 2019 17:04:19 -0700 Subject: [PATCH 048/131] added sample-metadata --- container-analysis/snippets/createNote.js | 4 ++++ container-analysis/snippets/createOccurrence.js | 4 ++++ container-analysis/snippets/deleteNote.js | 5 ++++- container-analysis/snippets/deleteOccurrence.js | 4 ++++ container-analysis/snippets/getDiscoveryInfo.js | 4 ++++ container-analysis/snippets/getNote.js | 4 ++++ container-analysis/snippets/getOccurrence.js | 5 ++++- container-analysis/snippets/highVulnerabilitiesForImage.js | 4 ++++ container-analysis/snippets/occurrencePubSub.js | 4 ++++ container-analysis/snippets/occurrencesForImage.js | 4 ++++ container-analysis/snippets/occurrencesForNote.js | 4 ++++ .../snippets/vulnerabilityOccurrencesForImage.js | 4 ++++ 12 files changed, 48 insertions(+), 2 deletions(-) diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index 9ad6839c3ca..e7d4f0eef06 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -1,3 +1,7 @@ +// sample-metadata: +// title: Create Note +// description: Creates a Note with specified ID +// usage: node createNote.js async function main( projectId = 'your-project-id', // Your GCP Project ID noteId = 'my-note-id' // Id of the note diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index 6bca0ee3d25..f4e7cea353e 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -1,3 +1,7 @@ +// 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 async function main( noteProjectId = 'your-project-id', // Your GCP Project Id noteId = 'my-note-id', // Id of the note diff --git a/container-analysis/snippets/deleteNote.js b/container-analysis/snippets/deleteNote.js index 24f6622bd9c..ecd07ebb05f 100644 --- a/container-analysis/snippets/deleteNote.js +++ b/container-analysis/snippets/deleteNote.js @@ -1,4 +1,7 @@ -// Deletes an existing Note from the server +// sample-metadata: +// title: Delete Note +// description: Deletes a specified Note +// usage: node deleteNote.js async function main( projectId = 'your-project-id', // Your GCP Project Id noteId = 'my-note-id' // Id of the note diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index f20c997dc1c..88e7cef8246 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -1,3 +1,7 @@ +// sample-metadata: +// title: Delete Occurrence +// description: Deletes a specified Occurrence +// usage: node deleteOccurrence.js async function main( projectId = 'your-project-id', // Your GCP Project ID occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index ae1e545c3a1..292e2f46b03 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -1,3 +1,7 @@ +// sample-metadata: +// title: Get Discovery Info +// description: Gets all Discovery Occurrences attached to specified image +// usage: node getDiscoveryInfo.js async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js index 823cf32154b..fde5cb36729 100644 --- a/container-analysis/snippets/getNote.js +++ b/container-analysis/snippets/getNote.js @@ -1,3 +1,7 @@ +// sample-metadata: +// title: Get Note +// description: Retrieves and prints a specified note +// usage: node getNote.js async function main( projectId = 'your-project-id', // Your GCP Project ID noteId = 'my-note-id' // Id of the note diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index eb9e0efa22f..602cdd784db 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -1,4 +1,7 @@ -// Retrieves and prints a specified Occurrence from the server +// sample-metadata: +// title: Get Occurrence +// description: Retrieves and prints a specified Occurrence +// usage: node getOccurrence.js async function main( projectId = 'your-project-id', // Your GCP Project ID occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 02461763844..afac03c02bc 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -1,3 +1,7 @@ +// sample-metadata: +// title: Get High Vulnerabilities for Image +// description: Retrieves all Vulnerability Occurrences of High Severity from Specified Image +// usage: node highVulnerabilitiesForImage.js async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index 0dc43818d72..2b3658347ca 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -1,3 +1,7 @@ +// sample-metadata: +// title: Occurrence PubSub +// description: Polls a specified PubSub subscription for Occurrences. Requires a subscription to a topic named 'container-analysis-occurrences-v1beta' +// usage: node occurrencePubSub.js async function main( projectId = 'your-project-id', // Your GCP Project ID subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index c1db8154a2f..02c1752c7eb 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -1,3 +1,7 @@ +// sample-metadata: +// title: Occurrences for Image +// description: Retrieves all Occurrences attached to the metadata of a specified image +// usage: node occurrencesForImage.js async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index b38fa2d1008..3837b3d4689 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -1,3 +1,7 @@ +// sample-metadata: +// title: Occurrences for Note +// description: Retrieves all Occurrences of a specified Note +// usage: node occurrencesForNote.js async function main( projectId = 'your-project-id', // Your GCP Project ID noteId = 'my-note-id' // Id of the note diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index aca7ce9454f..9fa1bb691c3 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -1,3 +1,7 @@ +// sample-metadata: +// title: Vulnerability Occurrences for Image +// description: Retrieves all Vulnerability Occurrences attached to a specified image +// usage: node exportAssets.js async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to From a71693d417e09d49465481e4ad5b47e9dc7520f1 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 28 May 2019 17:06:40 -0700 Subject: [PATCH 049/131] fixed occurrence typo --- container-analysis/snippets/createOccurrence.js | 6 +++--- container-analysis/snippets/test/containerAnalysis.test.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index f4e7cea353e..c332d21296b 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -5,7 +5,7 @@ async function main( noteProjectId = 'your-project-id', // Your GCP Project Id noteId = 'my-note-id', // Id of the note - occurenceProjectId = 'your-project-id', // GCP Project Id of Occurence + occurrenceProjectId = 'your-project-id', // GCP Project Id of Occurrence imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to ) { // [START containeranalysis_create_occurrence] @@ -14,7 +14,7 @@ async function main( */ // const noteProjectId = 'your-project-id', // Your GCP Project Id // const noteId = 'my-note-id', // Id of the note - // const occurenceProjectId = 'your-project-id', // GCP Project Id of Occurence + // const occurrenceProjectId = 'your-project-id', // GCP Project Id of Occurrence // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client @@ -22,7 +22,7 @@ async function main( const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); // Construct request - const formattedParent = client.projectPath(occurenceProjectId); + const formattedParent = client.projectPath(occurrenceProjectId); const formattedNote = client.notePath(noteProjectId, noteId); // Creates and returns a new Occurrence associated with an existing Note diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 03507f45b9b..f9f0857b224 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -88,7 +88,7 @@ describe('Note tests', () => { assert.include(output, `Occurrence name: ${occurrence.name}`); }); - it('should get occurences for note', () => { + it('should get occurrences for note', () => { let output; for (let i = 0; i < retries; i++) { output = execSync( From 4d32bdfe2ef9192eb63465ba593a4cb1e3588d1c Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Tue, 28 May 2019 17:43:04 -0700 Subject: [PATCH 050/131] added params to sample-metadata usage --- container-analysis/snippets/createNote.js | 2 +- container-analysis/snippets/createOccurrence.js | 2 +- container-analysis/snippets/deleteNote.js | 2 +- container-analysis/snippets/deleteOccurrence.js | 2 +- container-analysis/snippets/getDiscoveryInfo.js | 2 +- container-analysis/snippets/getNote.js | 2 +- container-analysis/snippets/getOccurrence.js | 2 +- container-analysis/snippets/highVulnerabilitiesForImage.js | 2 +- container-analysis/snippets/occurrencePubSub.js | 2 +- container-analysis/snippets/occurrencesForImage.js | 2 +- container-analysis/snippets/occurrencesForNote.js | 2 +- container-analysis/snippets/vulnerabilityOccurrencesForImage.js | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index e7d4f0eef06..64c7ca3e712 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Create Note // description: Creates a Note with specified ID -// usage: node createNote.js +// 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 diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index c332d21296b..20fa5113272 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -1,7 +1,7 @@ // 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 +// 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 diff --git a/container-analysis/snippets/deleteNote.js b/container-analysis/snippets/deleteNote.js index ecd07ebb05f..6f8bb204ecb 100644 --- a/container-analysis/snippets/deleteNote.js +++ b/container-analysis/snippets/deleteNote.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Delete Note // description: Deletes a specified Note -// usage: node deleteNote.js +// 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 diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index 88e7cef8246..f6dace0d5ed 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Delete Occurrence // description: Deletes a specified Occurrence -// usage: node deleteOccurrence.js +// 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 diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 292e2f46b03..517ff179094 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Get Discovery Info // description: Gets all Discovery Occurrences attached to specified image -// usage: node getDiscoveryInfo.js +// usage: node getDiscoveryInfo.js "project-id" "image-url" async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js index fde5cb36729..78153bbf6d3 100644 --- a/container-analysis/snippets/getNote.js +++ b/container-analysis/snippets/getNote.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Get Note // description: Retrieves and prints a specified note -// usage: node getNote.js +// usage: node getNote.js "project-id" "note-id" async function main( projectId = 'your-project-id', // Your GCP Project ID noteId = 'my-note-id' // Id of the note diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index 602cdd784db..36899edb6c3 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Get Occurrence // description: Retrieves and prints a specified Occurrence -// usage: node getOccurrence.js +// usage: node getOccurrence.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 diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index afac03c02bc..69348fda910 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Get High Vulnerabilities for Image // description: Retrieves all Vulnerability Occurrences of High Severity from Specified Image -// usage: node highVulnerabilitiesForImage.js +// usage: node highVulnerabilitiesForImage.js "project-id" "image-url" async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index 2b3658347ca..a7d60408c08 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Occurrence PubSub // description: Polls a specified PubSub subscription for Occurrences. Requires a subscription to a topic named 'container-analysis-occurrences-v1beta' -// usage: node occurrencePubSub.js +// usage: node occurrencePubSub.js "project-id" "subscription-id" "timeout-in-seconds" async function main( projectId = 'your-project-id', // Your GCP Project ID subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index 02c1752c7eb..afe87c70201 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Occurrences for Image // description: Retrieves all Occurrences attached to the metadata of a specified image -// usage: node occurrencesForImage.js +// usage: node occurrencesForImage.js "project-id" "image-url" async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index 3837b3d4689..2265ff5f5d0 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Occurrences for Note // description: Retrieves all Occurrences of a specified Note -// usage: node occurrencesForNote.js +// usage: node occurrencesForNote.js "project-id" "note-id" async function main( projectId = 'your-project-id', // Your GCP Project ID noteId = 'my-note-id' // Id of the note diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index 9fa1bb691c3..e77569581d0 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -1,7 +1,7 @@ // sample-metadata: // title: Vulnerability Occurrences for Image // description: Retrieves all Vulnerability Occurrences attached to a specified image -// usage: node exportAssets.js +// usage: node vulnerabilityOccurrencesForImage.js "project-id" "image-url" async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to From 0ee106dffc88260ee54e4b66bbafaf29f136d776 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Wed, 29 May 2019 10:07:28 -0700 Subject: [PATCH 051/131] added p-retry to prod deps, updated poll sample --- container-analysis/snippets/package.json | 4 ++-- .../snippets/pollDiscoveryOccurrenceFinished.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 7736231f955..3cd45b19d9a 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -15,12 +15,12 @@ }, "dependencies": { "@google-cloud/containeranalysis": "^0.1.0", - "@google-cloud/pubsub": "^0.28.1" + "@google-cloud/pubsub": "^0.28.1", + "p-retry": "^4.1.0" }, "devDependencies": { "chai": "^4.2.0", "mocha": "^6.1.4", - "p-retry": "^4.1.0", "uuid": "^3.3.2" } } diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 052e72f080d..fe9af621c99 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -1,7 +1,11 @@ +// sample-metadata: +// title: Poll Discovery Occurrence Finished +// description: Waits for a Discovery Occurrence to reach a terminal state +// usage: node pollDiscoveryOccurrenceFinished.js "project-id" "image-url" "retries" async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123', // Image to attach metadata to - timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub messages + retries = 'num-of-retries' // The number of retries to listen for the new Pub/Sub messages ) { // [START containeranalysis_poll_discovery_occurrence_finished] /** @@ -9,7 +13,7 @@ async function main( */ // const projectId = 'your-project-id', // Your GCP Project ID // const imageUrl = 'https://gcr.io/my-project/my-image:123', // Image to attach metadata to - // const timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub messages + // const retries = 'num-of-retries' // The number of retries to listen for the new Pub/Sub messages // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); @@ -39,7 +43,7 @@ async function main( return occurrences[0]; }, { - retries: 5, + retries: retries, } ); @@ -62,7 +66,7 @@ async function main( return updated; }, { - retries: 5, + retries: retries, } ); console.log( From 64bb80245fad8481605b852c09ff0bd0992f7272 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Thu, 30 May 2019 14:50:21 -0700 Subject: [PATCH 052/131] working poll discovery occurrence finished sample --- .../pollDiscoveryOccurrenceFinished.js | 5 ++--- .../snippets/test/containerAnalysis.test.js | 18 +++++++----------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index fe9af621c99..0d9959dbd67 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -47,8 +47,7 @@ async function main( } ); - console.log(`Polled Discovery Occurrences for ${imageUrl}`); - // Wait for discovery occurrence to enter a terminal state + // Wait for discovery occurrence to enter a terminal state or the timeout value has been exceeded const finishedOccurrence = await pRetry( async () => { let status = 'PENDING'; @@ -74,7 +73,7 @@ async function main( finishedOccurrence.discovered.discovered.analysisStatus }` ); + // [END containeranalysis_poll_discovery_occurrence_finished] } -// [END containeranalysis_poll_discovery_occurrence_finished] main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index f9f0857b224..be77e130b52 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -205,9 +205,7 @@ describe('Note tests', () => { }); }); -// eslint-disable-next-line no-warning-comments -// TODO: complete polling sample -xdescribe('polling', () => { +describe('polling', () => { before(async () => { // define project id and related vars projectId = await client.getProjectId(); @@ -218,9 +216,7 @@ xdescribe('polling', () => { parent: formattedParent, noteId: `${noteId}-discovery-polling`, note: { - discovery: { - continuousAnalysis: 'INACTIVE', - }, + discovery: {}, }, }; @@ -232,12 +228,12 @@ xdescribe('polling', () => { noteName: `${formattedNoteName}-discovery-polling`, discovered: { discovered: { - analysisStatus: 'FINISHED_SUCCESS', + analysisStatus: 3, }, }, - }, - resource: { - uri: resourceUrl, + resource: { + uri: resourceUrl, + }, }, }; @@ -258,7 +254,7 @@ xdescribe('polling', () => { const output = execSync( `node pollDiscoveryOccurrenceFinished.js "${projectId}" "${resourceUrl}" "${timeoutSeconds}"` ); - assert.include(output, `Polled Discovery Occurrences for ${resourceUrl}`); + assert.include(output, `Found discovery occurrence`); }); }); From 9d83fdf84cb682f1d68df5b49f2fe16216ac6dc9 Mon Sep 17 00:00:00 2001 From: Guillermina Muro Date: Thu, 30 May 2019 14:59:15 -0700 Subject: [PATCH 053/131] updated default value of retries and timeoutSeconds to be more readable --- container-analysis/snippets/occurrencePubSub.js | 4 ++-- .../snippets/pollDiscoveryOccurrenceFinished.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index a7d60408c08..913216fa9c1 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -5,7 +5,7 @@ async function main( projectId = 'your-project-id', // Your GCP Project ID subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic - timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub messages + timeoutSeconds = 30 // The number of seconds to listen for the new Pub/Sub messages ) { // [START containeranalysis_pubsub] /** @@ -13,7 +13,7 @@ async function main( */ // const projectId = 'your-project-id', // Your GCP Project ID // const subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic - // const timeoutSeconds = 'timeout-in-seconds' // The number of seconds to listen for the new Pub/Sub Messages + // const timeoutSeconds = 30 // The number of seconds to listen for the new Pub/Sub Messages // Import the pubsub library and create a client, topic and subscription const {PubSub} = require('@google-cloud/pubsub'); diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 0d9959dbd67..31f9f99544a 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -5,7 +5,7 @@ async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123', // Image to attach metadata to - retries = 'num-of-retries' // The number of retries to listen for the new Pub/Sub messages + retries = 5 // The number of retries to listen for the new Pub/Sub messages ) { // [START containeranalysis_poll_discovery_occurrence_finished] /** @@ -13,7 +13,7 @@ async function main( */ // const projectId = 'your-project-id', // Your GCP Project ID // const imageUrl = 'https://gcr.io/my-project/my-image:123', // Image to attach metadata to - // const retries = 'num-of-retries' // The number of retries to listen for the new Pub/Sub messages + // const retries = 5 // The number of retries to listen for the new Pub/Sub messages // Import the library and create a client const containerAnalysis = require('@google-cloud/containeranalysis'); From 8a069480b6343756ae7ab254d008e2860580b7f1 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Fri, 7 Jun 2019 07:29:27 -0700 Subject: [PATCH 054/131] refactor: changes formatting of various statements --- .../snippets/pollDiscoveryOccurrenceFinished.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 31f9f99544a..864b27bc10b 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -69,9 +69,7 @@ async function main( } ); console.log( - `Found discovery occurrence ${finishedOccurrence.name}. Status: ${ - finishedOccurrence.discovered.discovered.analysisStatus - }` + `Found discovery occurrence ${finishedOccurrence.name}. Status: ${finishedOccurrence.discovered.discovered.analysisStatus}` ); // [END containeranalysis_poll_discovery_occurrence_finished] } From eee72137d0a136d7096e1955ba70a5ffca982a94 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Sat, 8 Jun 2019 12:42:54 -0700 Subject: [PATCH 055/131] chore: release 1.0.0 (#33) * created CHANGELOG.md * updated package.json * updated samples/package.json --- container-analysis/snippets/package.json | 48 ++++++++++++------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 3cd45b19d9a..9935389b2cb 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -1,26 +1,26 @@ { - "name": "nodejs-containeranalysis-samples", - "private": true, - "license": "Apache-2.0", - "author": "Google Inc.", - "repository": "googleapis/nodejs-containeranalysis", - "files": [ - "*.js" - ], - "engines": { - "node": ">=10" - }, - "scripts": { - "test": "mocha --timeout 100000 test/**.test.js" - }, - "dependencies": { - "@google-cloud/containeranalysis": "^0.1.0", - "@google-cloud/pubsub": "^0.28.1", - "p-retry": "^4.1.0" - }, - "devDependencies": { - "chai": "^4.2.0", - "mocha": "^6.1.4", - "uuid": "^3.3.2" - } + "name": "nodejs-containeranalysis-samples", + "private": true, + "license": "Apache-2.0", + "author": "Google Inc.", + "repository": "googleapis/nodejs-containeranalysis", + "files": [ + "*.js" + ], + "engines": { + "node": ">=10" + }, + "scripts": { + "test": "mocha --timeout 100000 test/**.test.js" + }, + "dependencies": { + "@google-cloud/containeranalysis": "^1.0.0", + "@google-cloud/pubsub": "^0.28.1", + "p-retry": "^4.1.0" + }, + "devDependencies": { + "chai": "^4.2.0", + "mocha": "^6.1.4", + "uuid": "^3.3.2" + } } From 32c84340810903fc0b9adaa08734b66234fd5bdd Mon Sep 17 00:00:00 2001 From: "renovate[bot]" Date: Tue, 11 Jun 2019 11:46:57 -0400 Subject: [PATCH 056/131] fix(deps): update dependency @google-cloud/pubsub to ^0.29.0 (#36) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 9935389b2cb..e8e24610476 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@google-cloud/containeranalysis": "^1.0.0", - "@google-cloud/pubsub": "^0.28.1", + "@google-cloud/pubsub": "^0.29.0", "p-retry": "^4.1.0" }, "devDependencies": { From 2ac666b33375e471cef7066017755bc7d6692970 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 11 Jun 2019 09:11:48 -0700 Subject: [PATCH 057/131] chore: release 1.0.1 (#37) * updated CHANGELOG.md * updated package.json * updated samples/package.json --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index e8e24610476..4c3873c9472 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.0.0", + "@google-cloud/containeranalysis": "^1.0.1", "@google-cloud/pubsub": "^0.29.0", "p-retry": "^4.1.0" }, From 3a04b940e8157ca61f61e9ea257e83d58e6c2dba Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Fri, 14 Jun 2019 07:45:40 -0700 Subject: [PATCH 058/131] chore: release 1.0.2 (#40) * updated CHANGELOG.md * updated package.json * updated samples/package.json --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 4c3873c9472..1c5bcb1c1df 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.0.1", + "@google-cloud/containeranalysis": "^1.0.2", "@google-cloud/pubsub": "^0.29.0", "p-retry": "^4.1.0" }, From 9e8fbfbb755b92574af14052de79dd4b91bd2f4d Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 18 Jun 2019 13:17:00 -0700 Subject: [PATCH 059/131] chore: release 1.1.0 (#44) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 1c5bcb1c1df..b2ab0c04c9e 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.0.2", + "@google-cloud/containeranalysis": "^1.1.0", "@google-cloud/pubsub": "^0.29.0", "p-retry": "^4.1.0" }, From 3bcdcf92b849b99458b1465f04ff5e26d6ee5514 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Wed, 19 Jun 2019 15:51:14 -0700 Subject: [PATCH 060/131] feat: adds getGrafeasClient() method on ContainerAnalysisClient instance (#46) --- container-analysis/snippets/createNote.js | 24 ++++++-- container-analysis/snippets/quickstart.js | 73 ++++++++++++++++------- container-analysis/snippets/test/tests.js | 27 --------- 3 files changed, 71 insertions(+), 53 deletions(-) delete mode 100644 container-analysis/snippets/test/tests.js diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index 64c7ca3e712..c9edf2a958a 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -14,21 +14,35 @@ async function main( // const noteId = 'my-note-id' // Id of the note // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); + const grafeasClient = client.getGrafeasClient(); // 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.projectPath(projectId); + const formattedParent = grafeasClient.projectPath(projectId); // Creates and returns a new Note - const [note] = await client.createNote({ + const [note] = await grafeasClient.createNote({ parent: formattedParent, noteId: noteId, note: { - vulnerability: {}, + vulnerability: { + details: [ + { + affectedCpeUri: 'foo.uri', + affectedPackage: 'foo', + minAffectedVersion: { + kind: 'MINIMUM', + }, + fixedVersion: { + kind: 'MAXIMUM', + }, + }, + ], + }, }, }); diff --git a/container-analysis/snippets/quickstart.js b/container-analysis/snippets/quickstart.js index 47df69fc213..27d50bfe106 100644 --- a/container-analysis/snippets/quickstart.js +++ b/container-analysis/snippets/quickstart.js @@ -1,24 +1,55 @@ -// 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. +// sample-metadata: +// title: Quickstart +// description: fetching an instance of Grafeas and creating a note. +// usage: node quickstart.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_quickstart] + /** + * 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 -'use strict'; + // Import the library and create a client + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); + // Fetch an instance of a Grafeas client: + // see: https://googleapis.dev/nodejs/grafeas/latest + const grafeasClient = client.getGrafeasClient(); -// [START containeranalysis_quickstart] -async function quickstart() { - // Imports the @google-cloud/containeranalysis client library - const client = require('@google-cloud/containeranalysis'); - console.log(client); + // 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 = grafeasClient.projectPath(projectId); + + // Creates and returns a new Note + const [note] = await grafeasClient.createNote({ + parent: formattedParent, + noteId: noteId, + note: { + vulnerability: { + details: [ + { + affectedCpeUri: 'foo.uri', + affectedPackage: 'foo', + minAffectedVersion: { + kind: 'MINIMUM', + }, + fixedVersion: { + kind: 'MAXIMUM', + }, + }, + ], + }, + }, + }); + + console.log(`Note ${note.name} created.`); + // [END containeranalysis_quickstart] } -quickstart(); -// [END containeranalysis_quickstart] + +main(...process.argv.slice(2)); diff --git a/container-analysis/snippets/test/tests.js b/container-analysis/snippets/test/tests.js deleted file mode 100644 index 2d84838090f..00000000000 --- a/container-analysis/snippets/test/tests.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2018 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'; - -const {assert} = require('chai'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -describe('container analysis sample tests', () => { - it('should run the quickstart', async () => { - const output = execSync('node quickstart.js'); - assert.isNotEmpty(output); - }); -}); From d8523f7458780d58e7e0a584ea32aaffefe12952 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Wed, 19 Jun 2019 15:59:51 -0700 Subject: [PATCH 061/131] chore: release 1.2.0 (#47) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index b2ab0c04c9e..76d4433b484 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.1.0", + "@google-cloud/containeranalysis": "^1.2.0", "@google-cloud/pubsub": "^0.29.0", "p-retry": "^4.1.0" }, From 7ac60e4ab47b1ef196b6a022575101f31c7ff694 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Thu, 20 Jun 2019 12:40:16 -0700 Subject: [PATCH 062/131] chore: update samples to reflect v1 Grafeas API (#48) --- container-analysis/snippets/createNote.js | 5 +- .../snippets/createOccurrence.js | 31 +++- container-analysis/snippets/deleteNote.js | 6 +- .../snippets/deleteOccurrence.js | 10 +- .../snippets/getDiscoveryInfo.js | 11 +- container-analysis/snippets/getNote.js | 6 +- container-analysis/snippets/getOccurrence.js | 10 +- .../snippets/highVulnerabilitiesForImage.js | 11 +- .../snippets/occurrencesForImage.js | 11 +- .../snippets/occurrencesForNote.js | 9 +- .../pollDiscoveryOccurrenceFinished.js | 14 +- .../snippets/test/containerAnalysis.test.js | 149 ++++++++++++------ .../vulnerabilityOccurrencesForImage.js | 11 +- 13 files changed, 167 insertions(+), 117 deletions(-) diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index c9edf2a958a..82d905ee6ea 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -16,16 +16,15 @@ async function main( // Import the library and create a client const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); const client = new ContainerAnalysisClient(); - const grafeasClient = client.getGrafeasClient(); // 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 = grafeasClient.projectPath(projectId); + const formattedParent = client.getGrafeasClient().projectPath(projectId); // Creates and returns a new Note - const [note] = await grafeasClient.createNote({ + const [note] = await client.getGrafeasClient().createNote({ parent: formattedParent, noteId: noteId, note: { diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index 20fa5113272..9f5583b587e 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -18,21 +18,36 @@ async function main( // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); // Construct request - const formattedParent = client.projectPath(occurrenceProjectId); - const formattedNote = client.notePath(noteProjectId, noteId); + 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.createOccurrence({ + const [occurrence] = await client.getGrafeasClient().createOccurrence({ parent: formattedParent, occurrence: { noteName: formattedNote, - vulnerability: {}, - resource: { - uri: imageUrl, + resourceUri: imageUrl, + vulnerability: { + packageIssue: [ + { + affectedCpeUri: 'foo.uri', + affectedPackage: 'foo', + minAffectedVersion: { + kind: 'MINIMUM', + }, + fixedVersion: { + kind: 'MAXIMUM', + }, + }, + ], }, }, }); diff --git a/container-analysis/snippets/deleteNote.js b/container-analysis/snippets/deleteNote.js index 6f8bb204ecb..dfce8628b64 100644 --- a/container-analysis/snippets/deleteNote.js +++ b/container-analysis/snippets/deleteNote.js @@ -14,14 +14,14 @@ async function main( // const noteId = 'my-note-id' // Id of the note // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + 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.deleteNote({name: formattedName}); + await client.getGrafeasClient().deleteNote({name: formattedName}); console.log(`Note ${formattedName} deleted.`); // [END containeranalysis_delete_note] } diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index f6dace0d5ed..a9640f8017b 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -14,14 +14,16 @@ async function main( // const occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); // Get full path to occurrence - const formattedName = client.occurrencePath(projectId, occurrenceId); + const formattedName = client + .getGrafeasClient() + .occurrencePath(projectId, occurrenceId); // Deletes an existing Occurrence from the server - await client.deleteOccurrence({ + await client.getGrafeasClient().deleteOccurrence({ name: formattedName, }); diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 517ff179094..64c76c61f5d 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -14,13 +14,13 @@ async function main( // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); - const formattedParent = client.projectPath(projectId); + 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.listOccurrences({ + const [occurrences] = await client.getGrafeasClient().listOccurrences({ parent: formattedParent, filter: `kind = "DISCOVERY" AND resourceUrl = "${imageUrl}"`, }); @@ -29,9 +29,6 @@ async function main( console.log(`Discovery Occurrences for ${imageUrl}`); occurrences.forEach(occurrence => { console.log(`${occurrence.name}:`); - console.log( - ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` - ); }); } else { console.log('No occurrences found.'); diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js index 78153bbf6d3..66d7508a024 100644 --- a/container-analysis/snippets/getNote.js +++ b/container-analysis/snippets/getNote.js @@ -14,13 +14,13 @@ async function main( // const noteId = 'my-note-id' // Id of the note // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); // Get the full path to the note const formattedName = client.notePath(projectId, noteId); // Retrieve the specified note - const [note] = await client.getNote({name: formattedName}); + const [note] = await client.getGrafeasClient().getNote({name: formattedName}); console.log(`Note name: ${note.name}`); // [END containeranalysis_get_note] diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index 36899edb6c3..a7f92d1fcc4 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -14,14 +14,16 @@ async function main( // const occurrenceId = 'my-occurrence' // The API-generated identifier associated with the occurrence // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); // Get full path to occurrence - const formattedName = client.occurrencePath(projectId, occurrenceId); + const formattedName = client + .getGrafeasClient() + .occurrencePath(projectId, occurrenceId); // Retrieves the specified occurrence - const [occurrence] = await client.getOccurrence({ + const [occurrence] = await client.getGrafeasClient().getOccurrence({ name: formattedName, }); diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 69348fda910..52698a5bfbc 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -14,13 +14,13 @@ async function main( // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); - const formattedParent = client.projectPath(projectId); + const formattedParent = client.getGrafeasClient().projectPath(projectId); // Retrieve a list of vulnerability occurrences with a severity level of 'HIGH' or greater - const [occurrences] = await client.listOccurrences({ + const [occurrences] = await client.getGrafeasClient().listOccurrences({ parent: formattedParent, filter: `kind = "VULNERABILITY" AND resourceUrl = "${imageUrl}"`, }); @@ -33,9 +33,6 @@ async function main( occurrence.vulnerability.severity === 'CRITICAL' ) { console.log(`${occurrence.name}:`); - console.log( - ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` - ); } }); } else { diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index afe87c70201..30e721973a4 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -14,13 +14,13 @@ async function main( // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); - const formattedParent = client.projectPath(projectId); + const formattedParent = client.getGrafeasClient().projectPath(projectId); // Retrieves all the Occurrences associated with a specified image - const [occurrences] = await client.listOccurrences({ + const [occurrences] = await client.getGrafeasClient().listOccurrences({ parent: formattedParent, filter: `resourceUrl = "${imageUrl}"`, }); @@ -29,9 +29,6 @@ async function main( console.log(`Occurrences for ${imageUrl}`); occurrences.forEach(occurrence => { console.log(`${occurrence.name}:`); - console.log( - ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` - ); }); } else { console.log('No occurrences found.'); diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index 2265ff5f5d0..f3c5180814e 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -14,23 +14,20 @@ async function main( // const noteId = 'my-note-id' // Id of the note // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); // Get path to Note const formattedNote = client.notePath(projectId, noteId); // Retrieves all the Occurrences associated with a specified Note - const [occurrences] = await client.listNoteOccurrences({ + const [occurrences] = await client.getGrafeasClient().listNoteOccurrences({ name: formattedNote, }); if (occurrences.length) { console.log('Occurrences:'); occurrences.forEach(occurrence => { console.log(`${occurrence.name}:`); - console.log( - ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` - ); }); } else { console.log('No occurrences found.'); diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 864b27bc10b..6e72175541c 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -16,10 +16,10 @@ async function main( // const retries = 5 // The number of retries to listen for the new Pub/Sub messages // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); - const formattedParent = client.projectPath(projectId); + const formattedParent = client.getGrafeasClient().projectPath(projectId); let filter = `resourceUrl="${imageUrl}" AND noteProjectId="goog-analysis" AND noteId="PACKAGE_VULNERABILITY"`; // [END containeranalysis_poll_discovery_occurrence_finished] @@ -33,7 +33,7 @@ async function main( const pRetry = require('p-retry'); const discoveryOccurrence = await pRetry( async () => { - const [occurrences] = await client.listOccurrences({ + const [occurrences] = await client.getGrafeasClient().listOccurrences({ parent: formattedParent, filter: filter, }); @@ -51,10 +51,10 @@ async function main( const finishedOccurrence = await pRetry( async () => { let status = 'PENDING'; - const [updated] = await client.getOccurrence({ + const [updated] = await client.getGrafeasClient().getOccurrence({ name: discoveryOccurrence.name, }); - status = updated.discovered.discovered.analysisStatus; + status = updated.discovery.analysisStatus; if ( status !== 'FINISHED_SUCCESS' && status !== 'FINISHED_FAILED' && @@ -69,7 +69,7 @@ async function main( } ); console.log( - `Found discovery occurrence ${finishedOccurrence.name}. Status: ${finishedOccurrence.discovered.discovered.analysisStatus}` + `Found discovery occurrence ${finishedOccurrence.name}. Status: ${finishedOccurrence.discovery.analysisStatus}` ); // [END containeranalysis_poll_discovery_occurrence_finished] } diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index be77e130b52..f910f501f00 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -2,8 +2,8 @@ const {assert} = require('chai'); const cp = require('child_process'); const uuid = require(`uuid`); -const containerAnalysis = require('@google-cloud/containeranalysis'); -const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); +const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); +const client = new ContainerAnalysisClient(); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); @@ -31,22 +31,22 @@ describe('Note tests', () => { formattedNoteName = `projects/${projectId}/notes/${noteId}`; }); after(async () => { - const [allOccurrences] = await client.listOccurrences({ + const [allOccurrences] = await client.getGrafeasClient().listOccurrences({ parent: formattedParent, filter: `resourceUrl = "${resourceUrl}"`, }); allOccurrences.forEach(async occurrence => { - await client.deleteOccurrence({name: occurrence.name}); + await client.getGrafeasClient().deleteOccurrence({name: occurrence.name}); console.log(`deleted occurrence ${occurrence.name}`); }); - const [allNotes] = await client.listNotes({ + const [allNotes] = await client.getGrafeasClient().listNotes({ parent: formattedParent, }); allNotes.forEach(async note => { - await client.deleteNote({name: note.name}); + await client.getGrafeasClient().deleteNote({name: note.name}); console.log(`deleted note ${note.name}`); }); }); @@ -68,8 +68,9 @@ describe('Note tests', () => { }); it('should get occurrence', async () => { - const [occurrences] = await client.listOccurrences({ + const [occurrences] = await client.getGrafeasClient().listOccurrences({ parent: formattedParent, + filter: `resourceUrl = "${resourceUrl}"`, }); assert(occurrences.length > 0); @@ -84,7 +85,6 @@ describe('Note tests', () => { break; } } - assert.include(output, `Occurrence name: ${occurrence.name}`); }); @@ -113,28 +113,26 @@ describe('Note tests', () => { parent: formattedParent, noteId: `${noteId}-discovery`, note: { - discovery: {}, + discovery: { + analysisKind: 'DISCOVERY', + }, }, }; - await client.createNote(discoveryNoteRequest); + await client.getGrafeasClient().createNote(discoveryNoteRequest); const occurrenceRequest = { parent: formattedParent, occurrence: { noteName: `${formattedNoteName}-discovery`, - discovered: { - discovered: { - analysisStatus: 'FINISHED_SUCCESS', - }, - }, - resource: { - uri: resourceUrl, + resourceUri: resourceUrl, + discovery: { + analysisStatus: 'FINISHED_SUCCESS', }, }, }; - await client.createOccurrence(occurrenceRequest); + await client.getGrafeasClient().createOccurrence(occurrenceRequest); const output = execSync( `node getDiscoveryInfo "${projectId}" "${resourceUrl}"` @@ -149,28 +147,48 @@ describe('Note tests', () => { note: { vulnerability: { severity: 'CRITICAL', + details: [ + { + affectedCpeUri: 'foo.uri', + affectedPackage: 'foo', + minAffectedVersion: { + kind: 'MINIMUM', + }, + fixedVersion: { + kind: 'MAXIMUM', + }, + }, + ], }, }, }; - await client.createNote(criticalNoteReq); + await client.getGrafeasClient().createNote(criticalNoteReq); const criticalOccurrenceReq = { parent: formattedParent, occurrence: { noteName: `${formattedNoteName}-critical`, + resourceUri: resourceUrl, vulnerability: { - vulnerability: { - severity: 'CRITICAL', - }, - }, - resource: { - uri: resourceUrl, + severity: 'CRITICAL', + packageIssue: [ + { + affectedCpeUri: 'foo.uri', + affectedPackage: 'foo', + minAffectedVersion: { + kind: 'MINIMUM', + }, + fixedVersion: { + kind: 'MAXIMUM', + }, + }, + ], }, }, }; - await client.createOccurrence(criticalOccurrenceReq); + await client.getGrafeasClient().createOccurrence(criticalOccurrenceReq); const output = execSync( `node highVulnerabilitiesForImage "${projectId}" "${resourceUrl}"` @@ -187,8 +205,9 @@ describe('Note tests', () => { }); it('should delete occurrence', async () => { - const [occurrences] = await client.listOccurrences({ + const [occurrences] = await client.getGrafeasClient().listOccurrences({ parent: formattedParent, + filter: `resourceUrl = "${resourceUrl}"`, }); assert(occurrences.length > 0); const occurrence = occurrences[0]; @@ -216,38 +235,40 @@ describe('polling', () => { parent: formattedParent, noteId: `${noteId}-discovery-polling`, note: { - discovery: {}, + discovery: { + analysisKind: 'DISCOVERY', + }, }, }; - await client.createNote(discoveryNoteRequest); + await client.getGrafeasClient().createNote(discoveryNoteRequest); const occurrenceRequest = { parent: formattedParent, occurrence: { noteName: `${formattedNoteName}-discovery-polling`, - discovered: { - discovered: { - analysisStatus: 3, - }, - }, - resource: { - uri: resourceUrl, + resourceUri: resourceUrl, + discovery: { + analysisStatus: 'FINISHED_SUCCESS', }, }, }; - await client.createOccurrence(occurrenceRequest); + await client.getGrafeasClient().createOccurrence(occurrenceRequest); }); after(async () => { - const [discoveryOccurrences] = await client.listNoteOccurrences({ + const [ + discoveryOccurrences, + ] = await client.getGrafeasClient().listNoteOccurrences({ name: `${formattedNoteName}-discovery-polling`, }); discoveryOccurrences.forEach(async occurrence => { - await client.deleteOccurrence({name: occurrence.name}); + await client.getGrafeasClient().deleteOccurrence({name: occurrence.name}); }); - await client.deleteNote({name: `${formattedNoteName}-discovery-polling`}); + await client + .getGrafeasClient() + .deleteNote({name: `${formattedNoteName}-discovery-polling`}); }); it('should successfully poll latest discovery occurrence', () => { @@ -278,14 +299,29 @@ describe('pubsub', () => { parent: formattedParent, noteId: `${noteId}-pubsub`, note: { - vulnerability: {}, + vulnerability: { + details: [ + { + affectedCpeUri: 'foo.uri', + affectedPackage: 'foo', + minAffectedVersion: { + kind: 'MINIMUM', + }, + fixedVersion: { + kind: 'MAXIMUM', + }, + }, + ], + }, }, }; - await client.createNote(pubSubNoteReq); + await client.getGrafeasClient().createNote(pubSubNoteReq); }); afterEach(async () => { - await client.deleteNote({name: `${formattedNoteName}-pubsub`}); + await client + .getGrafeasClient() + .deleteNote({name: `${formattedNoteName}-pubsub`}); await pubsub.subscription(subscriptionId).delete(); }); @@ -295,11 +331,20 @@ describe('pubsub', () => { parent: formattedParent, occurrence: { noteName: `${formattedNoteName}-pubsub`, + resourceUri: resourceUrl, vulnerability: { - vulnerability: {}, - }, - resource: { - uri: resourceUrl, + packageIssue: [ + { + affectedCpeUri: 'foo.uri', + affectedPackage: 'foo', + minAffectedVersion: { + kind: 'MINIMUM', + }, + fixedVersion: { + kind: 'MAXIMUM', + }, + }, + ], }, }, }; @@ -317,10 +362,12 @@ describe('pubsub', () => { assert.include(empty, `Polled 0 occurrences`); // create test occurrences for (let i = 0; i < expectedNum; i++) { - const [pubSubOccurrence] = await client.createOccurrence( - pubSubOccurrenceReq - ); - await client.deleteOccurrence({name: pubSubOccurrence.name}); + const [ + pubSubOccurrence, + ] = await client.getGrafeasClient().createOccurrence(pubSubOccurrenceReq); + await client + .getGrafeasClient() + .deleteOccurrence({name: pubSubOccurrence.name}); } const output = execSync( `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index e77569581d0..0379a1daccb 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -14,13 +14,13 @@ async function main( // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to // Import the library and create a client - const containerAnalysis = require('@google-cloud/containeranalysis'); - const client = new containerAnalysis.v1beta1.GrafeasV1Beta1Client(); + const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); + const client = new ContainerAnalysisClient(); - const formattedParent = client.projectPath(projectId); + const formattedParent = client.getGrafeasClient().projectPath(projectId); // Retrieve a list of vulnerability occurrences assoviated with a resource - const [occurrences] = await client.listOccurrences({ + const [occurrences] = await client.getGrafeasClient().listOccurrences({ parent: formattedParent, filter: `kind = "VULNERABILITY" AND resourceUrl = "${imageUrl}"`, }); @@ -29,9 +29,6 @@ async function main( console.log(`All Vulnerabilities for ${imageUrl}`); occurrences.forEach(occurrence => { console.log(`${occurrence.name}:`); - console.log( - ` Created: ${new Date(occurrence.createTime.seconds * 1000)}` - ); }); } else { console.log('No occurrences found.'); From 6c43f69034fbcba7f874c42dac8c8bcdbb6dc8d3 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 24 Jun 2019 09:50:31 -0700 Subject: [PATCH 063/131] chore: release 1.2.1 (#50) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 76d4433b484..48192842b36 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.2.0", + "@google-cloud/containeranalysis": "^1.2.1", "@google-cloud/pubsub": "^0.29.0", "p-retry": "^4.1.0" }, From 53eb45d13ece07a1adcf725a1a1db50c2537b6d6 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Wed, 26 Jun 2019 15:11:45 -0700 Subject: [PATCH 064/131] chore: release 1.2.2 (#52) * updated CHANGELOG.md [ci skip] * updated package.json [ci skip] * updated samples/package.json [ci skip] --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 48192842b36..66ee0c7b47e 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.2.1", + "@google-cloud/containeranalysis": "^1.2.2", "@google-cloud/pubsub": "^0.29.0", "p-retry": "^4.1.0" }, From 3f9ca4aa275df94bc073d97723b418001a32fa24 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 8 Jul 2019 16:47:03 -0700 Subject: [PATCH 065/131] docs(samples): Update Topic ID in PubSub sample (#55) --- container-analysis/snippets/createNote.js | 4 ++-- .../snippets/createOccurrence.js | 2 +- .../snippets/occurrencePubSub.js | 6 +++--- .../snippets/test/containerAnalysis.test.js | 21 ++++++++++--------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index 82d905ee6ea..8190d9618ba 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -33,10 +33,10 @@ async function main( { affectedCpeUri: 'foo.uri', affectedPackage: 'foo', - minAffectedVersion: { + affectedVersionStart: { kind: 'MINIMUM', }, - fixedVersion: { + affectedVersionEnd: { kind: 'MAXIMUM', }, }, diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index 9f5583b587e..e4dabc4f14f 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -40,7 +40,7 @@ async function main( { affectedCpeUri: 'foo.uri', affectedPackage: 'foo', - minAffectedVersion: { + affectedVersion: { kind: 'MINIMUM', }, fixedVersion: { diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index 913216fa9c1..50322ebd0be 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -1,10 +1,10 @@ // sample-metadata: // title: Occurrence PubSub -// description: Polls a specified PubSub subscription for Occurrences. Requires a subscription to a topic named 'container-analysis-occurrences-v1beta' +// description: Polls a specified PubSub subscription for Occurrences. Requires a subscription to a topic named 'container-analysis-occurrences-v1' // usage: node occurrencePubSub.js "project-id" "subscription-id" "timeout-in-seconds" async function main( projectId = 'your-project-id', // Your GCP Project ID - subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic + subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1' topic timeoutSeconds = 30 // The number of seconds to listen for the new Pub/Sub messages ) { // [START containeranalysis_pubsub] @@ -12,7 +12,7 @@ async function main( * TODO(developer): Uncomment these variables before running the sample */ // const projectId = 'your-project-id', // Your GCP Project ID - // const subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1beta' topic + // const subscriptionId = 'my-sub-id', // A user-specified subscription to the 'container-analysis-occurrences-v1' topic // const timeoutSeconds = 30 // The number of seconds to listen for the new Pub/Sub Messages // Import the pubsub library and create a client, topic and subscription diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index f910f501f00..54291b1e4ce 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -16,7 +16,7 @@ const retries = 5; const {PubSub} = require('@google-cloud/pubsub'); const pubsub = new PubSub(); -const topicName = 'container-analysis-occurrences-v1beta1'; +const topicName = 'container-analysis-occurrences-v1'; let topic; let projectId; @@ -151,10 +151,10 @@ describe('Note tests', () => { { affectedCpeUri: 'foo.uri', affectedPackage: 'foo', - minAffectedVersion: { + affectedVersionStart: { kind: 'MINIMUM', }, - fixedVersion: { + affectedVersionEnd: { kind: 'MAXIMUM', }, }, @@ -176,7 +176,7 @@ describe('Note tests', () => { { affectedCpeUri: 'foo.uri', affectedPackage: 'foo', - minAffectedVersion: { + affectedVersion: { kind: 'MINIMUM', }, fixedVersion: { @@ -286,11 +286,12 @@ describe('pubsub', () => { formattedParent = `projects/${projectId}`; formattedNoteName = `projects/${projectId}/notes/${noteId}`; try { - topic = pubsub.topic(topicName); - } catch (err) { + // attempt to create topic if missing await pubsub.createTopic(topicName); - topic = pubsub.topic(topicName); + } catch (err) { + console.log(`topic creation failed: ${topicName}`); } + topic = pubsub.topic(topicName); }); beforeEach(async () => { @@ -304,10 +305,10 @@ describe('pubsub', () => { { affectedCpeUri: 'foo.uri', affectedPackage: 'foo', - minAffectedVersion: { + affectedVersionStart: { kind: 'MINIMUM', }, - fixedVersion: { + affectedVersionEnd: { kind: 'MAXIMUM', }, }, @@ -337,7 +338,7 @@ describe('pubsub', () => { { affectedCpeUri: 'foo.uri', affectedPackage: 'foo', - minAffectedVersion: { + affectedVersion: { kind: 'MINIMUM', }, fixedVersion: { From c93f1508e88c981e56d7fbcd3981c430681d2981 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 15 Jul 2019 11:18:48 -0700 Subject: [PATCH 066/131] chore: release 1.3.0 (#58) * updated CHANGELOG.md [ci skip] * updated package.json [ci skip] * updated samples/package.json [ci skip] --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 66ee0c7b47e..b422c127885 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.2.2", + "@google-cloud/containeranalysis": "^1.3.0", "@google-cloud/pubsub": "^0.29.0", "p-retry": "^4.1.0" }, From 0c40854de55145395b6d195075598525f5e6d753 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 26 Jul 2019 21:19:21 +0300 Subject: [PATCH 067/131] fix(deps): update dependency @google-cloud/pubsub to ^0.30.0 (#59) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index b422c127885..6ac3700cda5 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@google-cloud/containeranalysis": "^1.3.0", - "@google-cloud/pubsub": "^0.29.0", + "@google-cloud/pubsub": "^0.30.0", "p-retry": "^4.1.0" }, "devDependencies": { From 080b9c349b76e7d57151cf9b7bf5cc0188ffa400 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 29 Jul 2019 08:42:43 -0700 Subject: [PATCH 068/131] chore: release 1.3.1 (#61) * updated CHANGELOG.md [ci skip] * updated package.json [ci skip] * updated samples/package.json [ci skip] --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 6ac3700cda5..5db6af81111 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.3.0", + "@google-cloud/containeranalysis": "^1.3.1", "@google-cloud/pubsub": "^0.30.0", "p-retry": "^4.1.0" }, From 7982156cc894cae6f59eecd616f8313f988f1f9a Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Sat, 3 Aug 2019 16:04:47 -0700 Subject: [PATCH 069/131] chore: release 1.3.2 (#68) * updated CHANGELOG.md [ci skip] * updated package.json [ci skip] * updated samples/package.json [ci skip] --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 5db6af81111..36762c0e051 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.3.1", + "@google-cloud/containeranalysis": "^1.3.2", "@google-cloud/pubsub": "^0.30.0", "p-retry": "^4.1.0" }, From 90286982e30acfd9395cfb460e0d8356db51e065 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 16 Aug 2019 19:12:16 +0300 Subject: [PATCH 070/131] fix(deps): update dependency @google-cloud/pubsub to ^0.31.0 (#71) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 36762c0e051..9380f66688e 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@google-cloud/containeranalysis": "^1.3.2", - "@google-cloud/pubsub": "^0.30.0", + "@google-cloud/pubsub": "^0.31.0", "p-retry": "^4.1.0" }, "devDependencies": { From cc8b0cd72b748c032a4d811af0bd7d6e8197bc84 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Fri, 16 Aug 2019 10:34:34 -0700 Subject: [PATCH 071/131] chore: release 1.3.3 (#72) * updated CHANGELOG.md [ci skip] * updated package.json [ci skip] * updated samples/package.json [ci skip] --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 9380f66688e..0329265be6c 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.3.2", + "@google-cloud/containeranalysis": "^1.3.3", "@google-cloud/pubsub": "^0.31.0", "p-retry": "^4.1.0" }, From f1217d3c2715c0586987c9ec1352a0b3ae40b9dc Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 11 Sep 2019 18:09:10 +0300 Subject: [PATCH 072/131] fix(deps): update dependency @google-cloud/pubsub to ^0.32.0 (#81) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 0329265be6c..aef40e5c78c 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@google-cloud/containeranalysis": "^1.3.3", - "@google-cloud/pubsub": "^0.31.0", + "@google-cloud/pubsub": "^0.32.0", "p-retry": "^4.1.0" }, "devDependencies": { From 3ea94a09acd10e41d423b1f82c71e1370dcb5d72 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 16 Sep 2019 09:21:33 -0700 Subject: [PATCH 073/131] chore: release 1.4.0 (#78) * updated CHANGELOG.md [ci skip] * updated package.json [ci skip] * updated samples/package.json [ci skip] --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index aef40e5c78c..2a9eb376776 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.3.3", + "@google-cloud/containeranalysis": "^1.4.0", "@google-cloud/pubsub": "^0.32.0", "p-retry": "^4.1.0" }, From 857fdf56396d76670241ed522a2e0b60d0740bf4 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 18 Sep 2019 17:26:26 +0300 Subject: [PATCH 074/131] fix(deps): update dependency @google-cloud/pubsub to v1 (#84) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 2a9eb376776..7a3f63f744a 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@google-cloud/containeranalysis": "^1.4.0", - "@google-cloud/pubsub": "^0.32.0", + "@google-cloud/pubsub": "^1.0.0", "p-retry": "^4.1.0" }, "devDependencies": { From 58ff97c1ecde37757461f194b1b19f6686ba12f3 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 22 Oct 2019 13:31:20 -0700 Subject: [PATCH 075/131] chore: release 1.5.1 (#97) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 7a3f63f744a..506a7e3f483 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.4.0", + "@google-cloud/containeranalysis": "^1.5.1", "@google-cloud/pubsub": "^1.0.0", "p-retry": "^4.1.0" }, From cecf4d88266a95fa98a525b086059d0f4193332b Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Thu, 14 Nov 2019 09:25:46 -0800 Subject: [PATCH 076/131] chore: add license headers for samples (#106) --- container-analysis/snippets/createNote.js | 16 ++++++++++++++++ container-analysis/snippets/createOccurrence.js | 16 ++++++++++++++++ container-analysis/snippets/deleteNote.js | 16 ++++++++++++++++ container-analysis/snippets/deleteOccurrence.js | 16 ++++++++++++++++ container-analysis/snippets/getDiscoveryInfo.js | 16 ++++++++++++++++ container-analysis/snippets/getNote.js | 16 ++++++++++++++++ container-analysis/snippets/getOccurrence.js | 16 ++++++++++++++++ .../snippets/highVulnerabilitiesForImage.js | 16 ++++++++++++++++ container-analysis/snippets/occurrencePubSub.js | 16 ++++++++++++++++ .../snippets/occurrencesForImage.js | 16 ++++++++++++++++ .../snippets/occurrencesForNote.js | 16 ++++++++++++++++ .../snippets/pollDiscoveryOccurrenceFinished.js | 16 ++++++++++++++++ container-analysis/snippets/quickstart.js | 16 ++++++++++++++++ .../snippets/test/containerAnalysis.test.js | 16 ++++++++++++++++ .../snippets/vulnerabilityOccurrencesForImage.js | 16 ++++++++++++++++ 15 files changed, 240 insertions(+) diff --git a/container-analysis/snippets/createNote.js b/container-analysis/snippets/createNote.js index 8190d9618ba..6abf822a2ab 100644 --- a/container-analysis/snippets/createNote.js +++ b/container-analysis/snippets/createNote.js @@ -1,3 +1,19 @@ +// 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 diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index e4dabc4f14f..d593acf8779 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -1,3 +1,19 @@ +// 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 diff --git a/container-analysis/snippets/deleteNote.js b/container-analysis/snippets/deleteNote.js index dfce8628b64..a0c8a10782a 100644 --- a/container-analysis/snippets/deleteNote.js +++ b/container-analysis/snippets/deleteNote.js @@ -1,3 +1,19 @@ +// 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 diff --git a/container-analysis/snippets/deleteOccurrence.js b/container-analysis/snippets/deleteOccurrence.js index a9640f8017b..400b2659fff 100644 --- a/container-analysis/snippets/deleteOccurrence.js +++ b/container-analysis/snippets/deleteOccurrence.js @@ -1,3 +1,19 @@ +// 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 diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 64c76c61f5d..047d2ab9c2d 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -1,3 +1,19 @@ +// 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 diff --git a/container-analysis/snippets/getNote.js b/container-analysis/snippets/getNote.js index 66d7508a024..a1d3630545d 100644 --- a/container-analysis/snippets/getNote.js +++ b/container-analysis/snippets/getNote.js @@ -1,3 +1,19 @@ +// 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 Note // description: Retrieves and prints a specified note diff --git a/container-analysis/snippets/getOccurrence.js b/container-analysis/snippets/getOccurrence.js index a7f92d1fcc4..a3dc8292a48 100644 --- a/container-analysis/snippets/getOccurrence.js +++ b/container-analysis/snippets/getOccurrence.js @@ -1,3 +1,19 @@ +// 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 Occurrence // description: Retrieves and prints a specified Occurrence diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 52698a5bfbc..05dc80bc270 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -1,3 +1,19 @@ +// 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 High Vulnerabilities for Image // description: Retrieves all Vulnerability Occurrences of High Severity from Specified Image diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index 50322ebd0be..3bd44b67bfd 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -1,3 +1,19 @@ +// 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: Occurrence PubSub // description: Polls a specified PubSub subscription for Occurrences. Requires a subscription to a topic named 'container-analysis-occurrences-v1' diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index 30e721973a4..fb559db5690 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -1,3 +1,19 @@ +// 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: Occurrences for Image // description: Retrieves all Occurrences attached to the metadata of a specified image diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index f3c5180814e..594c4ec443d 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -1,3 +1,19 @@ +// 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: Occurrences for Note // description: Retrieves all Occurrences of a specified Note diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index 6e72175541c..b7fb16b8051 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -1,3 +1,19 @@ +// 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: Poll Discovery Occurrence Finished // description: Waits for a Discovery Occurrence to reach a terminal state diff --git a/container-analysis/snippets/quickstart.js b/container-analysis/snippets/quickstart.js index 27d50bfe106..f5490a39319 100644 --- a/container-analysis/snippets/quickstart.js +++ b/container-analysis/snippets/quickstart.js @@ -1,3 +1,19 @@ +// 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: Quickstart // description: fetching an instance of Grafeas and creating a note. diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 54291b1e4ce..5ab073e8e2b 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -1,3 +1,19 @@ +// 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'; + const {assert} = require('chai'); const cp = require('child_process'); const uuid = require(`uuid`); diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index 0379a1daccb..6a0cfc61581 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -1,3 +1,19 @@ +// 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: Vulnerability Occurrences for Image // description: Retrieves all Vulnerability Occurrences attached to a specified image From 63f797846cdd43e7357e2a361bad0cbd4d056132 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2019 12:54:43 -0800 Subject: [PATCH 077/131] chore: release 1.6.0 (#110) * updated CHANGELOG.md [ci skip] * updated package.json [ci skip] * updated samples/package.json [ci skip] --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 506a7e3f483..9a70a5f167f 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.5.1", + "@google-cloud/containeranalysis": "^1.6.0", "@google-cloud/pubsub": "^1.0.0", "p-retry": "^4.1.0" }, From 26721b38318fe5e26292701775a745aafff7b1ed Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 5 Dec 2019 14:27:17 -0800 Subject: [PATCH 078/131] chore: release 1.6.1 (#113) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 9a70a5f167f..59a9f2dc0b5 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.6.0", + "@google-cloud/containeranalysis": "^1.6.1", "@google-cloud/pubsub": "^1.0.0", "p-retry": "^4.1.0" }, From 2c6c0fcee3f8ef74efab51c723de8f6b7cf4955e Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Mon, 30 Dec 2019 10:17:01 -0800 Subject: [PATCH 079/131] refactor: use explicit mocha imports (#119) --- container-analysis/snippets/test/.eslintrc.yml | 6 ------ container-analysis/snippets/test/containerAnalysis.test.js | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 container-analysis/snippets/test/.eslintrc.yml diff --git a/container-analysis/snippets/test/.eslintrc.yml b/container-analysis/snippets/test/.eslintrc.yml deleted file mode 100644 index 3c1b1649787..00000000000 --- a/container-analysis/snippets/test/.eslintrc.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -rules: - node/no-unpublished-require: off - no-empty: off -env: - mocha: true diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 5ab073e8e2b..60dd4bff25f 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -15,6 +15,7 @@ 'use strict'; const {assert} = require('chai'); +const {describe, it, before, after, afterEach, beforeEach} = require('mocha'); const cp = require('child_process'); const uuid = require(`uuid`); From 1325c160c46a4e295c2b53f943e09427f58fb3cd Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2020 14:14:07 -0800 Subject: [PATCH 080/131] chore: release 1.7.0 (#115) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 59a9f2dc0b5..087ec09fc44 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.6.1", + "@google-cloud/containeranalysis": "^1.7.0", "@google-cloud/pubsub": "^1.0.0", "p-retry": "^4.1.0" }, From 1d07831e81bf4f56b9c13e03de4e3ff8d9afa2a7 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 6 Jan 2020 18:50:04 +0200 Subject: [PATCH 081/131] chore(deps): update dependency mocha to v7 (#121) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 087ec09fc44..257cb9c2fd9 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -20,7 +20,7 @@ }, "devDependencies": { "chai": "^4.2.0", - "mocha": "^6.1.4", + "mocha": "^7.0.0", "uuid": "^3.3.2" } } From 5b6c5acfa3cc004c62a18f878e87b7701f8e1507 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 4 Feb 2020 19:34:08 -0800 Subject: [PATCH 082/131] chore: release 1.7.1 (#131) * updated CHANGELOG.md [ci skip] * updated package.json [ci skip] * updated samples/package.json [ci skip] --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 257cb9c2fd9..61dbb3d4fba 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.7.0", + "@google-cloud/containeranalysis": "^1.7.1", "@google-cloud/pubsub": "^1.0.0", "p-retry": "^4.1.0" }, From c9c4f5abea69208bd68ef05ca30d68a1dc32681c Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Fri, 7 Feb 2020 11:41:17 -0800 Subject: [PATCH 083/131] feat: move API to typescript code generation (#135) * remove docs/ * move to ts * update synthtool * run synthtool * remove unneeded grafeas client * update synthtool * remove grafeas client * cap class name * broken link * make it work * lint * debug * sample test work * test * test * retry 10 times * finalize synth.py * clean a little bit * replace once, add to excludes * fix doc * feedback * import os * feedback * fix * remove file properly * make it work * linkinator * Update linkinator configure * rerun synthtool for resources reorder * remove google/api proto in list * remove unneeded proto files in list * format * new line in proto list * run synthtool --- container-analysis/snippets/occurrencesForNote.js | 1 + container-analysis/snippets/test/containerAnalysis.test.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/container-analysis/snippets/occurrencesForNote.js b/container-analysis/snippets/occurrencesForNote.js index 594c4ec443d..8960a36b209 100644 --- a/container-analysis/snippets/occurrencesForNote.js +++ b/container-analysis/snippets/occurrencesForNote.js @@ -40,6 +40,7 @@ async function main( const [occurrences] = await client.getGrafeasClient().listNoteOccurrences({ name: formattedNote, }); + if (occurrences.length) { console.log('Occurrences:'); occurrences.forEach(occurrence => { diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 60dd4bff25f..f010330b7f6 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -29,7 +29,7 @@ const noteId = `test-note-${uuidVal}`; const resourceUrl = `gcr.io/test-project/test-image-${uuidVal}`; const subscriptionId = `occurrence-subscription-${uuidVal}`; const timeoutSeconds = 5; -const retries = 5; +const retries = 10; const {PubSub} = require('@google-cloud/pubsub'); const pubsub = new PubSub(); From c84790eee0ef2c6c2d7b50893c59baa3e7733ef1 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 12 Feb 2020 11:09:24 -0800 Subject: [PATCH 084/131] chore: release 1.8.0 (#137) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 61dbb3d4fba..a705fee0f6e 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.7.1", + "@google-cloud/containeranalysis": "^1.8.0", "@google-cloud/pubsub": "^1.0.0", "p-retry": "^4.1.0" }, From 043506031beeae760b9a0a5fa2135a4d4f31d0b2 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 26 Feb 2020 21:34:36 +0100 Subject: [PATCH 085/131] chore(deps): update dependency uuid to v7 --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index a705fee0f6e..3b5b87efb53 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -21,6 +21,6 @@ "devDependencies": { "chai": "^4.2.0", "mocha": "^7.0.0", - "uuid": "^3.3.2" + "uuid": "^7.0.0" } } From 1205d7b7f097216a331bde452ff0dd48243e0808 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 2 Mar 2020 22:54:09 +0000 Subject: [PATCH 086/131] chore: release 1.9.0 (#144) :robot: I have created a release \*beep\* \*boop\* --- ## [1.9.0](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v1.8.0...v1.9.0) (2020-02-29) ### Features * export protos in src/index.ts ([29af69b](https://www.github.com/googleapis/nodejs-containeranalysis/commit/29af69b2e1af8763ee892d9325d089e401198330)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 3b5b87efb53..af255d40ced 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.8.0", + "@google-cloud/containeranalysis": "^1.9.0", "@google-cloud/pubsub": "^1.0.0", "p-retry": "^4.1.0" }, From 2324d29a808c5c648098c5f151e65e5dc5b5e9db Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 11 Mar 2020 23:10:06 +0000 Subject: [PATCH 087/131] chore: release 1.10.0 (#153) :robot: I have created a release \*beep\* \*boop\* --- ## [1.10.0](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v1.9.0...v1.10.0) (2020-03-06) ### Features * deferred client initialization ([#152](https://www.github.com/googleapis/nodejs-containeranalysis/issues/152)) ([0a01d71](https://www.github.com/googleapis/nodejs-containeranalysis/commit/0a01d71cc9b7f45c78215838d13c506e316d904d)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index af255d40ced..76033a0efe9 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.9.0", + "@google-cloud/containeranalysis": "^1.10.0", "@google-cloud/pubsub": "^1.0.0", "p-retry": "^4.1.0" }, From f46a57c7c16e38c7dae16a21f09e16117d09b00f Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Thu, 2 Apr 2020 12:48:21 -0700 Subject: [PATCH 088/131] feat!: drop node8 support, support for async iterators (#167) BREAKING CHANGE: The library now supports Node.js v10+. The last version to support Node.js v8 is tagged legacy-8 on NPM. New feature: methods with pagination now support async iteration. --- container-analysis/snippets/occurrencePubSub.js | 4 ++-- .../snippets/test/containerAnalysis.test.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/container-analysis/snippets/occurrencePubSub.js b/container-analysis/snippets/occurrencePubSub.js index 3bd44b67bfd..ac5ddc774c2 100644 --- a/container-analysis/snippets/occurrencePubSub.js +++ b/container-analysis/snippets/occurrencePubSub.js @@ -44,10 +44,10 @@ async function main( }; // Listen for new messages until timeout is hit - subscription.on(`message`, messageHandler); + subscription.on('message', messageHandler); setTimeout(() => { - subscription.removeListener(`message`, messageHandler); + subscription.removeListener('message', messageHandler); console.log(`Polled ${count} occurrences`); }, timeoutSeconds * 1000); // [END containeranalysis_pubsub] diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index f010330b7f6..20ebcedfbe8 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -17,7 +17,7 @@ const {assert} = require('chai'); const {describe, it, before, after, afterEach, beforeEach} = require('mocha'); const cp = require('child_process'); -const uuid = require(`uuid`); +const uuid = require('uuid'); const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); const client = new ContainerAnalysisClient(); @@ -81,7 +81,7 @@ describe('Note tests', () => { const output = execSync( `node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"` ); - assert.include(output, `Occurrence created`); + assert.include(output, 'Occurrence created'); }); it('should get occurrence', async () => { @@ -233,7 +233,7 @@ describe('Note tests', () => { const output = execSync( `node deleteOccurrence.js "${projectId}" "${occurrenceId}"` ); - assert.include(output, `Occurrence deleted:`); + assert.include(output, 'Occurrence deleted:'); }); it('should delete note', () => { const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); @@ -292,7 +292,7 @@ describe('polling', () => { const output = execSync( `node pollDiscoveryOccurrenceFinished.js "${projectId}" "${resourceUrl}" "${timeoutSeconds}"` ); - assert.include(output, `Found discovery occurrence`); + assert.include(output, 'Found discovery occurrence'); }); }); @@ -377,7 +377,7 @@ describe('pubsub', () => { `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` ); - assert.include(empty, `Polled 0 occurrences`); + assert.include(empty, 'Polled 0 occurrences'); // create test occurrences for (let i = 0; i < expectedNum; i++) { const [ From c1555556ed80ba870dc2d1527a263a9d74f48b57 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Fri, 3 Apr 2020 14:39:03 -0700 Subject: [PATCH 089/131] test: there's a race condition emptying queue (#175) --- .../snippets/test/containerAnalysis.test.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 20ebcedfbe8..38a6952a695 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -343,8 +343,8 @@ describe('pubsub', () => { await pubsub.subscription(subscriptionId).delete(); }); - it('should get accurate count of occurrences from pubsub topic', async () => { - const expectedNum = 3; + it('should get count of occurrences from pubsub topic', async () => { + const occurrenceCount = 3; const pubSubOccurrenceReq = { parent: formattedParent, occurrence: { @@ -372,14 +372,8 @@ describe('pubsub', () => { `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` ); - // make sure empty - const empty = execSync( - `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` - ); - - assert.include(empty, 'Polled 0 occurrences'); // create test occurrences - for (let i = 0; i < expectedNum; i++) { + for (let i = 0; i < occurrenceCount; i++) { const [ pubSubOccurrence, ] = await client.getGrafeasClient().createOccurrence(pubSubOccurrenceReq); @@ -391,7 +385,7 @@ describe('pubsub', () => { `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` ); - // make sure pubsub number matches - assert.include(output, `Polled ${expectedNum} occurrences`); + // ensure that our occcurences were enqueued: + assert.match(output, /Polled [1-9]+ occurrences/); }); }); From fc5addd89b02790edb5023ff147fd9628f379bef Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Mon, 13 Apr 2020 10:12:14 -0700 Subject: [PATCH 090/131] test: retry pubsub test, as it relies on many moving parts (#186) adds retry with exponential backoff to the flaky pubsub test. fixes: #184, #185 --- .../snippets/test/containerAnalysis.test.js | 6 +++- container-analysis/snippets/test/util.js | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 container-analysis/snippets/test/util.js diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 38a6952a695..d1235ded27a 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -17,6 +17,7 @@ const {assert} = require('chai'); const {describe, it, before, after, afterEach, beforeEach} = require('mocha'); const cp = require('child_process'); +const {delay} = require('./util'); const uuid = require('uuid'); const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); @@ -343,7 +344,10 @@ describe('pubsub', () => { await pubsub.subscription(subscriptionId).delete(); }); - it('should get count of occurrences from pubsub topic', async () => { + it('should get count of occurrences from pubsub topic', async function() { + this.retries(3); + await delay(this.test); + const occurrenceCount = 3; const pubSubOccurrenceReq = { parent: formattedParent, diff --git a/container-analysis/snippets/test/util.js b/container-analysis/snippets/test/util.js new file mode 100644 index 00000000000..97b804a43c0 --- /dev/null +++ b/container-analysis/snippets/test/util.js @@ -0,0 +1,28 @@ +// Copyright 2020 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. + +// ML tests frequently run into concurrency and quota issues, for which +// retrying with a backoff is a good strategy: +module.exports = { + async delay(test) { + const retries = test.currentRetry(); + if (retries === 0) return; // no retry on the first failure. + // see: https://cloud.google.com/storage/docs/exponential-backoff: + const ms = Math.pow(2, retries) * 1000 + Math.random() * 2000; + return new Promise(done => { + console.info(`retrying "${test.title}" in ${ms}ms`); + setTimeout(done, ms); + }); + }, +}; From 67366bd55a8fa5d944d73c7b03533a3e99472513 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Tue, 14 Apr 2020 14:20:41 -0700 Subject: [PATCH 091/131] test: retry queue deletion (#191) --- .../snippets/test/containerAnalysis.test.js | 147 +++++++++--------- 1 file changed, 77 insertions(+), 70 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index d1235ded27a..1fe48c32a95 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -15,7 +15,7 @@ 'use strict'; const {assert} = require('chai'); -const {describe, it, before, after, afterEach, beforeEach} = require('mocha'); +const {describe, it, before, after} = require('mocha'); const cp = require('child_process'); const {delay} = require('./util'); const uuid = require('uuid'); @@ -312,84 +312,91 @@ describe('pubsub', () => { topic = pubsub.topic(topicName); }); - beforeEach(async () => { - await topic.createSubscription(subscriptionId); - const pubSubNoteReq = { - parent: formattedParent, - noteId: `${noteId}-pubsub`, - note: { - vulnerability: { - details: [ - { - affectedCpeUri: 'foo.uri', - affectedPackage: 'foo', - affectedVersionStart: { - kind: 'MINIMUM', + describe('occurrences from pubsub subscription', () => { + before(async () => { + await topic.createSubscription(subscriptionId); + const pubSubNoteReq = { + parent: formattedParent, + noteId: `${noteId}-pubsub`, + note: { + vulnerability: { + details: [ + { + affectedCpeUri: 'foo.uri', + affectedPackage: 'foo', + affectedVersionStart: { + kind: 'MINIMUM', + }, + affectedVersionEnd: { + kind: 'MAXIMUM', + }, }, - affectedVersionEnd: { - kind: 'MAXIMUM', + ], + }, + }, + }; + await client.getGrafeasClient().createNote(pubSubNoteReq); + }); + + it('should get count of occurrences from pubsub topic', async function() { + this.retries(3); + await delay(this.test); + + const occurrenceCount = 3; + const pubSubOccurrenceReq = { + parent: formattedParent, + occurrence: { + noteName: `${formattedNoteName}-pubsub`, + resourceUri: resourceUrl, + vulnerability: { + packageIssue: [ + { + affectedCpeUri: 'foo.uri', + affectedPackage: 'foo', + affectedVersion: { + kind: 'MINIMUM', + }, + fixedVersion: { + kind: 'MAXIMUM', + }, }, - }, - ], + ], + }, }, - }, - }; - await client.getGrafeasClient().createNote(pubSubNoteReq); - }); + }; - afterEach(async () => { - await client - .getGrafeasClient() - .deleteNote({name: `${formattedNoteName}-pubsub`}); - await pubsub.subscription(subscriptionId).delete(); - }); + // empty subscription + execSync( + `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` + ); - it('should get count of occurrences from pubsub topic', async function() { - this.retries(3); - await delay(this.test); + // create test occurrences + for (let i = 0; i < occurrenceCount; i++) { + const [ + pubSubOccurrence, + ] = await client + .getGrafeasClient() + .createOccurrence(pubSubOccurrenceReq); + await client + .getGrafeasClient() + .deleteOccurrence({name: pubSubOccurrence.name}); + } + const output = execSync( + `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` + ); - const occurrenceCount = 3; - const pubSubOccurrenceReq = { - parent: formattedParent, - occurrence: { - noteName: `${formattedNoteName}-pubsub`, - resourceUri: resourceUrl, - vulnerability: { - packageIssue: [ - { - affectedCpeUri: 'foo.uri', - affectedPackage: 'foo', - affectedVersion: { - kind: 'MINIMUM', - }, - fixedVersion: { - kind: 'MAXIMUM', - }, - }, - ], - }, - }, - }; + // ensure that our occcurences were enqueued: + assert.match(output, /Polled [1-9]+ occurrences/); + }); - // empty subscription - execSync( - `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` - ); + it('should delete the pubsub subscription', async function() { + this.retries(3); + await delay(this.test); - // create test occurrences - for (let i = 0; i < occurrenceCount; i++) { - const [ - pubSubOccurrence, - ] = await client.getGrafeasClient().createOccurrence(pubSubOccurrenceReq); await client .getGrafeasClient() - .deleteOccurrence({name: pubSubOccurrence.name}); - } - const output = execSync( - `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` - ); - - // ensure that our occcurences were enqueued: - assert.match(output, /Polled [1-9]+ occurrences/); + .deleteNote({name: `${formattedNoteName}-pubsub`}); + await pubsub.subscription(subscriptionId).delete(); + }); }); }); From 705a62a45a8ee971f185217f219d8a4ef2083618 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 21 Apr 2020 20:15:22 -0700 Subject: [PATCH 092/131] build: adopt CI changes and generator formatting (#197) --- container-analysis/snippets/test/containerAnalysis.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 1fe48c32a95..f2f7c3dc68e 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -338,7 +338,7 @@ describe('pubsub', () => { await client.getGrafeasClient().createNote(pubSubNoteReq); }); - it('should get count of occurrences from pubsub topic', async function() { + it('should get count of occurrences from pubsub topic', async function () { this.retries(3); await delay(this.test); @@ -389,7 +389,7 @@ describe('pubsub', () => { assert.match(output, /Polled [1-9]+ occurrences/); }); - it('should delete the pubsub subscription', async function() { + it('should delete the pubsub subscription', async function () { this.retries(3); await delay(this.test); From 3ad89e66182d5adaebf5e79e168b2c09ebf67005 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Thu, 23 Apr 2020 15:15:49 -0700 Subject: [PATCH 093/131] test: make tests idempotent (#201) --- .../snippets/test/containerAnalysis.test.js | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index f2f7c3dc68e..a43d4b0735c 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -303,18 +303,32 @@ describe('pubsub', () => { projectId = await client.getProjectId(); formattedParent = `projects/${projectId}`; formattedNoteName = `projects/${projectId}/notes/${noteId}`; - try { - // attempt to create topic if missing - await pubsub.createTopic(topicName); - } catch (err) { - console.log(`topic creation failed: ${topicName}`); - } topic = pubsub.topic(topicName); }); describe('occurrences from pubsub subscription', () => { - before(async () => { - await topic.createSubscription(subscriptionId); + it('should get count of occurrences from pubsub topic', async function() { + this.retries(3); + await delay(this.test); + try { + // attempt to create topic if missing + await pubsub.createTopic(topicName); + } catch (err) { + console.log(`topic creation failed: ${topicName} ${err.message}`); + if (!err.message.includes('ALREADY_EXISTS')) { + throw err; + } + } + try { + await topic.createSubscription(subscriptionId); + } catch (err) { + console.log( + `subscription creation failed: ${subscriptionId} ${err.message}` + ); + if (!err.message.includes('ALREADY_EXISTS')) { + throw err; + } + } const pubSubNoteReq = { parent: formattedParent, noteId: `${noteId}-pubsub`, @@ -336,12 +350,6 @@ describe('pubsub', () => { }, }; await client.getGrafeasClient().createNote(pubSubNoteReq); - }); - - it('should get count of occurrences from pubsub topic', async function () { - this.retries(3); - await delay(this.test); - const occurrenceCount = 3; const pubSubOccurrenceReq = { parent: formattedParent, @@ -389,7 +397,7 @@ describe('pubsub', () => { assert.match(output, /Polled [1-9]+ occurrences/); }); - it('should delete the pubsub subscription', async function () { + it('should delete the pubsub subscription', async function() { this.retries(3); await delay(this.test); From 1cb4a1249b42a4be58d4e15700e5ad16cfcc6879 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Thu, 23 Apr 2020 15:24:33 -0700 Subject: [PATCH 094/131] fix(samples): should use effective_severity field (#200) Use new effective_severity field fixes b/142836422 --- container-analysis/snippets/highVulnerabilitiesForImage.js | 4 ++-- container-analysis/snippets/test/containerAnalysis.test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 05dc80bc270..929fc0b5c2d 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -45,8 +45,8 @@ async function main( console.log(`High Severity Vulnerabilities for ${imageUrl}`); occurrences.forEach(occurrence => { if ( - occurrence.vulnerability.severity === 'HIGH' || - occurrence.vulnerability.severity === 'CRITICAL' + occurrence.vulnerability.effective_severity === 'HIGH' || + occurrence.vulnerability.effective_severity === 'CRITICAL' ) { console.log(`${occurrence.name}:`); } diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index a43d4b0735c..799d479f0bb 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -189,7 +189,7 @@ describe('Note tests', () => { noteName: `${formattedNoteName}-critical`, resourceUri: resourceUrl, vulnerability: { - severity: 'CRITICAL', + effective_severity: 'CRITICAL', packageIssue: [ { affectedCpeUri: 'foo.uri', From 33a2cbea478f4ba2f6a6db5272b574245377855f Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2020 16:54:04 -0700 Subject: [PATCH 095/131] chore: release 2.0.0 (#170) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 76033a0efe9..74ee08937e9 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^1.10.0", + "@google-cloud/containeranalysis": "^2.0.0", "@google-cloud/pubsub": "^1.0.0", "p-retry": "^4.1.0" }, From 58d67b6bcade0a2bbd9e620df3acf08933435961 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 28 Apr 2020 12:08:39 -0700 Subject: [PATCH 096/131] build: modified export in protos.js --- container-analysis/snippets/test/containerAnalysis.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 799d479f0bb..9f8839d3124 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -307,7 +307,7 @@ describe('pubsub', () => { }); describe('occurrences from pubsub subscription', () => { - it('should get count of occurrences from pubsub topic', async function() { + it('should get count of occurrences from pubsub topic', async function () { this.retries(3); await delay(this.test); try { @@ -397,7 +397,7 @@ describe('pubsub', () => { assert.match(output, /Polled [1-9]+ occurrences/); }); - it('should delete the pubsub subscription', async function() { + it('should delete the pubsub subscription', async function () { this.retries(3); await delay(this.test); From 536f566fb31729b5c586ea957d051a2f7e40b018 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 1 May 2020 06:53:00 +0200 Subject: [PATCH 097/131] chore(deps): update dependency uuid to v8 (#206) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [uuid](https://togithub.com/uuidjs/uuid) | devDependencies | major | [`^7.0.0` -> `^8.0.0`](https://renovatebot.com/diffs/npm/uuid/7.0.3/8.0.0) | --- ### Release Notes
uuidjs/uuid ### [`v8.0.0`](https://togithub.com/uuidjs/uuid/blob/master/CHANGELOG.md#​800-httpsgithubcomuuidjsuuidcomparev703v800-2020-04-29) [Compare Source](https://togithub.com/uuidjs/uuid/compare/v7.0.3...v8.0.0) ##### âš  BREAKING CHANGES - For native ECMAScript Module (ESM) usage in Node.js only named exports are exposed, there is no more default export. ```diff -import uuid from 'uuid'; -console.log(uuid.v4()); // -> 'cd6c3b08-0adc-4f4b-a6ef-36087a1c9869' +import { v4 as uuidv4 } from 'uuid'; +uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' ``` - Deep requiring specific algorithms of this library like `require('uuid/v4')`, which has been deprecated in `uuid@7`, is no longer supported. Instead use the named exports that this module exports. For ECMAScript Modules (ESM): ```diff -import uuidv4 from 'uuid/v4'; +import { v4 as uuidv4 } from 'uuid'; uuidv4(); ``` For CommonJS: ```diff -const uuidv4 = require('uuid/v4'); +const { v4: uuidv4 } = require('uuid'); uuidv4(); ``` ##### Features - native Node.js ES Modules (wrapper approach) ([#​423](https://togithub.com/uuidjs/uuid/issues/423)) ([2d9f590](https://togithub.com/uuidjs/uuid/commit/2d9f590ad9701d692625c07ed62f0a0f91227991)), closes [#​245](https://togithub.com/uuidjs/uuid/issues/245) [#​419](https://togithub.com/uuidjs/uuid/issues/419) [#​342](https://togithub.com/uuidjs/uuid/issues/342) - remove deep requires ([#​426](https://togithub.com/uuidjs/uuid/issues/426)) ([daf72b8](https://togithub.com/uuidjs/uuid/commit/daf72b84ceb20272a81bb5fbddb05dd95922cbba)) ##### Bug Fixes - add CommonJS syntax example to README quickstart section ([#​417](https://togithub.com/uuidjs/uuid/issues/417)) ([e0ec840](https://togithub.com/uuidjs/uuid/commit/e0ec8402c7ad44b7ef0453036c612f5db513fda0)) ##### [7.0.3](https://togithub.com/uuidjs/uuid/compare/v7.0.2...v7.0.3) (2020-03-31) ##### Bug Fixes - make deep require deprecation warning work in browsers ([#​409](https://togithub.com/uuidjs/uuid/issues/409)) ([4b71107](https://togithub.com/uuidjs/uuid/commit/4b71107d8c0d2ef56861ede6403fc9dc35a1e6bf)), closes [#​408](https://togithub.com/uuidjs/uuid/issues/408) ##### [7.0.2](https://togithub.com/uuidjs/uuid/compare/v7.0.1...v7.0.2) (2020-03-04) ##### Bug Fixes - make access to msCrypto consistent ([#​393](https://togithub.com/uuidjs/uuid/issues/393)) ([8bf2a20](https://togithub.com/uuidjs/uuid/commit/8bf2a20f3565df743da7215eebdbada9d2df118c)) - simplify link in deprecation warning ([#​391](https://togithub.com/uuidjs/uuid/issues/391)) ([bb2c8e4](https://togithub.com/uuidjs/uuid/commit/bb2c8e4e9f4c5f9c1eaaf3ea59710c633cd90cb7)) - update links to match content in readme ([#​386](https://togithub.com/uuidjs/uuid/issues/386)) ([44f2f86](https://togithub.com/uuidjs/uuid/commit/44f2f86e9d2bbf14ee5f0f00f72a3db1292666d4)) ##### [7.0.1](https://togithub.com/uuidjs/uuid/compare/v7.0.0...v7.0.1) (2020-02-25) ##### Bug Fixes - clean up esm builds for node and browser ([#​383](https://togithub.com/uuidjs/uuid/issues/383)) ([59e6a49](https://togithub.com/uuidjs/uuid/commit/59e6a49e7ce7b3e8fb0f3ee52b9daae72af467dc)) - provide browser versions independent from module system ([#​380](https://togithub.com/uuidjs/uuid/issues/380)) ([4344a22](https://togithub.com/uuidjs/uuid/commit/4344a22e7aed33be8627eeaaf05360f256a21753)), closes [#​378](https://togithub.com/uuidjs/uuid/issues/378)
--- ### Renovate configuration :date: **Schedule**: "after 9am and before 3pm" (UTC). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#googleapis/nodejs-containeranalysis). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 74ee08937e9..23adc46ef65 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -21,6 +21,6 @@ "devDependencies": { "chai": "^4.2.0", "mocha": "^7.0.0", - "uuid": "^7.0.0" + "uuid": "^8.0.0" } } From 52abee572a1a3df70732be696aa1ede55bca58b3 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 27 May 2020 03:28:12 +0200 Subject: [PATCH 098/131] fix(deps): update dependency @google-cloud/pubsub to v2 (#215) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [@google-cloud/pubsub](https://togithub.com/googleapis/nodejs-pubsub) | dependencies | major | [`^1.0.0` -> `^2.0.0`](https://renovatebot.com/diffs/npm/@google-cloud%2fpubsub/1.7.3/2.0.0) | --- ### Release Notes
googleapis/nodejs-pubsub ### [`v2.0.0`](https://togithub.com/googleapis/nodejs-pubsub/blob/master/CHANGELOG.md#​200-httpswwwgithubcomgoogleapisnodejs-pubsubcomparevv171v200-2020-05-20) [Compare Source](https://togithub.com/googleapis/nodejs-pubsub/compare/v1.7.3...v2.0.0) Please note that Node 8 is no longer supported, and Node 10 is the new minimum version of the runtime. ##### âš  BREAKING CHANGES - Please note that Node 8 is no longer supported, and Node 10 is the new minimum version of the runtime. - drop support for custom promises ([#​970](https://togithub.com/googleapis/nodejs-pubsub/issues/970)) - convert to typescript ([#​923](https://togithub.com/googleapis/nodejs-pubsub/issues/923)) - **deps:** update dependency [@​google-cloud/projectify](https://togithub.com/google-cloud/projectify) to v2 ([#​929](https://togithub.com/googleapis/nodejs-pubsub/issues/929)) ##### Bug Fixes - **docs:** link to correct gaxOptions docs ([#​999](https://www.github.com/googleapis/nodejs-pubsub/issues/999)) ([312e318](https://www.github.com/googleapis/nodejs-pubsub/commit/312e318ceb36eafbeb487ede7e5dbf9ccd5dfb81)) - regen protos and tests, formatting ([#​991](https://www.github.com/googleapis/nodejs-pubsub/issues/991)) ([e350b97](https://www.github.com/googleapis/nodejs-pubsub/commit/e350b97ad19e49e5fe52d5eeb1ad67c8bb6ddf33)) - remove eslint, update gax, fix generated protos, run the generator ([#​955](https://www.github.com/googleapis/nodejs-pubsub/issues/955)) ([544a061](https://www.github.com/googleapis/nodejs-pubsub/commit/544a061b1b6d7fdc4051486c2b8ae5d14e1ec141)) - remove unused dependencies ([#​998](https://www.github.com/googleapis/nodejs-pubsub/issues/998)) ([7b242a3](https://www.github.com/googleapis/nodejs-pubsub/commit/7b242a36212e0871b3918621fe9a5f51d1e6b733)) - **close:** ensure in-flight messages are drained ([#​952](https://www.github.com/googleapis/nodejs-pubsub/issues/952)) ([93a2bd7](https://www.github.com/googleapis/nodejs-pubsub/commit/93a2bd726660b134fbd3e12335bfde29d13a2b78)) - **deps:** update dependency [@​google-cloud/paginator](https://togithub.com/google-cloud/paginator) to v3 ([#​931](https://www.github.com/googleapis/nodejs-pubsub/issues/931)) ([b621854](https://www.github.com/googleapis/nodejs-pubsub/commit/b62185426b7f958ee41a1cff429bc5fb70635b4a)) - **deps:** update dependency [@​google-cloud/precise-date](https://togithub.com/google-cloud/precise-date) to v2 ([#​934](https://www.github.com/googleapis/nodejs-pubsub/issues/934)) ([72b8d78](https://www.github.com/googleapis/nodejs-pubsub/commit/72b8d781ed3cbf9049101b9c2675f211fb3924ba)) - **deps:** update dependency [@​google-cloud/projectify](https://togithub.com/google-cloud/projectify) to v2 ([#​929](https://www.github.com/googleapis/nodejs-pubsub/issues/929)) ([45d9880](https://www.github.com/googleapis/nodejs-pubsub/commit/45d988077d2db2fddbb4d22aac43c7f8a77e4dcc)) - **deps:** update dependency [@​google-cloud/promisify](https://togithub.com/google-cloud/promisify) to v2 ([#​928](https://www.github.com/googleapis/nodejs-pubsub/issues/928)) ([3819877](https://www.github.com/googleapis/nodejs-pubsub/commit/3819877752d39cd042364bdd9ed01ff230aeed0b)) - **deps:** update dependency google-auth-library to v6 ([#​935](https://www.github.com/googleapis/nodejs-pubsub/issues/935)) ([73fc887](https://www.github.com/googleapis/nodejs-pubsub/commit/73fc887c662b526690167286d2d5afda0cccad1b)) ##### Build System - convert to typescript ([#​923](https://www.github.com/googleapis/nodejs-pubsub/issues/923)) ([2fc68ba](https://www.github.com/googleapis/nodejs-pubsub/commit/2fc68baff0cc2013468da7ef3dc8d547d4745989)) ##### Miscellaneous Chores - drop support for custom promises ([#​970](https://www.github.com/googleapis/nodejs-pubsub/issues/970)) ([df462d3](https://www.github.com/googleapis/nodejs-pubsub/commit/df462d3dec4f733cb309eb6413aad382424e2125)) ##### [1.7.1](https://www.github.com/googleapis/nodejs-pubsub/compare/v1.7.0...v1.7.1) (2020-04-06) ##### Bug Fixes - provide missing close() method in the generated gapic client ([#​941](https://www.github.com/googleapis/nodejs-pubsub/issues/941)) ([6bf8f14](https://www.github.com/googleapis/nodejs-pubsub/commit/6bf8f1481a1dea051c47697488e13b6facf20a26))
--- ### Renovate configuration :date: **Schedule**: "after 9am and before 3pm" (UTC). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#googleapis/nodejs-containeranalysis). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 23adc46ef65..b7127483f7d 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@google-cloud/containeranalysis": "^2.0.0", - "@google-cloud/pubsub": "^1.0.0", + "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, "devDependencies": { From 474d3ecd84a666327d17c0ea62e6aabe83b2a020 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 12 Jun 2020 06:34:12 +0200 Subject: [PATCH 099/131] chore(deps): update dependency mocha to v8 (#222) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [mocha](https://mochajs.org/) ([source](https://togithub.com/mochajs/mocha)) | devDependencies | major | [`^7.0.0` -> `^8.0.0`](https://renovatebot.com/diffs/npm/mocha/7.2.0/8.0.1) | | [mocha](https://mochajs.org/) ([source](https://togithub.com/mochajs/mocha)) | devDependencies | major | [`^6.1.4` -> `^8.0.0`](https://renovatebot.com/diffs/npm/mocha/6.2.3/8.0.1) | --- ### Release Notes
mochajs/mocha ### [`v8.0.1`](https://togithub.com/mochajs/mocha/blob/master/CHANGELOG.md#​801--2020-06-10) [Compare Source](https://togithub.com/mochajs/mocha/compare/v8.0.0...v8.0.1) The obligatory patch after a major. #### :bug: Fixes - [#​4328](https://togithub.com/mochajs/mocha/issues/4328): Fix `--parallel` when combined with `--watch` ([**@​boneskull**](https://togithub.com/boneskull)) ### [`v8.0.0`](https://togithub.com/mochajs/mocha/blob/master/CHANGELOG.md#​800--2020-06-10) [Compare Source](https://togithub.com/mochajs/mocha/compare/v7.2.0...v8.0.0) In this major release, Mocha adds the ability to _run tests in parallel_. Better late than never! Please note the **breaking changes** detailed below. Let's welcome [**@​giltayar**](https://togithub.com/giltayar) and [**@​nicojs**](https://togithub.com/nicojs) to the maintenance team! #### :boom: Breaking Changes - [#​4164](https://togithub.com/mochajs/mocha/issues/4164): **Mocha v8.0.0 now requires Node.js v10.0.0 or newer.** Mocha no longer supports the Node.js v8.x line ("Carbon"), which entered End-of-Life at the end of 2019 ([**@​UlisesGascon**](https://togithub.com/UlisesGascon)) - [#​4175](https://togithub.com/mochajs/mocha/issues/4175): Having been deprecated with a warning since v7.0.0, **`mocha.opts` is no longer supported** ([**@​juergba**](https://togithub.com/juergba)) :sparkles: **WORKAROUND:** Replace `mocha.opts` with a [configuration file](https://mochajs.org/#configuring-mocha-nodejs). - [#​4260](https://togithub.com/mochajs/mocha/issues/4260): Remove `enableTimeout()` (`this.enableTimeout()`) from the context object ([**@​craigtaub**](https://togithub.com/craigtaub)) :sparkles: **WORKAROUND:** Replace usage of `this.enableTimeout(false)` in your tests with `this.timeout(0)`. - [#​4315](https://togithub.com/mochajs/mocha/issues/4315): The `spec` option no longer supports a comma-delimited list of files ([**@​juergba**](https://togithub.com/juergba)) :sparkles: **WORKAROUND**: Use an array instead (e.g., `"spec": "foo.js,bar.js"` becomes `"spec": ["foo.js", "bar.js"]`). - [#​4309](https://togithub.com/mochajs/mocha/issues/4309): Drop support for Node.js v13.x line, which is now End-of-Life ([**@​juergba**](https://togithub.com/juergba)) - [#​4282](https://togithub.com/mochajs/mocha/issues/4282): `--forbid-only` will throw an error even if exclusive tests are avoided via `--grep` or other means ([**@​arvidOtt**](https://togithub.com/arvidOtt)) - [#​4223](https://togithub.com/mochajs/mocha/issues/4223): The context object's `skip()` (`this.skip()`) in a "before all" (`before()`) hook will no longer execute subsequent sibling hooks, in addition to hooks in child suites ([**@​juergba**](https://togithub.com/juergba)) - [#​4178](https://togithub.com/mochajs/mocha/issues/4178): Remove previously soft-deprecated APIs ([**@​wnghdcjfe**](https://togithub.com/wnghdcjfe)): - `Mocha.prototype.ignoreLeaks()` - `Mocha.prototype.useColors()` - `Mocha.prototype.useInlineDiffs()` - `Mocha.prototype.hideDiff()` #### :tada: Enhancements - [#​4245](https://togithub.com/mochajs/mocha/issues/4245): Add ability to run tests in parallel for Node.js (see [docs](https://mochajs.org/#parallel-tests)) ([**@​boneskull**](https://togithub.com/boneskull)) :exclamation: See also [#​4244](https://togithub.com/mochajs/mocha/issues/4244); [Root Hook Plugins (docs)](https://mochajs.org/#root-hook-plugins) -- _root hooks must be defined via Root Hook Plugins to work in parallel mode_ - [#​4304](https://togithub.com/mochajs/mocha/issues/4304): `--require` now works with ES modules ([**@​JacobLey**](https://togithub.com/JacobLey)) - [#​4299](https://togithub.com/mochajs/mocha/issues/4299): In some circumstances, Mocha can run ES modules under Node.js v10 -- _use at your own risk!_ ([**@​giltayar**](https://togithub.com/giltayar)) #### :book: Documentation - [#​4246](https://togithub.com/mochajs/mocha/issues/4246): Add documentation for parallel mode and Root Hook plugins ([**@​boneskull**](https://togithub.com/boneskull)) #### :bug: Fixes (All bug fixes in Mocha v8.0.0 are also breaking changes, and are listed above)
--- ### Renovate configuration :date: **Schedule**: "after 9am and before 3pm" (UTC). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#googleapis/nodejs-containeranalysis). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index b7127483f7d..dba36cc7e08 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -20,7 +20,7 @@ }, "devDependencies": { "chai": "^4.2.0", - "mocha": "^7.0.0", + "mocha": "^8.0.0", "uuid": "^8.0.0" } } From 1ed98b2ce4ae9f6f9811e92048fa446f33d41a6a Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Fri, 12 Jun 2020 09:18:07 -0700 Subject: [PATCH 100/131] test: attempt retry on note delete (#224) --- container-analysis/snippets/test/containerAnalysis.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 9f8839d3124..dad650c44a6 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -239,7 +239,12 @@ describe('Note tests', () => { it('should delete note', () => { const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); assert.include(output, `Note ${formattedNoteName} deleted.`); - }); + // Sometimes the delete note test is failing with the error: + // Error: 5 NOT_FOUND: note with ID "test-note-${uuid}" for project + // ${projectId} does not exist. + // Attempting to work around this issue by retrying a few times. + // DO NOT MERGE. If this works, we should submit an upstream bug. + }).retries(3); }); describe('polling', () => { From fbbd62cfb8f001536e1784168e0b031210bb2804 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2020 14:57:32 -0700 Subject: [PATCH 101/131] chore: release 2.1.0 (#210) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index dba36cc7e08..9dd38906f6f 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^2.0.0", + "@google-cloud/containeranalysis": "^2.1.0", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From 2e9806bf602ce67ca97142be1290aa3849c8d009 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Fri, 10 Jul 2020 23:16:08 +0000 Subject: [PATCH 102/131] chore: release 2.1.1 (#232) :robot: I have created a release \*beep\* \*boop\* --- ### [2.1.1](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v2.1.0...v2.1.1) (2020-07-10) ### Bug Fixes * typeo in nodejs .gitattribute ([#231](https://www.github.com/googleapis/nodejs-containeranalysis/issues/231)) ([c87033a](https://www.github.com/googleapis/nodejs-containeranalysis/commit/c87033a3c14065f7b461b4fc04751e67a40f2325)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 9dd38906f6f..67d4eea6373 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^2.1.0", + "@google-cloud/containeranalysis": "^2.1.1", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From d2c50bf926a97583906e7e2d455b61ff5c6ae169 Mon Sep 17 00:00:00 2001 From: Don McCasland Date: Mon, 16 Nov 2020 09:23:26 -0800 Subject: [PATCH 103/131] docs(samples): update sample to illustrate AR style urls Co-authored-by: Benjamin E. Coe --- container-analysis/snippets/createOccurrence.js | 10 ++++++++-- container-analysis/snippets/getDiscoveryInfo.js | 10 ++++++++-- .../snippets/highVulnerabilitiesForImage.js | 7 ++++++- container-analysis/snippets/occurrencesForImage.js | 7 ++++++- .../snippets/pollDiscoveryOccurrenceFinished.js | 7 ++++++- .../snippets/vulnerabilityOccurrencesForImage.js | 7 ++++++- 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/container-analysis/snippets/createOccurrence.js b/container-analysis/snippets/createOccurrence.js index d593acf8779..b2af600eebf 100644 --- a/container-analysis/snippets/createOccurrence.js +++ b/container-analysis/snippets/createOccurrence.js @@ -22,7 +22,10 @@ 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 - imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // 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] /** @@ -31,7 +34,10 @@ async function main( // 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 - // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // 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'); diff --git a/container-analysis/snippets/getDiscoveryInfo.js b/container-analysis/snippets/getDiscoveryInfo.js index 047d2ab9c2d..81960ed1981 100644 --- a/container-analysis/snippets/getDiscoveryInfo.js +++ b/container-analysis/snippets/getDiscoveryInfo.js @@ -20,14 +20,20 @@ // usage: node getDiscoveryInfo.js "project-id" "image-url" async function main( projectId = 'your-project-id', // Your GCP Project ID - imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // 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 - // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // 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'); diff --git a/container-analysis/snippets/highVulnerabilitiesForImage.js b/container-analysis/snippets/highVulnerabilitiesForImage.js index 929fc0b5c2d..6f696e8a63e 100644 --- a/container-analysis/snippets/highVulnerabilitiesForImage.js +++ b/container-analysis/snippets/highVulnerabilitiesForImage.js @@ -21,13 +21,18 @@ async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // Use imageURL = 'https://LOCATION-docker.pkg.dev/my-project/my-image:123' when + // using Artifact Registry ) { // [START containeranalysis_filter_vulnerability_occurrences] /** * TODO(developer): Uncomment these variables before running the sample */ // const projectId = 'your-project-id', // Your GCP Project ID - // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // 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 // Import the library and create a client const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); diff --git a/container-analysis/snippets/occurrencesForImage.js b/container-analysis/snippets/occurrencesForImage.js index fb559db5690..e077d2dfe53 100644 --- a/container-analysis/snippets/occurrencesForImage.js +++ b/container-analysis/snippets/occurrencesForImage.js @@ -21,13 +21,18 @@ async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/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_occurrences_for_image] /** * TODO(developer): Uncomment these variables before running the sample */ // const projectId = 'your-project-id', // Your GCP Project ID - // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // 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'); diff --git a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js index b7fb16b8051..fea680e5f51 100644 --- a/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js +++ b/container-analysis/snippets/pollDiscoveryOccurrenceFinished.js @@ -21,6 +21,8 @@ async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/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 retries = 5 // The number of retries to listen for the new Pub/Sub messages ) { // [START containeranalysis_poll_discovery_occurrence_finished] @@ -28,7 +30,10 @@ async function main( * TODO(developer): Uncomment these variables before running the sample */ // const projectId = 'your-project-id', // Your GCP Project ID - // const imageUrl = 'https://gcr.io/my-project/my-image:123', // Image to attach metadata to + // 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 // const retries = 5 // The number of retries to listen for the new Pub/Sub messages // Import the library and create a client diff --git a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js index 6a0cfc61581..611a161d01c 100644 --- a/container-analysis/snippets/vulnerabilityOccurrencesForImage.js +++ b/container-analysis/snippets/vulnerabilityOccurrencesForImage.js @@ -21,13 +21,18 @@ async function main( projectId = 'your-project-id', // Your GCP Project ID imageUrl = 'https://gcr.io/my-project/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_vulnerability_occurrences_for_image] /** * TODO(developer): Uncomment these variables before running the sample */ // const projectId = 'your-project-id', // Your GCP Project ID - // const imageUrl = 'https://gcr.io/my-project/my-image:123' // Image to attach metadata to + // 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'); From 10b6a2da94fef709106c455fd394abacc28fe3d8 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2020 13:15:22 -0800 Subject: [PATCH 104/131] chore: release 3.0.0 (#264) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 67d4eea6373..11e7c306de4 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^2.1.1", + "@google-cloud/containeranalysis": "^3.0.0", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From 28e7aaab541f4860d98eac7982329160551664d8 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 2 Dec 2020 19:40:36 +0000 Subject: [PATCH 105/131] chore: release 3.0.1 (#268) :robot: I have created a release \*beep\* \*boop\* --- ### [3.0.1](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v3.0.0...v3.0.1) (2020-11-25) ### Bug Fixes * **browser:** check for fetch on window ([#267](https://www.github.com/googleapis/nodejs-containeranalysis/issues/267)) ([003a128](https://www.github.com/googleapis/nodejs-containeranalysis/commit/003a128f84f0a7cdcff34ba77dc60d88a4d7969b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 11e7c306de4..93aa225822c 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.0.0", + "@google-cloud/containeranalysis": "^3.0.1", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From c2e9b638f1c57b1dc2fd50f558ccad375356b28b Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 14 Jan 2021 10:53:46 -0800 Subject: [PATCH 106/131] chore: release 3.1.0 (#278) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 93aa225822c..f54e14342be 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.0.1", + "@google-cloud/containeranalysis": "^3.1.0", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From 54c211ae9a0667c25c42e0e500659538109812bb Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 8 Mar 2021 12:01:56 -0800 Subject: [PATCH 107/131] build: update gapic-generator-typescript to v1.2.10. (#284) --- container-analysis/snippets/test/containerAnalysis.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index dad650c44a6..a26e121e662 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -236,7 +236,8 @@ describe('Note tests', () => { ); assert.include(output, 'Occurrence deleted:'); }); - it('should delete note', () => { + it('should delete note', function () { + this.retries(3); const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); assert.include(output, `Note ${formattedNoteName} deleted.`); // Sometimes the delete note test is failing with the error: @@ -244,7 +245,7 @@ describe('Note tests', () => { // ${projectId} does not exist. // Attempting to work around this issue by retrying a few times. // DO NOT MERGE. If this works, we should submit an upstream bug. - }).retries(3); + }); }); describe('polling', () => { From 4c26e307bfe8e65266d409fc9f4bb8df56cacf85 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 28 Apr 2021 23:30:35 +0000 Subject: [PATCH 108/131] chore: release 3.1.1 (#294) :robot: I have created a release \*beep\* \*boop\* --- ### [3.1.1](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v3.1.0...v3.1.1) (2021-04-27) ### Bug Fixes * specify valid go_package option ([#293](https://www.github.com/googleapis/nodejs-containeranalysis/issues/293)) ([84ba201](https://www.github.com/googleapis/nodejs-containeranalysis/commit/84ba201c2d2eb81faf36461cf1ff3bfccf33f5ed)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index f54e14342be..c685aad4bc9 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.1.0", + "@google-cloud/containeranalysis": "^3.1.1", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From b325b448fdb5b073b9413ae1ae774af1332c9a94 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Fri, 7 May 2021 17:40:27 -0400 Subject: [PATCH 109/131] chore: release 3.1.2 (#299) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index c685aad4bc9..345d4613f0d 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.1.1", + "@google-cloud/containeranalysis": "^3.1.2", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From 3b2c64258c4f0f62c1f6fff2fe84c6a7bf3b6af6 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 10 May 2021 17:00:39 +0000 Subject: [PATCH 110/131] chore: new owl bot post processor docker image (#300) gcr.io/repo-automation-bots/owlbot-nodejs:latest@sha256:f93bb861d6f12574437bb9aee426b71eafd63b419669ff0ed029f4b7e7162e3f --- .../snippets/test/containerAnalysis.test.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index a26e121e662..fed968c17d0 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -282,11 +282,11 @@ describe('polling', () => { }); after(async () => { - const [ - discoveryOccurrences, - ] = await client.getGrafeasClient().listNoteOccurrences({ - name: `${formattedNoteName}-discovery-polling`, - }); + const [discoveryOccurrences] = await client + .getGrafeasClient() + .listNoteOccurrences({ + name: `${formattedNoteName}-discovery-polling`, + }); discoveryOccurrences.forEach(async occurrence => { await client.getGrafeasClient().deleteOccurrence({name: occurrence.name}); }); @@ -386,9 +386,7 @@ describe('pubsub', () => { // create test occurrences for (let i = 0; i < occurrenceCount; i++) { - const [ - pubSubOccurrence, - ] = await client + const [pubSubOccurrence] = await client .getGrafeasClient() .createOccurrence(pubSubOccurrenceReq); await client From 317e1804d536c1a1330ebcdbc10c4d55b1ff54b1 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 12 May 2021 21:20:02 +0000 Subject: [PATCH 111/131] chore: release 3.1.3 (#303) :robot: I have created a release \*beep\* \*boop\* --- ### [3.1.3](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v3.1.2...v3.1.3) (2021-05-12) ### Bug Fixes * use require() to load JSON protos ([#301](https://www.github.com/googleapis/nodejs-containeranalysis/issues/301)) ([46bed2e](https://www.github.com/googleapis/nodejs-containeranalysis/commit/46bed2e0b0dadaae2504f2c765d13f2d46f4a0b0)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 345d4613f0d..3ff16f882ce 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.1.2", + "@google-cloud/containeranalysis": "^3.1.3", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From a4e6ec0de65b27affc3a791d714d1886d1a66743 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 27 May 2021 15:38:51 -0300 Subject: [PATCH 112/131] chore: release 3.1.4 (#309) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 3ff16f882ce..4244605c500 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.1.3", + "@google-cloud/containeranalysis": "^3.1.4", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From 6f2150a0e5cf2466f85ac0523329bf8527b82bf1 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 1 Jul 2021 00:02:13 +0000 Subject: [PATCH 113/131] chore: release 3.1.5 (#319) :robot: I have created a release \*beep\* \*boop\* --- ### [3.1.5](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v3.1.4...v3.1.5) (2021-06-30) ### Bug Fixes * make request optional in all cases ([#318](https://www.github.com/googleapis/nodejs-containeranalysis/issues/318)) ([35e8196](https://www.github.com/googleapis/nodejs-containeranalysis/commit/35e81964f971d4272b0c14f4e8b6e790229ba803)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 4244605c500..c86a0230dde 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.1.4", + "@google-cloud/containeranalysis": "^3.1.5", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From ac31261d6ee6cf2936fe375d1300c9793e1a78c9 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 1 Jul 2021 20:40:10 +0000 Subject: [PATCH 114/131] chore: release 3.1.6 (#325) :robot: I have created a release \*beep\* \*boop\* --- ### [3.1.6](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v3.1.5...v3.1.6) (2021-07-01) ### Bug Fixes * **deps:** require google-gax v2.17.0 ([#322](https://www.github.com/googleapis/nodejs-containeranalysis/issues/322)) ([3c841c0](https://www.github.com/googleapis/nodejs-containeranalysis/commit/3c841c05e58e128080384321e1145d56c4b94cdf)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index c86a0230dde..06f902ac300 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.1.5", + "@google-cloud/containeranalysis": "^3.1.6", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From 0f1df34194d9d11562107a2771126c522a6c961d Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 21 Jul 2021 00:18:16 +0000 Subject: [PATCH 115/131] chore: release 3.1.7 (#327) :robot: I have created a release \*beep\* \*boop\* --- ### [3.1.7](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v3.1.6...v3.1.7) (2021-07-21) ### Bug Fixes * **deps:** google-gax v2.17.1 ([#326](https://www.github.com/googleapis/nodejs-containeranalysis/issues/326)) ([9e3f627](https://www.github.com/googleapis/nodejs-containeranalysis/commit/9e3f62734cecd16c7bae394665b50e7212f55158)) * Updating WORKSPACE files to use the newest version of the Typescript generator. ([#329](https://www.github.com/googleapis/nodejs-containeranalysis/issues/329)) ([5403fb4](https://www.github.com/googleapis/nodejs-containeranalysis/commit/5403fb42c84354d439ea8f6414b6b7e28c57f5c1)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 06f902ac300..61094f9311a 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.1.6", + "@google-cloud/containeranalysis": "^3.1.7", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From ff2b2473dc26d400d9d3e7bb7d01ca3dc176ce72 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 17 Aug 2021 03:32:40 +0000 Subject: [PATCH 116/131] chore: release 3.1.8 (#337) :robot: I have created a release \*beep\* \*boop\* --- ### [3.1.8](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v3.1.7...v3.1.8) (2021-08-17) ### Bug Fixes * **build:** migrate to using main branch ([#336](https://www.github.com/googleapis/nodejs-containeranalysis/issues/336)) ([3fbaf02](https://www.github.com/googleapis/nodejs-containeranalysis/commit/3fbaf02e2dc83730d1222255ad2f6ab6d34f4be0)) * **deps:** google-gax v2.24.1 ([#338](https://www.github.com/googleapis/nodejs-containeranalysis/issues/338)) ([6f0b19a](https://www.github.com/googleapis/nodejs-containeranalysis/commit/6f0b19a20b73f542c6e88f954fc3e159b9e73f82)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 61094f9311a..52ea55e893c 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.1.7", + "@google-cloud/containeranalysis": "^3.1.8", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From 391bdf77ab74371adcdb8b278867e2d4c0e9d92e Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 23 Aug 2021 18:48:11 +0000 Subject: [PATCH 117/131] chore: release 3.2.0 (#340) :robot: I have created a release \*beep\* \*boop\* --- ## [3.2.0](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v3.1.8...v3.2.0) (2021-08-23) ### Features * turns on self-signed JWT feature flag ([#339](https://www.github.com/googleapis/nodejs-containeranalysis/issues/339)) ([98de66a](https://www.github.com/googleapis/nodejs-containeranalysis/commit/98de66a7ad503a0b1e5f4d3f8fd94f49ac156dfa)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 52ea55e893c..e623e9621dd 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.1.8", + "@google-cloud/containeranalysis": "^3.2.0", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From 398506203e84e6d20d7e72bcc94bc53428f42cba Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 15 Nov 2021 15:24:25 -0500 Subject: [PATCH 118/131] chore: release 3.3.0 (#353) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index e623e9621dd..8d784922d8d 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.2.0", + "@google-cloud/containeranalysis": "^3.3.0", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From 8fdfc6fc80377dcd014372fb78d0feaa61c6039d Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 5 Apr 2022 12:06:30 -0400 Subject: [PATCH 119/131] chore(main): release 3.4.0 (#389) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 8d784922d8d..0bb64bc6b00 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.3.0", + "@google-cloud/containeranalysis": "^3.4.0", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From bd0bbb50165887c509c58cae834db13939a65f88 Mon Sep 17 00:00:00 2001 From: Wietse Venema <356014+wietsevenema@users.noreply.github.com> Date: Wed, 20 Apr 2022 09:02:21 +0200 Subject: [PATCH 120/131] fix: Flaky pubsub test (#394) --- container-analysis/snippets/test/containerAnalysis.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index fed968c17d0..350e0e66075 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -321,7 +321,7 @@ describe('pubsub', () => { await pubsub.createTopic(topicName); } catch (err) { console.log(`topic creation failed: ${topicName} ${err.message}`); - if (!err.message.includes('ALREADY_EXISTS')) { + if (!err.details.includes('Resource already exists')) { throw err; } } @@ -331,7 +331,7 @@ describe('pubsub', () => { console.log( `subscription creation failed: ${subscriptionId} ${err.message}` ); - if (!err.message.includes('ALREADY_EXISTS')) { + if (!err.details.includes('Resource already exists')) { throw err; } } From dcb6e93164635c5f2f404fcca9ce213444f85488 Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Mon, 16 May 2022 17:40:35 -0700 Subject: [PATCH 121/131] build!: update library to use Node 12 (#408) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat!: Update library to use Node 12 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 0bb64bc6b00..e45eb9d1cfc 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -8,7 +8,7 @@ "*.js" ], "engines": { - "node": ">=10" + "node": ">=12.0.0" }, "scripts": { "test": "mocha --timeout 100000 test/**.test.js" From 90ba422c94b7a13490d523895d1ce6e151e25aea Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 26 May 2022 11:27:32 -0700 Subject: [PATCH 122/131] chore(main): release 4.0.0 (#407) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(main): release 4.0.0 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index e45eb9d1cfc..bb09e9edce0 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^3.4.0", + "@google-cloud/containeranalysis": "^4.0.0", "@google-cloud/pubsub": "^2.0.0", "p-retry": "^4.1.0" }, From 018fdd3cd663ad78af76818ee7609bbdc77a7b48 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 9 Jun 2022 19:23:39 +0200 Subject: [PATCH 123/131] fix(deps): update dependency @google-cloud/pubsub to v3 (#410) --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index bb09e9edce0..6cd5551d0fc 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@google-cloud/containeranalysis": "^4.0.0", - "@google-cloud/pubsub": "^2.0.0", + "@google-cloud/pubsub": "^3.0.0", "p-retry": "^4.1.0" }, "devDependencies": { From 4172a739dbfe453081213aa88ba89b3d3aadb424 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Fri, 10 Jun 2022 12:07:58 -0400 Subject: [PATCH 124/131] chore(main): release 4.1.0 (#416) See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 6cd5551d0fc..3e93254b878 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^4.0.0", + "@google-cloud/containeranalysis": "^4.1.0", "@google-cloud/pubsub": "^3.0.0", "p-retry": "^4.1.0" }, From 23739a21a72f7b9bf5ecc76fa21870ed6cba9eba Mon Sep 17 00:00:00 2001 From: Patti Shin Date: Thu, 23 Jun 2022 11:36:49 -0700 Subject: [PATCH 125/131] fix(issue-417): adding additional asserts to track flaky error (#421) * refactor: adding additional asserts to track flaky error * refactor: remove .only from test * refactor: fix lint * refactor: update assert.fail msg Co-authored-by: Averi Kitsch --- .../snippets/test/containerAnalysis.test.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 350e0e66075..56fd62134fc 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -405,10 +405,19 @@ describe('pubsub', () => { this.retries(3); await delay(this.test); - await client - .getGrafeasClient() - .deleteNote({name: `${formattedNoteName}-pubsub`}); - await pubsub.subscription(subscriptionId).delete(); + try { + await client + .getGrafeasClient() + .deleteNote({name: `${formattedNoteName}-pubsub`}); + } catch (err) { + assert.fail(err); + } + + try { + await pubsub.subscription(subscriptionId).delete(); + } catch (err) { + assert.fail(err); + } }); }); }); From dcd85d4ecfab5be13dc73e150ff8ba07599a3e14 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 4 Jul 2022 21:08:11 +0000 Subject: [PATCH 126/131] chore(main): release 4.2.0 (#422) :robot: I have created a release *beep* *boop* --- ## [4.2.0](https://github.com/googleapis/nodejs-containeranalysis/compare/v4.1.0...v4.2.0) (2022-07-04) ### Features * support regapic LRO ([1290f13](https://github.com/googleapis/nodejs-containeranalysis/commit/1290f1322a788735340ac1c10b57a38d78396bb8)) ### Bug Fixes * **deps:** update dependency @google-cloud/grafeas to v4 ([#420](https://github.com/googleapis/nodejs-containeranalysis/issues/420)) ([6e40ebe](https://github.com/googleapis/nodejs-containeranalysis/commit/6e40ebe146d61bb6594c3b7e76514250843a5ff0)) * **issue-417:** adding additional asserts to track flaky error ([#421](https://github.com/googleapis/nodejs-containeranalysis/issues/421)) ([23cd446](https://github.com/googleapis/nodejs-containeranalysis/commit/23cd446962c3e2a3ec00981d87dd9d41c17873ee)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 3e93254b878..9db30d23ac9 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^4.1.0", + "@google-cloud/containeranalysis": "^4.2.0", "@google-cloud/pubsub": "^3.0.0", "p-retry": "^4.1.0" }, From d00839e2856c4a978025c9b032b5fb2727042c02 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 9 Sep 2022 01:12:23 +0200 Subject: [PATCH 127/131] chore(deps): update dependency uuid to v9 (#435) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [uuid](https://togithub.com/uuidjs/uuid) | [`^8.0.0` -> `^9.0.0`](https://renovatebot.com/diffs/npm/uuid/8.3.2/9.0.0) | [![age](https://badges.renovateapi.com/packages/npm/uuid/9.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/uuid/9.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/uuid/9.0.0/compatibility-slim/8.3.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/uuid/9.0.0/confidence-slim/8.3.2)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
uuidjs/uuid ### [`v9.0.0`](https://togithub.com/uuidjs/uuid/blob/HEAD/CHANGELOG.md#​900-httpsgithubcomuuidjsuuidcomparev832v900-2022-09-05) [Compare Source](https://togithub.com/uuidjs/uuid/compare/v8.3.2...v9.0.0) ##### âš  BREAKING CHANGES - Drop Node.js 10.x support. This library always aims at supporting one EOLed LTS release which by this time now is 12.x which has reached EOL 30 Apr 2022. - Remove the minified UMD build from the package. Minified code is hard to audit and since this is a widely used library it seems more appropriate nowadays to optimize for auditability than to ship a legacy module format that, at best, serves educational purposes nowadays. For production browser use cases, users should be using a bundler. For educational purposes, today's online sandboxes like replit.com offer convenient ways to load npm modules, so the use case for UMD through repos like UNPKG or jsDelivr has largely vanished. - Drop IE 11 and Safari 10 support. Drop support for browsers that don't correctly implement const/let and default arguments, and no longer transpile the browser build to ES2015. This also removes the fallback on msCrypto instead of the crypto API. Browser tests are run in the first supported version of each supported browser and in the latest (as of this commit) version available on Browserstack. ##### Features - optimize uuid.v1 by 1.3x uuid.v4 by 4.3x (430%) ([#​597](https://togithub.com/uuidjs/uuid/issues/597)) ([3a033f6](https://togithub.com/uuidjs/uuid/commit/3a033f6bab6bb3780ece6d645b902548043280bc)) - remove UMD build ([#​645](https://togithub.com/uuidjs/uuid/issues/645)) ([e948a0f](https://togithub.com/uuidjs/uuid/commit/e948a0f22bf22f4619b27bd913885e478e20fe6f)), closes [#​620](https://togithub.com/uuidjs/uuid/issues/620) - use native crypto.randomUUID when available ([#​600](https://togithub.com/uuidjs/uuid/issues/600)) ([c9e076c](https://togithub.com/uuidjs/uuid/commit/c9e076c852edad7e9a06baaa1d148cf4eda6c6c4)) ##### Bug Fixes - add Jest/jsdom compatibility ([#​642](https://togithub.com/uuidjs/uuid/issues/642)) ([16f9c46](https://togithub.com/uuidjs/uuid/commit/16f9c469edf46f0786164cdf4dc980743984a6fd)) - change default export to named function ([#​545](https://togithub.com/uuidjs/uuid/issues/545)) ([c57bc5a](https://togithub.com/uuidjs/uuid/commit/c57bc5a9a0653273aa639cda9177ce52efabe42a)) - handle error when parameter is not set in v3 and v5 ([#​622](https://togithub.com/uuidjs/uuid/issues/622)) ([fcd7388](https://togithub.com/uuidjs/uuid/commit/fcd73881692d9fabb63872576ba28e30ff852091)) - run npm audit fix ([#​644](https://togithub.com/uuidjs/uuid/issues/644)) ([04686f5](https://togithub.com/uuidjs/uuid/commit/04686f54c5fed2cfffc1b619f4970c4bb8532353)) - upgrading from uuid3 broken link ([#​568](https://togithub.com/uuidjs/uuid/issues/568)) ([1c849da](https://togithub.com/uuidjs/uuid/commit/1c849da6e164259e72e18636726345b13a7eddd6)) ##### build - drop Node.js 8.x from babel transpile target ([#​603](https://togithub.com/uuidjs/uuid/issues/603)) ([aa11485](https://togithub.com/uuidjs/uuid/commit/aa114858260402107ec8a1e1a825dea0a259bcb5)) - drop support for legacy browsers (IE11, Safari 10) ([#​604](https://togithub.com/uuidjs/uuid/issues/604)) ([0f433e5](https://togithub.com/uuidjs/uuid/commit/0f433e5ec444edacd53016de67db021102f36148)) - drop node 10.x to upgrade dev dependencies ([#​653](https://togithub.com/uuidjs/uuid/issues/653)) ([28a5712](https://togithub.com/uuidjs/uuid/commit/28a571283f8abda6b9d85e689f95b7d3ee9e282e)), closes [#​643](https://togithub.com/uuidjs/uuid/issues/643) ##### [8.3.2](https://togithub.com/uuidjs/uuid/compare/v8.3.1...v8.3.2) (2020-12-08) ##### Bug Fixes - lazy load getRandomValues ([#​537](https://togithub.com/uuidjs/uuid/issues/537)) ([16c8f6d](https://togithub.com/uuidjs/uuid/commit/16c8f6df2f6b09b4d6235602d6a591188320a82e)), closes [#​536](https://togithub.com/uuidjs/uuid/issues/536) ##### [8.3.1](https://togithub.com/uuidjs/uuid/compare/v8.3.0...v8.3.1) (2020-10-04) ##### Bug Fixes - support expo>=39.0.0 ([#​515](https://togithub.com/uuidjs/uuid/issues/515)) ([c65a0f3](https://togithub.com/uuidjs/uuid/commit/c65a0f3fa73b901959d638d1e3591dfacdbed867)), closes [#​375](https://togithub.com/uuidjs/uuid/issues/375)
--- ### Configuration 📅 **Schedule**: Branch creation - "after 9am and before 3pm" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-containeranalysis). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 9db30d23ac9..e25c415178c 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -21,6 +21,6 @@ "devDependencies": { "chai": "^4.2.0", "mocha": "^8.0.0", - "uuid": "^8.0.0" + "uuid": "^9.0.0" } } From 10aeaaa3c3251a1ad15fb594bdcfe3c22e820eb5 Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Tue, 20 Sep 2022 13:22:24 -0700 Subject: [PATCH 128/131] test(samples): disable samples tests for this repository (#440) Fixes #430. --- .../snippets/test/containerAnalysis.test.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 56fd62134fc..fc5c04e86c2 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -41,7 +41,7 @@ let projectId; let formattedParent; let formattedNoteName; -describe('Note tests', () => { +describe.skip('Note tests', () => { before(async () => { // define projectId and related vars projectId = await client.getProjectId(); @@ -236,19 +236,17 @@ describe('Note tests', () => { ); assert.include(output, 'Occurrence deleted:'); }); - it('should delete note', function () { - this.retries(3); + + it('should delete note', () => { const output = execSync(`node deleteNote.js "${projectId}" "${noteId}" `); assert.include(output, `Note ${formattedNoteName} deleted.`); // Sometimes the delete note test is failing with the error: // Error: 5 NOT_FOUND: note with ID "test-note-${uuid}" for project // ${projectId} does not exist. - // Attempting to work around this issue by retrying a few times. - // DO NOT MERGE. If this works, we should submit an upstream bug. }); }); -describe('polling', () => { +describe.skip('polling', () => { before(async () => { // define project id and related vars projectId = await client.getProjectId(); @@ -303,7 +301,7 @@ describe('polling', () => { }); }); -describe('pubsub', () => { +describe.skip('pubsub', () => { before(async () => { // define project id and related vars projectId = await client.getProjectId(); From 58e082420156ab9333be65a75cc1e9345e9fc866 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 22 Sep 2022 14:14:45 -0700 Subject: [PATCH 129/131] chore(main): release 4.3.0 (#429) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(main): release 4.3.0 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index e25c415178c..0f9e72010b2 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^4.2.0", + "@google-cloud/containeranalysis": "^4.3.0", "@google-cloud/pubsub": "^3.0.0", "p-retry": "^4.1.0" }, From 2cdca7caf55df623859bc58c64389d2ad6a5e934 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Mon, 17 Oct 2022 19:08:24 +0000 Subject: [PATCH 130/131] chore(main): release 4.4.0 (#444) :robot: I have created a release *beep* *boop* --- ## [4.4.0](https://togithub.com/googleapis/nodejs-containeranalysis/compare/v4.3.0...v4.4.0) (2022-10-06) ### Features * Add new analysis status and cvss version fields ([#443](https://togithub.com/googleapis/nodejs-containeranalysis/issues/443)) ([2b4db8e](https://togithub.com/googleapis/nodejs-containeranalysis/commit/2b4db8ee9859823e32de8256853429adf88cf207)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index 0f9e72010b2..be8d730b480 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^4.3.0", + "@google-cloud/containeranalysis": "^4.4.0", "@google-cloud/pubsub": "^3.0.0", "p-retry": "^4.1.0" }, From 8967a8d1ccb2e51ffc9c6a0d3e1d3d80c474c0fe Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Fri, 11 Nov 2022 01:14:17 +0000 Subject: [PATCH 131/131] chore(main): release 4.4.1 (#449) :robot: I have created a release *beep* *boop* --- ## [4.4.1](https://togithub.com/googleapis/nodejs-containeranalysis/compare/v4.4.0...v4.4.1) (2022-11-10) ### Bug Fixes * **deps:** Use google-gax v3.5.2 ([#447](https://togithub.com/googleapis/nodejs-containeranalysis/issues/447)) ([c0631d5](https://togithub.com/googleapis/nodejs-containeranalysis/commit/c0631d54928b9fe6df493f79883341e66d19f0ca)) * Regenerated protos JS and TS definitions ([#451](https://togithub.com/googleapis/nodejs-containeranalysis/issues/451)) ([9710e71](https://togithub.com/googleapis/nodejs-containeranalysis/commit/9710e715ef10471e536b5329e1e71ffe8b7265ec)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please). --- container-analysis/snippets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-analysis/snippets/package.json b/container-analysis/snippets/package.json index be8d730b480..89bb3bcdfdc 100644 --- a/container-analysis/snippets/package.json +++ b/container-analysis/snippets/package.json @@ -14,7 +14,7 @@ "test": "mocha --timeout 100000 test/**.test.js" }, "dependencies": { - "@google-cloud/containeranalysis": "^4.4.0", + "@google-cloud/containeranalysis": "^4.4.1", "@google-cloud/pubsub": "^3.0.0", "p-retry": "^4.1.0" },