@@ -6,11 +6,11 @@ public sealed class OpenSearchBuilder : ContainerBuilder<OpenSearchBuilder, Open
66{
77 public const string OpenSearchImage = "opensearchproject/opensearch:2.12.0" ;
88
9- public const int OpenSearchRestApiPort = 9200 ;
9+ public const ushort OpenSearchRestApiPort = 9200 ;
1010
11- public const int OpenSearchTransportPort = 9300 ;
11+ public const ushort OpenSearchTransportPort = 9300 ;
1212
13- public const int OpenSearchPerformanceAnalyzerPort = 9600 ;
13+ public const ushort OpenSearchPerformanceAnalyzerPort = 9600 ;
1414
1515 public const string DefaultUsername = "admin" ;
1616
@@ -79,22 +79,26 @@ public override OpenSearchContainer Build()
7979 {
8080 Validate ( ) ;
8181
82- var openSearchBuilder = this ;
82+ OpenSearchBuilder openSearchBuilder ;
8383
84- const string oldInsecurePassword = "admin" ;
85- var imageIsBefore_v2_12 = DockerResourceConfiguration . Image . MatchVersion ( p => ( p . Major == 2 && p . Minor < 12 ) || p . Major == 1 ) ;
86- // OpenSearch images before v2.12.0 have hardcoded default password.
87- // If password have not been set (it equals DefaultPassword), set it to "admin".
88- if ( imageIsBefore_v2_12 && string . Equals ( DockerResourceConfiguration . Password , DefaultPassword , StringComparison . Ordinal ) )
84+ Predicate < System . Version > predicate = v => v . Major == 1 || ( v . Major == 2 && v . Minor < 12 ) ;
85+
86+ var image = DockerResourceConfiguration . Image ;
87+
88+ // Images before version 2.12.0 use a hardcoded default password.
89+ var requiresHardcodedDefaultPassword = image . MatchVersion ( predicate ) ;
90+ if ( requiresHardcodedDefaultPassword )
91+ {
92+ openSearchBuilder = WithPassword ( "admin" ) ;
93+ }
94+ else
8995 {
90- openSearchBuilder = WithPassword ( oldInsecurePassword ) ;
96+ openSearchBuilder = this ;
9197 }
9298
9399 // By default, the base builder waits until the container is running. However, for OpenSearch, a more advanced waiting strategy is necessary that requires access to the password.
94100 // If the user does not provide a custom waiting strategy, append the default OpenSearch waiting strategy.
95- openSearchBuilder = DockerResourceConfiguration . WaitStrategies . Count ( ) > 1 ?
96- openSearchBuilder :
97- openSearchBuilder . WithWaitStrategy ( Wait . ForUnixContainer ( ) . AddCustomWaitStrategy ( new WaitUntil ( openSearchBuilder . DockerResourceConfiguration ) ) ) ;
101+ openSearchBuilder = DockerResourceConfiguration . WaitStrategies . Count ( ) > 1 ? openSearchBuilder : openSearchBuilder . WithWaitStrategy ( Wait . ForUnixContainer ( ) . AddCustomWaitStrategy ( new WaitUntil ( DockerResourceConfiguration ) ) ) ;
98102 return new OpenSearchContainer ( openSearchBuilder . DockerResourceConfiguration ) ;
99103 }
100104
0 commit comments