Search in sources :

Example 1 with TppSshCertRetrieveRequest

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

the class TppConnectorUtils method convertToTppSshCertRetReq.

public static TppSshCertRetrieveRequest convertToTppSshCertRetReq(SshCertificateRequest sshCertificateRequest) throws VCertException {
    TppSshCertRetrieveRequest tppSshCertRetrieveRequest = new TppSshCertRetrieveRequest();
    tppSshCertRetrieveRequest.dn(isNotBlank(sshCertificateRequest.pickupID()) ? sshCertificateRequest.pickupID() : null);
    tppSshCertRetrieveRequest.guid(isNotBlank(sshCertificateRequest.guid()) ? sshCertificateRequest.guid() : null);
    tppSshCertRetrieveRequest.privateKeyPassphrase(isNotBlank(sshCertificateRequest.privateKeyPassphrase()) ? sshCertificateRequest.privateKeyPassphrase() : null);
    return tppSshCertRetrieveRequest;
}
Also used : TppSshCertRetrieveRequest(com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveRequest)

Example 2 with TppSshCertRetrieveRequest

use of com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveRequest 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)2 TppSshCertRetrieveResponse (com.venafi.vcert.sdk.connectors.tpp.endpoint.ssh.TppSshCertRetrieveResponse)1 Instant (java.time.Instant)1