| 19 | // description: fetching an instance of Grafeas and creating a note. |
| 20 | // usage: node quickstart.js "project-id" "note-id" |
| 21 | async function main( |
| 22 | projectId = 'your-project-id', // Your GCP Project ID |
| 23 | noteId = 'my-note-id' // Id of the note |
| 24 | ) { |
| 25 | // [START containeranalysis_quickstart] |
| 26 | /** |
| 27 | * TODO(developer): Uncomment these variables before running the sample |
| 28 | */ |
| 29 | // const projectId = 'your-project-id', // Your GCP Project ID |
| 30 | // const noteId = 'my-note-id' // Id of the note |
| 31 | |
| 32 | // Import the library and create a client |
| 33 | const {ContainerAnalysisClient} = require('@google-cloud/containeranalysis'); |
| 34 | const client = new ContainerAnalysisClient(); |
| 35 | // Fetch an instance of a Grafeas client: |
| 36 | // see: https://googleapis.dev/nodejs/grafeas/latest |
| 37 | const grafeasClient = client.getGrafeasClient(); |
| 38 | |
| 39 | // Construct request |
| 40 | // Associate the Note with a metadata type |
| 41 | // https://cloud.google.com/container-registry/docs/container-analysis#supported_metadata_types |
| 42 | // Here, we use the type "vulnerabiltity" |
| 43 | const formattedParent = grafeasClient.projectPath(projectId); |
| 44 | |
| 45 | // Creates and returns a new Note |
| 46 | const [note] = await grafeasClient.createNote({ |
| 47 | parent: formattedParent, |
| 48 | noteId: noteId, |
| 49 | note: { |
| 50 | vulnerability: { |
| 51 | details: [ |
| 52 | { |
| 53 | affectedCpeUri: 'foo.uri', |
| 54 | affectedPackage: 'foo', |
| 55 | minAffectedVersion: { |
| 56 | kind: 'MINIMUM', |
| 57 | }, |
| 58 | fixedVersion: { |
| 59 | kind: 'MAXIMUM', |
| 60 | }, |
| 61 | }, |
| 62 | ], |
| 63 | }, |
| 64 | }, |
| 65 | }); |
| 66 | |
| 67 | console.log(`Note ${note.name} created.`); |
| 68 | // [END containeranalysis_quickstart] |
| 69 | } |
| 70 | |
| 71 | main(...process.argv.slice(2)); |