Skip to content

Commit

Permalink
Elastic Search Health Checks - Support for Certificate Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Trent Smith committed Jul 4, 2019
1 parent 9de5202 commit 2f242a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<HealthCheckRedis>2.2.3</HealthCheckRedis>
<HealthCheckRabbitMQ>2.2.1</HealthCheckRabbitMQ>
<HealthCheckEventStore>2.2.2</HealthCheckEventStore>
<HealthCheckElasticsearch>2.2.2</HealthCheckElasticsearch>
<HealthCheckElasticsearch>2.2.3</HealthCheckElasticsearch>
<HealthCheckOracle>2.2.0</HealthCheckOracle>
<HealthCheckNpgSql>2.2.1</HealthCheckNpgSql>
<HealthCheckMongoDB>2.2.3</HealthCheckMongoDB>
Expand Down
5 changes: 5 additions & 0 deletions src/HealthChecks.Elasticsearch/ElasticsearchHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
settings = settings.ClientCertificate(_options.Certificate);
}

if (_options.CertificateValidationCallback != null)
{
settings = settings.ServerCertificateValidationCallback(_options.CertificateValidationCallback);
}

lowLevelClient = new ElasticClient(settings);

if (!_connections.TryAdd(_options.Uri, lowLevelClient))
Expand Down
7 changes: 7 additions & 0 deletions src/HealthChecks.Elasticsearch/ElasticsearchOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace HealthChecks.Elasticsearch
Expand All @@ -11,6 +12,7 @@ public class ElasticsearchOptions
public X509Certificate Certificate { get; private set; }
public bool AuthenticateWithBasicCredentials { get; private set; } = false;
public bool AuthenticateWithCertificate { get; private set; } = false;
public Func<object, X509Certificate, X509Chain, SslPolicyErrors, bool> CertificateValidationCallback { get; private set; }
public ElasticsearchOptions UseBasicAuthentication(string name, string password)
{
UserName = name ?? throw new ArgumentNullException(nameof(name));
Expand All @@ -37,5 +39,10 @@ public ElasticsearchOptions UseServer(string uri)

return this;
}
public ElasticsearchOptions UseCertificateValidationCallback(Func<object, X509Certificate, X509Chain, SslPolicyErrors, bool> callback)
{
CertificateValidationCallback = callback;
return this;
}
}
}

0 comments on commit 2f242a4

Please sign in to comment.