use of com.google.cloud.security.privateca.v1.CaPool in project java-security-private-ca by googleapis.
the class CertificateAuthorityServiceClientTest method listCaPoolsTest.
@Test
public void listCaPoolsTest() throws Exception {
CaPool responsesElement = CaPool.newBuilder().build();
ListCaPoolsResponse expectedResponse = ListCaPoolsResponse.newBuilder().setNextPageToken("").addAllCaPools(Arrays.asList(responsesElement)).build();
mockCertificateAuthorityService.addResponse(expectedResponse);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListCaPoolsPagedResponse pagedListResponse = client.listCaPools(parent);
List<CaPool> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getCaPoolsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockCertificateAuthorityService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListCaPoolsRequest actualRequest = ((ListCaPoolsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.security.privateca.v1.CaPool in project java-security-private-ca by googleapis.
the class DeleteCaPool method deleteCaPool.
// Delete the CA pool as mentioned by the pool_Id.
// Before deleting the pool, all CAs in the pool MUST BE deleted.
public static void deleteCaPool(String project, String location, String pool_Id) throws InterruptedException, ExecutionException, IOException {
// clean up any remaining background resources.
try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
// Set the project, location and pool_Id to delete.
CaPoolName caPool = CaPoolName.newBuilder().setProject(project).setLocation(location).setCaPool(pool_Id).build();
// Create the Delete request.
DeleteCaPoolRequest deleteCaPoolRequest = DeleteCaPoolRequest.newBuilder().setName(caPool.toString()).build();
// Delete the CA Pool.
ApiFuture<Operation> futureCall = certificateAuthorityServiceClient.deleteCaPoolCallable().futureCall(deleteCaPoolRequest);
Operation response = futureCall.get();
if (response.hasError()) {
System.out.println("Error while deleting CA pool !" + response.getError());
return;
}
System.out.println("Deleted CA Pool: " + pool_Id);
}
}
use of com.google.cloud.security.privateca.v1.CaPool in project java-security-private-ca by googleapis.
the class ListCaPools method listCaPools.
// List all CA pools present in the given project and location.
public static void listCaPools(String project, String location) throws IOException {
// clean up any remaining background resources.
try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
// Set the Location Name which contains project and location of the pool.
LocationName locationName = LocationName.newBuilder().setProject(project).setLocation(location).build();
String caPoolName = "";
System.out.println("Available CA pools: ");
// List the CA pools.
for (CaPool caPool : certificateAuthorityServiceClient.listCaPools(locationName).iterateAll()) {
caPoolName = caPool.getName();
// caPoolName represents the full resource name of the
// format 'projects/{project-id}/locations/{location}/ca-pools/{ca-pool-id}'.
// Hence stripping it down to just CA pool id.
System.out.println(caPoolName.substring(caPoolName.lastIndexOf("/") + 1) + " " + caPool.isInitialized());
}
}
}
use of com.google.cloud.security.privateca.v1.CaPool in project java-security-private-ca by googleapis.
the class FilterCertificates method filterCertificates.
// Filter certificates based on a condition and list them.
public static void filterCertificates(String project, String location, String pool_Id) throws IOException {
// clean up any remaining background resources.
try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
CaPoolName caPool = CaPoolName.newBuilder().setProject(project).setLocation(location).setCaPool(pool_Id).build();
// Create the certificate request and set the filter condition.
ListCertificatesRequest listCertificatesRequest = ListCertificatesRequest.newBuilder().setParent(caPool.toString()).setFilter("certificate_description.subject_description.subject.organization=csr-org-name").build();
// Retrieve and print the certificate names.
System.out.println("Available certificates: ");
for (Certificate certificate : certificateAuthorityServiceClient.listCertificates(listCertificatesRequest).iterateAll()) {
System.out.println(certificate.getName());
}
}
}
use of com.google.cloud.security.privateca.v1.CaPool in project java-security-private-ca by googleapis.
the class ListCertificates method listCertificates.
// List Certificates present in the given CA pool.
public static void listCertificates(String project, String location, String pool_Id) throws IOException {
// clean up any remaining background resources.
try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
CaPoolName caPool = CaPoolName.newBuilder().setProject(project).setLocation(location).setCaPool(pool_Id).build();
// Retrieve and print the certificate names.
System.out.println("Available certificates: ");
for (Certificate certificate : certificateAuthorityServiceClient.listCertificates(caPool).iterateAll()) {
System.out.println(certificate.getName());
}
}
}
Aggregations