Skip to content

Commit 4f7d26b

Browse files
authored
Merge branch 'main' into hivanalejandro-migrate-region-step1-392698287
2 parents 17a70c7 + f44cde8 commit 4f7d26b

10 files changed

+536
-6
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
'use strict';
17+
18+
/**
19+
* Demonstrates how to create a new event threat detection custom module
20+
*/
21+
function main(organizationId, customModuleDisplayName, location = 'global') {
22+
// [START securitycenter_create_event_threat_detection_custom_module]
23+
// Imports the Google cloud client library.
24+
const {SecurityCenterManagementClient} =
25+
require('@google-cloud/securitycentermanagement').v1;
26+
27+
// Create a Security Center Management client
28+
const client = new SecurityCenterManagementClient();
29+
30+
/**
31+
* Required. The name of the parent resource of the create event threat detection module. Its
32+
* format is "organizations/[organization_id]/locations/[location_id]",
33+
* "folders/[folder_id]/locations/[location_id]", or
34+
* "projects/[project_id]/locations/[location_id]".
35+
*/
36+
//TODO(developer): Update the following references for your own environment before running the sample.
37+
// const organizationId = 'YOUR_ORGANIZATION_ID';
38+
// const location = 'LOCATION_ID';
39+
const parent = `organizations/${organizationId}/locations/${location}`;
40+
41+
// define the event threat detection custom module configuration, update the EnablementState
42+
// below
43+
const eventThreatDetectionCustomModule = {
44+
displayName: customModuleDisplayName,
45+
enablementState: 'ENABLED',
46+
type: 'CONFIGURABLE_BAD_IP',
47+
config: prepareConfigDetails(),
48+
};
49+
50+
// Build the request.
51+
const createEventThreatDetectionCustomModuleRequest = {
52+
parent: parent,
53+
eventThreatDetectionCustomModule: eventThreatDetectionCustomModule,
54+
};
55+
56+
async function createEventThreatDetectionCustomModule() {
57+
// Call the API.
58+
const [response] = await client.createEventThreatDetectionCustomModule(
59+
createEventThreatDetectionCustomModuleRequest
60+
);
61+
console.log('EventThreatDetectionCustomModule created : %j', response);
62+
}
63+
64+
function prepareConfigDetails() {
65+
// define the metadata and other config parameters severity, description,
66+
// recommendation and ips below
67+
const config = {
68+
fields: {
69+
metadata: {
70+
structValue: {
71+
fields: {
72+
severity: {stringValue: 'LOW'},
73+
description: {stringValue: 'Flagged by Cymbal as malicious'},
74+
recommendation: {
75+
stringValue: 'Contact the owner of the relevant project.',
76+
},
77+
},
78+
},
79+
},
80+
ips: {
81+
listValue: {
82+
values: [{stringValue: '192.0.2.1'}, {stringValue: '192.0.2.0/24'}],
83+
},
84+
},
85+
},
86+
};
87+
return config;
88+
}
89+
90+
createEventThreatDetectionCustomModule();
91+
// [END securitycenter_create_event_threat_detection_custom_module]
92+
}
93+
94+
main(...process.argv.slice(2));
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
'use strict';
17+
18+
/**
19+
* Delete an existing event threat detection custom module
20+
*/
21+
function main(organizationId, customModuleId, location = 'global') {
22+
// [START securitycenter_delete_event_threat_detection_custom_module]
23+
// Imports the Google Cloud client library.
24+
const {SecurityCenterManagementClient} =
25+
require('@google-cloud/securitycentermanagement').v1;
26+
27+
// Create a Security Center Management client
28+
const client = new SecurityCenterManagementClient();
29+
30+
/*
31+
* Required. Resource name of event threat detection module.
32+
* Its format is
33+
* `organizations/[organization_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]`
34+
* `folders/[folder_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]`
35+
* `projects/[project_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]`
36+
*/
37+
// TODO(developer): Update the following references for your own environment before running the sample.
38+
// const organizationId = 'YOUR_ORGANIZATION_ID';
39+
// const location = 'LOCATION_ID';
40+
// const customModuleId = 'CUSTOM_MODULE_ID';
41+
const name = `organizations/${organizationId}/locations/${location}/eventThreatDetectionCustomModules/${customModuleId}`;
42+
43+
// Build the request.
44+
const deleteEventThreatDetectionCustomModuleRequest = {
45+
name: name,
46+
};
47+
48+
async function deleteEventThreatDetectionCustomModule() {
49+
// Call the API.
50+
const [response] = await client.deleteEventThreatDetectionCustomModule(
51+
deleteEventThreatDetectionCustomModuleRequest
52+
);
53+
console.log(
54+
'EventThreatDetectionCustomModule deleted successfully: %j',
55+
response
56+
);
57+
}
58+
59+
deleteEventThreatDetectionCustomModule();
60+
// [END securitycenter_delete_event_threat_detection_custom_module]
61+
}
62+
63+
main(...process.argv.slice(2));
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
'use strict';
17+
18+
/**
19+
* Retrieve an existing event threat detection custom module.
20+
*/
21+
function main(organizationId, customModuleId, location = 'global') {
22+
// [START securitycenter_get_event_threat_detection_custom_module]
23+
// Imports the Google Cloud client library.
24+
const {SecurityCenterManagementClient} =
25+
require('@google-cloud/securitycentermanagement').v1;
26+
27+
// Create a Security Center Management client
28+
const client = new SecurityCenterManagementClient();
29+
30+
/*
31+
* Required. Resource name of event threat detection module.
32+
* Its format is
33+
* `organizations/[organization_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]`
34+
* `folders/[folder_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]`
35+
* `projects/[project_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]`
36+
*/
37+
// TODO(developer): Update the following references for your own environment before running the sample.
38+
// const organizationId = 'YOUR_ORGANIZATION_ID';
39+
// const location = 'LOCATION_ID';
40+
// const customModuleId = 'CUSTOM_MODULE_ID';
41+
const name = `organizations/${organizationId}/locations/${location}/eventThreatDetectionCustomModules/${customModuleId}`;
42+
43+
// Build the request.
44+
const getEventThreatDetectionCustomModuleRequest = {
45+
name: name,
46+
};
47+
48+
async function getEventThreatDetectionCustomModule() {
49+
// Call the API.
50+
const [response] = await client.getEventThreatDetectionCustomModule(
51+
getEventThreatDetectionCustomModuleRequest
52+
);
53+
console.log('Retrieved EventThreatDetectionCustomModule: %j', response);
54+
}
55+
56+
getEventThreatDetectionCustomModule();
57+
// [END securitycenter_get_event_threat_detection_custom_module]
58+
}
59+
60+
main(...process.argv.slice(2));
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
'use strict';
17+
18+
// List all event threat detection custom module under a given parent resource.
19+
function main(organizationId, location = 'global') {
20+
// [START securitycenter_list_event_threat_detection_custom_module]
21+
// Imports the Google Cloud client library.
22+
const {SecurityCenterManagementClient} =
23+
require('@google-cloud/securitycentermanagement').v1;
24+
25+
// Create a Security Center Management client
26+
const client = new SecurityCenterManagementClient();
27+
28+
/**
29+
* Required. The name of the parent resource of the list event threat detection custom module. Its
30+
* format is "organizations/[organization_id]/locations/[location_id]",
31+
* "folders/[folder_id]/locations/[location_id]", or
32+
* "projects/[project_id]/locations/[location_id]".
33+
*/
34+
//TODO(developer): Update the following references for your own environment before running the sample.
35+
// const organizationId = 'YOUR_ORGANIZATION_ID';
36+
// const location = 'LOCATION_ID';
37+
const parent = `organizations/${organizationId}/locations/${location}`;
38+
39+
// Build the request.
40+
const listEventThreatDetectionCustomModulesRequest = {
41+
parent: parent,
42+
};
43+
44+
async function listEventThreatDetectionCustomModules() {
45+
// Call the API.
46+
const [modules] = await client.listEventThreatDetectionCustomModules(
47+
listEventThreatDetectionCustomModulesRequest
48+
);
49+
for (const module of modules) {
50+
console.log('Custom Module name:', module.name);
51+
}
52+
}
53+
54+
listEventThreatDetectionCustomModules();
55+
// [END securitycenter_list_event_threat_detection_custom_module]
56+
}
57+
58+
main(...process.argv.slice(2));
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
'use strict';
17+
18+
/**
19+
* Updates an existing event threat detection custom module.
20+
*/
21+
function main(organizationId, customModuleId, location = 'global') {
22+
// [START securitycenter_update_event_threat_detection_custom_module]
23+
// Imports the Google Cloud client library.
24+
const {SecurityCenterManagementClient} =
25+
require('@google-cloud/securitycentermanagement').v1;
26+
27+
// Create a Security Center Management client
28+
const client = new SecurityCenterManagementClient();
29+
30+
/*
31+
* Required. Resource name of event threat detection module.
32+
* Its format is
33+
* `organizations/[organization_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]`
34+
* `folders/[folder_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]`
35+
* `projects/[project_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]`
36+
*/
37+
// TODO(developer): Update the following references for your own environment before running the sample.
38+
// const organizationId = 'YOUR_ORGANIZATION_ID';
39+
// const location = 'LOCATION_ID';
40+
// const customModuleId = 'CUSTOM_MODULE_ID';
41+
const name = `organizations/${organizationId}/locations/${location}/eventThreatDetectionCustomModules/${customModuleId}`;
42+
43+
// Define the event threat detection custom module configuration, update the
44+
// EnablementState accordingly.
45+
const eventThreatDetectionCustomModule = {
46+
name: name,
47+
enablementState: 'DISABLED',
48+
};
49+
50+
// Set the field mask to specify which properties should be updated.
51+
const fieldMask = {
52+
paths: ['enablement_state'],
53+
};
54+
55+
// Build the request.
56+
const updateEventThreatDetectionCustomModuleRequest = {
57+
eventThreatDetectionCustomModule: eventThreatDetectionCustomModule,
58+
updateMask: fieldMask,
59+
};
60+
61+
async function updateEventThreatDetectionCustomModule() {
62+
// Call the API.
63+
const [response] = await client.updateEventThreatDetectionCustomModule(
64+
updateEventThreatDetectionCustomModuleRequest
65+
);
66+
console.log('Updated EventThreatDetectionCustomModule: %j', response);
67+
}
68+
69+
updateEventThreatDetectionCustomModule();
70+
// [END securitycenter_update_event_threat_detection_custom_module]
71+
}
72+
73+
main(...process.argv.slice(2));

security-center/snippets/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"license": "Apache-2.0",
1515
"dependencies": {
1616
"@google-cloud/pubsub": "^4.0.0",
17-
"@google-cloud/security-center": "^8.7.0"
17+
"@google-cloud/security-center": "^8.7.0",
18+
"@google-cloud/securitycentermanagement": "^0.5.0"
1819
},
1920
"devDependencies": {
2021
"c8": "^10.0.0",

0 commit comments

Comments
 (0)