diff --git a/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPlugin.cs b/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPlugin.cs index 1389ad5..d3e8219 100644 --- a/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPlugin.cs +++ b/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPlugin.cs @@ -59,7 +59,7 @@ public void ConfigureApplication(IApplicationBuilder applicationBuilder) public void ConfigureHealthChecks(IHealthChecksBuilder healthChecksBuilder) { - var uriBuilder = new UriBuilder(_keycloakPluginConfiguration.GetHealthCheck()) { Path = _keycloakPluginConfiguration.HealthCheckConfig.Prefix }; + var uriBuilder = new UriBuilder(_keycloakPluginConfiguration.GetHealthCheck()) { Path = _keycloakPluginConfiguration.HealthCheck.Prefix }; var uri = uriBuilder.Uri; healthChecksBuilder.AddUrlGroup(uri, "keycloak", HealthStatus.Unhealthy, new[] { HealthCheckTag.Readiness.Value }); } diff --git a/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPluginConfiguration.cs b/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPluginConfiguration.cs index f82b7ad..b219bb6 100644 --- a/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPluginConfiguration.cs +++ b/PiBox.Plugins/Authorization/Keycloak/src/PiBox.Plugins.Authorization.Keycloak/KeycloakPluginConfiguration.cs @@ -15,15 +15,15 @@ public class KeycloakPluginConfiguration public string ClientSecret { get; set; } public RealmsConfig Realms { get; set; } = new RealmsConfig(); public IList Policies { get; set; } = new List(); - public HealthCheckConfig HealthCheckConfig { get; set; } = new HealthCheckConfig(); + public HealthCheckConfig HealthCheck { get; set; } = new HealthCheckConfig(); public Uri GetHealthCheck() { - if (string.IsNullOrEmpty(HealthCheckConfig.Host)) throw new ArgumentException("Keycloak.Uri was not specified but health check is enabled!"); + if (string.IsNullOrEmpty(HealthCheck.Host)) throw new ArgumentException("Keycloak.Uri was not specified but health check is enabled!"); var httpScheme = (Insecure ? HttpScheme.Http : HttpScheme.Https).ToString(); return Port.HasValue - ? new UriBuilder(httpScheme, HealthCheckConfig.Host, HealthCheckConfig.Port.Value).Uri - : new UriBuilder(httpScheme, HealthCheckConfig.Host).Uri; + ? new UriBuilder(httpScheme, HealthCheck.Host, HealthCheck.Port.Value).Uri + : new UriBuilder(httpScheme, HealthCheck.Host).Uri; } public Uri GetAuthority() @@ -43,7 +43,7 @@ public class RealmsConfig public class HealthCheckConfig { - public string Host { get; set; } = "example.com"; + public string Host { get; set; } public int? Port { get; set; } = 9000; public string Prefix { get; set; } = "/health/ready"; } diff --git a/PiBox.Plugins/Authorization/Keycloak/test/PiBox.Plugins.Authorization.Keycloak.Tests/KeycloakPluginTests.cs b/PiBox.Plugins/Authorization/Keycloak/test/PiBox.Plugins.Authorization.Keycloak.Tests/KeycloakPluginTests.cs index f76ad06..a062dfe 100644 --- a/PiBox.Plugins/Authorization/Keycloak/test/PiBox.Plugins.Authorization.Keycloak.Tests/KeycloakPluginTests.cs +++ b/PiBox.Plugins/Authorization/Keycloak/test/PiBox.Plugins.Authorization.Keycloak.Tests/KeycloakPluginTests.cs @@ -97,7 +97,7 @@ public void ConfigureHealthChecksWorks() { var hcBuilder = Substitute.For(); hcBuilder.Services.Returns(new ServiceCollection()); - var config = new KeycloakPluginConfiguration { Enabled = true, Host = "example.com", Insecure = false }; + var config = new KeycloakPluginConfiguration { Enabled = true, Host = "example.com", Insecure = false, HealthCheck = new HealthCheckConfig { Host = "example.com" } }; GetPlugin(config).ConfigureHealthChecks(hcBuilder); hcBuilder.Received() .Add(Arg.Is(h => @@ -119,19 +119,19 @@ public void ConfigureHealthChecks_Use9000ForHealth() Host = "example.com", Insecure = false, Port = 8080, - HealthCheckConfig = new HealthCheckConfig + HealthCheck = new HealthCheckConfig { Host = "example.com", Port = 9000, Prefix = "/health/ready" } }; - var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheckConfig.Prefix }; + var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheck.Prefix }; uriBuilder.Uri.Should().Be("https://example.com:9000/health/ready"); } [Test] - public void ConfigureHealthChecks_WithoutSettingHealthCheckConfig() + public void ConfigureHealthChecks_WithSettingHealthCheckHost() { var config = new KeycloakPluginConfiguration { @@ -139,8 +139,13 @@ public void ConfigureHealthChecks_WithoutSettingHealthCheckConfig() Host = "example.com", Insecure = false, Port = 8080, + HealthCheck = new HealthCheckConfig + { + Host = "example.com" + } }; - var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheckConfig.Prefix }; + + var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheck.Prefix }; uriBuilder.Uri.Should().Be("https://example.com:9000/health/ready"); } @@ -153,14 +158,14 @@ public void ConfigureHealthChecks_DifferentPrefixAndPort() Host = "newhost.com", Insecure = false, Port = 8080, - HealthCheckConfig = new HealthCheckConfig + HealthCheck = new HealthCheckConfig { Host = "health.com", Port = 9999, Prefix = "/something/notready" } }; - var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheckConfig.Prefix }; + var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheck.Prefix }; uriBuilder.Uri.Should().Be("https://health.com:9999/something/notready"); } @@ -173,13 +178,14 @@ public void ConfigureHealthChecks_DefaultHealthHost() Host = "newhost.com", Insecure = false, Port = 8080, - HealthCheckConfig = new HealthCheckConfig + HealthCheck = new HealthCheckConfig { Port = 9999, - Prefix = "/something/notready" + Prefix = "/something/notready", + Host = "example.com" } }; - var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheckConfig.Prefix }; + var uriBuilder = new UriBuilder(config.GetHealthCheck()) { Path = config.HealthCheck.Prefix }; uriBuilder.Uri.Should().Be("https://example.com:9999/something/notready"); }