-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,219 additions
and
1,219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
using Microsoft.Azure.Devices; | ||
|
||
namespace HealthChecks.Azure.IoTHub; | ||
|
||
public class IoTHubOptions | ||
{ | ||
internal string ConnectionString { get; private set; } = null!; | ||
internal bool RegistryReadCheck { get; private set; } | ||
internal bool RegistryWriteCheck { get; private set; } | ||
internal bool ServiceConnectionCheck { get; private set; } | ||
internal string RegistryReadQuery { get; private set; } = null!; | ||
internal Func<string> RegistryWriteDeviceIdFactory { get; private set; } = null!; | ||
|
||
namespace HealthChecks.Azure.IoTHub; | ||
|
||
public class IoTHubOptions | ||
{ | ||
internal string ConnectionString { get; private set; } = null!; | ||
internal bool RegistryReadCheck { get; private set; } | ||
internal bool RegistryWriteCheck { get; private set; } | ||
internal bool ServiceConnectionCheck { get; private set; } | ||
internal string RegistryReadQuery { get; private set; } = null!; | ||
internal Func<string> RegistryWriteDeviceIdFactory { get; private set; } = null!; | ||
internal TransportType ServiceConnectionTransport { get; private set; } | ||
|
||
public IoTHubOptions AddConnectionString(string connectionString) | ||
{ | ||
ConnectionString = Guard.ThrowIfNull(connectionString); | ||
return this; | ||
} | ||
|
||
public IoTHubOptions AddRegistryReadCheck(string query = "SELECT deviceId FROM devices") | ||
{ | ||
RegistryReadCheck = true; | ||
RegistryReadQuery = query; | ||
return this; | ||
} | ||
|
||
public IoTHubOptions AddRegistryWriteCheck(Func<string>? deviceIdFactory = null) | ||
{ | ||
RegistryWriteCheck = true; | ||
RegistryWriteDeviceIdFactory = deviceIdFactory ?? (() => "health-check-registry-write-device-id"); | ||
return this; | ||
} | ||
|
||
public IoTHubOptions AddServiceConnectionCheck(TransportType transport = TransportType.Amqp) | ||
{ | ||
ServiceConnectionCheck = true; | ||
ServiceConnectionTransport = transport; | ||
return this; | ||
} | ||
} | ||
} | ||
|
||
public IoTHubOptions AddRegistryReadCheck(string query = "SELECT deviceId FROM devices") | ||
{ | ||
RegistryReadCheck = true; | ||
RegistryReadQuery = query; | ||
return this; | ||
} | ||
|
||
public IoTHubOptions AddRegistryWriteCheck(Func<string>? deviceIdFactory = null) | ||
{ | ||
RegistryWriteCheck = true; | ||
RegistryWriteDeviceIdFactory = deviceIdFactory ?? (() => "health-check-registry-write-device-id"); | ||
return this; | ||
} | ||
|
||
public IoTHubOptions AddServiceConnectionCheck(TransportType transport = TransportType.Amqp) | ||
{ | ||
ServiceConnectionCheck = true; | ||
ServiceConnectionTransport = transport; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
using System.Net.Http.Headers; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace HealthChecks.Consul; | ||
|
||
public class ConsulHealthCheck : IHealthCheck | ||
{ | ||
private readonly ConsulOptions _options; | ||
private readonly Func<HttpClient> _httpClientFactory; | ||
|
||
public ConsulHealthCheck(ConsulOptions options, Func<HttpClient> httpClientFactory) | ||
{ | ||
_options = Guard.ThrowIfNull(options); | ||
_httpClientFactory = Guard.ThrowIfNull(httpClientFactory); | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace HealthChecks.Consul; | ||
|
||
public class ConsulHealthCheck : IHealthCheck | ||
{ | ||
private readonly ConsulOptions _options; | ||
private readonly Func<HttpClient> _httpClientFactory; | ||
|
||
public ConsulHealthCheck(ConsulOptions options, Func<HttpClient> httpClientFactory) | ||
{ | ||
_options = Guard.ThrowIfNull(options); | ||
_httpClientFactory = Guard.ThrowIfNull(httpClientFactory); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
var client = _httpClientFactory(); | ||
/// <inheritdoc /> | ||
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
var client = _httpClientFactory(); | ||
if (_options.RequireBasicAuthentication) | ||
{ | ||
byte[] credentials = Encoding.ASCII.GetBytes($"{_options.Username}:{_options.Password}"); | ||
string authHeaderValue = Convert.ToBase64String(credentials); | ||
|
||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue); | ||
} | ||
using var result = await client.GetAsync($"{(_options.RequireHttps ? "https" : "http")}://{_options.HostName}:{_options.Port}/v1/status/leader", HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); | ||
|
||
return result.IsSuccessStatusCode ? HealthCheckResult.Healthy() : new HealthCheckResult(context.Registration.FailureStatus, description: "Consul response was not a successful HTTP status code"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); | ||
} | ||
} | ||
} | ||
{ | ||
byte[] credentials = Encoding.ASCII.GetBytes($"{_options.Username}:{_options.Password}"); | ||
string authHeaderValue = Convert.ToBase64String(credentials); | ||
|
||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue); | ||
} | ||
using var result = await client.GetAsync($"{(_options.RequireHttps ? "https" : "http")}://{_options.HostName}:{_options.Port}/v1/status/leader", HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); | ||
|
||
return result.IsSuccessStatusCode ? HealthCheckResult.Healthy() : new HealthCheckResult(context.Registration.FailureStatus, description: "Consul response was not a successful HTTP status code"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); | ||
} | ||
} | ||
} |
34 changes: 17 additions & 17 deletions
34
src/HealthChecks.Gcp.CloudFirestore/CloudFirestoreOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
using Google.Cloud.Firestore; | ||
|
||
namespace HealthChecks.Gcp.CloudFirestore; | ||
|
||
using Google.Cloud.Firestore; | ||
|
||
namespace HealthChecks.Gcp.CloudFirestore; | ||
|
||
/// <summary> | ||
/// Represent options for <see cref="CloudFirestoreHealthCheck"/>. | ||
/// </summary> | ||
public class CloudFirestoreOptions | ||
{ | ||
/// <summary> | ||
/// Firestore Cloud database object used in your application. | ||
/// </summary> | ||
public FirestoreDb FirestoreDatabase { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// Specify the root collections that needs to exist in the database. | ||
/// </summary> | ||
public string[]? RequiredCollections { get; set; } | ||
} | ||
/// </summary> | ||
public class CloudFirestoreOptions | ||
{ | ||
/// <summary> | ||
/// Firestore Cloud database object used in your application. | ||
/// </summary> | ||
public FirestoreDb FirestoreDatabase { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// Specify the root collections that needs to exist in the database. | ||
/// </summary> | ||
public string[]? RequiredCollections { get; set; } | ||
} |
Oops, something went wrong.