Search in sources :

Example 6 with Certificate

use of com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate in project data-prepper by opensearch-project.

the class S3CertificateProvider method getCertificate.

public Certificate getCertificate() {
    try {
        final URI certificateFileUri = new URI(certificateFilePath);
        final String certificate = getObjectWithKey(certificateFileUri.getHost(), certificateFileUri.getPath().substring(1));
        return new Certificate(certificate);
    } catch (URISyntaxException ex) {
        LOG.error("Error encountered while parsing the certificate's Amazon S3 URI.", ex);
        throw new RuntimeException(ex);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Certificate(com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate)

Example 7 with Certificate

use of com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate in project data-prepper by opensearch-project.

the class FileCertificateProviderTest method getCertificateValidPathSuccess.

@Test
public void getCertificateValidPathSuccess() throws IOException {
    final String certificateFilePath = FileCertificateProviderTest.class.getClassLoader().getResource("test-crt.crt").getPath();
    fileCertificateProvider = new FileCertificateProvider(certificateFilePath);
    final Certificate certificate = fileCertificateProvider.getCertificate();
    final Path certFilePath = new File(certificateFilePath).toPath();
    final String certAsString = Files.readString(certFilePath);
    assertThat(certificate.getCertificate(), is(certAsString));
}
Also used : Path(java.nio.file.Path) File(java.io.File) Certificate(com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate) Test(org.junit.Test)

Example 8 with Certificate

use of com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate in project data-prepper by opensearch-project.

the class S3CertificateProviderTest method getCertificateValidKeyPathSuccess.

@Test
public void getCertificateValidKeyPathSuccess() {
    final String certificateContent = UUID.randomUUID().toString();
    final String bucketName = UUID.randomUUID().toString();
    final String certificatePath = UUID.randomUUID().toString();
    final String s3SslKeyCertChainFile = String.format("s3://%s/%s", bucketName, certificatePath);
    final InputStream certObjectStream = IOUtils.toInputStream(certificateContent, StandardCharsets.UTF_8);
    final ResponseInputStream certResponseInputStream = new ResponseInputStream<>(GetObjectResponse.builder().build(), AbortableInputStream.create(certObjectStream));
    final GetObjectRequest certRequest = GetObjectRequest.builder().bucket(bucketName).key(certificatePath).build();
    when(s3Client.getObject(certRequest)).thenReturn(certResponseInputStream);
    s3CertificateProvider = new S3CertificateProvider(s3Client, s3SslKeyCertChainFile);
    final Certificate certificate = s3CertificateProvider.getCertificate();
    assertThat(certificate.getCertificate(), is(certificateContent));
}
Also used : AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) InputStream(java.io.InputStream) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) Certificate(com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate) Test(org.junit.Test)

Aggregations

Certificate (com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate)8 Test (org.junit.Test)5 File (java.io.File)4 Path (java.nio.file.Path)4 GetCertificateRequest (software.amazon.awssdk.services.acm.model.GetCertificateRequest)2 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)1 Server (com.linecorp.armeria.server.Server)1 ServerBuilder (com.linecorp.armeria.server.ServerBuilder)1 TraceServiceGrpc (io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 ResponseInputStream (software.amazon.awssdk.core.ResponseInputStream)1 AbortableInputStream (software.amazon.awssdk.http.AbortableInputStream)1 GetCertificateResponse (software.amazon.awssdk.services.acm.model.GetCertificateResponse)1 InvalidArnException (software.amazon.awssdk.services.acm.model.InvalidArnException)1 RequestInProgressException (software.amazon.awssdk.services.acm.model.RequestInProgressException)1 ResourceNotFoundException (software.amazon.awssdk.services.acm.model.ResourceNotFoundException)1 GetObjectRequest (software.amazon.awssdk.services.s3.model.GetObjectRequest)1