Search in sources :

Example 1 with BigQueryExport

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListBigQueryExportsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListBigQueryExportsPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 2 with BigQueryExport

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListBigQueryExportsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListBigQueryExportsPagedResponse) Test(org.junit.Test)

Example 3 with BigQueryExport

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListBigQueryExportsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListBigQueryExportsPagedResponse) Test(org.junit.Test)

Example 4 with BigQueryExport

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());
    }
}
Also used : CreateBigQueryExportRequest(com.google.cloud.securitycenter.v1.CreateBigQueryExportRequest) BigQueryExport(com.google.cloud.securitycenter.v1.BigQueryExport) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 5 with BigQueryExport

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());
    }
}
Also used : GetBigQueryExportRequest(com.google.cloud.securitycenter.v1.GetBigQueryExportRequest) BigQueryExport(com.google.cloud.securitycenter.v1.BigQueryExport) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Aggregations

ListBigQueryExportsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListBigQueryExportsPagedResponse)5 BigQueryExport (com.google.cloud.securitycenter.v1.BigQueryExport)4 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 Test (org.junit.Test)4 CreateBigQueryExportRequest (com.google.cloud.securitycenter.v1.CreateBigQueryExportRequest)1 GetBigQueryExportRequest (com.google.cloud.securitycenter.v1.GetBigQueryExportRequest)1 ListBigQueryExportsRequest (com.google.cloud.securitycenter.v1.ListBigQueryExportsRequest)1 UpdateBigQueryExportRequest (com.google.cloud.securitycenter.v1.UpdateBigQueryExportRequest)1 ByteString (com.google.protobuf.ByteString)1