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());
}
}
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);
}
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));
}
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));
}
}
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);
}
}
Aggregations