public async void HandleRefreshRequestAsync_ReturnsExpected() { var opts = new RefreshEndpointOptions(); var mopts = new ActuatorManagementOptions(); mopts.EndpointOptions.Add(opts); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddInMemoryCollection(AppSettings); var config = configurationBuilder.Build(); var ep = new RefreshEndpoint(opts, config); var middle = new RefreshEndpointMiddleware(null, ep, mopts); var context = CreateRequest("GET", "/refresh"); await middle.HandleRefreshRequestAsync(context); context.Response.Body.Seek(0, SeekOrigin.Begin); var reader = new StreamReader(context.Response.Body, Encoding.UTF8); var json = await reader.ReadLineAsync(); var expected = "[\"management\",\"management:endpoints\",\"management:endpoints:enabled\",\"Logging\",\"Logging:LogLevel\",\"Logging:LogLevel:Steeltoe\",\"Logging:LogLevel:Pivotal\",\"Logging:LogLevel:Default\",\"Logging:IncludeScopes\"]"; Assert.Equal(expected, json); }
public static void UseRefreshActuator(IConfiguration configuration, ILoggerFactory loggerFactory = null) { var ep = new RefreshEndpoint(new RefreshOptions(configuration), configuration, CreateLogger <RefreshEndpoint>(loggerFactory)); var handler = new RefreshHandler(ep, SecurityService, CreateLogger <RefreshHandler>(loggerFactory)); ConfiguredHandlers.Add(handler); }
public void DoInvoke_ReturnsExpected() { var opts = new RefreshOptions(); var appsettings = new Dictionary <string, string>() { ["management:endpoints:enabled"] = "false", ["management:endpoints:sensitive"] = "false", ["management:endpoints:path"] = "/cloudfoundryapplication", ["management:endpoints:loggers:enabled"] = "false", ["management:endpoints:loggers:sensitive"] = "true", ["management:endpoints:heapdump:enabled"] = "true", ["management:endpoints:heapdump:sensitive"] = "true", ["management:endpoints:cloudfoundry:validatecertificates"] = "true", ["management:endpoints:cloudfoundry:enabled"] = "true" }; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddInMemoryCollection(appsettings); var config = configurationBuilder.Build(); var ep = new RefreshEndpoint(opts, config); var result = ep.DoInvoke(config); Assert.NotNull(result); Assert.Contains("management:endpoints:loggers:enabled", result); Assert.Contains("management:endpoints:heapdump:sensitive", result); Assert.Contains("management:endpoints:cloudfoundry:enabled", result); }
/// <summary> /// Add (Config) Refresh actuator endpoint to OWIN Pipeline /// </summary> /// <param name="builder">OWIN <see cref="IAppBuilder" /></param> /// <param name="config"><see cref="IConfiguration"/> of application for configuring refresh endpoint</param> /// <param name="loggerFactory">For logging within the middleware</param> /// <returns>OWIN <see cref="IAppBuilder" /> with Refresh Endpoint added</returns> public static IAppBuilder UseRefreshActuator(this IAppBuilder builder, IConfiguration config, ILoggerFactory loggerFactory = null) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } IRefreshOptions options = new RefreshEndpointOptions(config); var mgmtOptions = ManagementOptions.Get(config); foreach (var mgmt in mgmtOptions) { mgmt.EndpointOptions.Add(options); } var endpoint = new RefreshEndpoint(options, config, loggerFactory?.CreateLogger <RefreshEndpoint>()); var logger = loggerFactory?.CreateLogger <EndpointOwinMiddleware <IList <string> > >(); return(builder.Use <EndpointOwinMiddleware <IList <string> > >(endpoint, mgmtOptions, new List <HttpMethod> { HttpMethod.Get }, true, logger)); }
public static void UseRefreshActuator(IConfiguration configuration, ILoggerFactory loggerFactory = null) { var options = new RefreshEndpointOptions(configuration); _mgmtOptions.RegisterEndpointOptions(configuration, options); var ep = new RefreshEndpoint(options, configuration, CreateLogger <RefreshEndpoint>(loggerFactory)); var handler = new RefreshHandler(ep, SecurityServices, _mgmtOptions, CreateLogger <RefreshHandler>(loggerFactory)); ConfiguredHandlers.Add(handler); }
public void RefreshEndpointMiddleware_PathAndVerbMatching_ReturnsExpected() { var opts = new RefreshOptions(); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddInMemoryCollection(OwinTestHelpers.Appsettings); var config = configurationBuilder.Build(); var ep = new RefreshEndpoint(opts, config); var middle = new EndpointOwinMiddleware <IList <string> >(null, ep); Assert.True(middle.RequestVerbAndPathMatch("GET", "/refresh")); Assert.False(middle.RequestVerbAndPathMatch("PUT", "/refresh")); Assert.False(middle.RequestVerbAndPathMatch("GET", "/badpath")); }
public void RefreshEndpointMiddleware_PathAndVerbMatching_ReturnsExpected() { var opts = new RefreshEndpointOptions(); var mopts = TestHelpers.GetManagementOptions(opts); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddInMemoryCollection(AppSettings); var config = configurationBuilder.Build(); var ep = new RefreshEndpoint(opts, config); var middle = new RefreshEndpointMiddleware(null, ep, mopts); Assert.True(middle.RequestVerbAndPathMatch("GET", "/cloudfoundryapplication/refresh")); Assert.False(middle.RequestVerbAndPathMatch("PUT", "/cloudfoundryapplication/refresh")); Assert.False(middle.RequestVerbAndPathMatch("GET", "/cloudfoundryapplication/badpath")); }
public RefreshHandler(RefreshEndpoint endpoint, IEnumerable<ISecurityService> securityServices, ILogger<RefreshHandler> logger = null) : base(endpoint, securityServices, null, true, logger) { }
public RefreshHandler(RefreshEndpoint endpoint, ISecurityService securityService, ILogger <RefreshHandler> logger = null) : base(endpoint, securityService, null, true, logger) { }