Search in sources :

Example 1 with TppSshCertRetrieveResponse

use of com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveResponse in project vcert-java by Venafi.

the class AbstractTppConnector method retrieveTppSshCertificate.

protected SshCertRetrieveDetails retrieveTppSshCertificate(SshCertificateRequest sshCertificateRequest) throws VCertException {
    TppSshCertRetrieveResponse tppSshCertRetrieveResponse = null;
    TppSshCertRetrieveRequest tppSshCertRetrieveRequest = TppConnectorUtils.convertToTppSshCertRetReq(sshCertificateRequest);
    // TODO move this retry logic to feign client
    Instant startTime = Instant.now();
    while (true) {
        tppSshCertRetrieveResponse = tppAPI.retrieveSshCertificate(tppSshCertRetrieveRequest);
        // if the certificate was returned(Issued)
        if (StringUtils.isNotBlank(tppSshCertRetrieveResponse.certificateData())) {
            break;
        }
        // if the certificate request was rejected
        if (tppSshCertRetrieveResponse.response().success() && tppSshCertRetrieveResponse.processingDetails().status().equals("Rejected"))
            throw new CertificateRejectedException(sshCertificateRequest.pickupID(), tppSshCertRetrieveResponse.processingDetails().statusDescription());
        // if the certificate is pending to be issued
        if (ZERO.equals(sshCertificateRequest.timeout())) {
            throw new CertificatePendingException(sshCertificateRequest.pickupID(), tppSshCertRetrieveResponse.processingDetails().statusDescription());
        }
        // if the timeout was reached
        if (Instant.now().isAfter(startTime.plus(sshCertificateRequest.timeout()))) {
            throw new RetrieveCertificateTimeoutException(sshCertificateRequest.pickupID());
        }
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            // Restore interrupted state...
            Thread.currentThread().interrupt();
            throw new AttemptToRetryException(e);
        }
    }
    return TppConnectorUtils.convertToSshCertRetrieveDetails(tppSshCertRetrieveResponse);
}
Also used : TppSshCertRetrieveResponse(com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveResponse) Instant(java.time.Instant) TppSshCertRetrieveRequest(com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveRequest)

Aggregations

TppSshCertRetrieveRequest (com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveRequest)1 TppSshCertRetrieveResponse (com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveResponse)1 Instant (java.time.Instant)1