Skip to content

Commit c076014

Browse files
authored
fix(security_center): Rename region tag security_center_list_findings_within_time_range and move sample into security_command_center folder (#10288)
* chore: move securitycenter sample and rename region tag * test: add pre-test cleanup logic to delete existing custom modules in setup methods * refactor: replace paged response types with ImmutableList in Security Command Center management snippets
1 parent bff0d3f commit c076014

15 files changed

Lines changed: 80 additions & 112 deletions

securitycenter/snippets/src/main/java/com/example/securitycenter/FindingSnippets.java renamed to security-command-center/snippets/src/main/java/com/example/securitycenter/FindingSnippets.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static ImmutableList<ListFindingsResult> listFilteredFindings(SourceName sourceN
289289
*
290290
* @param sourceName The source to list findings at a specific time for.
291291
*/
292-
// [START securitycenter_list_findings_at_time]
292+
// [START securitycenter_list_findings_within_time_range]
293293
static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceName) {
294294
try (SecurityCenterClient client = SecurityCenterClient.create()) {
295295
// parentId: must be one of the following:
@@ -321,7 +321,7 @@ static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceNam
321321
throw new RuntimeException("Couldn't create client.", e);
322322
}
323323
}
324-
// [END securitycenter_list_findings_at_time]
324+
// [END securitycenter_list_findings_within_time_range]
325325

326326
/**
327327
* Demonstrate calling testIamPermissions to determin if the service account has the correct

securitycenter/snippets/src/main/java/com/example/securitycenter/SourceSnippets.java renamed to security-command-center/snippets/src/main/java/com/example/securitycenter/SourceSnippets.java

File renamed without changes.

security-command-center/snippets/src/main/java/management/api/ListDescendantEventThreatDetectionCustomModules.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
package management.api;
1818

1919
// [START securitycenter_list_descendant_event_threat_detection_custom_module]
20+
import com.google.cloud.securitycentermanagement.v1.EventThreatDetectionCustomModule;
2021
import com.google.cloud.securitycentermanagement.v1.ListDescendantEventThreatDetectionCustomModulesRequest;
2122
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
22-
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListDescendantEventThreatDetectionCustomModulesPagedResponse;
23+
import com.google.common.collect.ImmutableList;
2324
import java.io.IOException;
2425

2526
public class ListDescendantEventThreatDetectionCustomModules {
@@ -31,7 +32,7 @@ public static void main(String[] args) throws IOException {
3132
listDescendantEventThreatDetectionCustomModules(projectId);
3233
}
3334

34-
public static ListDescendantEventThreatDetectionCustomModulesPagedResponse
35+
public static ImmutableList<EventThreatDetectionCustomModule>
3536
listDescendantEventThreatDetectionCustomModules(String projectId) throws IOException {
3637

3738
// Initialize client that will be used to send requests. This client only needs
@@ -46,10 +47,8 @@ public static void main(String[] args) throws IOException {
4647
.setParent(parent)
4748
.build();
4849

49-
ListDescendantEventThreatDetectionCustomModulesPagedResponse response =
50-
client.listDescendantEventThreatDetectionCustomModules(request);
51-
52-
return response;
50+
return ImmutableList.copyOf(
51+
client.listDescendantEventThreatDetectionCustomModules(request).iterateAll());
5352
}
5453
}
5554
}

security-command-center/snippets/src/main/java/management/api/ListDescendantSecurityHealthAnalyticsCustomModules.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
// [START securitycenter_list_descendant_security_health_analytics_custom_module]
2020
import com.google.cloud.securitycentermanagement.v1.ListDescendantSecurityHealthAnalyticsCustomModulesRequest;
2121
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
22-
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListDescendantSecurityHealthAnalyticsCustomModulesPagedResponse;
22+
import com.google.cloud.securitycentermanagement.v1.SecurityHealthAnalyticsCustomModule;
23+
import com.google.common.collect.ImmutableList;
2324
import java.io.IOException;
2425

2526
public class ListDescendantSecurityHealthAnalyticsCustomModules {
@@ -32,7 +33,7 @@ public static void main(String[] args) throws IOException {
3233
listDescendantSecurityHealthAnalyticsCustomModules(projectId);
3334
}
3435

35-
public static ListDescendantSecurityHealthAnalyticsCustomModulesPagedResponse
36+
public static ImmutableList<SecurityHealthAnalyticsCustomModule>
3637
listDescendantSecurityHealthAnalyticsCustomModules(String projectId) throws IOException {
3738

3839
// Initialize client that will be used to send requests. This client only needs
@@ -45,10 +46,8 @@ public static void main(String[] args) throws IOException {
4546
.setParent(String.format("projects/%s/locations/global", projectId))
4647
.build();
4748

48-
ListDescendantSecurityHealthAnalyticsCustomModulesPagedResponse response =
49-
client.listDescendantSecurityHealthAnalyticsCustomModules(request);
50-
51-
return response;
49+
return ImmutableList.copyOf(
50+
client.listDescendantSecurityHealthAnalyticsCustomModules(request).iterateAll());
5251
}
5352
}
5453
}

security-command-center/snippets/src/main/java/management/api/ListEffectiveEventThreatDetectionCustomModules.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
package management.api;
1818

1919
// [START securitycenter_list_effective_event_threat_detection_custom_module]
20+
import com.google.cloud.securitycentermanagement.v1.EffectiveEventThreatDetectionCustomModule;
2021
import com.google.cloud.securitycentermanagement.v1.ListEffectiveEventThreatDetectionCustomModulesRequest;
2122
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
22-
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEffectiveEventThreatDetectionCustomModulesPagedResponse;
23+
import com.google.common.collect.ImmutableList;
2324
import java.io.IOException;
2425

2526
public class ListEffectiveEventThreatDetectionCustomModules {
@@ -31,7 +32,7 @@ public static void main(String[] args) throws IOException {
3132
listEffectiveEventThreatDetectionCustomModules(projectId);
3233
}
3334

34-
public static ListEffectiveEventThreatDetectionCustomModulesPagedResponse
35+
public static ImmutableList<EffectiveEventThreatDetectionCustomModule>
3536
listEffectiveEventThreatDetectionCustomModules(String projectId) throws IOException {
3637

3738
// Initialize client that will be used to send requests. This client only needs
@@ -46,10 +47,8 @@ public static void main(String[] args) throws IOException {
4647
.setParent(parent)
4748
.build();
4849

49-
ListEffectiveEventThreatDetectionCustomModulesPagedResponse response =
50-
client.listEffectiveEventThreatDetectionCustomModules(request);
51-
52-
return response;
50+
return ImmutableList.copyOf(
51+
client.listEffectiveEventThreatDetectionCustomModules(request).iterateAll());
5352
}
5453
}
5554
}

security-command-center/snippets/src/main/java/management/api/ListEffectiveSecurityHealthAnalyticsCustomModules.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
package management.api;
1818

1919
// [START securitycenter_list_effective_security_health_analytics_custom_module]
20+
import com.google.cloud.securitycentermanagement.v1.EffectiveSecurityHealthAnalyticsCustomModule;
2021
import com.google.cloud.securitycentermanagement.v1.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest;
2122
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
22-
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEffectiveSecurityHealthAnalyticsCustomModulesPagedResponse;
23+
import com.google.common.collect.ImmutableList;
2324
import java.io.IOException;
2425

2526
public class ListEffectiveSecurityHealthAnalyticsCustomModules {
@@ -32,7 +33,7 @@ public static void main(String[] args) throws IOException {
3233
listEffectiveSecurityHealthAnalyticsCustomModules(projectId);
3334
}
3435

35-
public static ListEffectiveSecurityHealthAnalyticsCustomModulesPagedResponse
36+
public static ImmutableList<EffectiveSecurityHealthAnalyticsCustomModule>
3637
listEffectiveSecurityHealthAnalyticsCustomModules(String projectId) throws IOException {
3738

3839
// Initialize client that will be used to send requests. This client only needs
@@ -45,10 +46,8 @@ public static void main(String[] args) throws IOException {
4546
.setParent(String.format("projects/%s/locations/global", projectId))
4647
.build();
4748

48-
ListEffectiveSecurityHealthAnalyticsCustomModulesPagedResponse response =
49-
client.listEffectiveSecurityHealthAnalyticsCustomModules(request);
50-
51-
return response;
49+
return ImmutableList.copyOf(
50+
client.listEffectiveSecurityHealthAnalyticsCustomModules(request).iterateAll());
5251
}
5352
}
5453
}

security-command-center/snippets/src/main/java/management/api/ListEventThreatDetectionCustomModules.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
package management.api;
1818

1919
// [START securitycenter_list_event_threat_detection_custom_module]
20+
import com.google.cloud.securitycentermanagement.v1.EventThreatDetectionCustomModule;
2021
import com.google.cloud.securitycentermanagement.v1.ListEventThreatDetectionCustomModulesRequest;
2122
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
22-
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEventThreatDetectionCustomModulesPagedResponse;
23+
import com.google.common.collect.ImmutableList;
2324
import java.io.IOException;
2425

2526
public class ListEventThreatDetectionCustomModules {
@@ -32,7 +33,7 @@ public static void main(String[] args) throws IOException {
3233
listEventThreatDetectionCustomModules(projectId);
3334
}
3435

35-
public static ListEventThreatDetectionCustomModulesPagedResponse
36+
public static ImmutableList<EventThreatDetectionCustomModule>
3637
listEventThreatDetectionCustomModules(String projectId) throws IOException {
3738

3839
// Initialize client that will be used to send requests. This client only needs
@@ -45,10 +46,8 @@ public static void main(String[] args) throws IOException {
4546
ListEventThreatDetectionCustomModulesRequest request =
4647
ListEventThreatDetectionCustomModulesRequest.newBuilder().setParent(parent).build();
4748

48-
ListEventThreatDetectionCustomModulesPagedResponse response =
49-
client.listEventThreatDetectionCustomModules(request);
50-
51-
return response;
49+
return ImmutableList.copyOf(
50+
client.listEventThreatDetectionCustomModules(request).iterateAll());
5251
}
5352
}
5453
}

security-command-center/snippets/src/main/java/management/api/ListSecurityCenterServices.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
// [START securitycenter_list_security_center_service]
2020
import com.google.cloud.securitycentermanagement.v1.ListSecurityCenterServicesRequest;
2121
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
22-
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListSecurityCenterServicesPagedResponse;
22+
import com.google.cloud.securitycentermanagement.v1.SecurityCenterService;
23+
import com.google.common.collect.ImmutableList;
2324
import java.io.IOException;
2425

2526
public class ListSecurityCenterServices {
@@ -32,7 +33,7 @@ public static void main(String[] args) throws IOException {
3233
listSecurityCenterServices(projectId);
3334
}
3435

35-
public static ListSecurityCenterServicesPagedResponse listSecurityCenterServices(String projectId)
36+
public static ImmutableList<SecurityCenterService> listSecurityCenterServices(String projectId)
3637
throws IOException {
3738
// Initialize client that will be used to send requests. This client only needs
3839
// to be created
@@ -42,8 +43,7 @@ public static ListSecurityCenterServicesPagedResponse listSecurityCenterServices
4243
ListSecurityCenterServicesRequest.newBuilder()
4344
.setParent(String.format("projects/%s/locations/global", projectId))
4445
.build();
45-
ListSecurityCenterServicesPagedResponse response = client.listSecurityCenterServices(request);
46-
return response;
46+
return ImmutableList.copyOf(client.listSecurityCenterServices(request).iterateAll());
4747
}
4848
}
4949
}

security-command-center/snippets/src/main/java/management/api/ListSecurityHealthAnalyticsCustomModules.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
// [START securitycenter_list_security_health_analytics_custom_module]
2020
import com.google.cloud.securitycentermanagement.v1.ListSecurityHealthAnalyticsCustomModulesRequest;
2121
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
22-
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListSecurityHealthAnalyticsCustomModulesPagedResponse;
22+
import com.google.cloud.securitycentermanagement.v1.SecurityHealthAnalyticsCustomModule;
23+
import com.google.common.collect.ImmutableList;
2324
import java.io.IOException;
2425

2526
public class ListSecurityHealthAnalyticsCustomModules {
@@ -32,7 +33,7 @@ public static void main(String[] args) throws IOException {
3233
listSecurityHealthAnalyticsCustomModules(projectId);
3334
}
3435

35-
public static ListSecurityHealthAnalyticsCustomModulesPagedResponse
36+
public static ImmutableList<SecurityHealthAnalyticsCustomModule>
3637
listSecurityHealthAnalyticsCustomModules(String projectId) throws IOException {
3738
// Initialize client that will be used to send requests. This client only needs
3839
// to be created
@@ -44,10 +45,8 @@ public static void main(String[] args) throws IOException {
4445
.setParent(String.format("projects/%s/locations/global", projectId))
4546
.build();
4647

47-
ListSecurityHealthAnalyticsCustomModulesPagedResponse response =
48-
client.listSecurityHealthAnalyticsCustomModules(request);
49-
50-
return response;
48+
return ImmutableList.copyOf(
49+
client.listSecurityHealthAnalyticsCustomModules(request).iterateAll());
5150
}
5251
}
5352
}

securitycenter/snippets/src/test/java/com/example/securitycenter/ITFindingSnippets.java renamed to security-command-center/snippets/src/test/java/com/example/securitycenter/ITFindingSnippets.java

File renamed without changes.

0 commit comments

Comments
 (0)