@@ -20,14 +20,29 @@ public ElasticsearchContainer(ElasticsearchConfiguration configuration)
2020 /// Gets the Elasticsearch connection string.
2121 /// </summary>
2222 /// <remarks>
23- /// The Elasticsearch module does not export the SSL certificate from the container by default.
24- /// If you are trying to connect to the Elasticsearch service, you need to override the certificate validation callback to establish the connection.
23+ /// The Elasticsearch module does not export the SSL certificate from the container
24+ /// by default. If you are trying to connect to the Elasticsearch service, you need
25+ /// to override the certificate validation callback to establish the connection.
2526 /// We will export the certificate and support trusted SSL connections in the future.
2627 /// </remarks>
2728 /// <returns>The Elasticsearch connection string.</returns>
2829 public string GetConnectionString ( )
2930 {
30- var endpoint = new UriBuilder ( Uri . UriSchemeHttps , Hostname , GetMappedPublicPort ( ElasticsearchBuilder . ElasticsearchHttpsPort ) ) ;
31+ var hasSecurityEnabled = _configuration . Environments
32+ . TryGetValue ( "xpack.security.enabled" , out var securityEnabled ) ;
33+
34+ var hasHttpSslEnabled = _configuration . Environments
35+ . TryGetValue ( "xpack.security.http.ssl.enabled" , out var httpSslEnabled ) ;
36+
37+ var httpsDisabled =
38+ hasSecurityEnabled &&
39+ hasHttpSslEnabled &&
40+ "false" . Equals ( securityEnabled , StringComparison . OrdinalIgnoreCase ) &&
41+ "false" . Equals ( httpSslEnabled , StringComparison . OrdinalIgnoreCase ) ;
42+
43+ var scheme = httpsDisabled ? Uri . UriSchemeHttp : Uri . UriSchemeHttps ;
44+
45+ var endpoint = new UriBuilder ( scheme , Hostname , GetMappedPublicPort ( ElasticsearchBuilder . ElasticsearchHttpsPort ) ) ;
3146 endpoint . UserName = _configuration . Username ;
3247 endpoint . Password = _configuration . Password ;
3348 return endpoint . ToString ( ) ;
0 commit comments