Search in sources :

Example 1 with EnableCertificateAuthorityRequest

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

the class EnableCertificateAuthority method enableCertificateAuthority.

// Enable the Certificate Authority present in the given ca pool.
// CA cannot be enabled if it has been already deleted.
public static void enableCertificateAuthority(String project, String location, String pool_Id, String certificateAuthorityName) throws IOException, ExecutionException, InterruptedException {
    try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
        // Create the Certificate Authority Name.
        CertificateAuthorityName certificateAuthorityParent = CertificateAuthorityName.newBuilder().setProject(project).setLocation(location).setCaPool(pool_Id).setCertificateAuthority(certificateAuthorityName).build();
        // Create the Enable Certificate Authority Request.
        EnableCertificateAuthorityRequest enableCertificateAuthorityRequest = EnableCertificateAuthorityRequest.newBuilder().setName(certificateAuthorityParent.toString()).build();
        // Enable the Certificate Authority.
        ApiFuture<Operation> futureCall = certificateAuthorityServiceClient.enableCertificateAuthorityCallable().futureCall(enableCertificateAuthorityRequest);
        Operation response = futureCall.get();
        if (response.hasError()) {
            System.out.println("Error while enabling Certificate Authority !" + response.getError());
            return;
        }
        // Get the current CA state.
        State caState = certificateAuthorityServiceClient.getCertificateAuthority(certificateAuthorityParent).getState();
        // Check if the CA is enabled.
        if (caState == State.ENABLED) {
            System.out.println("Enabled Certificate Authority : " + certificateAuthorityName);
        } else {
            System.out.println("Cannot enable the Certificate Authority ! Current CA State: " + caState);
        }
    }
}
Also used : State(com.google.cloud.security.privateca.v1.CertificateAuthority.State) CertificateAuthorityServiceClient(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient) CertificateAuthorityName(com.google.cloud.security.privateca.v1.CertificateAuthorityName) EnableCertificateAuthorityRequest(com.google.cloud.security.privateca.v1.EnableCertificateAuthorityRequest) Operation(com.google.longrunning.Operation)

Aggregations

State (com.google.cloud.security.privateca.v1.CertificateAuthority.State)1 CertificateAuthorityName (com.google.cloud.security.privateca.v1.CertificateAuthorityName)1 CertificateAuthorityServiceClient (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient)1 EnableCertificateAuthorityRequest (com.google.cloud.security.privateca.v1.EnableCertificateAuthorityRequest)1 Operation (com.google.longrunning.Operation)1