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