From 816394a3f2fed9d5a4330f4be6a16d770b0b5fb6 Mon Sep 17 00:00:00 2001 From: Chris Baudin Date: Fri, 8 Mar 2019 17:25:57 -0800 Subject: [PATCH 1/2] Update the health check endpoint route builder extensions to make the endpoint display name configurable. (#8359) --- ...althCheckEndpointRouteBuilderExtensions.cs | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Middleware/HealthChecks/src/Builder/HealthCheckEndpointRouteBuilderExtensions.cs b/src/Middleware/HealthChecks/src/Builder/HealthCheckEndpointRouteBuilderExtensions.cs index 8ea35b8043ae..4493e8a41ba9 100644 --- a/src/Middleware/HealthChecks/src/Builder/HealthCheckEndpointRouteBuilderExtensions.cs +++ b/src/Middleware/HealthChecks/src/Builder/HealthCheckEndpointRouteBuilderExtensions.cs @@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Builder /// public static class HealthCheckEndpointRouteBuilderExtensions { + private const string DefaultDisplayName = "Health checks"; + /// /// Adds a health checks endpoint to the with the specified template. /// @@ -29,7 +31,7 @@ public static IEndpointConventionBuilder MapHealthChecks( throw new ArgumentNullException(nameof(builder)); } - return MapHealthChecksCore(builder, pattern, null); + return MapHealthChecksCore(builder, pattern, null, DefaultDisplayName); } /// @@ -54,10 +56,42 @@ public static IEndpointConventionBuilder MapHealthChecks( throw new ArgumentNullException(nameof(options)); } - return MapHealthChecksCore(builder, pattern, options); + return MapHealthChecksCore(builder, pattern, options, DefaultDisplayName); + } + + /// + /// Adds a health checks endpoint to the with the specified template, options and display name. + /// + /// The to add the health checks endpoint to. + /// The URL pattern of the health checks endpoint. + /// A used to configure the health checks. + /// The display name for the endpoint. + /// A convention builder for the health checks endpoint. + public static IEndpointConventionBuilder MapHealthChecks( + this IEndpointRouteBuilder builder, + string pattern, + HealthCheckOptions options, + string displayName) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + + if (string.IsNullOrEmpty(displayName)) + { + throw new ArgumentException("A valid non-empty display name must be provided.", nameof(displayName)); + } + + return MapHealthChecksCore(builder, pattern, options, displayName); } - private static IEndpointConventionBuilder MapHealthChecksCore(IEndpointRouteBuilder builder, string pattern, HealthCheckOptions options) + private static IEndpointConventionBuilder MapHealthChecksCore(IEndpointRouteBuilder builder, string pattern, HealthCheckOptions options, string displayName) { var args = options != null ? new[] { Options.Create(options) } : Array.Empty(); @@ -65,7 +99,7 @@ private static IEndpointConventionBuilder MapHealthChecksCore(IEndpointRouteBuil .UseMiddleware(args) .Build(); - return builder.Map(pattern, "Health checks", pipeline); + return builder.Map(pattern, displayName, pipeline); } } } From b0e8b52d089ef3e18cb2d39074cc67c0c7a8a1fe Mon Sep 17 00:00:00 2001 From: Chris Baudin Date: Fri, 12 Apr 2019 16:13:25 -0700 Subject: [PATCH 2/2] #5810: Why isn't MemoryStream in DataProtectionTokenProvider disposed? --- .../Core/src/DataProtectorTokenProvider.cs | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Identity/Core/src/DataProtectorTokenProvider.cs b/src/Identity/Core/src/DataProtectorTokenProvider.cs index b268cc142df3..1df8c021752b 100644 --- a/src/Identity/Core/src/DataProtectorTokenProvider.cs +++ b/src/Identity/Core/src/DataProtectorTokenProvider.cs @@ -69,22 +69,24 @@ public virtual async Task GenerateAsync(string purpose, UserManager @@ -103,7 +105,7 @@ public virtual async Task ValidateAsync(string purpose, string token, User try { var unprotectedData = Protector.Unprotect(Convert.FromBase64String(token)); - var ms = new MemoryStream(unprotectedData); + using (var ms = new MemoryStream(unprotectedData)) using (var reader = ms.CreateReader()) { var creationTime = reader.ReadDateTimeOffset();