-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(securitycenter): Add Resource SCC Management API Org ETD Custom Module code samples (Update, Get Eff, List Eff, List Desc, Validate) #9912
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
*/ | ||
|
||
package management.api; | ||
|
||
// [START securitycenter_get_effective_event_threat_detection_custom_module] | ||
import com.google.cloud.securitycentermanagement.v1.EffectiveEventThreatDetectionCustomModule; | ||
import com.google.cloud.securitycentermanagement.v1.GetEffectiveEventThreatDetectionCustomModuleRequest; | ||
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient; | ||
import java.io.IOException; | ||
|
||
public class GetEffectiveEventThreatDetectionCustomModule { | ||
|
||
public static void main(String[] args) throws IOException { | ||
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.effectiveEventThreatDetectionCustomModules/get | ||
// TODO: Developer should replace project_id with a real project ID before running this code | ||
String projectId = "project_id"; | ||
|
||
String customModuleId = "custom_module_id"; | ||
minherz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
getEffectiveEventThreatDetectionCustomModule(projectId, customModuleId); | ||
} | ||
|
||
public static EffectiveEventThreatDetectionCustomModule | ||
getEffectiveEventThreatDetectionCustomModule(String projectId, String customModuleId) | ||
throws IOException { | ||
|
||
// Initialize client that will be used to send requests. This client only needs | ||
// to be created | ||
// once, and can be reused for multiple requests. | ||
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) { | ||
|
||
String qualifiedModuleName = | ||
String.format( | ||
"projects/%s/locations/global/effectiveEventThreatDetectionCustomModules/%s", | ||
projectId, customModuleId); | ||
|
||
GetEffectiveEventThreatDetectionCustomModuleRequest request = | ||
GetEffectiveEventThreatDetectionCustomModuleRequest.newBuilder() | ||
.setName(qualifiedModuleName) | ||
.build(); | ||
|
||
EffectiveEventThreatDetectionCustomModule response = | ||
client.getEffectiveEventThreatDetectionCustomModule(request); | ||
|
||
return response; | ||
} | ||
} | ||
} | ||
// [END securitycenter_get_effective_event_threat_detection_custom_module] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package management.api; | ||
|
||
// [START securitycenter_list_descendant_event_threat_detection_custom_module] | ||
import com.google.cloud.securitycentermanagement.v1.ListDescendantEventThreatDetectionCustomModulesRequest; | ||
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient; | ||
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListDescendantEventThreatDetectionCustomModulesPagedResponse; | ||
import java.io.IOException; | ||
|
||
public class ListDescendantEventThreatDetectionCustomModules { | ||
|
||
public static void main(String[] args) throws IOException { | ||
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.eventThreatDetectionCustomModules/listDescendant | ||
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. nit: I do not think this comment is required. Users are expected to land here from documentation. 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. same here 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. if the comment(s) are not required, please delete them 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. Addressed |
||
// TODO: Developer should replace project_id with a real project ID before running this code | ||
minherz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String projectId = "project_id"; | ||
|
||
listDescendantEventThreatDetectionCustomModules(projectId); | ||
} | ||
|
||
public static ListDescendantEventThreatDetectionCustomModulesPagedResponse | ||
listDescendantEventThreatDetectionCustomModules(String projectId) throws IOException { | ||
|
||
// Initialize client that will be used to send requests. This client only needs | ||
// to be created | ||
// once, and can be reused for multiple requests. | ||
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) { | ||
|
||
String parent = String.format("projects/%s/locations/global", projectId); | ||
|
||
ListDescendantEventThreatDetectionCustomModulesRequest request = | ||
ListDescendantEventThreatDetectionCustomModulesRequest.newBuilder() | ||
.setParent(parent) | ||
.build(); | ||
|
||
ListDescendantEventThreatDetectionCustomModulesPagedResponse response = | ||
client.listDescendantEventThreatDetectionCustomModules(request); | ||
|
||
return response; | ||
} | ||
} | ||
} | ||
// [END securitycenter_list_descendant_event_threat_detection_custom_module] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package management.api; | ||
|
||
// [START securitycenter_list_effective_event_threat_detection_custom_module] | ||
import com.google.cloud.securitycentermanagement.v1.ListEffectiveEventThreatDetectionCustomModulesRequest; | ||
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient; | ||
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEffectiveEventThreatDetectionCustomModulesPagedResponse; | ||
import java.io.IOException; | ||
|
||
public class ListEffectiveEventThreatDetectionCustomModules { | ||
|
||
public static void main(String[] args) throws IOException { | ||
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.effectiveEventThreatDetectionCustomModules/list | ||
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. nit: I do not think this comment is required. Users are expected to land here from documentation. 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. same here 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. if the comment(s) are not required, please delete them 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. Addressed |
||
// TODO: Developer should replace project_id with a real project ID before running this code | ||
minherz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String projectId = "project_id"; | ||
|
||
listEffectiveEventThreatDetectionCustomModules(projectId); | ||
} | ||
|
||
public static ListEffectiveEventThreatDetectionCustomModulesPagedResponse | ||
listEffectiveEventThreatDetectionCustomModules(String projectId) throws IOException { | ||
|
||
// Initialize client that will be used to send requests. This client only needs | ||
// to be created | ||
// once, and can be reused for multiple requests. | ||
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) { | ||
|
||
String parent = String.format("projects/%s/locations/global", projectId); | ||
|
||
ListEffectiveEventThreatDetectionCustomModulesRequest request = | ||
ListEffectiveEventThreatDetectionCustomModulesRequest.newBuilder() | ||
.setParent(parent) | ||
.build(); | ||
|
||
ListEffectiveEventThreatDetectionCustomModulesPagedResponse response = | ||
client.listEffectiveEventThreatDetectionCustomModules(request); | ||
|
||
return response; | ||
} | ||
} | ||
} | ||
// [END securitycenter_list_effective_event_threat_detection_custom_module] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package management.api; | ||
|
||
// [START securitycenter_update_event_threat_detection_custom_module] | ||
import com.google.cloud.securitycentermanagement.v1.EventThreatDetectionCustomModule; | ||
import com.google.cloud.securitycentermanagement.v1.EventThreatDetectionCustomModule.EnablementState; | ||
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient; | ||
import com.google.cloud.securitycentermanagement.v1.UpdateEventThreatDetectionCustomModuleRequest; | ||
import com.google.protobuf.FieldMask; | ||
import java.io.IOException; | ||
|
||
public class UpdateEventThreatDetectionCustomModule { | ||
|
||
public static void main(String[] args) throws IOException { | ||
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.eventThreatDetectionCustomModules/patch | ||
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. nit: I do not think this comment is required. Users are expected to land here from documentation. 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. same here 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. if the comment(s) are not required, please delete them 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. Addressed |
||
// TODO: Developer should replace project_id with a real project ID before running this code | ||
String projectId = "project_id"; | ||
|
||
String customModuleId = "custom_module_id"; | ||
minherz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
updateEventThreatDetectionCustomModule(projectId, customModuleId); | ||
} | ||
|
||
public static EventThreatDetectionCustomModule updateEventThreatDetectionCustomModule( | ||
String projectId, String customModuleId) throws IOException { | ||
|
||
// Initialize client that will be used to send requests. This client only needs | ||
// to be created | ||
// once, and can be reused for multiple requests. | ||
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) { | ||
|
||
String qualifiedModuleName = | ||
String.format( | ||
"projects/%s/locations/global/eventThreatDetectionCustomModules/%s", | ||
projectId, customModuleId); | ||
|
||
// Define the event threat detection custom module configuration, update the | ||
// EnablementState accordingly. | ||
EventThreatDetectionCustomModule eventThreatDetectionCustomModule = | ||
EventThreatDetectionCustomModule.newBuilder() | ||
.setName(qualifiedModuleName) | ||
.setEnablementState(EnablementState.DISABLED) | ||
.build(); | ||
|
||
// Set the field mask to specify which properties should be updated. | ||
FieldMask fieldMask = FieldMask.newBuilder().addPaths("enablement_state").build(); | ||
|
||
UpdateEventThreatDetectionCustomModuleRequest request = | ||
UpdateEventThreatDetectionCustomModuleRequest.newBuilder() | ||
.setEventThreatDetectionCustomModule(eventThreatDetectionCustomModule) | ||
.setUpdateMask(fieldMask) | ||
.build(); | ||
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. this example does not look to me as a generic example of the module's update. If a user needs to update something else than the enablement state, do they always use "addPaths"? How they do it if they update more than one value? What values they can update? Where do they find the literals to use with "addPaths"? Please, refactor the code samples to provide answers to these questions. Try to use the code to show the answers. Where it is not possible, place the URL to documentation into a comment line. 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. documentation link is already present in the top and it will have all the details for the list of field mask properties 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. is it user-friendly? would it be easy for you to figure out that the link 60 lines up is the one you should look at to figure out parameters? Also the link points neither to the mask format nor to the request. It means a user has to scroll up to find the link, to open the link, to read the full article and then open two other articles. 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. Addressed |
||
|
||
EventThreatDetectionCustomModule response = | ||
client.updateEventThreatDetectionCustomModule(request); | ||
|
||
return response; | ||
} | ||
} | ||
} | ||
// [END securitycenter_update_event_threat_detection_custom_module] |
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.
nit: I do not think this comment is required. Users are expected to land here from documentation.
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.
same here
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.
if the comment(s) are not required, please delete them
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.
Addressed