-
Notifications
You must be signed in to change notification settings - Fork 798
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
128 changed files
with
5,390 additions
and
5,517 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
47 changes: 23 additions & 24 deletions
47
build/docker-images/HealthChecks.UI.Image/Configuration/AzureAppConfiguration.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,38 +1,37 @@ | ||
using HealthChecks.UI.Image.Configuration.Helpers; | ||
|
||
namespace HealthChecks.UI.Image.Configuration | ||
namespace HealthChecks.UI.Image.Configuration; | ||
|
||
public class AzureAppConfiguration | ||
{ | ||
public class AzureAppConfiguration | ||
public static bool Enabled | ||
{ | ||
public static bool Enabled | ||
get | ||
{ | ||
get | ||
{ | ||
return EnvironmentVariable.HasValue(AzureAppConfigurationKeys.Enabled) && | ||
bool.TryParse(EnvironmentVariable.GetValue(AzureAppConfigurationKeys.Enabled), out bool enabled) && | ||
enabled; | ||
} | ||
return EnvironmentVariable.HasValue(AzureAppConfigurationKeys.Enabled) && | ||
bool.TryParse(EnvironmentVariable.GetValue(AzureAppConfigurationKeys.Enabled), out bool enabled) && | ||
enabled; | ||
} | ||
} | ||
|
||
public static bool UseConnectionString => | ||
EnvironmentVariable.HasValue(AzureAppConfigurationKeys.ConnectionString); | ||
public static bool UseConnectionString => | ||
EnvironmentVariable.HasValue(AzureAppConfigurationKeys.ConnectionString); | ||
|
||
public static bool UseLabel => | ||
EnvironmentVariable.HasValue(AzureAppConfigurationKeys.Label); | ||
public static bool UseLabel => | ||
EnvironmentVariable.HasValue(AzureAppConfigurationKeys.Label); | ||
|
||
public static bool UseCacheExpiration => | ||
EnvironmentVariable.HasValue(AzureAppConfigurationKeys.CacheExpiration) | ||
&& double.TryParse(EnvironmentVariable.GetValue(AzureAppConfigurationKeys.CacheExpiration), out var _); | ||
public static bool UseCacheExpiration => | ||
EnvironmentVariable.HasValue(AzureAppConfigurationKeys.CacheExpiration) | ||
&& double.TryParse(EnvironmentVariable.GetValue(AzureAppConfigurationKeys.CacheExpiration), out var _); | ||
|
||
public static double CacheExpiration => double.Parse(EnvironmentVariable.GetValue(AzureAppConfigurationKeys.CacheExpiration)!); | ||
public static double CacheExpiration => double.Parse(EnvironmentVariable.GetValue(AzureAppConfigurationKeys.CacheExpiration)!); | ||
|
||
public static string? ConnectionString => | ||
EnvironmentVariable.GetValue(AzureAppConfigurationKeys.ConnectionString); | ||
public static string? ConnectionString => | ||
EnvironmentVariable.GetValue(AzureAppConfigurationKeys.ConnectionString); | ||
|
||
public static string? ManagedIdentityEndpoint => | ||
EnvironmentVariable.GetValue(AzureAppConfigurationKeys.ManagedIdentityEndpoint); | ||
public static string? ManagedIdentityEndpoint => | ||
EnvironmentVariable.GetValue(AzureAppConfigurationKeys.ManagedIdentityEndpoint); | ||
|
||
public static string? Label => | ||
EnvironmentVariable.GetValue(AzureAppConfigurationKeys.Label); | ||
} | ||
public static string? Label => | ||
EnvironmentVariable.GetValue(AzureAppConfigurationKeys.Label); | ||
} |
17 changes: 8 additions & 9 deletions
17
build/docker-images/HealthChecks.UI.Image/Configuration/AzureAppConfigurationKeys.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,11 +1,10 @@ | ||
namespace HealthChecks.UI.Image.Configuration | ||
namespace HealthChecks.UI.Image.Configuration; | ||
|
||
public class AzureAppConfigurationKeys | ||
{ | ||
public class AzureAppConfigurationKeys | ||
{ | ||
public const string Enabled = "AAC_Enabled"; | ||
public const string ConnectionString = "AAC_ConnectionString"; | ||
public const string ManagedIdentityEndpoint = "AAC_ManagedIdentityEndpoint"; | ||
public const string Label = "AAC_Label"; | ||
public const string CacheExpiration = "AAC_CacheExpiration"; | ||
} | ||
public const string Enabled = "AAC_Enabled"; | ||
public const string ConnectionString = "AAC_ConnectionString"; | ||
public const string ManagedIdentityEndpoint = "AAC_ManagedIdentityEndpoint"; | ||
public const string Label = "AAC_Label"; | ||
public const string CacheExpiration = "AAC_CacheExpiration"; | ||
} |
15 changes: 7 additions & 8 deletions
15
build/docker-images/HealthChecks.UI.Image/Configuration/Helpers/EnvironmentVariable.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,11 +1,10 @@ | ||
namespace HealthChecks.UI.Image.Configuration.Helpers | ||
namespace HealthChecks.UI.Image.Configuration.Helpers; | ||
|
||
public class EnvironmentVariable | ||
{ | ||
public class EnvironmentVariable | ||
{ | ||
public static string? GetValue(string variable) => | ||
Environment.GetEnvironmentVariable(variable); | ||
public static string? GetValue(string variable) => | ||
Environment.GetEnvironmentVariable(variable); | ||
|
||
public static bool HasValue(string variable) => | ||
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(variable)); | ||
} | ||
public static bool HasValue(string variable) => | ||
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(variable)); | ||
} |
19 changes: 9 additions & 10 deletions
19
build/docker-images/HealthChecks.UI.Image/Configuration/PushServiceKeys.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,12 +1,11 @@ | ||
namespace HealthChecks.UI.Image.Configuration | ||
namespace HealthChecks.UI.Image.Configuration; | ||
|
||
public class PushServiceKeys | ||
{ | ||
public class PushServiceKeys | ||
{ | ||
public const string Enabled = "enable_push_endpoint"; | ||
public const string PushEndpointSecret = "push_endpoint_secret"; | ||
public const int ServiceAdded = 0; | ||
public const int ServiceUpdated = 1; | ||
public const int ServiceRemoved = 2; | ||
public const string AuthParameter = "key"; | ||
} | ||
public const string Enabled = "enable_push_endpoint"; | ||
public const string PushEndpointSecret = "push_endpoint_secret"; | ||
public const int ServiceAdded = 0; | ||
public const int ServiceUpdated = 1; | ||
public const int ServiceRemoved = 2; | ||
public const string AuthParameter = "key"; | ||
} |
89 changes: 44 additions & 45 deletions
89
build/docker-images/HealthChecks.UI.Image/Configuration/StorageProvider.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,53 +1,52 @@ | ||
namespace HealthChecks.UI.Image.Configuration | ||
namespace HealthChecks.UI.Image.Configuration; | ||
|
||
public class Storage | ||
{ | ||
public class Storage | ||
public static IDictionary<StorageProviderEnum, StorageProvider> GetProviders() | ||
{ | ||
public static IDictionary<StorageProviderEnum, StorageProvider> GetProviders() | ||
return new Dictionary<StorageProviderEnum, StorageProvider> | ||
{ | ||
return new Dictionary<StorageProviderEnum, StorageProvider> | ||
[StorageProviderEnum.InMemory] = new StorageProvider | ||
{ | ||
SetupProvider = (builder, connection) => builder.AddInMemoryStorage(), | ||
RequiresConnectionString = false | ||
}, | ||
[StorageProviderEnum.SqlServer] = new StorageProvider | ||
{ | ||
SetupProvider = (builder, connection) => builder.AddSqlServerStorage(connection), | ||
RequiresConnectionString = true, | ||
}, | ||
[StorageProviderEnum.Sqlite] = new StorageProvider | ||
{ | ||
SetupProvider = (builder, connection) => builder.AddSqliteStorage(connection), | ||
RequiresConnectionString = true, | ||
}, | ||
[StorageProviderEnum.PostgreSql] = new StorageProvider | ||
{ | ||
[StorageProviderEnum.InMemory] = new StorageProvider | ||
{ | ||
SetupProvider = (builder, connection) => builder.AddInMemoryStorage(), | ||
RequiresConnectionString = false | ||
}, | ||
[StorageProviderEnum.SqlServer] = new StorageProvider | ||
{ | ||
SetupProvider = (builder, connection) => builder.AddSqlServerStorage(connection), | ||
RequiresConnectionString = true, | ||
}, | ||
[StorageProviderEnum.Sqlite] = new StorageProvider | ||
{ | ||
SetupProvider = (builder, connection) => builder.AddSqliteStorage(connection), | ||
RequiresConnectionString = true, | ||
}, | ||
[StorageProviderEnum.PostgreSql] = new StorageProvider | ||
{ | ||
SetupProvider = (builder, connection) => builder.AddPostgreSqlStorage(connection), | ||
RequiresConnectionString = true, | ||
}, | ||
[StorageProviderEnum.MySql] = new StorageProvider | ||
{ | ||
SetupProvider = (builder, connection) => builder.AddMySqlStorage(connection), | ||
RequiresConnectionString = true, | ||
} | ||
}; | ||
} | ||
SetupProvider = (builder, connection) => builder.AddPostgreSqlStorage(connection), | ||
RequiresConnectionString = true, | ||
}, | ||
[StorageProviderEnum.MySql] = new StorageProvider | ||
{ | ||
SetupProvider = (builder, connection) => builder.AddMySqlStorage(connection), | ||
RequiresConnectionString = true, | ||
} | ||
}; | ||
} | ||
} | ||
|
||
public class StorageProvider | ||
{ | ||
public bool RequiresConnectionString { get; set; } | ||
public Action<HealthChecksUIBuilder, string> SetupProvider { get; set; } | ||
= (_, connection) => throw new InvalidOperationException($"Misconfigured storage provider for {connection}"); | ||
} | ||
public class StorageProvider | ||
{ | ||
public bool RequiresConnectionString { get; set; } | ||
public Action<HealthChecksUIBuilder, string> SetupProvider { get; set; } | ||
= (_, connection) => throw new InvalidOperationException($"Misconfigured storage provider for {connection}"); | ||
} | ||
|
||
public enum StorageProviderEnum | ||
{ | ||
InMemory = 0, | ||
SqlServer = 1, | ||
Sqlite = 2, | ||
PostgreSql = 3, | ||
MySql = 4 | ||
} | ||
public enum StorageProviderEnum | ||
{ | ||
InMemory = 0, | ||
SqlServer = 1, | ||
Sqlite = 2, | ||
PostgreSql = 3, | ||
MySql = 4 | ||
} |
23 changes: 11 additions & 12 deletions
23
build/docker-images/HealthChecks.UI.Image/Configuration/UIKeys.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,14 +1,13 @@ | ||
namespace HealthChecks.UI.Image.Configuration | ||
namespace HealthChecks.UI.Image.Configuration; | ||
|
||
public class UIKeys | ||
{ | ||
public class UIKeys | ||
{ | ||
public const string UI_STYLESHEET = "ui_stylesheet"; | ||
public const string UI_API_PATH = "ui_api_path"; | ||
public const string UI_PATH = "ui_path"; | ||
public const string UI_RESOURCES_PATH = "ui_resources_path"; | ||
public const string UI_WEBHOOKS_PATH = "ui_webhooks_path"; | ||
public const string UI_NO_RELATIVE_PATHS = "ui_no_relative_paths"; | ||
public const string STORAGE_PROVIDER = "storage_provider"; | ||
public const string STORAGE_CONNECTION = "storage_connection"; | ||
} | ||
public const string UI_STYLESHEET = "ui_stylesheet"; | ||
public const string UI_API_PATH = "ui_api_path"; | ||
public const string UI_PATH = "ui_path"; | ||
public const string UI_RESOURCES_PATH = "ui_resources_path"; | ||
public const string UI_WEBHOOKS_PATH = "ui_webhooks_path"; | ||
public const string UI_NO_RELATIVE_PATHS = "ui_no_relative_paths"; | ||
public const string STORAGE_PROVIDER = "storage_provider"; | ||
public const string STORAGE_CONNECTION = "storage_connection"; | ||
} |
49 changes: 24 additions & 25 deletions
49
build/docker-images/HealthChecks.UI.Image/Extensions/HealthChecksUIBuilderExtensions.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,39 +1,38 @@ | ||
using HealthChecks.UI.Image.Configuration; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
public static class HealthChecksUIBuilderExtensions | ||
{ | ||
public static class HealthChecksUIBuilderExtensions | ||
public static IServiceCollection AddStorageProvider(this HealthChecksUIBuilder builder, IConfiguration configuration) | ||
{ | ||
public static IServiceCollection AddStorageProvider(this HealthChecksUIBuilder builder, IConfiguration configuration) | ||
{ | ||
string? configuredStorage = configuration[UIKeys.STORAGE_PROVIDER]; | ||
string? connectionString = configuration[UIKeys.STORAGE_CONNECTION]; | ||
|
||
if (string.IsNullOrEmpty(configuredStorage)) | ||
configuredStorage = StorageProviderEnum.InMemory.ToString(); | ||
string? configuredStorage = configuration[UIKeys.STORAGE_PROVIDER]; | ||
string? connectionString = configuration[UIKeys.STORAGE_CONNECTION]; | ||
|
||
if (Enum.TryParse(configuredStorage, out StorageProviderEnum storageEnum)) | ||
{ | ||
var providers = Storage.GetProviders(); | ||
|
||
var targetProvider = providers[storageEnum]; | ||
if (string.IsNullOrEmpty(configuredStorage)) | ||
configuredStorage = StorageProviderEnum.InMemory.ToString(); | ||
|
||
if (targetProvider.RequiresConnectionString && string.IsNullOrEmpty(connectionString)) | ||
{ | ||
throw new ArgumentNullException($"{UIKeys.STORAGE_CONNECTION} value has not been configured and it's required for {storageEnum}"); | ||
} | ||
if (Enum.TryParse(configuredStorage, out StorageProviderEnum storageEnum)) | ||
{ | ||
var providers = Storage.GetProviders(); | ||
|
||
Console.WriteLine($"Configuring image to work with {storageEnum} provider"); | ||
var targetProvider = providers[storageEnum]; | ||
|
||
targetProvider.SetupProvider(builder, connectionString!); | ||
} | ||
else | ||
if (targetProvider.RequiresConnectionString && string.IsNullOrEmpty(connectionString)) | ||
{ | ||
throw new ArgumentException($"Variable {UIKeys.STORAGE_PROVIDER} has an invalid value: {configuredStorage}." + | ||
$" Available providers are {string.Join(" , ", Enum.GetNames(typeof(StorageProviderEnum)))}"); | ||
throw new ArgumentNullException($"{UIKeys.STORAGE_CONNECTION} value has not been configured and it's required for {storageEnum}"); | ||
} | ||
|
||
return builder.Services; | ||
Console.WriteLine($"Configuring image to work with {storageEnum} provider"); | ||
|
||
targetProvider.SetupProvider(builder, connectionString!); | ||
} | ||
else | ||
{ | ||
throw new ArgumentException($"Variable {UIKeys.STORAGE_PROVIDER} has an invalid value: {configuredStorage}." + | ||
$" Available providers are {string.Join(" , ", Enum.GetNames(typeof(StorageProviderEnum)))}"); | ||
} | ||
|
||
return builder.Services; | ||
} | ||
} |
13 changes: 6 additions & 7 deletions
13
build/docker-images/HealthChecks.UI.Image/Extensions/HttpRequestExtensions.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,13 +1,12 @@ | ||
using HealthChecks.UI.Image.Configuration; | ||
|
||
namespace HealthChecks.UI.Image.Extensions | ||
namespace HealthChecks.UI.Image.Extensions; | ||
|
||
public static class HttpRequestExtensions | ||
{ | ||
public static class HttpRequestExtensions | ||
public static bool IsAuthenticated(this HttpRequest request) | ||
{ | ||
public static bool IsAuthenticated(this HttpRequest request) | ||
{ | ||
return request.Query.ContainsKey(PushServiceKeys.AuthParameter) && | ||
request.Query[PushServiceKeys.AuthParameter] == Environment.GetEnvironmentVariable(PushServiceKeys.PushEndpointSecret); | ||
} | ||
return request.Query.ContainsKey(PushServiceKeys.AuthParameter) && | ||
request.Query[PushServiceKeys.AuthParameter] == Environment.GetEnvironmentVariable(PushServiceKeys.PushEndpointSecret); | ||
} | ||
} |
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
Oops, something went wrong.