diff --git a/.repo-metadata.json b/.repo-metadata.json
index 6c70828..d2246f8 100644
--- a/.repo-metadata.json
+++ b/.repo-metadata.json
@@ -4,10 +4,10 @@
"product_documentation": "https://cloud.google.com/container-registry/docs/container-analysis",
"client_documentation": "https://googleapis.dev/nodejs/containeranalysis/latest",
"issue_tracker": "",
- "release_level": "alpha",
+ "release_level": "ga",
"language": "nodejs",
"repo": "googleapis/nodejs-containeranalysis",
"distribution_name": "@google-cloud/containeranalysis",
"api_id": "containeranalysis.googleapis.com",
"requires_billing": true
-}
\ No newline at end of file
+}
diff --git a/README.md b/README.md
index 05852e0..925448e 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
# [Google Container Analysis: Node.js Client](https://github.com/googleapis/nodejs-containeranalysis)
-[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style=flat)](https://cloud.google.com/terms/launch-stages)
+[![release level](https://img.shields.io/badge/release%20level-general%20availability%20%28GA%29-brightgreen.svg?style=flat)](https://cloud.google.com/terms/launch-stages)
[![npm version](https://img.shields.io/npm/v/@google-cloud/containeranalysis.svg)](https://www.npmjs.org/package/@google-cloud/containeranalysis)
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-containeranalysis/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-containeranalysis)
@@ -55,12 +55,48 @@ npm install @google-cloud/containeranalysis
### Using the client library
```javascript
-async function quickstart() {
- // Imports the @google-cloud/containeranalysis client library
- const client = require('@google-cloud/containeranalysis');
- console.log(client);
-}
-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
+
+ // 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();
+
+ // 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.`);
```
@@ -98,11 +134,13 @@ also contains samples.
This library follows [Semantic Versioning](http://semver.org/).
+This library is considered to be **General Availability (GA)**. This means it
+is stable; the code surface will not change in backwards-incompatible ways
+unless absolutely necessary (e.g. because of critical security issues) or with
+an extensive deprecation period. Issues and requests against **GA** libraries
+are addressed with the highest priority.
-This library is considered to be in **alpha**. This means it is still a
-work-in-progress and under active development. Any release is subject to
-backwards-incompatible changes at any time.
diff --git a/package.json b/package.json
index bb1ad0b..38fd83a 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,7 @@
"Container Analysis API"
],
"dependencies": {
+ "@google-cloud/grafeas": "^2.0.0",
"google-gax": "^1.0.0"
},
"devDependencies": {
diff --git a/samples/README.md b/samples/README.md
index 29ed0cb..4616a15 100644
--- a/samples/README.md
+++ b/samples/README.md
@@ -266,6 +266,8 @@ __Usage:__
### Quickstart
+fetching an instance of Grafeas and creating a note.
+
View the [source code](https://github.com/googleapis/nodejs-containeranalysis/blob/master/samples/quickstart.js).
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-containeranalysis&page=editor&open_in_editor=samples/quickstart.js,samples/README.md)
@@ -273,7 +275,7 @@ View the [source code](https://github.com/googleapis/nodejs-containeranalysis/bl
__Usage:__
-`node quickstart.js`
+`node quickstart.js "project-id" "note-id"`
-----
diff --git a/samples/createNote.js b/samples/createNote.js
index 64c7ca3..c9edf2a 100644
--- a/samples/createNote.js
+++ b/samples/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/samples/quickstart.js b/samples/quickstart.js
index 47df69f..27d50bf 100644
--- a/samples/quickstart.js
+++ b/samples/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/samples/test/tests.js b/samples/test/tests.js
deleted file mode 100644
index 2d84838..0000000
--- a/samples/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);
- });
-});
diff --git a/src/v1/container_analysis_client.js b/src/v1/container_analysis_client.js
index e3589ec..e0c1ee0 100644
--- a/src/v1/container_analysis_client.js
+++ b/src/v1/container_analysis_client.js
@@ -17,6 +17,7 @@
const gapicConfig = require('./container_analysis_client_config.json');
const gax = require('google-gax');
const path = require('path');
+const {GrafeasClient} = require('@google-cloud/grafeas');
const VERSION = require('../../package.json').version;
@@ -155,10 +156,14 @@ class ContainerAnalysisClient {
throw err;
}
),
+
defaults[methodName],
null
);
}
+ // expose the fully hydrated options, for the benefit of
+ // the client.getGrafeas() method.
+ this.opts = opts;
}
/**
@@ -447,6 +452,19 @@ class ContainerAnalysisClient {
matchNoteFromNoteName(noteName) {
return this._pathTemplates.notePathTemplate.match(noteName).note;
}
+
+ /**
+ * Returns an instance of a @google-cloud/grafeas client, configured to
+ * connect to Google Cloud's Container Analysis API. For documentation
+ * on this client, see:
+ * https://googleapis.dev/nodejs/grafeas/latest/index.html
+ *
+ * @returns {GrafeasClient} - An instance of a Grafeas client.
+ *
+ */
+ getGrafeasClient() {
+ return new GrafeasClient(this.opts);
+ }
}
module.exports = ContainerAnalysisClient;
diff --git a/synth.metadata b/synth.metadata
index 7d08617..fdc81fa 100644
--- a/synth.metadata
+++ b/synth.metadata
@@ -1,5 +1,5 @@
{
- "updateTime": "2019-06-19T11:09:27.543558Z",
+ "updateTime": "2019-06-19T22:36:26.600770Z",
"sources": [
{
"generator": {
@@ -12,8 +12,8 @@
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
- "sha": "ac13167e31a20314aa05cc9911c95df250880485",
- "internalRef": "253867808"
+ "sha": "45e125f9e30dc5d45b52752b3ab78dd4f6084f2d",
+ "internalRef": "254026509"
}
},
{
diff --git a/synth.py b/synth.py
index 7fdf1b4..231a332 100644
--- a/synth.py
+++ b/synth.py
@@ -34,13 +34,61 @@
templates = common_templates.node_library()
s.copy(templates)
+# fix the URL of grafeas.io (this is already fixed upstream).
s.replace('src/v1beta1/*.js',
'cloud.google.comgrafeas.io',
'grafeas.io')
-s.replace('src/v1/*.js',
- 'cloud.google.comgrafeas.io',
- 'grafeas.io')
+# perform surgery inserting the Grafeas client.
+s.replace("src/v1/container_analysis_client.js",
+r"""const path = require\('path'\);
+""",
+r"""const path = require('path');
+const { GrafeasClient } = require('@google-cloud/grafeas');
+""")
+
+s.replace("src/v1/container_analysis_client.js",
+r""" defaults\[methodName\],
+ null
+ \);
+ }
+ }""",
+r"""
+ defaults[methodName],
+ null
+ );
+ }
+ // expose the fully hydrated options, for the benefit of
+ // the client.getGrafeas() method.
+ this.opts = opts;
+ }
+""")
+
+s.replace("src/v1/container_analysis_client.js",
+r""" matchNoteFromNoteName\(noteName\) {
+ return this\._pathTemplates\.notePathTemplate
+ \.match\(noteName\)
+ \.note;
+ }
+""",
+r""" matchNoteFromNoteName(noteName) {
+ return this._pathTemplates.notePathTemplate.match(noteName).note;
+ }
+
+
+ /**
+ * Returns an instance of a @google-cloud/grafeas client, configured to
+ * connect to Google Cloud's Container Analysis API. For documentation
+ * on this client, see:
+ * https://googleapis.dev/nodejs/grafeas/latest/index.html
+ *
+ * @returns {GrafeasClient} - An instance of a Grafeas client.
+ *
+ */
+ getGrafeasClient() {
+ return new GrafeasClient(this.opts);
+ }
+""")
# Node.js specific cleanup
subprocess.run(['npm', 'install'])