use of com.google.cloud.securitycenter.v1.OrganizationName in project gapic-generator-java by googleapis.
the class ConfigClientTest method listExclusionsTest3.
@Test
public void listExclusionsTest3() throws Exception {
LogExclusion responsesElement = LogExclusion.newBuilder().build();
ListExclusionsResponse expectedResponse = ListExclusionsResponse.newBuilder().setNextPageToken("").addAllExclusions(Arrays.asList(responsesElement)).build();
mockConfigServiceV2.addResponse(expectedResponse);
OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
ListExclusionsPagedResponse pagedListResponse = client.listExclusions(parent);
List<LogExclusion> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getExclusionsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListExclusionsRequest actualRequest = ((ListExclusionsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.securitycenter.v1.OrganizationName in project gapic-generator-java by googleapis.
the class ConfigClientTest method createSinkExceptionTest3.
@Test
public void createSinkExceptionTest3() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockConfigServiceV2.addException(exception);
try {
OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
LogSink sink = LogSink.newBuilder().build();
client.createSink(parent, sink);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.cloud.securitycenter.v1.OrganizationName in project gapic-generator-java by googleapis.
the class ConfigClientTest method createExclusionExceptionTest3.
@Test
public void createExclusionExceptionTest3() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockConfigServiceV2.addException(exception);
try {
OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
LogExclusion exclusion = LogExclusion.newBuilder().build();
client.createExclusion(parent, exclusion);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.cloud.securitycenter.v1.OrganizationName in project google-cloud-java by googleapis.
the class SourceSnippets method listSources.
// [END securitycenter_create_source]
/**
* List sources under an organization.
*
* @param organizationName The organization for the source.
*/
// [START securitycenter_list_sources]
static ImmutableList<Source> listSources(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request to list sources in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
ListSourcesRequest.Builder request = ListSourcesRequest.newBuilder().setParent(organizationName.toString());
// Call the API.
ListSourcesPagedResponse response = client.listSources(request.build());
// This creates one list for all sources. If your organization has a large number of sources
// this can cause out of memory issues. You can process them batches by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<Source> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Sources:");
System.out.println(results);
return results;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
use of com.google.cloud.securitycenter.v1.OrganizationName in project google-cloud-java by googleapis.
the class AssetSnippets method listAssetsAsOfYesterday.
// [END securitycenter_list_assets_with_filter]
/**
* Lists all project assets for an organization at a given point in time.
*
* @param organizationName The organization to list assets for.
* @param asOf The snapshot time to query for assets. If null defaults to one day ago.
*/
// [START securitycenter_list_assets_at_time]
static ImmutableList<ListAssetsResult> listAssetsAsOfYesterday(OrganizationName organizationName, Instant asOf) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to search for all assets in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
// Initialize the builder with the organization and filter
ListAssetsRequest.Builder request = ListAssetsRequest.newBuilder().setParent(organizationName.toString()).setFilter("security_center_properties.resource_type=\"google.cloud.resourcemanager.Project\"");
// Set read time to either the instant passed in or one day ago.
asOf = MoreObjects.firstNonNull(asOf, Instant.now().minus(Duration.ofDays(1)));
request.getReadTimeBuilder().setSeconds(asOf.getEpochSecond()).setNanos(asOf.getNano());
// Call the API.
ListAssetsPagedResponse response = client.listAssets(request.build());
// This creates one list for all assets. If your organization has a large number of assets
// this can cause out of memory issues. You can process them incrementally by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<ListAssetsResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Projects:");
System.out.println(results);
return results;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
Aggregations