MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

security-center/snippets/v2/updateSource.js:18–111  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16
17// Demonstrates how to update a source.
18async function main() {
19 // [START securitycenter_update_source_v2]
20 // npm install '@google-cloud/security-center'
21 const {SecurityCenterClient} = require('@google-cloud/security-center').v2;
22
23 const client = new SecurityCenterClient();
24
25 // TODO(developer): Update the following for your own environment.
26 const organizationId = '1081635000895';
27 const location = 'global';
28
29 async function createSampleFinding() {
30 const uuid = require('uuid');
31
32 const [source] = await client.createSource({
33 source: {
34 displayName: 'Customized Display Name V2',
35 description: 'A new custom source that does X',
36 },
37 parent: client.organizationPath(organizationId),
38 });
39
40 const sourceId = source.name.split('/')[3];
41
42 // Resource name of the new finding's parent. Examples:
43 // - `organizations/[organization_id]/sources/[source_id]`
44 // - `organizations/[organization_id]/sources/[source_id]/locations/[location_id]`
45 const parent = `organizations/${organizationId}/sources/${sourceId}/locations/${location}`;
46
47 // The resource this finding applied to. The Cloud Security Command Center UI can link the
48 // findings for a resource to the corresponding asset of a resource if there are matches.
49 const resourceName = `//cloudresourcemanager.googleapis.com/organizations/${organizationId}`;
50
51 // Unique identifier provided by the client within the parent scope.
52 // It must be alphanumeric and less than or equal to 32 characters and
53 // greater than 0 characters in length.
54 const findingId = uuid.v4().replace(/-/g, '');
55
56 // Get the current timestamp.
57 const eventDate = new Date();
58
59 // Finding category.
60 const category = 'MEDIUM_RISK_ONE';
61
62 // Build the finding request object.
63 const createFindingRequest = {
64 parent: parent,
65 findingId: findingId,
66 finding: {
67 resourceName,
68 category,
69 state: 'ACTIVE',
70 // The time associated with discovering the issue.
71 eventTime: {
72 seconds: Math.floor(eventDate.getTime() / 1000),
73 nanos: (eventDate.getTime() % 1000) * 1e6,
74 },
75 },

Callers 1

updateSource.jsFile · 0.70

Calls 2

createSampleFindingFunction · 0.70
updateSourceFunction · 0.70

Tested by

no test coverage detected