Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make config fields nullable #596

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class ActiveHealthCheckOptions
/// <summary>
/// Whether active health checks are enabled.
/// </summary>
public bool Enabled { get; set; }
public bool? Enabled { get; set; }

/// <summary>
/// Health probe interval.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.ReverseProxy.Abstractions
/// </summary>
public sealed class LoadBalancingOptions
{
public LoadBalancingMode Mode { get; set; }
public LoadBalancingMode? Mode { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: Conflicts with #600. We'll see which merges first.


internal LoadBalancingOptions DeepClone()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class PassiveHealthCheckOptions
/// <summary>
/// Whether passive health checks are enabled.
/// </summary>
public bool Enabled { get; set; }
public bool? Enabled { get; set; }

/// <summary>
/// Passive health check policy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class ProxyHttpClientOptions
{
public SslProtocols? SslProtocols { get; set; }

public bool DangerousAcceptAnyServerCertificate { get; set; }
public bool? DangerousAcceptAnyServerCertificate { get; set; }

public X509Certificate2 ClientCertificate { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class SessionAffinityOptions
/// <summary>
/// Indicates whether session affinity is enabled.
/// </summary>
public bool Enabled { get; set; }
public bool? Enabled { get; set; }

/// <summary>
/// Session affinity mode which is implemented by one of providers.
Expand Down
6 changes: 3 additions & 3 deletions src/ReverseProxy/Service/Config/ConfigValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private async ValueTask ValidateCorsPolicyAsync(IList<Exception> errors, string

private void ValidateSessionAffinity(IList<Exception> errors, Cluster cluster)
{
if (cluster.SessionAffinity == null || !cluster.SessionAffinity.Enabled)
if (!(cluster.SessionAffinity?.Enabled ?? false))
{
// Session affinity is disabled
return;
Expand Down Expand Up @@ -343,7 +343,7 @@ private void ValidateProxyHttpRequest(IList<Exception> errors, Cluster cluster)

private void ValidateActiveHealthCheck(IList<Exception> errors, Cluster cluster)
{
if (cluster.HealthCheck == null || cluster.HealthCheck.Active == null || !cluster.HealthCheck.Active.Enabled)
if (!(cluster.HealthCheck?.Active?.Enabled ?? false))
{
// Active health check is disabled
return;
Expand Down Expand Up @@ -373,7 +373,7 @@ private void ValidateActiveHealthCheck(IList<Exception> errors, Cluster cluster)

private void ValidatePassiveHealthCheck(IList<Exception> errors, Cluster cluster)
{
if (cluster.HealthCheck == null || cluster.HealthCheck.Passive == null || !cluster.HealthCheck.Passive.Enabled)
if (!(cluster.HealthCheck?.Passive?.Enabled ?? false))
{
// Passive health check is disabled
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public HttpMessageInvoker CreateClient(ProxyHttpClientContext context)
{
handler.MaxConnectionsPerServer = newClientOptions.MaxConnectionsPerServer.Value;
}
if (newClientOptions.DangerousAcceptAnyServerCertificate)
if (newClientOptions.DangerousAcceptAnyServerCertificate ?? false)
{
handler.SslOptions.RemoteCertificateValidationCallback = delegate { return true; };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.ReverseProxy.RuntimeModel
{
public ClusterProxyHttpClientOptions(
SslProtocols? sslProtocols,
bool acceptAnyServerCertificate,
bool? acceptAnyServerCertificate,
X509Certificate2 clientCertificate,
int? maxConnectionsPerServer,
bool? propagateActivityContext)
Expand All @@ -26,7 +26,7 @@ public ClusterProxyHttpClientOptions(

public SslProtocols? SslProtocols { get; }

public bool DangerousAcceptAnyServerCertificate { get; }
public bool? DangerousAcceptAnyServerCertificate { get; }

public X509Certificate2 ClientCertificate { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,21 @@ public void BuildCluster_IncompleteLabels_UsesDefaultValues()
var expectedCluster = new Cluster
{
Id = "MyCoolClusterId",
SessionAffinity = new SessionAffinityOptions(),
SessionAffinity = new SessionAffinityOptions
{
Enabled = false,
},
HttpRequest = new ProxyHttpRequestOptions(),
HealthCheck = new HealthCheckOptions
{
Active = new ActiveHealthCheckOptions(),
Passive = new PassiveHealthCheckOptions()
Active = new ActiveHealthCheckOptions
{
Enabled = false,
},
Passive = new PassiveHealthCheckOptions
{
Enabled = false,
}
},
Metadata = new Dictionary<string, string>(),
};
Expand Down Expand Up @@ -249,13 +258,13 @@ public void BuildRoutes_SingleRoute_Works()
Transforms = new List<IDictionary<string, string>>
{
new Dictionary<string, string>
{
{
{"ResponseHeader", "X-Foo"},
{"Append", "Bar"},
{"When", "Always"}
},
new Dictionary<string, string>
{
{
{"ResponseHeader", "X-Ping"},
{"Append", "Pong"},
{"When", "Success"}
Expand Down