@@ -60,6 +60,7 @@ public abstract static class TlsInstanceBuilder<T extends TlsInstanceBuilder<T>>
6060 protected final ParameterProfile profile ;
6161 protected final ImageProperties imageProperties ;
6262 protected final String version ;
63+ protected Image image ;
6364 protected boolean autoRemove = true ;
6465 // shared constructor parameters
6566 // Host Info:
@@ -90,6 +91,21 @@ public TlsInstanceBuilder(
9091 this .transportType = transportType ;
9192 }
9293
94+ public TlsInstanceBuilder (Image image , TransportType transportType ) {
95+ this .version = image .getLabels ().get (TlsImageLabels .VERSION .getLabelName ());
96+ TlsImplementationType type =
97+ TlsImplementationType .fromString (
98+ image .getLabels ().get (TlsImageLabels .IMPLEMENTATION .getLabelName ()));
99+ ConnectionRole role =
100+ ConnectionRole .valueOf (
101+ image .getLabels ()
102+ .get (TlsImageLabels .CONNECTION_ROLE .getLabelName ())
103+ .toUpperCase ());
104+ this .profile = retrieveParameterProfile (type , version , role );
105+ this .imageProperties = retrieveImageProperties (role , type );
106+ this .transportType = transportType ;
107+ }
108+
93109 public T autoRemove (boolean value ) {
94110 autoRemove = value ;
95111 return (T ) this ;
@@ -206,6 +222,10 @@ public TlsClientInstanceBuilder(
206222 super (type , version , ConnectionRole .CLIENT , transportType );
207223 }
208224
225+ public TlsClientInstanceBuilder (Image image , TransportType transportType ) {
226+ super (image , transportType );
227+ }
228+
209229 public TlsClientInstanceBuilder pull () {
210230 super .pull (ConnectionRole .CLIENT );
211231 return this ;
@@ -214,6 +234,7 @@ public TlsClientInstanceBuilder pull() {
214234 @ Override
215235 public DockerTlsClientInstance build () throws DockerException , InterruptedException {
216236 return new DockerTlsClientInstance (
237+ image ,
217238 containerName ,
218239 profile ,
219240 imageProperties ,
@@ -241,6 +262,10 @@ public TlsServerInstanceBuilder(
241262 super (type , version , ConnectionRole .SERVER , transportType );
242263 }
243264
265+ public TlsServerInstanceBuilder (Image image , TransportType transportType ) {
266+ super (image , transportType );
267+ }
268+
244269 public TlsServerInstanceBuilder pull () {
245270 super .pull (ConnectionRole .SERVER );
246271 return this ;
@@ -249,6 +274,7 @@ public TlsServerInstanceBuilder pull() {
249274 @ Override
250275 public DockerTlsServerInstance build () throws DockerException , InterruptedException {
251276 return new DockerTlsServerInstance (
277+ image ,
252278 containerName ,
253279 profile ,
254280 imageProperties ,
@@ -349,6 +375,28 @@ public static List<Image> getAllImages() {
349375 .exec ();
350376 }
351377
378+ public static Image getMatchingImage (
379+ List <Image > images , TlsImplementationType type , String version , ConnectionRole role ) {
380+ return images .stream ()
381+ .filter (
382+ image ->
383+ image .getLabels ()
384+ .get (TlsImageLabels .VERSION .getLabelName ())
385+ .equals (version ))
386+ .filter (
387+ image ->
388+ image .getLabels ()
389+ .get (TlsImageLabels .IMPLEMENTATION .getLabelName ())
390+ .equals (type .name ().toLowerCase ()))
391+ .filter (
392+ image ->
393+ image .getLabels ()
394+ .get (TlsImageLabels .CONNECTION_ROLE .getLabelName ())
395+ .equals (role .name ().toLowerCase ()))
396+ .findFirst ()
397+ .orElse (null );
398+ }
399+
352400 private static void executeCommand (Runtime runtime , String command , int timeout )
353401 throws InterruptedException , IOException {
354402 Process process = runtime .exec (command );
0 commit comments