diff --git a/security-center/snippets/system-test/v2/findings.test.js b/security-center/snippets/system-test/v2/findings.test.js index 4d6e4d9f7e..c9646744ce 100644 --- a/security-center/snippets/system-test/v2/findings.test.js +++ b/security-center/snippets/system-test/v2/findings.test.js @@ -14,134 +14,145 @@ * limitations under the License. */ -const { SecurityCenterClient } = require('@google-cloud/security-center').v2; -const { assert } = require('chai'); -const { execSync } = require('child_process'); -const exec = cmd => execSync(cmd, { encoding: 'utf8' }); -const { describe, it, before } = require('mocha'); +const {SecurityCenterClient} = require('@google-cloud/security-center').v2; +const {assert} = require('chai'); +const {execSync} = require('child_process'); +const exec = cmd => execSync(cmd, {encoding: 'utf8'}); +const {describe, it, before} = require('mocha'); const uuid = require('uuid'); const organizationId = process.env['GCLOUD_ORGANIZATION']; const location = 'global'; describe('Client with sources and findings V2', async () => { - let data; - before(async () => { - // Creates a new client. - const client = new SecurityCenterClient(); - - const [projectId] = await client.getProjectId(); - const [source] = await client - .createSource({ - source: { - displayName: 'Customized Display Name V2', - description: 'A new custom source that does X', - }, - parent: client.organizationPath(organizationId), - }) - .catch(error => console.error(error)); - - const sourceId = source.name.split('/')[3]; - const parent = `organizations/${organizationId}/sources/${sourceId}/locations/${location}`; - const resourceName = `//cloudresourcemanager.googleapis.com/organizations/${organizationId}`; - const findingId = uuid.v4().replace(/-/g, ''); - - const eventTime = new Date(); - const createFindingTemplate = { - parent: parent, - findingId: findingId, - finding: { - state: 'ACTIVE', - // Resource the finding is associated with. This is an - // example any resource identifier can be used. - resourceName: resourceName, - // A free-form category. - category: 'MEDIUM_RISK_ONE', - // The time associated with discovering the issue. - eventTime: { - seconds: Math.floor(eventTime.getTime() / 1000), - nanos: (eventTime.getTime() % 1000) * 1e6, - }, - }, - }; - - const [finding] = await client.createFinding(createFindingTemplate); - createFindingTemplate.findingId = 'untouchedFindingId'; - createFindingTemplate.finding.category = 'XSS'; - const [untouchedFinding] = await client - .createFinding(createFindingTemplate) - .catch(error => console.error(error)); - - data = { - orgId: organizationId, - sourceId: sourceId, - sourceName: source.name, - findingId: findingId, - projectId: projectId, - findingName: finding.name, - untouchedFindingName: untouchedFinding.name, - }; - console.log('my data %j', data); - }); - - it('client can create source V2', () => { - const output = exec(`node v2/createSource.js ${data.orgId}`); - assert.match(output, new RegExp(data.orgId)); - assert.match(output, /New Source created/); - assert.notMatch(output, /undefined/); - }); - - it('client can create a finding V2', () => { - const output = exec(`node v2/createFinding.js ${data.orgId} ${data.sourceId}`); - assert.match(output, new RegExp(data.sourceName)); - assert.match(output, /New finding created/); - assert.notMatch(output, /undefined/); - }); - - it('client can list all findings V2', () => { - const output = exec(`node v2/listAllFindings.js ${data.orgId}`); - assert.match(output, new RegExp(data.findingName)); - assert.match(output, new RegExp(data.untouchedFindingName)); - assert.notMatch(output, /undefined/); - }); - - it('client can list only some findings V2', () => { - const output = exec(`node v2/listFilteredFindings.js ${data.orgId}`); - assert.match(output, new RegExp(data.findingName)); - assert.notMatch(output, new RegExp(data.untouchedFindingName)); - assert.notMatch(output, /undefined/); - }); - - it('client can mute a findings V2', () => { - const output = exec(`node v2/setMuteFinding.js ${data.orgId} ${data.sourceId} ${data.findingId}`); - assert.match(output, new RegExp('MUTED')); - assert.match(output, /Mute value for the finding/); - assert.notMatch(output, /undefined/); - }); - - it('client can un mute a findings V2', () => { - const output = exec(`node v2/setUnmuteFinding.js ${data.orgId} ${data.sourceId} ${data.findingId}`); - assert.match(output, new RegExp('UNMUTED')); - assert.match(output, /Unmute a finding/); - assert.notMatch(output, /undefined/); - }); - - it('client can group all findings V2', () => { - const output = exec(`node v2/groupFindings.js ${data.orgId} ${data.sourceId}`); - assert.isAtLeast(4, output.match(/\n/g).length + 1); - assert.notMatch(output, /undefined/); - }); - - it('client group filtered findings V2', () => { - const output = exec(`node v2/groupFindingsWithFilter.js ${data.orgId} ${data.sourceId}`); - assert.isAtLeast(4, output.match(/\n/g).length + 1); - assert.notMatch(output, /undefined/); - }); - - it('client can bulk a mute a findings V2', () => { - const output = exec(`node v2/bulkMuteFindings.js ${data.orgId} ${data.projectId}`); - assert.match(output, /Bulk mute findings completed successfully/); - assert.notMatch(output, /undefined/); - }); - -}); \ No newline at end of file + let data; + before(async () => { + // Creates a new client. + const client = new SecurityCenterClient(); + + const [projectId] = await client.getProjectId(); + const [source] = await client + .createSource({ + source: { + displayName: 'Customized Display Name V2', + description: 'A new custom source that does X', + }, + parent: client.organizationPath(organizationId), + }) + .catch(error => console.error(error)); + + const sourceId = source.name.split('/')[3]; + const parent = `organizations/${organizationId}/sources/${sourceId}/locations/${location}`; + const resourceName = `//cloudresourcemanager.googleapis.com/organizations/${organizationId}`; + const findingId = uuid.v4().replace(/-/g, ''); + + const eventTime = new Date(); + const createFindingTemplate = { + parent: parent, + findingId: findingId, + finding: { + state: 'ACTIVE', + // Resource the finding is associated with. This is an + // example any resource identifier can be used. + resourceName: resourceName, + // A free-form category. + category: 'MEDIUM_RISK_ONE', + // The time associated with discovering the issue. + eventTime: { + seconds: Math.floor(eventTime.getTime() / 1000), + nanos: (eventTime.getTime() % 1000) * 1e6, + }, + }, + }; + + const [finding] = await client.createFinding(createFindingTemplate); + createFindingTemplate.findingId = 'untouchedFindingId'; + createFindingTemplate.finding.category = 'XSS'; + const [untouchedFinding] = await client + .createFinding(createFindingTemplate) + .catch(error => console.error(error)); + + data = { + orgId: organizationId, + sourceId: sourceId, + sourceName: source.name, + findingId: findingId, + projectId: projectId, + findingName: finding.name, + untouchedFindingName: untouchedFinding.name, + }; + console.log('my data %j', data); + }); + + it('client can create source V2', () => { + const output = exec(`node v2/createSource.js ${data.orgId}`); + assert.match(output, new RegExp(data.orgId)); + assert.match(output, /New Source created/); + assert.notMatch(output, /undefined/); + }); + + it('client can create a finding V2', () => { + const output = exec( + `node v2/createFinding.js ${data.orgId} ${data.sourceId}` + ); + assert.match(output, new RegExp(data.sourceName)); + assert.match(output, /New finding created/); + assert.notMatch(output, /undefined/); + }); + + it('client can list all findings V2', () => { + const output = exec(`node v2/listAllFindings.js ${data.orgId}`); + assert.match(output, new RegExp(data.findingName)); + assert.match(output, new RegExp(data.untouchedFindingName)); + assert.notMatch(output, /undefined/); + }); + + it('client can list only some findings V2', () => { + const output = exec(`node v2/listFilteredFindings.js ${data.orgId}`); + assert.match(output, new RegExp(data.findingName)); + assert.notMatch(output, new RegExp(data.untouchedFindingName)); + assert.notMatch(output, /undefined/); + }); + + it('client can mute a findings V2', () => { + const output = exec( + `node v2/setMuteFinding.js ${data.orgId} ${data.sourceId} ${data.findingId}` + ); + assert.match(output, new RegExp('MUTED')); + assert.match(output, /Mute value for the finding/); + assert.notMatch(output, /undefined/); + }); + + it('client can un mute a findings V2', () => { + const output = exec( + `node v2/setUnmuteFinding.js ${data.orgId} ${data.sourceId} ${data.findingId}` + ); + assert.match(output, new RegExp('UNMUTED')); + assert.match(output, /Unmute a finding/); + assert.notMatch(output, /undefined/); + }); + + it('client can group all findings V2', () => { + const output = exec( + `node v2/groupFindings.js ${data.orgId} ${data.sourceId}` + ); + assert.isAtLeast(4, output.match(/\n/g).length + 1); + assert.notMatch(output, /undefined/); + }); + + it('client group filtered findings V2', () => { + const output = exec( + `node v2/groupFindingsWithFilter.js ${data.orgId} ${data.sourceId}` + ); + assert.isAtLeast(4, output.match(/\n/g).length + 1); + assert.notMatch(output, /undefined/); + }); + + it('client can bulk a mute a findings V2', () => { + const output = exec( + `node v2/bulkMuteFindings.js ${data.orgId} ${data.projectId}` + ); + assert.match(output, /Bulk mute findings completed successfully/); + assert.notMatch(output, /undefined/); + }); +}); diff --git a/security-center/snippets/system-test/v2/muterule.test.js b/security-center/snippets/system-test/v2/muterule.test.js index 0346612166..df161a5d45 100644 --- a/security-center/snippets/system-test/v2/muterule.test.js +++ b/security-center/snippets/system-test/v2/muterule.test.js @@ -14,91 +14,98 @@ * limitations under the License. */ -const { SecurityCenterClient } = require('@google-cloud/security-center').v2; -const { assert } = require('chai'); -const { execSync } = require('child_process'); -const exec = cmd => execSync(cmd, { encoding: 'utf8' }); -const { describe, it, before } = require('mocha'); +const {SecurityCenterClient} = require('@google-cloud/security-center').v2; +const {assert} = require('chai'); +const {execSync} = require('child_process'); +const exec = cmd => execSync(cmd, {encoding: 'utf8'}); +const {describe, it, before} = require('mocha'); const uuidv1 = require('uuid').v1; const organizationId = process.env['GCLOUD_ORGANIZATION']; const location = 'global'; describe('Client with mute rule V2', async () => { - let data; - before(async () => { - // Creates a new client. - const client = new SecurityCenterClient(); - - // Build the create mute rule request. - const muteId = 'muteid-'+uuidv1().replace(/-/g, '').substring(0, 20); - const createMuteRuleRequest = { - parent:`organizations/${organizationId}/locations/${location}`, - muteConfigId:muteId, - muteConfig:{ - name:`organizations/${organizationId}/locations/${location}/muteConfigs/${muteId}`, - description: "Mute low-medium IAM grants excluding 'compute' resources", - filter: - "severity=\"LOW\" OR severity=\"MEDIUM\" AND " + - "category=\"Persistence: IAM Anomalous Grant\" AND " + - "-resource.type:\"compute\"", - type: "STATIC", - }, - }; + let data; + before(async () => { + // Creates a new client. + const client = new SecurityCenterClient(); - const [muteConfigResponse] = await client - .createMuteConfig(createMuteRuleRequest) - .catch(error => console.error(error)); + // Build the create mute rule request. + const muteId = 'muteid-' + uuidv1().replace(/-/g, '').substring(0, 20); + const createMuteRuleRequest = { + parent: `organizations/${organizationId}/locations/${location}`, + muteConfigId: muteId, + muteConfig: { + name: `organizations/${organizationId}/locations/${location}/muteConfigs/${muteId}`, + description: "Mute low-medium IAM grants excluding 'compute' resources", + filter: + 'severity="LOW" OR severity="MEDIUM" AND ' + + 'category="Persistence: IAM Anomalous Grant" AND ' + + '-resource.type:"compute"', + type: 'STATIC', + }, + }; - const muteConfigId = muteConfigResponse.name.split('/')[5]; + const [muteConfigResponse] = await client + .createMuteConfig(createMuteRuleRequest) + .catch(error => console.error(error)); - data = { - orgId: organizationId, - muteConfigId: muteConfigId, - muteConfigName: muteConfigResponse.name, - untouchedMuteConfigName: "", - }; - console.log('my data %j', data); - }); + const muteConfigId = muteConfigResponse.name.split('/')[5]; - after(async () => { - const client = new SecurityCenterClient(); + data = { + orgId: organizationId, + muteConfigId: muteConfigId, + muteConfigName: muteConfigResponse.name, + untouchedMuteConfigName: '', + }; + console.log('my data %j', data); + }); - const name = `organizations/${organizationId}/locations/${location}/muteConfigs/${data.muteConfigId}`; - await client.deleteMuteConfig({name: name}).catch(error => console.error(error)); - }); + after(async () => { + const client = new SecurityCenterClient(); - it('client can create mute rule V2', () => { - const output = exec(`node v2/createMuteRule.js ${data.orgId}`); - assert.match(output, new RegExp(data.orgId)); - assert.match(output, /New mute rule config created/); - assert.notMatch(output, /undefined/); - }); + const name = `organizations/${organizationId}/locations/${location}/muteConfigs/${data.muteConfigId}`; + await client + .deleteMuteConfig({name: name}) + .catch(error => console.error(error)); + }); - it('client can list all mute rules V2', () => { - const output = exec(`node v2/listAllMuteRules.js ${data.orgId}`); - assert.match(output, new RegExp(data.orgId)); - assert.match(output, new RegExp(data.untouchedMuteConfigName)); - assert.notMatch(output, /undefined/); - }); + it('client can create mute rule V2', () => { + const output = exec(`node v2/createMuteRule.js ${data.orgId}`); + assert.match(output, new RegExp(data.orgId)); + assert.match(output, /New mute rule config created/); + assert.notMatch(output, /undefined/); + }); - it('client can get a mute rule V2', () => { - const output = exec(`node v2/getMuteRule.js ${data.orgId} ${data.muteConfigId}`); - assert.match(output, new RegExp(data.muteConfigName)); - assert.match(output, /Get mute rule config/); - assert.notMatch(output, /undefined/); - }); + it('client can list all mute rules V2', () => { + const output = exec(`node v2/listAllMuteRules.js ${data.orgId}`); + assert.match(output, new RegExp(data.orgId)); + assert.match(output, new RegExp(data.untouchedMuteConfigName)); + assert.notMatch(output, /undefined/); + }); - it('client can update a mute rule V2', () => { - const output = exec(`node v2/updateMuteRule.js ${data.orgId} ${data.muteConfigId}`); - assert.match(output, /Update mute rule config/); - assert.notMatch(output, /undefined/); - }); + it('client can get a mute rule V2', () => { + const output = exec( + `node v2/getMuteRule.js ${data.orgId} ${data.muteConfigId}` + ); + assert.match(output, new RegExp(data.muteConfigName)); + assert.match(output, /Get mute rule config/); + assert.notMatch(output, /undefined/); + }); - it('client can delete a mute rule V2', () => { - const output = exec(`node v2/deleteMuteRule.js ${data.orgId} ${data.muteConfigId}`); - assert.match(output, /Delete mute rule config/); - assert.notMatch(output, /undefined/); - }); + it('client can update a mute rule V2', () => { + const output = exec( + `node v2/updateMuteRule.js ${data.orgId} ${data.muteConfigId}` + ); + assert.match(output, /Update mute rule config/); + assert.notMatch(output, /undefined/); + }); -}); \ No newline at end of file + it('client can delete a mute rule V2', () => { + const output = exec( + `node v2/deleteMuteRule.js ${data.orgId} ${data.muteConfigId}` + ); + assert.match(output, /Delete mute rule config/); + assert.notMatch(output, /undefined/); + }); +}); diff --git a/security-center/snippets/v2/bulkMuteFindings.js b/security-center/snippets/v2/bulkMuteFindings.js index 00a0c5cb1c..81b570fd9d 100644 --- a/security-center/snippets/v2/bulkMuteFindings.js +++ b/security-center/snippets/v2/bulkMuteFindings.js @@ -23,12 +23,12 @@ function main(organizationId, projectId, location = 'global') { // [START securitycenter_bulk_mute_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Create a Security Center client const client = new SecurityCenterClient(); - /** + /** * Required. The parent, at which bulk action needs to be applied. If no * location is specified, findings are updated in global. The following list * shows some examples: @@ -49,19 +49,18 @@ function main(organizationId, projectId, location = 'global') { // Build the request. const bulkMuteFindingRequest = { parent, - filter + filter, }; async function callBulkMuteFindings() { - // Call the API. const [operation] = await client.bulkMuteFindings(bulkMuteFindingRequest); const [response] = await operation.promise(); console.log('Bulk mute findings completed successfully: %j', response); } - + callBulkMuteFindings(); // [END securitycenter_bulk_mute_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/createFinding.js b/security-center/snippets/v2/createFinding.js index 19332b23d1..2c004fa613 100644 --- a/security-center/snippets/v2/createFinding.js +++ b/security-center/snippets/v2/createFinding.js @@ -18,10 +18,15 @@ /** * Demonstrates how to create a new security finding in CSCC. */ -function main(organizationId, sourceId, location = 'global', category = 'LOW_RISK_ONE') { +function main( + organizationId, + sourceId, + location = 'global', + category = 'LOW_RISK_ONE' +) { // [START securitycenter_create_finding_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; const uuid = require('uuid'); // Create a Security Center client @@ -72,14 +77,13 @@ function main(organizationId, sourceId, location = 'global', category = 'LOW_RIS }; async function createFinding() { - // Call the API. const [finding] = await client.createFinding(createFindingRequest); console.log('New finding created: %j', finding); } - + createFinding(); // [END securitycenter_create_finding_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/createMuteRule.js b/security-center/snippets/v2/createMuteRule.js index c54023cd01..4c6391b643 100644 --- a/security-center/snippets/v2/createMuteRule.js +++ b/security-center/snippets/v2/createMuteRule.js @@ -21,7 +21,7 @@ function main(organizationId, location = 'global') { // [START securitycenter_create_mute_config_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; const uuidv1 = require('uuid').v1; // Create a Security Center client @@ -41,19 +41,19 @@ function main(organizationId, location = 'global') { * with a letter, must end with either a letter or a number, and must be 63 * characters or less. */ - const muteConfigId = 'muteid-'+uuidv1().replace(/-/g, '').substring(0, 20); + const muteConfigId = 'muteid-' + uuidv1().replace(/-/g, '').substring(0, 20); const name = `${parent}/muteConfigs/${muteConfigId}`; // Build the muteRuleConfig object. const muteConfig = { - name:name, + name: name, description: "Mute low-medium IAM grants excluding 'compute' resources", filter: - "severity=\"LOW\" OR severity=\"MEDIUM\" AND " + - "category=\"Persistence: IAM Anomalous Grant\" AND " + - "-resource.type:\"compute\"", - type: "STATIC", + 'severity="LOW" OR severity="MEDIUM" AND ' + + 'category="Persistence: IAM Anomalous Grant" AND ' + + '-resource.type:"compute"', + type: 'STATIC', }; // Build the create mute rule request. @@ -64,14 +64,13 @@ function main(organizationId, location = 'global') { }; async function createMuteRuleConfig() { - // Call the API. const [muteConfig] = await client.createMuteConfig(createMuteRuleRequest); console.log('New mute rule config created: %j', muteConfig); } - + createMuteRuleConfig(); // [END securitycenter_create_mute_config_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/createSource.js b/security-center/snippets/v2/createSource.js index 28a7278054..5d53bfe114 100644 --- a/security-center/snippets/v2/createSource.js +++ b/security-center/snippets/v2/createSource.js @@ -21,15 +21,15 @@ function main(organizationId) { // [START securitycenter_create_source_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Create a new Security Center client const client = new SecurityCenterClient(); /** - * Required. Resource name of the new source's parent. Its format should be - * "organizations/[organization_id]". - */ + * Required. Resource name of the new source's parent. Its format should be + * "organizations/[organization_id]". + */ const parent = client.organizationPath(organizationId); // Build the source object. @@ -47,7 +47,6 @@ function main(organizationId) { // The source is not visible in the Security Command Center dashboard // until it generates findings. async function createSource() { - // Call the API const [source] = await client.createSource(createSourceRequest); console.log('New Source created: %j', source); @@ -57,4 +56,4 @@ function main(organizationId) { // [END securitycenter_create_source_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/deleteMuteRule.js b/security-center/snippets/v2/deleteMuteRule.js index 0f4b75273f..42823d6457 100644 --- a/security-center/snippets/v2/deleteMuteRule.js +++ b/security-center/snippets/v2/deleteMuteRule.js @@ -21,12 +21,12 @@ function main(organizationId, muteConfigId, location = 'global') { // [START securitycenter_delete_mute_config_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Create a Security Center client const client = new SecurityCenterClient(); - /** + /** * Required. Name of the mute config to delete. The following list shows some * examples of the format: * `organizations/{organization}/muteConfigs/{config_id}` @@ -44,14 +44,13 @@ function main(organizationId, muteConfigId, location = 'global') { }; async function deleteMuteConfig() { - // Call the API. const [muteConfig] = await client.deleteMuteConfig(deleteMuteRuleRequest); console.log('Delete mute rule config: %j', muteConfig); } - + deleteMuteConfig(); // [END securitycenter_delete_mute_config_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/getMuteRule.js b/security-center/snippets/v2/getMuteRule.js index 87d461f9eb..7fbd011044 100644 --- a/security-center/snippets/v2/getMuteRule.js +++ b/security-center/snippets/v2/getMuteRule.js @@ -21,7 +21,7 @@ function main(organizationId, muteConfigId) { // [START securitycenter_create_mute_config_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Create a Security Center client const client = new SecurityCenterClient(); @@ -44,14 +44,13 @@ function main(organizationId, muteConfigId) { }; async function createMuteRuleConfig() { - // Call the API. const [muteConfig] = await client.getMuteConfig(getMuteRuleRequest); console.log('Get mute rule config: %j', muteConfig); } - + createMuteRuleConfig(); // [END securitycenter_create_mute_config_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/groupFindings.js b/security-center/snippets/v2/groupFindings.js index 9a41a12271..7b4e1aa040 100644 --- a/security-center/snippets/v2/groupFindings.js +++ b/security-center/snippets/v2/groupFindings.js @@ -22,11 +22,11 @@ function main(organizationId, sourceId, location = 'global') { // [START securitycenter_group_all_findings_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Creates a new client. const client = new SecurityCenterClient(); - /** + /** * Required. Name of the source to groupBy. If no location is specified, * finding is assumed to be in global. * The following list shows some examples: @@ -45,12 +45,12 @@ function main(organizationId, sourceId, location = 'global') { * `projects/{project_id}/sources/-` * `projects/{project_id}/sources/-/locations/[location_id]` */ - const parent = `organizations/${organizationId}/sources/${sourceId}/locations/${location}`; + const parent = `organizations/${organizationId}/sources/${sourceId}/locations/${location}`; + + // Supported grouping properties: resource_name/ category/ state/ parent/ severity. + // Multiple properties should be separated by comma. + const groupBy = 'category,state'; - // Supported grouping properties: resource_name/ category/ state/ parent/ severity. - // Multiple properties should be separated by comma. - const groupBy = 'category,state'; - // Build the group findings request. const groupFindingsRequest = { parent, @@ -58,15 +58,14 @@ function main(organizationId, sourceId, location = 'global') { }; async function groupFindings() { - // Call the API. const iterable = client.groupFindingsAsync(groupFindingsRequest); let count = 0; - + for await (const response of iterable) { - console.log( - `${++count} ${response.properties.category} ${response.properties.state}` - ); + console.log( + `${++count} ${response.properties.category} ${response.properties.state}` + ); } } @@ -74,4 +73,4 @@ function main(organizationId, sourceId, location = 'global') { // [END securitycenter_group_all_findings_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/groupFindingsWithFilter.js b/security-center/snippets/v2/groupFindingsWithFilter.js index 74f25bc383..b9dcf1d49e 100644 --- a/security-center/snippets/v2/groupFindingsWithFilter.js +++ b/security-center/snippets/v2/groupFindingsWithFilter.js @@ -22,11 +22,11 @@ function main(organizationId, sourceId, location = 'global') { // [START securitycenter_group_filtered_findings_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Creates a new client. const client = new SecurityCenterClient(); - /** + /** * Required. Name of the source to groupBy. If no location is specified, * finding is assumed to be in global. * The following list shows some examples: @@ -45,14 +45,14 @@ function main(organizationId, sourceId, location = 'global') { * `projects/{project_id}/sources/-` * `projects/{project_id}/sources/-/locations/[location_id]` */ - const parent = `organizations/${organizationId}/sources/${sourceId}/locations/${location}`; + const parent = `organizations/${organizationId}/sources/${sourceId}/locations/${location}`; - // Supported grouping properties: resource_name/ category/ state/ parent/ severity. - // Multiple properties should be separated by comma. - const groupBy = 'category,state'; + // Supported grouping properties: resource_name/ category/ state/ parent/ severity. + // Multiple properties should be separated by comma. + const groupBy = 'category,state'; - // Group all findings of category "MEDIUM_RISK_ONE". - const filter = "category=\"MEDIUM_RISK_ONE\""; + // Group all findings of category "MEDIUM_RISK_ONE". + const filter = 'category="MEDIUM_RISK_ONE"'; // Build the group findings request. const groupFilteredFindingsRequest = { @@ -62,15 +62,14 @@ function main(organizationId, sourceId, location = 'global') { }; async function groupFilteredFindings() { - // Call the API. const iterable = client.groupFindingsAsync(groupFilteredFindingsRequest); let count = 0; - + for await (const response of iterable) { - console.log( - `${++count} ${response.properties.category} ${response.properties.state}` - ); + console.log( + `${++count} ${response.properties.category} ${response.properties.state}` + ); } } @@ -78,4 +77,4 @@ function main(organizationId, sourceId, location = 'global') { // [END securitycenter_group_filtered_findings_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/listAllFindings.js b/security-center/snippets/v2/listAllFindings.js index bed0aeb5fc..b339e2aec0 100644 --- a/security-center/snippets/v2/listAllFindings.js +++ b/security-center/snippets/v2/listAllFindings.js @@ -21,11 +21,11 @@ function main(organizationId, location = 'global') { // [START securitycenter_list_all_findings_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Creates a new client. const client = new SecurityCenterClient(); - /** + /** * Required. Name of the source the findings belong to. If no location is * specified, the default is global. The following list shows some examples: * `organizations/[organization_id]/sources/[source_id]/locations/[location_id]` @@ -34,7 +34,7 @@ function main(organizationId, location = 'global') { * `projects/[project_id]/sources/[source_id]` * `projects/[project_id]/sources/[source_id]/locations/[location_id]` */ - const parent = `organizations/${organizationId}/sources/-/locations/${location}`; + const parent = `organizations/${organizationId}/sources/-/locations/${location}`; // Build the list findings request. const listFindingsRequest = { @@ -42,15 +42,14 @@ function main(organizationId, location = 'global') { }; async function listAllFindings() { - // Call the API. const iterable = client.listFindingsAsync(listFindingsRequest); let count = 0; - + for await (const response of iterable) { - console.log( - `${++count} ${response.finding.name} ${response.finding.resourceName}` - ); + console.log( + `${++count} ${response.finding.name} ${response.finding.resourceName}` + ); } } @@ -58,4 +57,4 @@ function main(organizationId, location = 'global') { // [END securitycenter_list_all_findings_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/listAllMuteRules.js b/security-center/snippets/v2/listAllMuteRules.js index 3af454be5f..f9c702a793 100644 --- a/security-center/snippets/v2/listAllMuteRules.js +++ b/security-center/snippets/v2/listAllMuteRules.js @@ -21,11 +21,11 @@ function main(organizationId, location = 'global') { // [START securitycenter_list_mute_configs_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Creates a new client. const client = new SecurityCenterClient(); - /** + /** * Required. The parent, which owns the collection of mute configs. Its format * is "organizations/[organization_id]", "folders/[folder_id]", * "projects/[project_id]", @@ -33,7 +33,7 @@ function main(organizationId, location = 'global') { * "folders/[folder_id]/locations/[location_id]", * "projects/[project_id]/locations/[location_id]". */ - const parent = `organizations/${organizationId}/locations/${location}`; + const parent = `organizations/${organizationId}/locations/${location}`; // Build the request. const listMuteRulesRequest = { @@ -41,15 +41,12 @@ function main(organizationId, location = 'global') { }; async function listAllMuteRules() { - // Call the API. const iterable = client.listMuteConfigsAsync(listMuteRulesRequest); let count = 0; - + for await (const response of iterable) { - console.log( - `${++count} ${response.name}` - ); + console.log(`${++count} ${response.name}`); } } @@ -57,4 +54,4 @@ function main(organizationId, location = 'global') { // [END securitycenter_list_mute_configs_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/listFilteredFindings.js b/security-center/snippets/v2/listFilteredFindings.js index cd7d27b5ca..181fe7a9b8 100644 --- a/security-center/snippets/v2/listFilteredFindings.js +++ b/security-center/snippets/v2/listFilteredFindings.js @@ -21,12 +21,12 @@ function main(organizationId, location = 'global') { // [START securitycenter_list_filtered_findings_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Creates a new client. const client = new SecurityCenterClient(); - - /** + + /** * Required. Name of the source to groupBy. If no location is specified, * finding is assumed to be in global. * The following list shows some examples: @@ -38,7 +38,7 @@ function main(organizationId, location = 'global') { * `projects/[project_id]/sources/[source_id]/locations/[location_id]` * To groupBy across all sources provide a source_id of `-`. */ - const parent = `organizations/${organizationId}/sources/-/locations/${location}`; + const parent = `organizations/${organizationId}/sources/-/locations/${location}`; // Listing all findings of category "MEDIUM_RISK_ONE". const filter = 'category="MEDIUM_RISK_ONE"'; @@ -50,19 +50,18 @@ function main(organizationId, location = 'global') { }; async function listFilteredFindings() { - - // Call the API. + // Call the API. const iterable = client.listFindingsAsync(listFilteredFindingsRequest); let count = 0; for await (const response of iterable) { - console.log( - `${++count} ${response.finding.name} ${response.finding.resourceName}` - ); + console.log( + `${++count} ${response.finding.name} ${response.finding.resourceName}` + ); } } listFilteredFindings(); // [END securitycenter_list_filtered_findings_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/setMuteFinding.js b/security-center/snippets/v2/setMuteFinding.js index c5288a64a1..e33d2a7ef8 100644 --- a/security-center/snippets/v2/setMuteFinding.js +++ b/security-center/snippets/v2/setMuteFinding.js @@ -23,7 +23,7 @@ function main(organizationId, sourceId, findingId, location = 'global') { // [START securitycenter_set_mute_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Create a Security Center client const client = new SecurityCenterClient(); @@ -45,18 +45,17 @@ function main(organizationId, sourceId, findingId, location = 'global') { // Build the request. const setMuteRequest = { name, - mute: 'MUTED' + mute: 'MUTED', }; async function setMute() { - // Call the API. const [finding] = await client.setMute(setMuteRequest); console.log('Mute value for the finding: %j', finding.mute); } - + setMute(); // [END securitycenter_set_mute_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/setUnmuteFinding.js b/security-center/snippets/v2/setUnmuteFinding.js index 4db20f9f2b..25137e30f7 100644 --- a/security-center/snippets/v2/setUnmuteFinding.js +++ b/security-center/snippets/v2/setUnmuteFinding.js @@ -23,7 +23,7 @@ function main(organizationId, sourceId, findingId, location = 'global') { // [START securitycenter_set_unmute_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Create a Security Center client const client = new SecurityCenterClient(); @@ -45,18 +45,17 @@ function main(organizationId, sourceId, findingId, location = 'global') { // Build the request. const setMuteRequest = { name, - mute: 'UNMUTED' + mute: 'UNMUTED', }; async function setUnmute() { - // Call the API. const [finding] = await client.setMute(setMuteRequest); console.log('Unmute a finding: %j', finding.mute); } - + setUnmute(); // [END securitycenter_set_unmute_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2)); diff --git a/security-center/snippets/v2/updateMuteRule.js b/security-center/snippets/v2/updateMuteRule.js index b4d270bf0d..d642ee01d2 100644 --- a/security-center/snippets/v2/updateMuteRule.js +++ b/security-center/snippets/v2/updateMuteRule.js @@ -18,10 +18,10 @@ /** * Updates an existing mute configuration. */ -function main(organizationId, muteConfigId ,location = 'global',) { +function main(organizationId, muteConfigId, location = 'global') { // [START securitycenter_update_mute_config_v2] // Imports the Google Cloud client library. - const { SecurityCenterClient } = require('@google-cloud/security-center').v2; + const {SecurityCenterClient} = require('@google-cloud/security-center').v2; // Create a Security Center client const client = new SecurityCenterClient(); @@ -30,7 +30,7 @@ function main(organizationId, muteConfigId ,location = 'global',) { /** * The list of fields to be updated. * If empty all mutable fields will be updated. - */ + */ const updateMask = { paths: ['description'], }; @@ -38,29 +38,28 @@ function main(organizationId, muteConfigId ,location = 'global',) { // Build the mute rule object. const muteConfig = { name, - description: "Updated mute config description", + description: 'Updated mute config description', updateMask, filter: - "severity=\"LOW\" OR severity=\"MEDIUM\" AND " + - "category=\"Persistence: IAM Anomalous Grant\" AND " + - "-resource.type:\"compute\"", - type: "STATIC", + 'severity="LOW" OR severity="MEDIUM" AND ' + + 'category="Persistence: IAM Anomalous Grant" AND ' + + '-resource.type:"compute"', + type: 'STATIC', }; // Build the update mute rule request. const updateMuteConfigRequest = { - muteConfig + muteConfig, }; async function updateMuteConfig() { - // Call the API. const [muteConfig] = await client.updateMuteConfig(updateMuteConfigRequest); console.log('Update mute rule config: %j', muteConfig); } - + updateMuteConfig(); // [END securitycenter_update_mute_config_v2] } -main(...process.argv.slice(2)); \ No newline at end of file +main(...process.argv.slice(2));