Search in sources :

Example 1 with CaPoolName

use of com.google.cloud.security.privateca.v1.CaPoolName in project java-security-private-ca by googleapis.

the class CertificateAuthorityServiceClientTest method listCertificatesTest.

@Test
public void listCertificatesTest() throws Exception {
    Certificate responsesElement = Certificate.newBuilder().build();
    ListCertificatesResponse expectedResponse = ListCertificatesResponse.newBuilder().setNextPageToken("").addAllCertificates(Arrays.asList(responsesElement)).build();
    mockCertificateAuthorityService.addResponse(expectedResponse);
    CaPoolName parent = CaPoolName.of("[PROJECT]", "[LOCATION]", "[CA_POOL]");
    ListCertificatesPagedResponse pagedListResponse = client.listCertificates(parent);
    List<Certificate> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getCertificatesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockCertificateAuthorityService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListCertificatesRequest actualRequest = ((ListCertificatesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListCertificatesPagedResponse(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListCertificatesPagedResponse) Test(org.junit.Test)

Example 2 with CaPoolName

use of com.google.cloud.security.privateca.v1.CaPoolName 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 CaPoolName

use of com.google.cloud.security.privateca.v1.CaPoolName 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 CaPoolName

use of com.google.cloud.security.privateca.v1.CaPoolName 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 CaPoolName

use of com.google.cloud.security.privateca.v1.CaPoolName 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 Test (org.junit.Test)3 Certificate (com.google.cloud.security.privateca.v1.Certificate)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 CaPool (com.google.cloud.security.privateca.v1.CaPool)1 ListCertificateAuthoritiesPagedResponse (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListCertificateAuthoritiesPagedResponse)1 ListCertificatesPagedResponse (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListCertificatesPagedResponse)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 Operation (com.google.longrunning.Operation)1 ByteString (com.google.protobuf.ByteString)1