88import static org .assertj .core .api .Assertions .assertThat ;
99
1010import com .google .errorprone .annotations .CanIgnoreReturnValue ;
11+ import java .nio .file .Path ;
1112import java .time .Duration ;
1213import java .util .ArrayList ;
14+ import java .util .Arrays ;
15+ import java .util .Collections ;
1316import java .util .HashSet ;
1417import java .util .List ;
1518import java .util .Locale ;
@@ -29,6 +32,10 @@ public class JmxScraperContainer extends GenericContainer<JmxScraperContainer> {
2932 private String password ;
3033 private final List <String > extraJars ;
3134 private boolean testJmx ;
35+ private Path keyStore ;
36+ private String keyStorePassword ;
37+ private Path trustStore ;
38+ private String trustStorePassword ;
3239
3340 public JmxScraperContainer (String otlpEndpoint , String baseImage ) {
3441 super (baseImage );
@@ -112,6 +119,20 @@ public JmxScraperContainer withTestJmx() {
112119 return this ;
113120 }
114121
122+ @ CanIgnoreReturnValue
123+ public JmxScraperContainer withKeyStore (Path keyStore , String password ) {
124+ this .keyStore = keyStore ;
125+ this .keyStorePassword = password ;
126+ return this ;
127+ }
128+
129+ @ CanIgnoreReturnValue
130+ public JmxScraperContainer withTrustStore (Path trustStore , String password ) {
131+ this .trustStore = trustStore ;
132+ this .trustStorePassword = password ;
133+ return this ;
134+ }
135+
115136 @ Override
116137 public void start () {
117138 // for now only configure through JVM args
@@ -138,6 +159,9 @@ public void start() {
138159 arguments .add ("-Dotel.jmx.password=" + password );
139160 }
140161
162+ arguments .addAll (addKeyStore (keyStore , keyStorePassword , /* keyStore= */ true ));
163+ arguments .addAll (addKeyStore (trustStore , trustStorePassword , /* keyStore= */ false ));
164+
141165 if (!customYamlFiles .isEmpty ()) {
142166 for (String yaml : customYamlFiles ) {
143167 this .withCopyFileToContainer (MountableFile .forClasspathResource (yaml ), yaml );
@@ -171,4 +195,15 @@ public void start() {
171195
172196 super .start ();
173197 }
198+
199+ private List <String > addKeyStore (Path path , String password , boolean keyStore ) {
200+ if (path == null ) {
201+ return Collections .emptyList ();
202+ }
203+ String containerPath = "/" + path .getFileName ().toString ();
204+ this .withCopyFileToContainer (MountableFile .forHostPath (path ), containerPath );
205+
206+ String prefix = String .format ("-Djavax.net.ssl.%sStore" , keyStore ? "key" : "trust" );
207+ return Arrays .asList (prefix + "=" + containerPath , prefix + "Password=" + password );
208+ }
174209}
0 commit comments