Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -289,7 +289,7 @@ static ImmutableList<ListFindingsResult> listFilteredFindings(SourceName sourceN
*
* @param sourceName The source to list findings at a specific time for.
*/
// [START securitycenter_list_findings_at_time]
// [START securitycenter_list_findings_within_time_range]
Comment thread
Kef131 marked this conversation as resolved.
Comment thread
Kef131 marked this conversation as resolved.
static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// parentId: must be one of the following:
Expand Down Expand Up @@ -321,7 +321,7 @@ static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceNam
throw new RuntimeException("Couldn't create client.", e);
}
}
// [END securitycenter_list_findings_at_time]
// [END securitycenter_list_findings_within_time_range]

/**
* Demonstrate calling testIamPermissions to determin if the service account has the correct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package management.api;

// [START securitycenter_list_descendant_event_threat_detection_custom_module]
import com.google.cloud.securitycentermanagement.v1.EventThreatDetectionCustomModule;
import com.google.cloud.securitycentermanagement.v1.ListDescendantEventThreatDetectionCustomModulesRequest;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListDescendantEventThreatDetectionCustomModulesPagedResponse;
import com.google.common.collect.ImmutableList;
import java.io.IOException;

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

public static ListDescendantEventThreatDetectionCustomModulesPagedResponse
public static ImmutableList<EventThreatDetectionCustomModule>
listDescendantEventThreatDetectionCustomModules(String projectId) throws IOException {

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

ListDescendantEventThreatDetectionCustomModulesPagedResponse response =
client.listDescendantEventThreatDetectionCustomModules(request);

return response;
return ImmutableList.copyOf(
client.listDescendantEventThreatDetectionCustomModules(request).iterateAll());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
// [START securitycenter_list_descendant_security_health_analytics_custom_module]
import com.google.cloud.securitycentermanagement.v1.ListDescendantSecurityHealthAnalyticsCustomModulesRequest;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListDescendantSecurityHealthAnalyticsCustomModulesPagedResponse;
import com.google.cloud.securitycentermanagement.v1.SecurityHealthAnalyticsCustomModule;
import com.google.common.collect.ImmutableList;
import java.io.IOException;

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

public static ListDescendantSecurityHealthAnalyticsCustomModulesPagedResponse
public static ImmutableList<SecurityHealthAnalyticsCustomModule>
listDescendantSecurityHealthAnalyticsCustomModules(String projectId) throws IOException {

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

ListDescendantSecurityHealthAnalyticsCustomModulesPagedResponse response =
client.listDescendantSecurityHealthAnalyticsCustomModules(request);

return response;
return ImmutableList.copyOf(
client.listDescendantSecurityHealthAnalyticsCustomModules(request).iterateAll());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package management.api;

// [START securitycenter_list_effective_event_threat_detection_custom_module]
import com.google.cloud.securitycentermanagement.v1.EffectiveEventThreatDetectionCustomModule;
import com.google.cloud.securitycentermanagement.v1.ListEffectiveEventThreatDetectionCustomModulesRequest;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEffectiveEventThreatDetectionCustomModulesPagedResponse;
import com.google.common.collect.ImmutableList;
import java.io.IOException;

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

public static ListEffectiveEventThreatDetectionCustomModulesPagedResponse
public static ImmutableList<EffectiveEventThreatDetectionCustomModule>
listEffectiveEventThreatDetectionCustomModules(String projectId) throws IOException {

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

ListEffectiveEventThreatDetectionCustomModulesPagedResponse response =
client.listEffectiveEventThreatDetectionCustomModules(request);

return response;
return ImmutableList.copyOf(
client.listEffectiveEventThreatDetectionCustomModules(request).iterateAll());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package management.api;

// [START securitycenter_list_effective_security_health_analytics_custom_module]
import com.google.cloud.securitycentermanagement.v1.EffectiveSecurityHealthAnalyticsCustomModule;
import com.google.cloud.securitycentermanagement.v1.ListEffectiveSecurityHealthAnalyticsCustomModulesRequest;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEffectiveSecurityHealthAnalyticsCustomModulesPagedResponse;
import com.google.common.collect.ImmutableList;
import java.io.IOException;

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

public static ListEffectiveSecurityHealthAnalyticsCustomModulesPagedResponse
public static ImmutableList<EffectiveSecurityHealthAnalyticsCustomModule>
listEffectiveSecurityHealthAnalyticsCustomModules(String projectId) throws IOException {

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

ListEffectiveSecurityHealthAnalyticsCustomModulesPagedResponse response =
client.listEffectiveSecurityHealthAnalyticsCustomModules(request);

return response;
return ImmutableList.copyOf(
client.listEffectiveSecurityHealthAnalyticsCustomModules(request).iterateAll());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package management.api;

// [START securitycenter_list_event_threat_detection_custom_module]
import com.google.cloud.securitycentermanagement.v1.EventThreatDetectionCustomModule;
import com.google.cloud.securitycentermanagement.v1.ListEventThreatDetectionCustomModulesRequest;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEventThreatDetectionCustomModulesPagedResponse;
import com.google.common.collect.ImmutableList;
import java.io.IOException;

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

public static ListEventThreatDetectionCustomModulesPagedResponse
public static ImmutableList<EventThreatDetectionCustomModule>
listEventThreatDetectionCustomModules(String projectId) throws IOException {

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

ListEventThreatDetectionCustomModulesPagedResponse response =
client.listEventThreatDetectionCustomModules(request);

return response;
return ImmutableList.copyOf(
client.listEventThreatDetectionCustomModules(request).iterateAll());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
// [START securitycenter_list_security_center_service]
import com.google.cloud.securitycentermanagement.v1.ListSecurityCenterServicesRequest;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListSecurityCenterServicesPagedResponse;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterService;
import com.google.common.collect.ImmutableList;
import java.io.IOException;

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

public static ListSecurityCenterServicesPagedResponse listSecurityCenterServices(String projectId)
public static ImmutableList<SecurityCenterService> listSecurityCenterServices(String projectId)
throws IOException {
// Initialize client that will be used to send requests. This client only needs
// to be created
Expand All @@ -42,8 +43,7 @@ public static ListSecurityCenterServicesPagedResponse listSecurityCenterServices
ListSecurityCenterServicesRequest.newBuilder()
.setParent(String.format("projects/%s/locations/global", projectId))
.build();
ListSecurityCenterServicesPagedResponse response = client.listSecurityCenterServices(request);
return response;
return ImmutableList.copyOf(client.listSecurityCenterServices(request).iterateAll());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
// [START securitycenter_list_security_health_analytics_custom_module]
import com.google.cloud.securitycentermanagement.v1.ListSecurityHealthAnalyticsCustomModulesRequest;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListSecurityHealthAnalyticsCustomModulesPagedResponse;
import com.google.cloud.securitycentermanagement.v1.SecurityHealthAnalyticsCustomModule;
import com.google.common.collect.ImmutableList;
import java.io.IOException;

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

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

ListSecurityHealthAnalyticsCustomModulesPagedResponse response =
client.listSecurityHealthAnalyticsCustomModules(request);

return response;
return ImmutableList.copyOf(
client.listSecurityHealthAnalyticsCustomModules(request).iterateAll());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
import com.google.cloud.securitycentermanagement.v1.EffectiveEventThreatDetectionCustomModule;
import com.google.cloud.securitycentermanagement.v1.EventThreatDetectionCustomModule;
import com.google.cloud.securitycentermanagement.v1.EventThreatDetectionCustomModule.EnablementState;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListDescendantEventThreatDetectionCustomModulesPagedResponse;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEffectiveEventThreatDetectionCustomModulesPagedResponse;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEventThreatDetectionCustomModulesPagedResponse;
import com.google.cloud.securitycentermanagement.v1.ValidateEventThreatDetectionCustomModuleResponse;
import com.google.cloud.testing.junit4.MultipleAttemptsRule;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -69,6 +67,20 @@ public static void requireEnvVar(String envVarName) {
public static void setUp() {
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
requireEnvVar("SCC_PROJECT_ID");
try {
ImmutableList<EventThreatDetectionCustomModule> response =
ListEventThreatDetectionCustomModules
.listEventThreatDetectionCustomModules(PROJECT_ID);
for (EventThreatDetectionCustomModule module : response) {
if (module.getDisplayName() != null
&& module.getDisplayName().startsWith("java_sample_etd_custom_module_test_")) {
deleteCustomModule(PROJECT_ID, extractCustomModuleId(module.getName()));
}
}
} catch (Exception e) {
System.err.println(
"Warning: Pre-test cleanup of custom modules failed: " + e.getMessage());
}
}

@AfterClass
Expand Down Expand Up @@ -134,10 +146,10 @@ public void testListEventThreatDetectionCustomModules() throws IOException {
CreateEventThreatDetectionCustomModule.createEventThreatDetectionCustomModule(
PROJECT_ID, CUSTOM_MODULE_DISPLAY_NAME);
createdCustomModuleIds.add(extractCustomModuleId(createCustomModuleResponse.getName()));
ListEventThreatDetectionCustomModulesPagedResponse response =
ImmutableList<EventThreatDetectionCustomModule> response =
ListEventThreatDetectionCustomModules.listEventThreatDetectionCustomModules(PROJECT_ID);
assertTrue(
StreamSupport.stream(response.iterateAll().spliterator(), false)
response.stream()
.anyMatch(module -> CUSTOM_MODULE_DISPLAY_NAME.equals(module.getDisplayName())));
}

Expand Down Expand Up @@ -193,11 +205,11 @@ public void testListEffectiveEventThreatDetectionCustomModules() throws IOExcept
CreateEventThreatDetectionCustomModule.createEventThreatDetectionCustomModule(
PROJECT_ID, CUSTOM_MODULE_DISPLAY_NAME);
createdCustomModuleIds.add(extractCustomModuleId(createCustomModuleResponse.getName()));
ListEffectiveEventThreatDetectionCustomModulesPagedResponse response =
ImmutableList<EffectiveEventThreatDetectionCustomModule> response =
ListEffectiveEventThreatDetectionCustomModules
.listEffectiveEventThreatDetectionCustomModules(PROJECT_ID);
assertTrue(
StreamSupport.stream(response.iterateAll().spliterator(), false)
response.stream()
.anyMatch(module -> CUSTOM_MODULE_DISPLAY_NAME.equals(module.getDisplayName())));
}

Expand All @@ -207,11 +219,11 @@ public void testListDescendantEventThreatDetectionCustomModules() throws IOExcep
CreateEventThreatDetectionCustomModule.createEventThreatDetectionCustomModule(
PROJECT_ID, CUSTOM_MODULE_DISPLAY_NAME);
createdCustomModuleIds.add(extractCustomModuleId(createCustomModuleResponse.getName()));
ListDescendantEventThreatDetectionCustomModulesPagedResponse response =
ImmutableList<EventThreatDetectionCustomModule> response =
ListDescendantEventThreatDetectionCustomModules
.listDescendantEventThreatDetectionCustomModules(PROJECT_ID);
assertTrue(
StreamSupport.stream(response.iterateAll().spliterator(), false)
response.stream()
.anyMatch(module -> CUSTOM_MODULE_DISPLAY_NAME.equals(module.getDisplayName())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListSecurityCenterServicesPagedResponse;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterService;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterService.EnablementState;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.stream.StreamSupport;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -63,12 +62,12 @@ public void testGetSecurityCenterService() throws IOException {

@Test
public void testListSecurityCenterServices() throws IOException {
ListSecurityCenterServicesPagedResponse response =
ImmutableList<SecurityCenterService> response =
ListSecurityCenterServices.listSecurityCenterServices(PROJECT_ID);
assertNotNull(response);
// check whether the response contains the specified service
assertTrue(
StreamSupport.stream(response.iterateAll().spliterator(), false)
response.stream()
.anyMatch(service -> service.getName().contains(SERVICE)));
}

Expand Down
Loading