From 3983ed943bbd2556510437fd55290a6e12367e7c Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 16 Jul 2019 15:24:50 -0700 Subject: [PATCH] feat!: adds findingSecurityMarksPathTemplate (#122) --- .../google-cloud-securitycenter/src/index.js | 48 +- .../src/v1beta1/security_center_client.js | 58 + .../synth.metadata | 10 +- packages/google-cloud-securitycenter/synth.py | 25 +- .../test/gapic-v1beta1.js | 1307 ----------------- 5 files changed, 107 insertions(+), 1341 deletions(-) delete mode 100644 packages/google-cloud-securitycenter/test/gapic-v1beta1.js diff --git a/packages/google-cloud-securitycenter/src/index.js b/packages/google-cloud-securitycenter/src/index.js index 5242419795b..d56ca644030 100644 --- a/packages/google-cloud-securitycenter/src/index.js +++ b/packages/google-cloud-securitycenter/src/index.js @@ -1,4 +1,4 @@ -// Copyright 2018 Google LLC +// 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. @@ -18,68 +18,69 @@ /** * @namespace google.type */ - /** - * @namespace google.type + * @namespace google.longrunning */ - /** - * @namespace google.cloud + * @namespace google.protobuf */ /** - * @namespace google.cloud.securitycenter + * @namespace google.type */ /** - * @namespace google.cloud.securitycenter.v1beta1 + * @namespace google.rpc */ /** * @namespace google.cloud.securitycenter.v1 */ +/** + * @namespace google.cloud.securitycenter.v1beta1 + */ /** * @namespace google.iam.v1 */ + /** - * @namespace google.protobuf + * @namespace google.cloud */ /** - * @namespace google.longrunning + * @namespace google.cloud.security-center */ /** - * @namespace google.rpc + * @namespace google.cloud.security-center.v1 */ 'use strict'; // Import the clients for each version supported by this package. const gapic = Object.freeze({ - v1beta1: require('./v1beta1'), v1: require('./v1'), }); /** - * The `securitycenter` package has the following named exports: + * The `@google-cloud/security-center` package has the following named exports: * * - `SecurityCenterClient` - Reference to - * {@link v1beta1.SecurityCenterClient} - * - `v1beta1` - This is used for selecting or pinning a + * {@link v1.SecurityCenterClient} + * - `v1` - This is used for selecting or pinning a * particular backend service version. It exports: * - `SecurityCenterClient` - Reference to - * {@link v1beta1.SecurityCenterClient} + * {@link v1.SecurityCenterClient} * * @module {object} @google-cloud/security-center - * @alias nodejs-securitycenter + * @alias nodejs-security-center * * @example Install the client library with npm: * npm install --save @google-cloud/security-center * * @example Import the client library: - * const securitycenter = require('@google-cloud/security-center'); + * const security-center = require('@google-cloud/security-center'); * * @example Create a client that uses Application Default Credentials (ADC): - * const client = new securitycenter.SecurityCenterClient(); + * const client = new security-center.SecurityCenterClient(); * * @example Create a client with explicit credentials: - * const client = new securitycenter.SecurityCenterClient({ + * const client = new security-center.SecurityCenterClient({ * projectId: 'your-project-id', * keyFilename: '/path/to/keyfile.json', * }); @@ -88,17 +89,10 @@ const gapic = Object.freeze({ /** * @type {object} * @property {constructor} SecurityCenterClient - * Reference to {@link v1beta1.SecurityCenterClient} + * Reference to {@link v1.SecurityCenterClient} */ module.exports = gapic.v1; -/** - * @type {object} - * @property {constructor} SecurityCenterClient - * Reference to {@link v1beta1.SecurityCenterClient} - */ -module.exports.v1beta1 = gapic.v1beta1; - /** * @type {object} * @property {constructor} SecurityCenterClient diff --git a/packages/google-cloud-securitycenter/src/v1beta1/security_center_client.js b/packages/google-cloud-securitycenter/src/v1beta1/security_center_client.js index 463fb2f9252..ba92f1bfe89 100644 --- a/packages/google-cloud-securitycenter/src/v1beta1/security_center_client.js +++ b/packages/google-cloud-securitycenter/src/v1beta1/security_center_client.js @@ -107,6 +107,9 @@ class SecurityCenterClient { findingPathTemplate: new gax.PathTemplate( 'organizations/{organization}/sources/{source}/findings/{finding}' ), + findingSecurityMarksPathTemplate: new gax.PathTemplate( + 'organizations/{organization}/sources/{source}/findings/{finding}/securityMarks' + ), organizationPathTemplate: new gax.PathTemplate( 'organizations/{organization}' ), @@ -2511,6 +2514,22 @@ class SecurityCenterClient { }); } + /** + * Return a fully-qualified finding_security_marks resource name string. + * + * @param {String} organization + * @param {String} source + * @param {String} finding + * @returns {String} + */ + findingSecurityMarksPath(organization, source, finding) { + return this._pathTemplates.findingSecurityMarksPathTemplate.render({ + organization: organization, + source: source, + finding: finding, + }); + } + /** * Return a fully-qualified organization resource name string. * @@ -2609,6 +2628,45 @@ class SecurityCenterClient { return this._pathTemplates.findingPathTemplate.match(findingName).finding; } + /** + * Parse the findingSecurityMarksName from a finding_security_marks resource. + * + * @param {String} findingSecurityMarksName + * A fully-qualified path representing a finding_security_marks resources. + * @returns {String} - A string representing the organization. + */ + matchOrganizationFromFindingSecurityMarksName(findingSecurityMarksName) { + return this._pathTemplates.findingSecurityMarksPathTemplate.match( + findingSecurityMarksName + ).organization; + } + + /** + * Parse the findingSecurityMarksName from a finding_security_marks resource. + * + * @param {String} findingSecurityMarksName + * A fully-qualified path representing a finding_security_marks resources. + * @returns {String} - A string representing the source. + */ + matchSourceFromFindingSecurityMarksName(findingSecurityMarksName) { + return this._pathTemplates.findingSecurityMarksPathTemplate.match( + findingSecurityMarksName + ).source; + } + + /** + * Parse the findingSecurityMarksName from a finding_security_marks resource. + * + * @param {String} findingSecurityMarksName + * A fully-qualified path representing a finding_security_marks resources. + * @returns {String} - A string representing the finding. + */ + matchFindingFromFindingSecurityMarksName(findingSecurityMarksName) { + return this._pathTemplates.findingSecurityMarksPathTemplate.match( + findingSecurityMarksName + ).finding; + } + /** * Parse the organizationName from a organization resource. * diff --git a/packages/google-cloud-securitycenter/synth.metadata b/packages/google-cloud-securitycenter/synth.metadata index 50da33d4d9a..c0090af385d 100644 --- a/packages/google-cloud-securitycenter/synth.metadata +++ b/packages/google-cloud-securitycenter/synth.metadata @@ -1,19 +1,19 @@ { - "updateTime": "2019-07-03T11:19:04.252185Z", + "updateTime": "2019-07-16T21:57:58.657213Z", "sources": [ { "generator": { "name": "artman", - "version": "0.29.3", - "dockerImage": "googleapis/artman@sha256:8900f94a81adaab0238965aa8a7b3648791f4f3a95ee65adc6a56cfcc3753101" + "version": "0.30.0", + "dockerImage": "googleapis/artman@sha256:a44d9fb6fe826ca0ea7d6f7be23c596346bed82ee513a0043f3c068279717439" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "69916b6ffbb7717fa009033351777d0c9909fb79", - "internalRef": "256241904" + "sha": "96d5a05171e99b6a2378eb0a3423f765351878b7", + "internalRef": "258424288" } }, { diff --git a/packages/google-cloud-securitycenter/synth.py b/packages/google-cloud-securitycenter/synth.py index 6f8afcee202..2faecd05b3d 100644 --- a/packages/google-cloud-securitycenter/synth.py +++ b/packages/google-cloud-securitycenter/synth.py @@ -24,12 +24,12 @@ versions = ['v1beta1', 'v1'] for version in versions: library = gapic.node_library('securitycenter', version) - s.copy(library, excludes=['src/index.js', 'README.md', 'package.json', '.kokoro/sample-test.sh']) + s.copy(library, excludes=['README.md', 'package.json', 'test/gapic-v1beta1.js']) # Copy common templates common_templates = gcp.CommonTemplates() templates = common_templates.node_library() -s.copy(templates) +s.copy(templates, excludes=['.kokoro/samples-test.sh']) s.replace('src/v1*/doc/google/cloud/securitycenter/v1*/doc_source.js', r"\[\\p\{L\}\\p\{N\}\]\(https:\/\/cloud\.google\.com\{\\p\{L\}\\p\{N\}_- \]\{0\,30\}\[\\p\{L\}\\p\{N\}\]\)\?", @@ -47,6 +47,27 @@ /** * @namespace google.type */ +/** + * @namespace google.longrunning + */ +/** + * @namespace google.protobuf + */ +/** + * @namespace google.type + */ +/** + * @namespace google.rpc + */ +/** + * @namespace google.cloud.securitycenter.v1 + */ +/** + * @namespace google.cloud.securitycenter.v1beta1 + */ +/** + * @namespace google.iam.v1 + */ """) # [START fix-dead-link] diff --git a/packages/google-cloud-securitycenter/test/gapic-v1beta1.js b/packages/google-cloud-securitycenter/test/gapic-v1beta1.js deleted file mode 100644 index 71139ae8301..00000000000 --- a/packages/google-cloud-securitycenter/test/gapic-v1beta1.js +++ /dev/null @@ -1,1307 +0,0 @@ -// 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('assert'); - -const securityCenterModule = require('../src'); - -const FAKE_STATUS_CODE = 1; -const error = new Error(); -error.code = FAKE_STATUS_CODE; - -describe('SecurityCenterClient', () => { - it('has servicePath', () => { - const servicePath = - securityCenterModule.v1beta1.SecurityCenterClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = - securityCenterModule.v1beta1.SecurityCenterClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = securityCenterModule.v1beta1.SecurityCenterClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no options', () => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient(); - assert(client); - }); - - describe('createSource', () => { - it('invokes createSource without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.organizationPath('[ORGANIZATION]'); - const source = {}; - const request = { - parent: formattedParent, - source: source, - }; - - // Mock response - const name = 'name3373707'; - const displayName = 'displayName1615086568'; - const description = 'description-1724546052'; - const expectedResponse = { - name: name, - displayName: displayName, - description: description, - }; - - // Mock Grpc layer - client._innerApiCalls.createSource = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.createSource(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createSource with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.organizationPath('[ORGANIZATION]'); - const source = {}; - const request = { - parent: formattedParent, - source: source, - }; - - // Mock Grpc layer - client._innerApiCalls.createSource = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.createSource(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('createFinding', () => { - it('invokes createFinding without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const findingId = 'findingId728776081'; - const finding = {}; - const request = { - parent: formattedParent, - findingId: findingId, - finding: finding, - }; - - // Mock response - const name = 'name3373707'; - const parent2 = 'parent21175163357'; - const resourceName = 'resourceName979421212'; - const category = 'category50511102'; - const externalUri = 'externalUri-1385596168'; - const expectedResponse = { - name: name, - parent: parent2, - resourceName: resourceName, - category: category, - externalUri: externalUri, - }; - - // Mock Grpc layer - client._innerApiCalls.createFinding = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.createFinding(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createFinding with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const findingId = 'findingId728776081'; - const finding = {}; - const request = { - parent: formattedParent, - findingId: findingId, - finding: finding, - }; - - // Mock Grpc layer - client._innerApiCalls.createFinding = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.createFinding(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('getIamPolicy', () => { - it('invokes getIamPolicy without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedResource = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const request = { - resource: formattedResource, - }; - - // Mock response - const version = 351608024; - const etag = '21'; - const expectedResponse = { - version: version, - etag: etag, - }; - - // Mock Grpc layer - client._innerApiCalls.getIamPolicy = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.getIamPolicy(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getIamPolicy with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedResource = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const request = { - resource: formattedResource, - }; - - // Mock Grpc layer - client._innerApiCalls.getIamPolicy = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.getIamPolicy(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('getOrganizationSettings', () => { - it('invokes getOrganizationSettings without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedName = client.organizationSettingsPath('[ORGANIZATION]'); - const request = { - name: formattedName, - }; - - // Mock response - const name2 = 'name2-1052831874'; - const enableAssetDiscovery = false; - const expectedResponse = { - name: name2, - enableAssetDiscovery: enableAssetDiscovery, - }; - - // Mock Grpc layer - client._innerApiCalls.getOrganizationSettings = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.getOrganizationSettings(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getOrganizationSettings with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedName = client.organizationSettingsPath('[ORGANIZATION]'); - const request = { - name: formattedName, - }; - - // Mock Grpc layer - client._innerApiCalls.getOrganizationSettings = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.getOrganizationSettings(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('getSource', () => { - it('invokes getSource without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedName = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const request = { - name: formattedName, - }; - - // Mock response - const name2 = 'name2-1052831874'; - const displayName = 'displayName1615086568'; - const description = 'description-1724546052'; - const expectedResponse = { - name: name2, - displayName: displayName, - description: description, - }; - - // Mock Grpc layer - client._innerApiCalls.getSource = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.getSource(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getSource with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedName = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const request = { - name: formattedName, - }; - - // Mock Grpc layer - client._innerApiCalls.getSource = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.getSource(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('groupAssets', () => { - it('invokes groupAssets without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.organizationPath('[ORGANIZATION]'); - const groupBy = 'groupBy506361367'; - const request = { - parent: formattedParent, - groupBy: groupBy, - }; - - // Mock response - const nextPageToken = ''; - const groupByResultsElement = {}; - const groupByResults = [groupByResultsElement]; - const expectedResponse = { - nextPageToken: nextPageToken, - groupByResults: groupByResults, - }; - - // Mock Grpc layer - client._innerApiCalls.groupAssets = ( - actualRequest, - options, - callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse.groupByResults); - }; - - client.groupAssets(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse.groupByResults); - done(); - }); - }); - - it('invokes groupAssets with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.organizationPath('[ORGANIZATION]'); - const groupBy = 'groupBy506361367'; - const request = { - parent: formattedParent, - groupBy: groupBy, - }; - - // Mock Grpc layer - client._innerApiCalls.groupAssets = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.groupAssets(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('groupFindings', () => { - it('invokes groupFindings without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const groupBy = 'groupBy506361367'; - const request = { - parent: formattedParent, - groupBy: groupBy, - }; - - // Mock response - const nextPageToken = ''; - const groupByResultsElement = {}; - const groupByResults = [groupByResultsElement]; - const expectedResponse = { - nextPageToken: nextPageToken, - groupByResults: groupByResults, - }; - - // Mock Grpc layer - client._innerApiCalls.groupFindings = ( - actualRequest, - options, - callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse.groupByResults); - }; - - client.groupFindings(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse.groupByResults); - done(); - }); - }); - - it('invokes groupFindings with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const groupBy = 'groupBy506361367'; - const request = { - parent: formattedParent, - groupBy: groupBy, - }; - - // Mock Grpc layer - client._innerApiCalls.groupFindings = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.groupFindings(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('listAssets', () => { - it('invokes listAssets without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.organizationPath('[ORGANIZATION]'); - const request = { - parent: formattedParent, - }; - - // Mock response - const nextPageToken = ''; - const totalSize = 705419236; - const listAssetsResultsElement = {}; - const listAssetsResults = [listAssetsResultsElement]; - const expectedResponse = { - nextPageToken: nextPageToken, - totalSize: totalSize, - listAssetsResults: listAssetsResults, - }; - - // Mock Grpc layer - client._innerApiCalls.listAssets = (actualRequest, options, callback) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse.listAssetsResults); - }; - - client.listAssets(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse.listAssetsResults); - done(); - }); - }); - - it('invokes listAssets with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.organizationPath('[ORGANIZATION]'); - const request = { - parent: formattedParent, - }; - - // Mock Grpc layer - client._innerApiCalls.listAssets = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.listAssets(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('listFindings', () => { - it('invokes listFindings without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const request = { - parent: formattedParent, - }; - - // Mock response - const nextPageToken = ''; - const totalSize = 705419236; - const findingsElement = {}; - const findings = [findingsElement]; - const expectedResponse = { - nextPageToken: nextPageToken, - totalSize: totalSize, - findings: findings, - }; - - // Mock Grpc layer - client._innerApiCalls.listFindings = ( - actualRequest, - options, - callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse.findings); - }; - - client.listFindings(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse.findings); - done(); - }); - }); - - it('invokes listFindings with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const request = { - parent: formattedParent, - }; - - // Mock Grpc layer - client._innerApiCalls.listFindings = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.listFindings(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('listSources', () => { - it('invokes listSources without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.organizationPath('[ORGANIZATION]'); - const request = { - parent: formattedParent, - }; - - // Mock response - const nextPageToken = ''; - const sourcesElement = {}; - const sources = [sourcesElement]; - const expectedResponse = { - nextPageToken: nextPageToken, - sources: sources, - }; - - // Mock Grpc layer - client._innerApiCalls.listSources = ( - actualRequest, - options, - callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse.sources); - }; - - client.listSources(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse.sources); - done(); - }); - }); - - it('invokes listSources with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.organizationPath('[ORGANIZATION]'); - const request = { - parent: formattedParent, - }; - - // Mock Grpc layer - client._innerApiCalls.listSources = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.listSources(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('runAssetDiscovery', function() { - it('invokes runAssetDiscovery without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.organizationPath('[ORGANIZATION]'); - const request = { - parent: formattedParent, - }; - - // Mock response - const expectedResponse = {}; - - // Mock Grpc layer - client._innerApiCalls.runAssetDiscovery = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - - client - .runAssetDiscovery(request) - .then(responses => { - const operation = responses[0]; - return operation.promise(); - }) - .then(responses => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch(err => { - done(err); - }); - }); - - it('invokes runAssetDiscovery with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedParent = client.organizationPath('[ORGANIZATION]'); - const request = { - parent: formattedParent, - }; - - // Mock Grpc layer - client._innerApiCalls.runAssetDiscovery = mockLongRunningGrpcMethod( - request, - null, - error - ); - - client - .runAssetDiscovery(request) - .then(responses => { - const operation = responses[0]; - return operation.promise(); - }) - .then(() => { - assert.fail(); - }) - .catch(err => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - - it('has longrunning decoder functions', () => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert( - client._descriptors.longrunning.runAssetDiscovery - .responseDecoder instanceof Function - ); - assert( - client._descriptors.longrunning.runAssetDiscovery - .metadataDecoder instanceof Function - ); - }); - }); - - describe('setFindingState', () => { - it('invokes setFindingState without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedName = client.findingPath( - '[ORGANIZATION]', - '[SOURCE]', - '[FINDING]' - ); - const state = 'STATE_UNSPECIFIED'; - const startTime = {}; - const request = { - name: formattedName, - state: state, - startTime: startTime, - }; - - // Mock response - const name2 = 'name2-1052831874'; - const parent = 'parent-995424086'; - const resourceName = 'resourceName979421212'; - const category = 'category50511102'; - const externalUri = 'externalUri-1385596168'; - const expectedResponse = { - name: name2, - parent: parent, - resourceName: resourceName, - category: category, - externalUri: externalUri, - }; - - // Mock Grpc layer - client._innerApiCalls.setFindingState = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.setFindingState(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes setFindingState with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedName = client.findingPath( - '[ORGANIZATION]', - '[SOURCE]', - '[FINDING]' - ); - const state = 'STATE_UNSPECIFIED'; - const startTime = {}; - const request = { - name: formattedName, - state: state, - startTime: startTime, - }; - - // Mock Grpc layer - client._innerApiCalls.setFindingState = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.setFindingState(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('setIamPolicy', () => { - it('invokes setIamPolicy without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedResource = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const policy = {}; - const request = { - resource: formattedResource, - policy: policy, - }; - - // Mock response - const version = 351608024; - const etag = '21'; - const expectedResponse = { - version: version, - etag: etag, - }; - - // Mock Grpc layer - client._innerApiCalls.setIamPolicy = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.setIamPolicy(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes setIamPolicy with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedResource = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const policy = {}; - const request = { - resource: formattedResource, - policy: policy, - }; - - // Mock Grpc layer - client._innerApiCalls.setIamPolicy = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.setIamPolicy(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('testIamPermissions', () => { - it('invokes testIamPermissions without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedResource = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const permissions = []; - const request = { - resource: formattedResource, - permissions: permissions, - }; - - // Mock response - const expectedResponse = {}; - - // Mock Grpc layer - client._innerApiCalls.testIamPermissions = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.testIamPermissions(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes testIamPermissions with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const formattedResource = client.sourcePath('[ORGANIZATION]', '[SOURCE]'); - const permissions = []; - const request = { - resource: formattedResource, - permissions: permissions, - }; - - // Mock Grpc layer - client._innerApiCalls.testIamPermissions = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.testIamPermissions(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('updateFinding', () => { - it('invokes updateFinding without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const finding = {}; - const request = { - finding: finding, - }; - - // Mock response - const name = 'name3373707'; - const parent = 'parent-995424086'; - const resourceName = 'resourceName979421212'; - const category = 'category50511102'; - const externalUri = 'externalUri-1385596168'; - const expectedResponse = { - name: name, - parent: parent, - resourceName: resourceName, - category: category, - externalUri: externalUri, - }; - - // Mock Grpc layer - client._innerApiCalls.updateFinding = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.updateFinding(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateFinding with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const finding = {}; - const request = { - finding: finding, - }; - - // Mock Grpc layer - client._innerApiCalls.updateFinding = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.updateFinding(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('updateOrganizationSettings', () => { - it('invokes updateOrganizationSettings without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const organizationSettings = {}; - const request = { - organizationSettings: organizationSettings, - }; - - // Mock response - const name = 'name3373707'; - const enableAssetDiscovery = false; - const expectedResponse = { - name: name, - enableAssetDiscovery: enableAssetDiscovery, - }; - - // Mock Grpc layer - client._innerApiCalls.updateOrganizationSettings = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.updateOrganizationSettings(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateOrganizationSettings with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const organizationSettings = {}; - const request = { - organizationSettings: organizationSettings, - }; - - // Mock Grpc layer - client._innerApiCalls.updateOrganizationSettings = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.updateOrganizationSettings(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('updateSource', () => { - it('invokes updateSource without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const source = {}; - const request = { - source: source, - }; - - // Mock response - const name = 'name3373707'; - const displayName = 'displayName1615086568'; - const description = 'description-1724546052'; - const expectedResponse = { - name: name, - displayName: displayName, - description: description, - }; - - // Mock Grpc layer - client._innerApiCalls.updateSource = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.updateSource(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateSource with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const source = {}; - const request = { - source: source, - }; - - // Mock Grpc layer - client._innerApiCalls.updateSource = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.updateSource(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - - describe('updateSecurityMarks', () => { - it('invokes updateSecurityMarks without error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const securityMarks = {}; - const request = { - securityMarks: securityMarks, - }; - - // Mock response - const name = 'name3373707'; - const expectedResponse = { - name: name, - }; - - // Mock Grpc layer - client._innerApiCalls.updateSecurityMarks = mockSimpleGrpcMethod( - request, - expectedResponse - ); - - client.updateSecurityMarks(request, (err, response) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateSecurityMarks with error', done => { - const client = new securityCenterModule.v1beta1.SecurityCenterClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - - // Mock request - const securityMarks = {}; - const request = { - securityMarks: securityMarks, - }; - - // Mock Grpc layer - client._innerApiCalls.updateSecurityMarks = mockSimpleGrpcMethod( - request, - null, - error - ); - - client.updateSecurityMarks(request, (err, response) => { - assert(err instanceof Error); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); -}); - -function mockSimpleGrpcMethod(expectedRequest, response, error) { - return function(actualRequest, options, callback) { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} - -function mockLongRunningGrpcMethod(expectedRequest, response, error) { - return request => { - assert.deepStrictEqual(request, expectedRequest); - const mockOperation = { - promise: function() { - return new Promise((resolve, reject) => { - if (error) { - reject(error); - } else { - resolve([response]); - } - }); - }, - }; - return Promise.resolve([mockOperation]); - }; -}