public void Invoke_HandlesExceptions() { var opts = new InfoEndpointOptions(); var contributors = new List <IInfoContributor>() { new TestContrib(), new TestContrib(true), new TestContrib() }; var ep = new InfoEndpoint(opts, contributors, GetLogger <InfoEndpoint>()); var info = ep.Invoke(); foreach (var contrib in contributors) { var tc = (TestContrib)contrib; if (tc.Throws) { Assert.False(tc.Called); } else { Assert.True(tc.Called); } } }
/// <summary> /// Add Info actuator endpoint to OWIN Pipeline /// </summary> /// <param name="builder">OWIN <see cref="IAppBuilder" /></param> /// <param name="config"><see cref="IConfiguration"/> of application for configuring info endpoint</param> /// <param name="contributors">IInfo Contributors to collect into from</param> /// <param name="loggerFactory">For logging within the middleware</param> /// <returns>OWIN <see cref="IAppBuilder" /> with Info Endpoint added</returns> public static IAppBuilder UseInfoActuator(this IAppBuilder builder, IConfiguration config, IList <IInfoContributor> contributors, ILoggerFactory loggerFactory = null) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } if (contributors == null) { throw new ArgumentNullException(nameof(contributors)); } var mgmtOptions = ManagementOptions.Get(config); var options = new InfoEndpointOptions(config); foreach (var mgmt in mgmtOptions) { mgmt.EndpointOptions.Add(options); } var endpoint = new InfoEndpoint(options, contributors, loggerFactory?.CreateLogger <InfoEndpoint>()); var logger = loggerFactory?.CreateLogger <EndpointOwinMiddleware <Dictionary <string, object> > >(); return(builder.Use <EndpointOwinMiddleware <Dictionary <string, object> > >(endpoint, mgmtOptions, new List <HttpMethod> { HttpMethod.Get }, true, logger)); }
internal static Task <GetV1InfoResponse> CustomGetV1Info(InfoEndpoint arg1) { return(Task.Factory.StartNew <GetV1InfoResponse>(() => { return new GetV1InfoResponse() { AppLogEndpoint = "ws://logs.1.2.3.4.xip.io" }; })); }
public void Invoke_NoContributors_ReturnsExpectedInfo() { var opts = new InfoEndpointOptions(); var contributors = new List <IInfoContributor>(); var ep = new InfoEndpoint(opts, contributors, GetLogger <InfoEndpoint>()); var info = ep.Invoke(); Assert.NotNull(info); Assert.Empty(info); }
public static void UseInfoActuator(IConfiguration configuration, IEnumerable <IInfoContributor> contributors = null, ILoggerFactory loggerFactory = null) { var options = new InfoOptions(configuration); contributors = contributors ?? new List <IInfoContributor>() { new GitInfoContributor(), new AppSettingsInfoContributor(configuration) }; var ep = new InfoEndpoint(options, contributors, CreateLogger <InfoEndpoint>(loggerFactory)); var handler = new InfoHandler(ep, SecurityService, CreateLogger <InfoHandler>(loggerFactory)); ConfiguredHandlers.Add(handler); }
public void InfoEndpointMiddleware_PathAndVerbMatching_ReturnsExpected() { var opts = new InfoOptions(); var contribs = new List <IInfoContributor>() { new GitInfoContributor() }; var ep = new InfoEndpoint(opts, contribs); var middle = new InfoEndpointMiddleware(null, ep); Assert.True(middle.RequestVerbAndPathMatch("GET", "/info")); Assert.False(middle.RequestVerbAndPathMatch("PUT", "/info")); Assert.False(middle.RequestVerbAndPathMatch("GET", "/badpath")); }
public void InfoEndpointMiddleware_PathAndVerbMatching_ReturnsExpected() { var opts = new InfoEndpointOptions(); var mopts = TestHelpers.GetManagementOptions(opts); var contribs = new List <IInfoContributor>() { new GitInfoContributor() }; var ep = new InfoEndpoint(opts, contribs); var middle = new InfoEndpointMiddleware(null, ep, mopts); Assert.True(middle.RequestVerbAndPathMatch("GET", "/cloudfoundryapplication/info")); Assert.False(middle.RequestVerbAndPathMatch("PUT", "/cloudfoundryapplication/info")); Assert.False(middle.RequestVerbAndPathMatch("GET", "/cloudfoundryapplication/badpath")); }
public void Invoke_CallsAllContributors() { var opts = new InfoEndpointOptions(); var contributors = new List <IInfoContributor>() { new TestContrib(), new TestContrib(), new TestContrib() }; var ep = new InfoEndpoint(opts, contributors, GetLogger <InfoEndpoint>()); var info = ep.Invoke(); foreach (var contrib in contributors) { var tc = (TestContrib)contrib; Assert.True(tc.Called); } }
public void IsInfoRequest_ReturnsExpected() { var opts = new InfoOptions(); var contribs = new List <IInfoContributor>() { new GitInfoContributor() }; var ep = new InfoEndpoint(opts, contribs); var middle = new InfoEndpointMiddleware(null, ep); var context = CreateRequest("GET", "/info"); Assert.True(middle.IsInfoRequest(context)); var context2 = CreateRequest("PUT", "/info"); Assert.False(middle.IsInfoRequest(context2)); var context3 = CreateRequest("GET", "/badpath"); Assert.False(middle.IsInfoRequest(context3)); }
public InfoHandler(InfoEndpoint endpoint, IEnumerable <ISecurityService> securityServices, ILogger <InfoHandler> logger = null) : base(endpoint, securityServices, null, true, logger) { }
///<summary>Gets and refreshes all available configuration information this <see cref="UsbDevice"/>.</summary> ///<returns>A <see cref="InfoConfigs"/> list containing all device config information.</returns> public InfoConfigs RefreshConfigs() { mConfigs = new InfoConfigs(); StringBuilder sbTemp = new StringBuilder(255); for (int iConfig = 0; iConfig < mDev.mDeviceDescriptor.bNumConfigurations; iConfig++) { LibUsb_ConfigDescriptor usb_config = mDev.GetConfig(iConfig); InfoConfig config = new InfoConfig(this); mConfigs.Add(config); config.bLength = usb_config.bLength; config.bDescriptorType = usb_config.bDescriptorType; config.wTotalLength = usb_config.wTotalLength; config.bNumInterfaces = usb_config.bNumInterfaces; config.bConfigurationValue = usb_config.bConfigurationValue; config.iConfiguration = usb_config.iConfiguration; config.bmAttributes = usb_config.bmAttributes; config.bMaxPower = usb_config.MaxPower; if (usb_config.extralen > 0 && usb_config.extra != IntPtr.Zero) { config.aExtra = new byte[usb_config.extralen]; Marshal.Copy(usb_config.extra, config.aExtra, 0, usb_config.extralen); } config.mUSBInfoInterfaces = new InfoInterfaces(); for (int iInterface = 0; iInterface < usb_config.bNumInterfaces; iInterface++) { LibUsb_InterfaceDescriptor usb_int = usb_config.GetInterface(iInterface); for (int iAlt = 0; iAlt < usb_int.mNumAltSetting; iAlt++) { LibUsb_AltInterfaceDescriptor usb_id = usb_int.GetAltInterface(iAlt); InfoInterface UsbInt = new InfoInterface(this); config.mUSBInfoInterfaces.Add(UsbInt); UsbInt.bLength = usb_id.bLength; UsbInt.bDescriptorType = usb_id.bDescriptorType; UsbInt.bInterfaceNumber = usb_id.bInterfaceNumber; UsbInt.bAlternateSetting = usb_id.bAlternateSetting; UsbInt.bNumEndpoints = usb_id.bNumEndpoints; UsbInt.bInterfaceClass = usb_id.bInterfaceClass; UsbInt.bInterfaceSubClass = usb_id.bInterfaceSubClass; UsbInt.bInterfaceProtocol = usb_id.bInterfaceProtocol; UsbInt.iInterface = usb_id.iInterface; UsbInt.usbInfoEndpoints = new InfoEndpoints(); for (int iEndpoint = 0; iEndpoint < usb_id.bNumEndpoints; iEndpoint++) { InfoEndpoint endPoint = new InfoEndpoint(this); UsbInt.usbInfoEndpoints.Add(endPoint); LibUsb_EndpointDescriptor usb_endpoint = usb_id.GetEndpoint(iEndpoint); endPoint.bLength = usb_endpoint.bLength; endPoint.bDescriptorType = usb_endpoint.bDescriptorType; endPoint.bEndpointAddress = usb_endpoint.bEndpointAddress; endPoint.bmAttributes = usb_endpoint.bmAttributes; endPoint.wMaxPacketSize = usb_endpoint.wMaxPacketSize; endPoint.bInterval = usb_endpoint.bInterval; endPoint.bRefresh = usb_endpoint.bRefresh; endPoint.bSynchAddress = usb_endpoint.bSynchAddress; } //Endpoints } //Alt Interfaces } //Interfaces } //Configs return(mConfigs); }
public InfoHandler(InfoEndpoint endpoint, ISecurityService securityService, ILogger <InfoHandler> logger = null) : base(endpoint, securityService, null, true, logger) { }