use of com.google.cloud.securitycenter.v1.BigQueryExport in project java-securitycenter by googleapis.
the class SecurityCenterClientTest method listBigQueryExportsTest4.
@Test
public void listBigQueryExportsTest4() throws Exception {
BigQueryExport responsesElement = BigQueryExport.newBuilder().build();
ListBigQueryExportsResponse expectedResponse = ListBigQueryExportsResponse.newBuilder().setNextPageToken("").addAllBigQueryExports(Arrays.asList(responsesElement)).build();
mockSecurityCenter.addResponse(expectedResponse);
String parent = "parent-995424086";
ListBigQueryExportsPagedResponse pagedListResponse = client.listBigQueryExports(parent);
List<BigQueryExport> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getBigQueryExportsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecurityCenter.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListBigQueryExportsRequest actualRequest = ((ListBigQueryExportsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.securitycenter.v1.BigQueryExport in project java-securitycenter by googleapis.
the class SecurityCenterClientTest method listBigQueryExportsTest3.
@Test
public void listBigQueryExportsTest3() throws Exception {
BigQueryExport responsesElement = BigQueryExport.newBuilder().build();
ListBigQueryExportsResponse expectedResponse = ListBigQueryExportsResponse.newBuilder().setNextPageToken("").addAllBigQueryExports(Arrays.asList(responsesElement)).build();
mockSecurityCenter.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListBigQueryExportsPagedResponse pagedListResponse = client.listBigQueryExports(parent);
List<BigQueryExport> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getBigQueryExportsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecurityCenter.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListBigQueryExportsRequest actualRequest = ((ListBigQueryExportsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.securitycenter.v1.BigQueryExport in project java-securitycenter by googleapis.
the class SecurityCenterClientTest method listBigQueryExportsTest2.
@Test
public void listBigQueryExportsTest2() throws Exception {
BigQueryExport responsesElement = BigQueryExport.newBuilder().build();
ListBigQueryExportsResponse expectedResponse = ListBigQueryExportsResponse.newBuilder().setNextPageToken("").addAllBigQueryExports(Arrays.asList(responsesElement)).build();
mockSecurityCenter.addResponse(expectedResponse);
OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
ListBigQueryExportsPagedResponse pagedListResponse = client.listBigQueryExports(parent);
List<BigQueryExport> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getBigQueryExportsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecurityCenter.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListBigQueryExportsRequest actualRequest = ((ListBigQueryExportsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.securitycenter.v1.BigQueryExport in project java-securitycenter by googleapis.
the class CreateBigQueryExport method createBigQueryExport.
// Create export configuration to export findings from a project to a BigQuery dataset.
// Optionally specify filter to export certain findings only.
public static void createBigQueryExport(String parent, String filter, String bigQueryDatasetId, String bigQueryExportId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Create the BigQuery export configuration.
BigQueryExport bigQueryExport = BigQueryExport.newBuilder().setDescription("Export low and medium findings if the compute resource " + "has an IAM anomalous grant").setFilter(filter).setDataset(String.format("%s/datasets/%s", parent, bigQueryDatasetId)).build();
CreateBigQueryExportRequest bigQueryExportRequest = CreateBigQueryExportRequest.newBuilder().setParent(parent).setBigQueryExport(bigQueryExport).setBigQueryExportId(bigQueryExportId).build();
// Create the export request.
BigQueryExport response = client.createBigQueryExport(bigQueryExportRequest);
System.out.printf("BigQuery export request created successfully: %s\n", response.getName());
}
}
use of com.google.cloud.securitycenter.v1.BigQueryExport in project java-securitycenter by googleapis.
the class GetBigQueryExport method getBigQueryExport.
// Retrieve an existing BigQuery export.
public static void getBigQueryExport(String parent, String bigQueryExportId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecurityCenterClient client = SecurityCenterClient.create()) {
GetBigQueryExportRequest bigQueryExportRequest = GetBigQueryExportRequest.newBuilder().setName(String.format("%s/bigQueryExports/%s", parent, bigQueryExportId)).build();
BigQueryExport response = client.getBigQueryExport(bigQueryExportRequest);
System.out.printf("Retrieved the BigQuery export: %s", response.getName());
}
}
Aggregations