Search in sources :

Example 1 with DisableCertificateAuthorityRequest

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

the class DisableCertificateAuthority method disableCertificateAuthority.

// Disable a Certificate Authority which is present in the given CA pool.
public static void disableCertificateAuthority(String project, String location, String pool_Id, String certificateAuthorityName) throws IOException, ExecutionException, InterruptedException {
    // clean up any remaining background resources.
    try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
        // Create the Certificate Authority Name.
        CertificateAuthorityName certificateAuthorityNameParent = CertificateAuthorityName.newBuilder().setProject(project).setLocation(location).setCaPool(pool_Id).setCertificateAuthority(certificateAuthorityName).build();
        // Create the Disable Certificate Authority Request.
        DisableCertificateAuthorityRequest disableCertificateAuthorityRequest = DisableCertificateAuthorityRequest.newBuilder().setName(certificateAuthorityNameParent.toString()).build();
        // Disable the Certificate Authority.
        ApiFuture<Operation> futureCall = certificateAuthorityServiceClient.disableCertificateAuthorityCallable().futureCall(disableCertificateAuthorityRequest);
        Operation response = futureCall.get();
        if (response.hasError()) {
            System.out.println("Error while disabling Certificate Authority !" + response.getError());
            return;
        }
        // Get the current CA state.
        State caState = certificateAuthorityServiceClient.getCertificateAuthority(certificateAuthorityNameParent).getState();
        // Check if the Certificate Authority is disabled.
        if (caState == State.DISABLED) {
            System.out.println("Disabled Certificate Authority : " + certificateAuthorityName);
        } else {
            System.out.println("Cannot disable 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) DisableCertificateAuthorityRequest(com.google.cloud.security.privateca.v1.DisableCertificateAuthorityRequest) 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 DisableCertificateAuthorityRequest (com.google.cloud.security.privateca.v1.DisableCertificateAuthorityRequest)1 Operation (com.google.longrunning.Operation)1