Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public static EventThreatDetectionCustomModule createEventThreatDetectionCustomM
// once, and can be reused for multiple requests.
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) {

String parent = String.format("projects/%s/locations/global", projectId);

// define the metadata and other config parameters severity, description,
// recommendation and ips below
Map<String, Value> metadata = new HashMap<>();
Expand Down Expand Up @@ -83,7 +85,7 @@ public static EventThreatDetectionCustomModule createEventThreatDetectionCustomM

CreateEventThreatDetectionCustomModuleRequest request =
CreateEventThreatDetectionCustomModuleRequest.newBuilder()
.setParent(String.format("projects/%s/locations/global", projectId))
.setParent(parent)
.setEventThreatDetectionCustomModule(eventThreatDetectionCustomModule)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ public static boolean deleteEventThreatDetectionCustomModule(
// once, and can be reused for multiple requests.
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) {

String name =
String qualifiedModuleName =
String.format(
"projects/%s/locations/global/eventThreatDetectionCustomModules/%s",
projectId, customModuleId);

DeleteEventThreatDetectionCustomModuleRequest request =
DeleteEventThreatDetectionCustomModuleRequest.newBuilder().setName(name).build();
DeleteEventThreatDetectionCustomModuleRequest.newBuilder()
.setName(qualifiedModuleName)
.build();

client.deleteEventThreatDetectionCustomModule(request);

Expand Down
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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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";

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
Expand Up @@ -42,13 +42,15 @@ public static EventThreatDetectionCustomModule getEventThreatDetectionCustomModu
// once, and can be reused for multiple requests.
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) {

String name =
String qualifiedModuleName =
String.format(
"projects/%s/locations/global/eventThreatDetectionCustomModules/%s",
projectId, customModuleId);

GetEventThreatDetectionCustomModuleRequest request =
GetEventThreatDetectionCustomModuleRequest.newBuilder().setName(name).build();
GetEventThreatDetectionCustomModuleRequest.newBuilder()
.setName(qualifiedModuleName)
.build();

EventThreatDetectionCustomModule response =
client.getEventThreatDetectionCustomModule(request);
Expand Down
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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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";

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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";

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
Expand Up @@ -40,10 +40,10 @@ public static void main(String[] args) throws IOException {
// once, and can be reused for multiple requests.
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) {

String parent = String.format("projects/%s/locations/global", projectId);

ListEventThreatDetectionCustomModulesRequest request =
ListEventThreatDetectionCustomModulesRequest.newBuilder()
.setParent(String.format("projects/%s/locations/global", projectId))
.build();
ListEventThreatDetectionCustomModulesRequest.newBuilder().setParent(parent).build();

ListEventThreatDetectionCustomModulesPagedResponse response =
client.listEventThreatDetectionCustomModules(request);
Expand Down
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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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";

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();
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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]
Loading