Search in sources :

Example 1 with ListCertificatesRequest

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

the class CertificateAuthorityServiceClientTest method listCertificatesTest2.

@Test
public void listCertificatesTest2() throws Exception {
    Certificate responsesElement = Certificate.newBuilder().build();
    ListCertificatesResponse expectedResponse = ListCertificatesResponse.newBuilder().setNextPageToken("").addAllCertificates(Arrays.asList(responsesElement)).build();
    mockCertificateAuthorityService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    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, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) ListCertificatesPagedResponse(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListCertificatesPagedResponse) Test(org.junit.Test)

Example 2 with ListCertificatesRequest

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

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

Aggregations

ListCertificatesPagedResponse (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListCertificatesPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 CaPoolName (com.google.cloud.security.privateca.v1.CaPoolName)1 Certificate (com.google.cloud.security.privateca.v1.Certificate)1 CertificateAuthorityServiceClient (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient)1 ListCertificatesRequest (com.google.cloud.security.privateca.v1.ListCertificatesRequest)1 ByteString (com.google.protobuf.ByteString)1