Skip to content

Commit 6390ada

Browse files
Merge branch 'main' into Improving_tpu
2 parents 9a45e2e + 99e983e commit 6390ada

File tree

6 files changed

+452
-0
lines changed

6 files changed

+452
-0
lines changed

security-command-center/snippets/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545
<version>2.45.0</version>
4646
</dependency>
4747

48+
<dependency>
49+
<groupId>com.google.cloud</groupId>
50+
<artifactId>google-cloud-securitycentermanagement</artifactId>
51+
<version>0.20.0</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>com.google.api.grpc</groupId>
56+
<artifactId>proto-google-cloud-securitycentermanagement-v1</artifactId>
57+
<version>0.20.0</version>
58+
</dependency>
59+
4860
<dependency>
4961
<groupId>com.google.cloud</groupId>
5062
<artifactId>google-cloud-pubsub</artifactId>
@@ -80,4 +92,13 @@
8092
<scope>test</scope>
8193
</dependency>
8294
</dependencies>
95+
<build>
96+
<plugins>
97+
<plugin>
98+
<groupId>org.apache.maven.plugins</groupId>
99+
<artifactId>maven-surefire-plugin</artifactId>
100+
<version>3.2.5</version>
101+
</plugin>
102+
</plugins>
103+
</build>
83104
</project>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright 2024 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+
17+
package management.api;
18+
19+
// [START securitycenter_create_security_health_analytics_custom_module]
20+
import com.google.cloud.securitycentermanagement.v1.CreateSecurityHealthAnalyticsCustomModuleRequest;
21+
import com.google.cloud.securitycentermanagement.v1.CustomConfig;
22+
import com.google.cloud.securitycentermanagement.v1.CustomConfig.ResourceSelector;
23+
import com.google.cloud.securitycentermanagement.v1.CustomConfig.Severity;
24+
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
25+
import com.google.cloud.securitycentermanagement.v1.SecurityHealthAnalyticsCustomModule;
26+
import com.google.cloud.securitycentermanagement.v1.SecurityHealthAnalyticsCustomModule.EnablementState;
27+
import com.google.type.Expr;
28+
import java.io.IOException;
29+
30+
public class CreateSecurityHealthAnalyticsCustomModule {
31+
32+
public static void main(String[] args) throws IOException {
33+
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.securityHealthAnalyticsCustomModules/create
34+
// replace "project_id" with a real project ID
35+
String parent = String.format("projects/%s/locations/%s", "project_id", "global");
36+
37+
String customModuleDisplayName = "custom_module_display_name";
38+
39+
createSecurityHealthAnalyticsCustomModule(parent, customModuleDisplayName);
40+
}
41+
42+
public static SecurityHealthAnalyticsCustomModule createSecurityHealthAnalyticsCustomModule(
43+
String parent, String customModuleDisplayName) throws IOException {
44+
45+
// Initialize client that will be used to send requests. This client only needs
46+
// to be created
47+
// once, and can be reused for multiple requests.
48+
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) {
49+
50+
String name =
51+
String.format("%s/securityHealthAnalyticsCustomModules/%s", parent, "custom_module");
52+
53+
// define the CEL expression here, change it according to the your requirements
54+
Expr expr =
55+
Expr.newBuilder()
56+
.setExpression(
57+
"has(resource.rotationPeriod) && (resource.rotationPeriod > "
58+
+ "duration('2592000s'))")
59+
.build();
60+
61+
// define the resource selector
62+
ResourceSelector resourceSelector =
63+
ResourceSelector.newBuilder()
64+
.addResourceTypes("cloudkms.googleapis.com/CryptoKey")
65+
.build();
66+
67+
// define the custom module configuration, update the severity, description,
68+
// recommendation below
69+
CustomConfig customConfig =
70+
CustomConfig.newBuilder()
71+
.setPredicate(expr)
72+
.setResourceSelector(resourceSelector)
73+
.setSeverity(Severity.MEDIUM)
74+
.setDescription("add your description here")
75+
.setRecommendation("add your recommendation here")
76+
.build();
77+
78+
// define the security health analytics custom module configuration, update the
79+
// EnablementState below
80+
SecurityHealthAnalyticsCustomModule securityHealthAnalyticsCustomModule =
81+
SecurityHealthAnalyticsCustomModule.newBuilder()
82+
.setName(name)
83+
.setDisplayName(customModuleDisplayName)
84+
.setEnablementState(EnablementState.ENABLED)
85+
.setCustomConfig(customConfig)
86+
.build();
87+
88+
CreateSecurityHealthAnalyticsCustomModuleRequest request =
89+
CreateSecurityHealthAnalyticsCustomModuleRequest.newBuilder()
90+
.setParent(parent)
91+
.setSecurityHealthAnalyticsCustomModule(securityHealthAnalyticsCustomModule)
92+
.build();
93+
94+
SecurityHealthAnalyticsCustomModule response =
95+
client.createSecurityHealthAnalyticsCustomModule(request);
96+
97+
return response;
98+
}
99+
}
100+
}
101+
// [END securitycenter_create_security_health_analytics_custom_module]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2024 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+
17+
package management.api;
18+
19+
// [START securitycenter_delete_security_health_analytics_custom_module]
20+
import com.google.cloud.securitycentermanagement.v1.DeleteSecurityHealthAnalyticsCustomModuleRequest;
21+
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
22+
import java.io.IOException;
23+
24+
public class DeleteSecurityHealthAnalyticsCustomModule {
25+
26+
public static void main(String[] args) throws IOException {
27+
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.securityHealthAnalyticsCustomModules/delete
28+
// replace "project_id" with a real project ID
29+
String parent = String.format("projects/%s/locations/%s", "project_id", "global");
30+
31+
String customModuleId = "custom_module_id";
32+
33+
deleteSecurityHealthAnalyticsCustomModule(parent, customModuleId);
34+
}
35+
36+
public static boolean deleteSecurityHealthAnalyticsCustomModule(
37+
String parent, String customModuleId) throws IOException {
38+
39+
// Initialize client that will be used to send requests. This client only needs
40+
// to be created
41+
// once, and can be reused for multiple requests.
42+
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) {
43+
String name =
44+
String.format("%s/securityHealthAnalyticsCustomModules/%s", parent, customModuleId);
45+
46+
DeleteSecurityHealthAnalyticsCustomModuleRequest request =
47+
DeleteSecurityHealthAnalyticsCustomModuleRequest.newBuilder().setName(name).build();
48+
49+
client.deleteSecurityHealthAnalyticsCustomModule(request);
50+
51+
return true;
52+
}
53+
}
54+
}
55+
// [END securitycenter_delete_security_health_analytics_custom_module]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2024 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+
17+
package management.api;
18+
19+
// [START securitycenter_get_security_health_analytics_custom_module]
20+
import com.google.cloud.securitycentermanagement.v1.GetSecurityHealthAnalyticsCustomModuleRequest;
21+
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
22+
import com.google.cloud.securitycentermanagement.v1.SecurityHealthAnalyticsCustomModule;
23+
import java.io.IOException;
24+
25+
public class GetSecurityHealthAnalyticsCustomModule {
26+
27+
public static void main(String[] args) throws IOException {
28+
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.securityHealthAnalyticsCustomModules/get
29+
// replace "project_id" with a real project ID
30+
String parent = String.format("projects/%s/locations/%s", "project_id", "global");
31+
32+
String customModuleId = "custom_module_id";
33+
34+
getSecurityHealthAnalyticsCustomModule(parent, customModuleId);
35+
}
36+
37+
public static SecurityHealthAnalyticsCustomModule getSecurityHealthAnalyticsCustomModule(
38+
String parent, String customModuleId) throws IOException {
39+
40+
// Initialize client that will be used to send requests. This client only needs
41+
// to be created
42+
// once, and can be reused for multiple requests.
43+
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) {
44+
45+
String name =
46+
String.format("%s/securityHealthAnalyticsCustomModules/%s", parent, customModuleId);
47+
48+
GetSecurityHealthAnalyticsCustomModuleRequest request =
49+
GetSecurityHealthAnalyticsCustomModuleRequest.newBuilder().setName(name).build();
50+
51+
SecurityHealthAnalyticsCustomModule response =
52+
client.getSecurityHealthAnalyticsCustomModule(request);
53+
54+
return response;
55+
}
56+
}
57+
}
58+
// [END securitycenter_get_security_health_analytics_custom_module]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2024 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+
17+
package management.api;
18+
19+
// [START securitycenter_list_security_health_analytics_custom_module]
20+
import com.google.cloud.securitycentermanagement.v1.ListSecurityHealthAnalyticsCustomModulesRequest;
21+
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
22+
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListSecurityHealthAnalyticsCustomModulesPagedResponse;
23+
import java.io.IOException;
24+
25+
public class ListSecurityHealthAnalyticsCustomModules {
26+
27+
public static void main(String[] args) throws IOException {
28+
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.securityHealthAnalyticsCustomModules/list
29+
// replace "project_id" with a real project ID
30+
String parent = String.format("projects/%s/locations/%s", "project_id", "global");
31+
32+
listSecurityHealthAnalyticsCustomModules(parent);
33+
}
34+
35+
public static ListSecurityHealthAnalyticsCustomModulesPagedResponse
36+
listSecurityHealthAnalyticsCustomModules(String parent) throws IOException {
37+
// Initialize client that will be used to send requests. This client only needs
38+
// to be created
39+
// once, and can be reused for multiple requests.
40+
try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) {
41+
42+
ListSecurityHealthAnalyticsCustomModulesRequest request =
43+
ListSecurityHealthAnalyticsCustomModulesRequest.newBuilder().setParent(parent).build();
44+
45+
ListSecurityHealthAnalyticsCustomModulesPagedResponse response =
46+
client.listSecurityHealthAnalyticsCustomModules(request);
47+
48+
return response;
49+
}
50+
}
51+
}
52+
// [END securitycenter_list_security_health_analytics_custom_module]

0 commit comments

Comments
 (0)