-
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
Merged
lovenishs04
merged 5 commits into
GoogleCloudPlatform:main
from
lovenishs04:scc-management-api-etd-remaining-modules
Jan 9, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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
This file contains hidden or 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
62 changes: 62 additions & 0 deletions
62
...r/snippets/src/main/java/management/api/GetEffectiveEventThreatDetectionCustomModule.java
This file contains hidden or 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,62 @@ | ||
| /* | ||
| * 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 { | ||
| // 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] | ||
This file contains hidden or 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
56 changes: 56 additions & 0 deletions
56
...nippets/src/main/java/management/api/ListDescendantEventThreatDetectionCustomModules.java
This file contains hidden or 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,56 @@ | ||
| /* | ||
| * 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 { | ||
| // 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] | ||
56 changes: 56 additions & 0 deletions
56
...snippets/src/main/java/management/api/ListEffectiveEventThreatDetectionCustomModules.java
This file contains hidden or 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,56 @@ | ||
| /* | ||
| * 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 { | ||
| // 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] | ||
This file contains hidden or 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
80 changes: 80 additions & 0 deletions
80
...-center/snippets/src/main/java/management/api/UpdateEventThreatDetectionCustomModule.java
This file contains hidden or 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,80 @@ | ||
| /* | ||
| * 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 { | ||
| // 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 | ||
| // DisplayName and EnablementState accordingly. | ||
| EventThreatDetectionCustomModule eventThreatDetectionCustomModule = | ||
| EventThreatDetectionCustomModule.newBuilder() | ||
| .setName(qualifiedModuleName) | ||
| .setDisplayName("updated_custom_module_name") | ||
| .setEnablementState(EnablementState.DISABLED) | ||
| .build(); | ||
|
|
||
| // Set the field mask to specify which properties should be updated. In the below example we | ||
| // are updating displayName and EnablementState | ||
| // https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.eventThreatDetectionCustomModules/patch#query-parameters | ||
| // https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask | ||
| FieldMask fieldMask = | ||
| FieldMask.newBuilder().addPaths("display_name").addPaths("enablement_state").build(); | ||
|
|
||
| UpdateEventThreatDetectionCustomModuleRequest request = | ||
| UpdateEventThreatDetectionCustomModuleRequest.newBuilder() | ||
| .setEventThreatDetectionCustomModule(eventThreatDetectionCustomModule) | ||
| .setUpdateMask(fieldMask) | ||
| .build(); | ||
|
|
||
| EventThreatDetectionCustomModule response = | ||
| client.updateEventThreatDetectionCustomModule(request); | ||
|
|
||
| return response; | ||
| } | ||
| } | ||
| } | ||
| // [END securitycenter_update_event_threat_detection_custom_module] | ||
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.
Uh oh!
There was an error while loading. Please reload this page.