public static ElasticsearchClient GetOrAddClient <TConfig>( this IEphemeralCluster <TConfig> cluster, Func <ElasticsearchClientSettings, ElasticsearchClientSettings> modifySettings = null ) where TConfig : EphemeralClusterConfiguration { modifySettings ??= s => s; return(cluster.GetOrAddClient(c => { var settings = modifySettings(cluster.CreateConnectionSettings()); var current = (ITransportClientConfigurationValues)settings; var notAlreadyAuthenticated = current.Authentication == null && current.ClientCertificates == null; var noCertValidation = current.ServerCertificateValidationCallback == null; if (cluster.ClusterConfiguration.EnableSecurity && notAlreadyAuthenticated) { settings = settings.Authentication(new BasicAuthentication(ClusterAuthentication.Admin.Username, ClusterAuthentication.Admin.Password)); } if (cluster.ClusterConfiguration.EnableSsl && noCertValidation) { //todo use CA callback instead of allowall // ReSharper disable once UnusedVariable var ca = new X509Certificate2(cluster.ClusterConfiguration.FileSystem.CaCertificate); settings = settings.ServerCertificateValidationCallback(CertificateValidations.AllowAll); } var client = new ElasticsearchClient(settings); return client; })); }
public static IElasticClient GetOrAddClient <TConfig>( this IEphemeralCluster <TConfig> cluster, Func <ConnectionSettings, ConnectionSettings> createSettings = null, Func <ICollection <Uri>, IConnectionPool> createPool = null) where TConfig : EphemeralClusterConfiguration { createSettings = createSettings ?? (s => s); return(cluster.GetOrAddClient(c => { var host = (RunningFiddler) ? "ipv4.fiddler" : "localhost"; createPool = createPool ?? (uris => new StaticConnectionPool(uris)); var connectionPool = createPool(c.NodesUris(host)); var connection = TestClient.Configuration.RunIntegrationTests ? TestClient.CreateLiveConnection() : new InMemoryConnection(); var settings = TestClient.CreateSettings(createSettings, connection, connectionPool); var current = (IConnectionConfigurationValues)settings; var notAlreadyAuthenticated = current.BasicAuthenticationCredentials == null && current.ClientCertificates == null; var noCertValidation = current.ServerCertificateValidationCallback == null; if (cluster.ClusterConfiguration.EnableSecurity && notAlreadyAuthenticated) { settings = settings.BasicAuthentication(ClusterAuthentication.Admin.Username, ClusterAuthentication.Admin.Password); } if (cluster.ClusterConfiguration.EnableSsl && noCertValidation) { var ca = new X509Certificate2(cluster.ClusterConfiguration.FileSystem.CaCertificate); settings = settings.ServerCertificateValidationCallback(CertificateValidations.AllowAll); } var client = new ElasticClient(settings); return client; })); }