Search in sources :

Example 1 with CaPool

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListCaPoolsPagedResponse(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListCaPoolsPagedResponse) Test(org.junit.Test)

Example 2 with CaPool

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);
    }
}
Also used : DeleteCaPoolRequest(com.google.cloud.security.privateca.v1.DeleteCaPoolRequest) CertificateAuthorityServiceClient(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient) Operation(com.google.longrunning.Operation) CaPoolName(com.google.cloud.security.privateca.v1.CaPoolName)

Example 3 with CaPool

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());
        }
    }
}
Also used : CertificateAuthorityServiceClient(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient) CaPool(com.google.cloud.security.privateca.v1.CaPool) LocationName(com.google.cloud.security.privateca.v1.LocationName)

Example 4 with CaPool

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());
        }
    }
}
Also used : CertificateAuthorityServiceClient(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient) ListCertificatesRequest(com.google.cloud.security.privateca.v1.ListCertificatesRequest) CaPoolName(com.google.cloud.security.privateca.v1.CaPoolName) Certificate(com.google.cloud.security.privateca.v1.Certificate)

Example 5 with CaPool

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());
        }
    }
}
Also used : CertificateAuthorityServiceClient(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient) CaPoolName(com.google.cloud.security.privateca.v1.CaPoolName) Certificate(com.google.cloud.security.privateca.v1.Certificate)

Aggregations

CertificateAuthorityServiceClient (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient)5 CaPoolName (com.google.cloud.security.privateca.v1.CaPoolName)3 CaPool (com.google.cloud.security.privateca.v1.CaPool)2 Certificate (com.google.cloud.security.privateca.v1.Certificate)2 ListCaPoolsPagedResponse (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListCaPoolsPagedResponse)2 Operation (com.google.longrunning.Operation)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 IssuancePolicy (com.google.cloud.security.privateca.v1.CaPool.IssuancePolicy)1 DeleteCaPoolRequest (com.google.cloud.security.privateca.v1.DeleteCaPoolRequest)1 ListCertificatesRequest (com.google.cloud.security.privateca.v1.ListCertificatesRequest)1 LocationName (com.google.cloud.security.privateca.v1.LocationName)1 UpdateCaPoolRequest (com.google.cloud.security.privateca.v1.UpdateCaPoolRequest)1 ByteString (com.google.protobuf.ByteString)1