Commit 12d65d0a authored by Marc Gravell's avatar Marc Gravell

Merge pull request #218 from hrishi18pathak/master

Default SslHost in clustering mode
parents 248d936d 1b01dc86
......@@ -271,5 +271,24 @@ public void RedisLabsEnvironmentVariableClientCertificate(bool setEnv)
}
[Test]
public void SSLHostInferredFromEndpoints() {
var options = new ConfigurationOptions() {
EndPoints = {
{ "mycache.rediscache.windows.net", 15000},
{ "mycache.rediscache.windows.net", 15001 },
{ "mycache.rediscache.windows.net", 15002 },
}
};
options.Ssl = true;
Assert.True(options.SslHost == "mycache.rediscache.windows.net");
options = new ConfigurationOptions() {
EndPoints = {
{ "121.23.23.45", 15000},
}
};
Assert.True(options.SslHost == null);
}
}
}
......@@ -243,7 +243,7 @@ public CommandMap CommandMap
/// <summary>
/// The target-host to use when validating SSL certificate; setting a value here enables SSL mode
/// </summary>
public string SslHost { get { return sslHost; } set { sslHost = value; } }
public string SslHost { get { return sslHost ?? InferSslHostFromEndpoints(); } set { sslHost = value; } }
/// <summary>
/// Specifies the time in milliseconds that the system should allow for synchronous operations (defaults to 1 second)
......@@ -608,5 +608,15 @@ private void DoParse(string configuration, bool ignoreUnknown)
this.CommandMap = CommandMap.Create(map);
}
}
private string InferSslHostFromEndpoints() {
var dnsEndpoints = endpoints.Select(endpoint => endpoint as DnsEndPoint);
string dnsHost = dnsEndpoints.First() != null ? dnsEndpoints.First().Host : null;
if (dnsEndpoints.All(dnsEndpoint => (dnsEndpoint != null && dnsEndpoint.Host == dnsHost))) {
return dnsHost;
}
return null;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment