Search in sources :

Example 1 with Certificate

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

the class PeerClientPoolTest method testGetClientWithSSL.

@Test
public void testGetClientWithSSL() throws IOException {
    // Set up test server with SSL
    ServerBuilder sb = Server.builder();
    sb.disableServerHeader();
    sb.service(GrpcService.builder().addService(new TestPeerService()).build());
    sb.tls(SSL_CRT_FILE, SSL_KEY_FILE).https(PORT);
    try (Server server = sb.build()) {
        server.start();
        // Configure client pool
        PeerClientPool pool = PeerClientPool.getInstance();
        pool.setSsl(true);
        final Path certFilePath = new File(PeerClientPoolTest.class.getClassLoader().getResource("test-crt.crt").getFile()).toPath();
        final String certAsString = Files.readString(certFilePath);
        final Certificate certificate = new Certificate(certAsString);
        pool.setCertificate(certificate);
        TraceServiceGrpc.TraceServiceBlockingStub client = pool.getClient(LOCALHOST);
        assertNotNull(client);
        // Call API should not throw exception
        client.export(ExportTraceServiceRequest.newBuilder().build());
    }
}
Also used : Path(java.nio.file.Path) Server(com.linecorp.armeria.server.Server) ServerBuilder(com.linecorp.armeria.server.ServerBuilder) File(java.io.File) TraceServiceGrpc(io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc) Certificate(com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate) Test(org.junit.Test)

Example 2 with Certificate

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

the class PeerForwarderConfigTest method testBuildConfigValidSSL.

@Test
public void testBuildConfigValidSSL() throws IOException {
    final HashMap<String, Object> settings = new HashMap<>();
    settings.put(PeerForwarderConfig.DISCOVERY_MODE, DiscoveryMode.STATIC.toString());
    settings.put(PeerForwarderConfig.STATIC_ENDPOINTS, TEST_ENDPOINTS);
    settings.put(PeerForwarderConfig.SSL, true);
    settings.put(PeerForwarderConfig.SSL_KEY_CERT_FILE, VALID_SSL_KEY_CERT_FILE);
    final PluginSetting pluginSetting = new PluginSetting("peer_forwarder", settings);
    pluginSetting.setPipelineName(PIPELINE_NAME);
    PeerForwarderConfig.buildConfig(pluginSetting);
    verify(peerClientPool, times(1)).setSsl(true);
    final ArgumentCaptor<Certificate> certificateArgumentCaptor = ArgumentCaptor.forClass(Certificate.class);
    verify(peerClientPool, times(1)).setCertificate(certificateArgumentCaptor.capture());
    final Certificate certificate = certificateArgumentCaptor.getValue();
    final Path certFilePath = new File(VALID_SSL_KEY_CERT_FILE).toPath();
    final String certAsString = Files.readString(certFilePath);
    Assert.assertEquals(certificate.getCertificate(), certAsString);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) File(java.io.File) Certificate(com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate) Test(org.junit.Test)

Example 3 with Certificate

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

the class ACMCertificateProviderTest method getACMCertificateSuccess.

@Test
public void getACMCertificateSuccess() {
    final String certificateContent = UUID.randomUUID().toString();
    when(getCertificateResponse.certificate()).thenReturn(certificateContent);
    when(acmClient.getCertificate(any(GetCertificateRequest.class))).thenReturn(getCertificateResponse);
    final Certificate certificate = acmCertificateProvider.getCertificate();
    assertThat(certificate.getCertificate(), is(certificateContent));
}
Also used : GetCertificateRequest(software.amazon.awssdk.services.acm.model.GetCertificateRequest) Certificate(com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate) Test(org.junit.Test)

Example 4 with Certificate

use of com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate 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 5 with Certificate

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

the class FileCertificateProvider method getCertificate.

public Certificate getCertificate() {
    try {
        final Path certFilePath = new File(certificateFilePath).toPath();
        final byte[] bytes = Files.readAllBytes(certFilePath);
        final String certAsString = new String(bytes);
        return new Certificate(certAsString);
    } catch (final Exception ex) {
        LOG.error("Error encountered while reading the certificate.", ex);
        throw new RuntimeException(ex);
    }
}
Also used : Path(java.nio.file.Path) File(java.io.File) Certificate(com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate)

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