Search in sources :

Example 6 with BigQueryExport

use of com.google.cloud.securitycenter.v1.BigQueryExport in project java-securitycenter by googleapis.

the class ListBigQueryExports method listBigQueryExports.

// List BigQuery exports in the given parent.
public static void listBigQueryExports(String parent) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        ListBigQueryExportsRequest request = ListBigQueryExportsRequest.newBuilder().setParent(parent).build();
        ListBigQueryExportsPagedResponse response = client.listBigQueryExports(request);
        System.out.println("Listing BigQuery exports:");
        for (BigQueryExport bigQueryExport : response.iterateAll()) {
            System.out.println(bigQueryExport.getName());
        }
    }
}
Also used : ListBigQueryExportsRequest(com.google.cloud.securitycenter.v1.ListBigQueryExportsRequest) BigQueryExport(com.google.cloud.securitycenter.v1.BigQueryExport) ListBigQueryExportsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListBigQueryExportsPagedResponse) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 7 with BigQueryExport

use of com.google.cloud.securitycenter.v1.BigQueryExport in project java-securitycenter by googleapis.

the class SecurityCenterClientTest method listBigQueryExportsTest.

@Test
public void listBigQueryExportsTest() throws Exception {
    BigQueryExport responsesElement = BigQueryExport.newBuilder().build();
    ListBigQueryExportsResponse expectedResponse = ListBigQueryExportsResponse.newBuilder().setNextPageToken("").addAllBigQueryExports(Arrays.asList(responsesElement)).build();
    mockSecurityCenter.addResponse(expectedResponse);
    FolderName parent = FolderName.of("[FOLDER]");
    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 8 with BigQueryExport

use of com.google.cloud.securitycenter.v1.BigQueryExport in project java-securitycenter by googleapis.

the class UpdateBigQueryExport method updateBigQueryExport.

// Updates an existing BigQuery export.
public static void updateBigQueryExport(String parent, String filter, String bigQueryExportId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Set the new values for export configuration.
        BigQueryExport bigQueryExport = BigQueryExport.newBuilder().setName(String.format("%s/bigQueryExports/%s", parent, bigQueryExportId)).setFilter(filter).build();
        UpdateBigQueryExportRequest request = UpdateBigQueryExportRequest.newBuilder().setBigQueryExport(bigQueryExport).setUpdateMask(FieldMask.newBuilder().addPaths("filter").build()).build();
        BigQueryExport response = client.updateBigQueryExport(request);
        if (!response.getFilter().equalsIgnoreCase(filter)) {
            System.out.println("Failed to update BigQueryExport!");
            return;
        }
        System.out.println("BigQueryExport updated successfully!");
    }
}
Also used : BigQueryExport(com.google.cloud.securitycenter.v1.BigQueryExport) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) UpdateBigQueryExportRequest(com.google.cloud.securitycenter.v1.UpdateBigQueryExportRequest)

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