Search in sources :

Example 1 with RequestInProgressException

use of software.amazon.awssdk.services.acm.model.RequestInProgressException in project data-prepper by opensearch-project.

the class ACMCertificateProvider method getCertificate.

public Certificate getCertificate() {
    GetCertificateResponse getCertificateResponse = null;
    long timeSlept = 0L;
    while (getCertificateResponse == null && timeSlept < totalTimeout) {
        try {
            GetCertificateRequest getCertificateRequest = GetCertificateRequest.builder().certificateArn(acmArn).build();
            getCertificateResponse = acmClient.getCertificate(getCertificateRequest);
        } catch (final RequestInProgressException ex) {
            try {
                Thread.sleep(SLEEP_INTERVAL);
            } catch (InterruptedException iex) {
                throw new RuntimeException(iex);
            }
        } catch (final ResourceNotFoundException | InvalidArnException ex) {
            LOG.error("Exception retrieving the certificate with arn: {}", acmArn, ex);
            throw ex;
        }
        timeSlept += SLEEP_INTERVAL;
    }
    if (getCertificateResponse != null) {
        return new Certificate(getCertificateResponse.certificate());
    } else {
        throw new IllegalStateException(String.format("Exception retrieving certificate results. Time spent retrieving certificate is %d ms and total time out set is %d ms.", timeSlept, totalTimeout));
    }
}
Also used : GetCertificateRequest(software.amazon.awssdk.services.acm.model.GetCertificateRequest) RequestInProgressException(software.amazon.awssdk.services.acm.model.RequestInProgressException) GetCertificateResponse(software.amazon.awssdk.services.acm.model.GetCertificateResponse) InvalidArnException(software.amazon.awssdk.services.acm.model.InvalidArnException) ResourceNotFoundException(software.amazon.awssdk.services.acm.model.ResourceNotFoundException) Certificate(com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate)

Example 2 with RequestInProgressException

use of software.amazon.awssdk.services.acm.model.RequestInProgressException in project data-prepper by opensearch-project.

the class ACMCertificateProvider method getCertificate.

public Certificate getCertificate() {
    ExportCertificateResponse exportCertificateResponse = null;
    long timeSlept = 0L;
    // The private key from ACM is encrypted. Passphrase is the privateKey password that will be used to decrypt the
    // private key. If it's not provided, generate a random password. The configured passphrase can
    // be used to decrypt the private key manually using openssl commands for any inspection or debugging.
    final String pkPassphrase = Optional.ofNullable(passphrase).orElse(generatePassphrase(PASSPHRASE_CHAR_COUNT));
    while (exportCertificateResponse == null && timeSlept < totalTimeout) {
        try {
            ExportCertificateRequest exportCertificateRequest = ExportCertificateRequest.builder().certificateArn(acmArn).passphrase(SdkBytes.fromByteArray(pkPassphrase.getBytes())).build();
            exportCertificateResponse = acmClient.exportCertificate(exportCertificateRequest);
        } catch (final RequestInProgressException ex) {
            try {
                Thread.sleep(SLEEP_INTERVAL);
            } catch (InterruptedException iex) {
                throw new RuntimeException(iex);
            }
        } catch (final ResourceNotFoundException | InvalidArnException ex) {
            LOG.error("Exception retrieving the certificate with arn: {}", acmArn, ex);
            throw ex;
        }
        timeSlept += SLEEP_INTERVAL;
    }
    if (exportCertificateResponse != null) {
        final String decryptedPrivateKey = getDecryptedPrivateKey(exportCertificateResponse.privateKey(), pkPassphrase);
        return new Certificate(exportCertificateResponse.certificate(), decryptedPrivateKey);
    } else {
        throw new IllegalStateException(String.format("Exception retrieving certificate results. Time spent retrieving certificate is" + " %d ms and total time out set is %d ms.", timeSlept, totalTimeout));
    }
}
Also used : RequestInProgressException(software.amazon.awssdk.services.acm.model.RequestInProgressException) ExportCertificateResponse(software.amazon.awssdk.services.acm.model.ExportCertificateResponse) InvalidArnException(software.amazon.awssdk.services.acm.model.InvalidArnException) ExportCertificateRequest(software.amazon.awssdk.services.acm.model.ExportCertificateRequest) ResourceNotFoundException(software.amazon.awssdk.services.acm.model.ResourceNotFoundException) Certificate(com.amazon.dataprepper.plugins.certificate.model.Certificate)

Aggregations

InvalidArnException (software.amazon.awssdk.services.acm.model.InvalidArnException)2 RequestInProgressException (software.amazon.awssdk.services.acm.model.RequestInProgressException)2 ResourceNotFoundException (software.amazon.awssdk.services.acm.model.ResourceNotFoundException)2 Certificate (com.amazon.dataprepper.plugins.certificate.model.Certificate)1 Certificate (com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate)1 ExportCertificateRequest (software.amazon.awssdk.services.acm.model.ExportCertificateRequest)1 ExportCertificateResponse (software.amazon.awssdk.services.acm.model.ExportCertificateResponse)1 GetCertificateRequest (software.amazon.awssdk.services.acm.model.GetCertificateRequest)1 GetCertificateResponse (software.amazon.awssdk.services.acm.model.GetCertificateResponse)1