-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(securitycenter): Add Resource SCC Management API Org ETD Custom … #3943
Open
lovenishs04
wants to merge
1
commit into
main
Choose a base branch
from
scc-management-api-etd-code-samples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+531
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
security-center/snippets/management_api/createEventThreatDetectionCustomModule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,94 @@ | ||||||||||
/* | ||||||||||
* Copyright 2025 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 | ||||||||||
* | ||||||||||
* http://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'; | ||||||||||
|
||||||||||
/** | ||||||||||
* Demonstrates how to create a new event threat detection custom module | ||||||||||
*/ | ||||||||||
function main(organizationId, customModuleDisplayName, location = 'global') { | ||||||||||
// [START securitycenter_create_event_threat_detection_custom_module] | ||||||||||
// Imports the Google cloud client library. | ||||||||||
const {SecurityCenterManagementClient} = | ||||||||||
require('@google-cloud/securitycentermanagement').v1; | ||||||||||
|
||||||||||
// Create a Security Center Management client | ||||||||||
const client = new SecurityCenterManagementClient(); | ||||||||||
|
||||||||||
/** | ||||||||||
* Required. The name of the parent resource of the create event threat detection module. Its | ||||||||||
* format is "organizations/[organization_id]/locations/[location_id]", | ||||||||||
* "folders/[folder_id]/locations/[location_id]", or | ||||||||||
* "projects/[project_id]/locations/[location_id]". | ||||||||||
*/ | ||||||||||
//TODO(developer): Update the following references for your own environment before running the sample. | ||||||||||
// const organizationId = 'YOUR_ORGANIZATION_ID'; | ||||||||||
// const location = 'LOCATION_ID'; | ||||||||||
const parent = `organizations/${organizationId}/locations/${location}`; | ||||||||||
|
||||||||||
// define the event threat detection custom module configuration, update the EnablementState | ||||||||||
// below | ||||||||||
Comment on lines
+41
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment about updating EnablementState is not clear. Rephrase it to be more descriptive and explain the purpose of EnablementState.
Suggested change
|
||||||||||
const eventThreatDetectionCustomModule = { | ||||||||||
displayName: customModuleDisplayName, | ||||||||||
enablementState: 'ENABLED', | ||||||||||
type: 'CONFIGURABLE_BAD_IP', | ||||||||||
config: prepareConfigDetails(), | ||||||||||
}; | ||||||||||
|
||||||||||
// Build the request. | ||||||||||
const createEventThreatDetectionCustomModuleRequest = { | ||||||||||
parent: parent, | ||||||||||
eventThreatDetectionCustomModule: eventThreatDetectionCustomModule, | ||||||||||
}; | ||||||||||
|
||||||||||
async function createEventThreatDetectionCustomModule() { | ||||||||||
// Call the API. | ||||||||||
const [response] = await client.createEventThreatDetectionCustomModule( | ||||||||||
createEventThreatDetectionCustomModuleRequest | ||||||||||
); | ||||||||||
console.log('EventThreatDetectionCustomModule created : %j', response); | ||||||||||
} | ||||||||||
|
||||||||||
function prepareConfigDetails() { | ||||||||||
// define the metadata and other config parameters severity, description, | ||||||||||
// recommendation and ips below | ||||||||||
const config = { | ||||||||||
fields: { | ||||||||||
metadata: { | ||||||||||
structValue: { | ||||||||||
fields: { | ||||||||||
severity: {stringValue: 'LOW'}, | ||||||||||
description: {stringValue: 'Flagged by Cymbal as malicious'}, | ||||||||||
recommendation: { | ||||||||||
stringValue: 'Contact the owner of the relevant project.', | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
ips: { | ||||||||||
listValue: { | ||||||||||
values: [{stringValue: '192.0.2.1'}, {stringValue: '192.0.2.0/24'}], | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}; | ||||||||||
return config; | ||||||||||
} | ||||||||||
|
||||||||||
createEventThreatDetectionCustomModule(); | ||||||||||
// [END securitycenter_create_event_threat_detection_custom_module] | ||||||||||
} | ||||||||||
|
||||||||||
main(...process.argv.slice(2)); |
63 changes: 63 additions & 0 deletions
63
security-center/snippets/management_api/deleteEventThreatDetectionCustomModule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2025 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 | ||
* | ||
* http://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'; | ||
|
||
/** | ||
* Delete an existing event threat detection custom module | ||
*/ | ||
function main(organizationId, customModuleId, location = 'global') { | ||
// [START securitycenter_delete_event_threat_detection_custom_module] | ||
// Imports the Google Cloud client library. | ||
const {SecurityCenterManagementClient} = | ||
require('@google-cloud/securitycentermanagement').v1; | ||
|
||
// Create a Security Center Management client | ||
const client = new SecurityCenterManagementClient(); | ||
|
||
/* | ||
* Required. Resource name of event threat detection module. | ||
* Its format is | ||
* `organizations/[organization_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]` | ||
* `folders/[folder_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]` | ||
* `projects/[project_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]` | ||
*/ | ||
// TODO(developer): Update the following references for your own environment before running the sample. | ||
// const organizationId = 'YOUR_ORGANIZATION_ID'; | ||
// const location = 'LOCATION_ID'; | ||
// const customModuleId = 'CUSTOM_MODULE_ID'; | ||
const name = `organizations/${organizationId}/locations/${location}/eventThreatDetectionCustomModules/${customModuleId}`; | ||
|
||
// Build the request. | ||
const deleteEventThreatDetectionCustomModuleRequest = { | ||
name: name, | ||
}; | ||
|
||
async function deleteEventThreatDetectionCustomModule() { | ||
// Call the API. | ||
const [response] = await client.deleteEventThreatDetectionCustomModule( | ||
deleteEventThreatDetectionCustomModuleRequest | ||
); | ||
console.log( | ||
'EventThreatDetectionCustomModule deleted successfully: %j', | ||
response | ||
); | ||
} | ||
|
||
deleteEventThreatDetectionCustomModule(); | ||
// [END securitycenter_delete_event_threat_detection_custom_module] | ||
} | ||
|
||
main(...process.argv.slice(2)); |
60 changes: 60 additions & 0 deletions
60
security-center/snippets/management_api/getEventThreatDetectionCustomModule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2025 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 | ||
* | ||
* http://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'; | ||
|
||
/** | ||
* Retrieve an existing event threat detection custom module. | ||
*/ | ||
function main(organizationId, customModuleId, location = 'global') { | ||
// [START securitycenter_get_event_threat_detection_custom_module] | ||
// Imports the Google Cloud client library. | ||
const {SecurityCenterManagementClient} = | ||
require('@google-cloud/securitycentermanagement').v1; | ||
|
||
// Create a Security Center Management client | ||
const client = new SecurityCenterManagementClient(); | ||
|
||
/* | ||
* Required. Resource name of event threat detection module. | ||
* Its format is | ||
* `organizations/[organization_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]` | ||
* `folders/[folder_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]` | ||
* `projects/[project_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]` | ||
*/ | ||
// TODO(developer): Update the following references for your own environment before running the sample. | ||
// const organizationId = 'YOUR_ORGANIZATION_ID'; | ||
// const location = 'LOCATION_ID'; | ||
// const customModuleId = 'CUSTOM_MODULE_ID'; | ||
const name = `organizations/${organizationId}/locations/${location}/eventThreatDetectionCustomModules/${customModuleId}`; | ||
|
||
// Build the request. | ||
const getEventThreatDetectionCustomModuleRequest = { | ||
name: name, | ||
}; | ||
|
||
async function getEventThreatDetectionCustomModule() { | ||
// Call the API. | ||
const [response] = await client.getEventThreatDetectionCustomModule( | ||
getEventThreatDetectionCustomModuleRequest | ||
); | ||
console.log('Retrieved EventThreatDetectionCustomModule: %j', response); | ||
} | ||
|
||
getEventThreatDetectionCustomModule(); | ||
// [END securitycenter_get_event_threat_detection_custom_module] | ||
} | ||
|
||
main(...process.argv.slice(2)); |
58 changes: 58 additions & 0 deletions
58
security-center/snippets/management_api/listEventThreatDetectionCustomModules.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2025 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 | ||
* | ||
* http://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'; | ||
|
||
// List all event threat detection custom module under a given parent resource. | ||
function main(organizationId, location = 'global') { | ||
// [START securitycenter_list_event_threat_detection_custom_module] | ||
// Imports the Google Cloud client library. | ||
const {SecurityCenterManagementClient} = | ||
require('@google-cloud/securitycentermanagement').v1; | ||
|
||
// Create a Security Center Management client | ||
const client = new SecurityCenterManagementClient(); | ||
|
||
/** | ||
* Required. The name of the parent resource of the list event threat detection custom module. Its | ||
* format is "organizations/[organization_id]/locations/[location_id]", | ||
* "folders/[folder_id]/locations/[location_id]", or | ||
* "projects/[project_id]/locations/[location_id]". | ||
*/ | ||
//TODO(developer): Update the following references for your own environment before running the sample. | ||
// const organizationId = 'YOUR_ORGANIZATION_ID'; | ||
// const location = 'LOCATION_ID'; | ||
const parent = `organizations/${organizationId}/locations/${location}`; | ||
|
||
// Build the request. | ||
const listEventThreatDetectionCustomModulesRequest = { | ||
parent: parent, | ||
}; | ||
|
||
async function listEventThreatDetectionCustomModules() { | ||
// Call the API. | ||
const [modules] = await client.listEventThreatDetectionCustomModules( | ||
listEventThreatDetectionCustomModulesRequest | ||
); | ||
for (const module of modules) { | ||
console.log('Custom Module name:', module.name); | ||
} | ||
} | ||
|
||
listEventThreatDetectionCustomModules(); | ||
// [END securitycenter_list_event_threat_detection_custom_module] | ||
} | ||
|
||
main(...process.argv.slice(2)); |
73 changes: 73 additions & 0 deletions
73
security-center/snippets/management_api/updateEventThreatDetectionCustomModule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2025 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 | ||
* | ||
* http://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'; | ||
|
||
/** | ||
* Updates an existing event threat detection custom module. | ||
*/ | ||
function main(organizationId, customModuleId, location = 'global') { | ||
// [START securitycenter_update_event_threat_detection_custom_module] | ||
// Imports the Google Cloud client library. | ||
const {SecurityCenterManagementClient} = | ||
require('@google-cloud/securitycentermanagement').v1; | ||
|
||
// Create a Security Center Management client | ||
const client = new SecurityCenterManagementClient(); | ||
|
||
/* | ||
* Required. Resource name of event threat detection module. | ||
* Its format is | ||
* `organizations/[organization_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]` | ||
* `folders/[folder_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]` | ||
* `projects/[project_id]/locations/[location_id]/eventThreatDetectionCustomModules/[custom_module]` | ||
*/ | ||
// TODO(developer): Update the following references for your own environment before running the sample. | ||
// const organizationId = 'YOUR_ORGANIZATION_ID'; | ||
// const location = 'LOCATION_ID'; | ||
// const customModuleId = 'CUSTOM_MODULE_ID'; | ||
const name = `organizations/${organizationId}/locations/${location}/eventThreatDetectionCustomModules/${customModuleId}`; | ||
|
||
// Define the event threat detection custom module configuration, update the | ||
// EnablementState accordingly. | ||
const eventThreatDetectionCustomModule = { | ||
name: name, | ||
enablementState: 'DISABLED', | ||
}; | ||
|
||
// Set the field mask to specify which properties should be updated. | ||
const fieldMask = { | ||
paths: ['enablement_state'], | ||
}; | ||
|
||
// Build the request. | ||
const updateEventThreatDetectionCustomModuleRequest = { | ||
eventThreatDetectionCustomModule: eventThreatDetectionCustomModule, | ||
updateMask: fieldMask, | ||
}; | ||
|
||
async function updateEventThreatDetectionCustomModule() { | ||
// Call the API. | ||
const [response] = await client.updateEventThreatDetectionCustomModule( | ||
updateEventThreatDetectionCustomModuleRequest | ||
); | ||
console.log('Updated EventThreatDetectionCustomModule: %j', response); | ||
} | ||
|
||
updateEventThreatDetectionCustomModule(); | ||
// [END securitycenter_update_event_threat_detection_custom_module] | ||
} | ||
|
||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using
TODO(developer)
, consider using JSDoc style comments to explain the parameters and provide examples.