Example #1
0
        public virtual void Dispose()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            ManagementOptions.SetInstance(null);
#pragma warning restore CS0618 // Type or member is obsolete
            DiagnosticsManager.Instance.Dispose();
        }
Example #2
0
    /// <summary>
    /// Initializes a new instance of the <see cref="ManagementClient"/> class for managing content of the specified project.
    /// </summary>
    /// <param name="ManagementOptions">The settings of the Kontent project.</param>
    public ManagementClient(ManagementOptions ManagementOptions)
    {
        if (ManagementOptions == null)
        {
            throw new ArgumentNullException(nameof(ManagementOptions));
        }

        if (string.IsNullOrEmpty(ManagementOptions.ProjectId))
        {
            throw new ArgumentException("Kontent project identifier is not specified.", nameof(ManagementOptions.ProjectId));
        }

        if (!Guid.TryParse(ManagementOptions.ProjectId, out _))
        {
            throw new ArgumentException($"Provided string is not a valid project identifier ({ManagementOptions.ProjectId}). Haven't you accidentally passed the API key instead of the project identifier?", nameof(ManagementOptions.ProjectId));
        }

        if (string.IsNullOrEmpty(ManagementOptions.ApiKey))
        {
            throw new ArgumentException("The API key is not specified.", nameof(ManagementOptions.ApiKey));
        }


        _urlBuilder    = new EndpointUrlBuilder(ManagementOptions);
        _actionInvoker = new ActionInvoker(
            new ManagementHttpClient(new DefaultResiliencePolicyProvider(ManagementOptions.MaxRetryAttempts), ManagementOptions.EnableResilienceLogic),
            new MessageCreator(ManagementOptions.ApiKey));
        _modelProvider = ManagementOptions.ModelProvider ?? new ModelProvider();
    }
Example #3
0
        /// <summary>
        /// Add Http Request Trace actuator endpoint to OWIN Pipeline
        /// </summary>
        /// <param name="builder">OWIN <see cref="IAppBuilder" /></param>
        /// <param name="config"><see cref="IConfiguration"/> of application for configuring thread dump endpoint</param>
        /// <param name="traceRepository">repository to put traces in</param>
        /// <param name="loggerFactory">For logging within the middleware</param>
        /// <returns>OWIN <see cref="IAppBuilder" /> with Trace Endpoint added</returns>
        public static IAppBuilder UseHttpTraceActuator(this IAppBuilder builder, IConfiguration config, IHttpTraceRepository traceRepository, ILoggerFactory loggerFactory)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            ITraceOptions options = new HttpTraceEndpointOptions(config);

            var mgmtOptions = ManagementOptions.Get(config);

            foreach (var mgmt in mgmtOptions)
            {
                mgmt.EndpointOptions.Add(options);
            }

            traceRepository = traceRepository ?? new HttpTraceDiagnosticObserver(options, loggerFactory?.CreateLogger <HttpTraceDiagnosticObserver>());
            DiagnosticsManager.Instance.Observers.Add((IDiagnosticObserver)traceRepository);
            var endpoint = new HttpTraceEndpoint(options, traceRepository, loggerFactory?.CreateLogger <HttpTraceEndpoint>());
            var logger   = loggerFactory?.CreateLogger <EndpointOwinMiddleware <HttpTraceEndpoint, HttpTraceResult> >();

            return(builder.Use <EndpointOwinMiddleware <HttpTraceResult> >(endpoint, mgmtOptions, new List <HttpMethod> {
                HttpMethod.Get
            }, true, logger));
        }
        public void BindsConfigurationCorrectly()
        {
            var    appsettings = @"
{
    'management': {
        'endpoints': {
            'enabled': false,
            'sensitive': false,
            'path': '/management',
            'info' : {
                'enabled': true,
                'sensitive': true,
                'id': '/infomanagement'
            }
        }
    }
}";
            var    path        = TestHelpers.CreateTempFile(appsettings);
            string directory   = Path.GetDirectoryName(path);
            string fileName    = Path.GetFileName(path);
            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.SetBasePath(directory);

            configurationBuilder.AddJsonFile(fileName);
            var config = configurationBuilder.Build();

            ManagementOptions opts = ManagementOptions.GetInstance(config);

            Assert.False(opts.Enabled);
            Assert.False(opts.Sensitive);
            Assert.Equal("/management", opts.Path);
        }
        /// <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));
        }
        /// <summary>
        /// Add Environment middleware to OWIN Pipeline
        /// </summary>
        /// <param name="builder">OWIN <see cref="IAppBuilder" /></param>
        /// <param name="config"><see cref="IConfiguration"/> of application for configuring env endpoint and inclusion in response</param>
        /// <param name="hostingEnvironment"><see cref="IHostingEnvironment"/> of the application</param>
        /// <param name="loggerFactory">For logging within the middleware</param>
        /// <returns>OWIN <see cref="IAppBuilder" /> with Env Endpoint added</returns>
        public static IAppBuilder UseEnvActuator(this IAppBuilder builder, IConfiguration config, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (hostingEnvironment == null)
            {
                throw new ArgumentNullException(nameof(hostingEnvironment));
            }

            IEnvOptions options     = new EnvEndpointOptions(config);
            var         mgmtOptions = ManagementOptions.Get(config);

            foreach (var mgmt in mgmtOptions)
            {
                if (!mgmt.EndpointOptions.Contains(options))
                {
                    mgmt.EndpointOptions.Add(options);
                }
            }

            var endpoint = new EnvEndpoint(options, config, hostingEnvironment, loggerFactory?.CreateLogger <EnvEndpoint>());
            var logger   = loggerFactory?.CreateLogger <EndpointOwinMiddleware <EnvironmentDescriptor> >();

            return(builder.Use <EndpointOwinMiddleware <EnvironmentDescriptor> >(endpoint, mgmtOptions, new List <HttpMethod> {
                HttpMethod.Get
            }, true, logger));
        }
Example #7
0
        /// <summary>
        /// Add Route Mappings 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="apiExplorer">An <see cref="ApiExplorer"/> for iterating routes and their metadata</param>
        /// <param name="loggerFactory">For logging within the middleware</param>
        /// <returns>OWIN <see cref="IAppBuilder" /> with Refresh Endpoint added</returns>
        public static IAppBuilder UseMappingActuator(this IAppBuilder builder, IConfiguration config, IApiExplorer apiExplorer, ILoggerFactory loggerFactory = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (apiExplorer == null)
            {
                throw new ArgumentNullException(nameof(apiExplorer));
            }

            IMappingsOptions options = new MappingsEndpointOptions(config);
            var mgmtOptions          = ManagementOptions.Get(config);

            foreach (var mgmt in mgmtOptions)
            {
                mgmt.EndpointOptions.Add(options);
            }

            var logger = loggerFactory?.CreateLogger <EndpointOwinMiddleware <IList <string> > >();

            return(builder.Use <MappingsEndpointOwinMiddleware>(options, mgmtOptions, apiExplorer, loggerFactory?.CreateLogger <MappingsEndpointOwinMiddleware>()));
        }
Example #8
0
        private static IAppBuilder UseTraceActuatorComponents(this IAppBuilder builder, IConfiguration config, ITraceRepository traceRepository, ILoggerFactory loggerFactory)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            ITraceOptions options = new TraceEndpointOptions(config);

            var mgmtOptions = ManagementOptions.Get(config);

            foreach (var mgmt in mgmtOptions)
            {
                mgmt.EndpointOptions.Add(options);
            }

            traceRepository = traceRepository ?? new TraceDiagnosticObserver(options, loggerFactory?.CreateLogger <TraceDiagnosticObserver>());
            DiagnosticsManager.Instance.Observers.Add((IDiagnosticObserver)traceRepository);
            var endpoint = new TraceEndpoint(options, traceRepository, loggerFactory?.CreateLogger <TraceEndpoint>());
            var logger   = loggerFactory?.CreateLogger <TraceEndpointOwinMiddleware>();

            return(builder.Use <TraceEndpointOwinMiddleware>(endpoint, mgmtOptions, logger));
        }
Example #9
0
        /// <summary>
        /// Add Cloud Foundry actuator to OWIN Pipeline
        /// </summary>
        /// <param name="builder">Your OWIN <see cref="IAppBuilder"/></param>
        /// <param name="config">Your application's <see cref="IConfiguration"/></param>
        /// <param name="mgmtOptions">Shared management options</param>
        /// <param name="loggerFactory"><see cref="ILoggerFactory"/> for logging within the middleware</param>
        /// <returns>Your OWIN <see cref="IAppBuilder"/> with Cloud Foundry actuator attached</returns>
        public static IAppBuilder UseCloudFoundryActuator(this IAppBuilder builder, IConfiguration config, IEnumerable <IManagementOptions> mgmtOptions, ILoggerFactory loggerFactory = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (mgmtOptions == null)
            {
                mgmtOptions = ManagementOptions.Get(config);
            }

            var cloudFoundryOptions = new CloudFoundryEndpointOptions(config);
            var mgmt = mgmtOptions.OfType <CloudFoundryManagementOptions>().Single();

            mgmt.EndpointOptions.Add(cloudFoundryOptions);

            var endpoint = new CloudFoundryEndpoint(cloudFoundryOptions, mgmtOptions, loggerFactory?.CreateLogger <CloudFoundryEndpoint>());
            var logger   = loggerFactory?.CreateLogger <CloudFoundryEndpointOwinMiddleware>();

            return(builder.Use <CloudFoundryEndpointOwinMiddleware>(endpoint, mgmtOptions, logger));
        }
Example #10
0
        public async void CloudFoundryHttpCall_ReturnsExpected()
        {
            ManagementOptions.Clear();
            using (var server = TestServer.Create <Startup>())
            {
                var client = server.HttpClient;
                var result = await client.GetAsync("http://localhost/cloudfoundryapplication");

                Assert.Equal(HttpStatusCode.OK, result.StatusCode);
                var json = await result.Content.ReadAsStringAsync();

                Assert.NotNull(json);
#pragma warning disable CS0612 // Type or member is obsolete
                var links = JsonConvert.DeserializeObject <Links>(json);
#pragma warning restore CS0612 // Type or member is obsolete
                Assert.NotNull(links);
                Assert.True(links._links.ContainsKey("self"), "Self is one of the available links");
                Assert.Equal("http://localhost/cloudfoundryapplication", links._links["self"].href);
                Assert.True(links._links.ContainsKey("info"), "Info is one of the available links");
                Assert.Equal("http://localhost/cloudfoundryapplication/info", links._links["info"].href);

                // this test is here to prevent breaking changes in response serialization
                Assert.Equal("{\"type\":\"steeltoe\",\"_links\":{\"self\":{\"href\":\"http://localhost/cloudfoundryapplication\",\"templated\":false},\"info\":{\"href\":\"http://localhost/cloudfoundryapplication/info\",\"templated\":false}}}", json);
            }
        }
        /// <summary>
        /// Add Thread Dump actuator endpoint to OWIN Pipeline
        /// </summary>
        /// <param name="builder">OWIN <see cref="IAppBuilder" /></param>
        /// <param name="config"><see cref="IConfiguration"/> of application for configuring thread dump endpoint</param>
        /// <param name="loggerFactory">For logging within the middleware</param>
        /// <param name="version">MediaTypeVersion for endpoint response</param>
        /// <returns>OWIN <see cref="IAppBuilder" /> with Thread Dump Endpoint added</returns>
        public static IAppBuilder UseThreadDumpActuator(this IAppBuilder builder, IConfiguration config, ILoggerFactory loggerFactory, MediaTypeVersion version)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var options = new ThreadDumpEndpointOptions(config);

            if (version == MediaTypeVersion.V2 && options.Id == "dump")
            {
                options.Id = "threaddump";
            }

            var mgmtOptions = ManagementOptions.Get(config);

            foreach (var mgmt in mgmtOptions)
            {
                mgmt.EndpointOptions.Add(options);
            }

            var threadDumper = new ThreadDumper(options, loggerFactory?.CreateLogger <ThreadDumper>());

            return(builder.UseThreadDumpActuator(options, threadDumper, loggerFactory, version));
        }
Example #12
0
        /// <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));
        }
        /// <summary>
        /// Add Cloud Foundry actuator to OWIN Pipeline
        /// </summary>
        /// <param name="builder">Your OWIN <see cref="IAppBuilder"/></param>
        /// <param name="config">Your application's <see cref="IConfiguration"/></param>
        /// <param name="loggerFactory"><see cref="ILoggerFactory"/> for logging within the middleware</param>
        /// <returns>Your OWIN <see cref="IAppBuilder"/> with Cloud Foundry actuator attached</returns>
        public static IAppBuilder UseHypermediaActuator(this IAppBuilder builder, IConfiguration config, ILoggerFactory loggerFactory = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            IActuatorHypermediaOptions options;

            options = new HypermediaEndpointOptions(config);
            var mgmtOptions = ManagementOptions.Get(config);
            var mgmt        = mgmtOptions.OfType <ActuatorManagementOptions>().Single();

            mgmt.EndpointOptions.Add(options);

            var endpoint = new ActuatorEndpoint(options, mgmtOptions, loggerFactory?.CreateLogger <ActuatorEndpoint>());
            var logger   = loggerFactory?.CreateLogger <ActuatorHypermediaEndpointOwinMiddleware>();

            return(builder.Use <ActuatorHypermediaEndpointOwinMiddleware>(endpoint, mgmtOptions, logger));
        }
        /// <summary>
        /// Add Loggers actuator endpoint to OWIN Pipeline
        /// </summary>
        /// <param name="builder">OWIN <see cref="IAppBuilder" /></param>
        /// <param name="config"><see cref="IConfiguration"/> of application for configuring loggers endpoint</param>
        /// <param name="loggerProvider">Provider of loggers to report on and configure</param>
        /// <param name="loggerFactory">For logging within the middleware</param>
        /// <returns>OWIN <see cref="IAppBuilder" /> with Loggers Endpoint added</returns>
        public static IAppBuilder UseLoggersActuator(this IAppBuilder builder, IConfiguration config, ILoggerProvider loggerProvider, ILoggerFactory loggerFactory = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (loggerProvider == null)
            {
                throw new ArgumentNullException(nameof(loggerProvider));
            }

            var options     = new LoggersEndpointOptions(config);
            var mgmtOptions = ManagementOptions.Get(config);

            foreach (var mgmt in mgmtOptions)
            {
                mgmt.EndpointOptions.Add(options);
            }

            var endpoint = new LoggersEndpoint(options, loggerProvider as IDynamicLoggerProvider, loggerFactory?.CreateLogger <LoggersEndpoint>());
            var logger   = loggerFactory?.CreateLogger <LoggersEndpointOwinMiddleware>();

            return(builder.Use <LoggersEndpointOwinMiddleware>(endpoint, mgmtOptions, logger));
        }
Example #15
0
        public void InitializedWithDefaults()
        {
            ManagementOptions opts = ManagementOptions.GetInstance();

            Assert.False(opts.Enabled.HasValue);
            Assert.Equal("/", opts.Path);
        }
Example #16
0
        private static IServiceCollection LoadOptionsConfiguration(this IServiceCollection services, IConfiguration configuration, string configurationSectionName)
        {
            var managementOptions = new ManagementOptions();

            configuration.GetSection(configurationSectionName).Bind(managementOptions);
            services.AddSingleton(managementOptions);

            return(services);
        }
        private static IAppBuilder UseThreadDumpV2Components(IAppBuilder builder, IThreadDumpOptions options, IThreadDumper threadDumper, ILoggerFactory loggerFactory)
        {
            var endpoint    = new ThreadDumpEndpoint_v2(options, threadDumper, loggerFactory?.CreateLogger <ThreadDumpEndpoint_v2>());
            var logger      = loggerFactory?.CreateLogger <EndpointOwinMiddleware <ThreadDumpResult> >();
            var mgmtOptions = ManagementOptions.Get();

            return(builder.Use <EndpointOwinMiddleware <ThreadDumpResult> >(endpoint, mgmtOptions, new List <HttpMethod> {
                HttpMethod.Get
            }, true, logger));
        }
Example #18
0
        public TaxonomyImporter(KontentKeys keys)
        {
            ManagementOptions options = new ManagementOptions
            {
                ProjectId = keys.ProjectId,
                ApiKey    = keys.ManagementApiKey,
            };

            // Initializes an instance of the ManagementClient client
            client = new ManagementClient(options);
        }
Example #19
0
    public FileSystemFixture()
    {
        var managementOptions = new ManagementOptions()
        {
            ApiKey         = "Dummy_API_key",
            ProjectId      = PROJECT_ID,
            SubscriptionId = SUBCRIPTION_ID
        };

        _urlBuilder     = new EndpointUrlBuilder(managementOptions);
        _messageCreator = new MessageCreator(managementOptions.ApiKey);
    }
Example #20
0
        public RecordService(IChainService chainService, ITransactionService transactionService, INodeService
                             nodeService, INetworkService networkService, IOptionsSnapshot <ManagementOptions> options)
        {
            Logger = NullLogger <RecordService> .Instance;

            _chainService       = chainService;
            _transactionService = transactionService;
            _nodeService        = nodeService;
            _networkService     = networkService;
            _managementOptions  = options.Value;
            _timer          = new Timer(_managementOptions.MonitoringInterval * 1000);
            _timer.Elapsed += TimerOnElapsed;
        }
Example #21
0
        /// <summary>
        /// Validates that ManagementOptions are initialized
        /// </summary>
        /// <param name="managementOptions">ManagementOptions object to be validated</param>
        /// <exception cref="Exception"></exception>
        private static void Validate(this ManagementOptions managementOptions)
        {
            var seePart = SeePart(true);

            if (managementOptions?.ProjectId == null)
            {
                throw new Exception($"You have to provide the '{nameof(ManagementOptions.ProjectId)}' to generate type for Management SDK. {seePart}");
            }

            if (string.IsNullOrWhiteSpace(managementOptions.ApiKey))
            {
                throw new Exception($"You have to provide the '{nameof(ManagementOptions.ApiKey)}' to generate type for Management SDK. {seePart}");
            }
        }
        public ManagementClient GetManagementClient()
        {
            if (_managementClient == null)
            {
                ManagementOptions options = new ManagementOptions
                {
                    ApiKey    = _configuration.GetValue <string>("ManagementOptions:APIKey"),
                    ProjectId = _configuration.GetValue <string>("ManagementOptions:ProjectId")
                };
                _managementClient = new ManagementClient(options);
            }
            ;

            return(_managementClient);
        }
        internal static ManagementClient CreateManagementClient(ManagementOptions options, TestRunType runType, string testName)
        {
            if (runType != TestRunType.LiveEndPoint)
            {
                var saveToFileSystem = runType == TestRunType.LiveEndPoint_SaveToFileSystem;
                var httpClient       = new FileSystemHttpClientMock(options, saveToFileSystem, testName);

                var urlBuilder    = new EndpointUrlBuilder(options);
                var actionInvoker = new ActionInvoker(httpClient, new MessageCreator(options.ApiKey));

                return(new ManagementClient(urlBuilder, actionInvoker));
            }

            return(new ManagementClient(options));
        }
        /// <summary>
        /// Adds OWIN Middleware for providing Heap Dumps to OWIN pipeline
        /// </summary>
        /// <param name="builder">Your <see cref="IAppBuilder"/></param>
        /// <param name="options"><see cref="IHeapDumpOptions"/> to configure the endpoint</param>
        /// <param name="heapDumper"><see cref="HeapDumper"/> or other implementer of <see cref="IHeapDumper"/> for retrieving a heap dump</param>
        /// <param name="loggerFactory"><see cref="ILoggerFactory"/> for logging inside the middleware and its components</param>
        /// <returns>Your <see cref="IAppBuilder"/> with Heap Dump middleware attached</returns>
        public static IAppBuilder UseHeapDumpActuator(this IAppBuilder builder, IHeapDumpOptions options, IHeapDumper heapDumper, ILoggerFactory loggerFactory = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (heapDumper == null)
            {
                throw new ArgumentNullException(nameof(heapDumper));
            }

            var endpoint = new HeapDumpEndpoint(options, heapDumper, loggerFactory?.CreateLogger <HeapDumpEndpoint>());
            var logger   = loggerFactory?.CreateLogger <HeapDumpEndpointOwinMiddleware>();

            return(builder.Use <HeapDumpEndpointOwinMiddleware>(endpoint, ManagementOptions.Get(), logger));
        }
Example #25
0
        /// <summary>
        /// Add Metrics actuator endpoint to OWIN Pipeline
        /// </summary>
        /// <param name="builder">OWIN <see cref="IAppBuilder" /></param>
        /// <param name="config"><see cref="IConfiguration"/> of application for configuring metrics endpoint</param>
        /// <param name="stats">Class for recording statistics - See also: <seealso cref="OpenCensusStats"/></param>
        /// <param name="tags">Class using for recording statistics</param>
        /// <param name="loggerFactory">For logging within the middleware</param>
        /// <returns>OWIN <see cref="IAppBuilder" /> with Metrics Endpoint added</returns>
        public static IAppBuilder UseMetricsActuator(this IAppBuilder builder, IConfiguration config, IStats stats, ITags tags, ILoggerFactory loggerFactory = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (stats == null)
            {
                throw new ArgumentNullException(nameof(stats));
            }

            if (tags == null)
            {
                throw new ArgumentNullException(nameof(tags));
            }

            IMetricsOptions options     = new MetricsEndpointOptions(config);
            var             mgmtOptions = ManagementOptions.Get(config);

            foreach (var mgmt in mgmtOptions)
            {
                mgmt.EndpointOptions.Add(options);
            }

            var hostObserver = new OwinHostingObserver(options, stats, tags, loggerFactory?.CreateLogger <OwinHostingObserver>());
            var clrObserver  = new CLRRuntimeObserver(options, stats, tags, loggerFactory?.CreateLogger <CLRRuntimeObserver>());

            DiagnosticsManager.Instance.Observers.Add(hostObserver);
            DiagnosticsManager.Instance.Observers.Add(clrObserver);

            var clrSource = new CLRRuntimeSource();

            DiagnosticsManager.Instance.Sources.Add(clrSource);

            var endpoint = new MetricsEndpoint(options, stats, loggerFactory?.CreateLogger <MetricsEndpoint>());
            var logger   = loggerFactory?.CreateLogger <MetricsEndpointOwinMiddleware>();

            return(builder.Use <MetricsEndpointOwinMiddleware>(endpoint, mgmtOptions, logger));
        }
Example #26
0
        /// <summary>
        /// Add Cloud Foundry security to actuator requests in the OWIN Pipeline
        /// </summary>
        /// <param name="builder">Your OWIN <see cref="IAppBuilder"/></param>
        /// <param name="config">Your application's <see cref="IConfiguration"/></param>
        /// <param name="loggerFactory"><see cref="ILoggerFactory"/> for logging within the middleware</param>
        /// <returns>Your OWIN <see cref="IAppBuilder"/> with Cloud Foundry request security and CORS configured</returns>
        public static IAppBuilder UseCloudFoundrySecurityMiddleware(this IAppBuilder builder, IConfiguration config, ILoggerFactory loggerFactory = null)
        {
            if (builder == null)
            {
                throw new System.ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new System.ArgumentNullException(nameof(config));
            }

            var mgmtOptions         = ManagementOptions.Get(config);
            var cloudFoundryOptions = new CloudFoundryEndpointOptions(config);
            var logger = loggerFactory?.CreateLogger <CloudFoundrySecurityOwinMiddleware>();

            return(builder.Use <CloudFoundrySecurityOwinMiddleware>(cloudFoundryOptions, mgmtOptions, logger));
        }
Example #27
0
    public EndpointUrlBuilder(ManagementOptions options)
    {
        _taxonomyTemplate       = new TaxonomyTemplate();
        _assetTemplate          = new AssetTemplate();
        _assetRenditionTemplate = new AssetRenditionTemplate();
        _languageTemplate       = new LanguageTemplate();
        _snippetTemplate        = new SnippetTemplate();
        _collectionTemplate     = new CollectionTemplate();
        _typeTemplate           = new TypeTemplate();
        _validateTemplate       = new ValidateTemplate();
        _variantTemplate        = new VariantTemplate();
        _webhookTemplate        = new WebhookTemplate();
        _workflowTemplate       = new WorkflowTemplate();
        _itemTemplate           = new ItemTemplate();
        _projectRolesTemplate   = new ProjectRolesTemplate();
        _userTemplate           = new UserTemplate();

        _options = options;
    }
Example #28
0
        public void BindsConfigurationCorrectly()
        {
            var appsettings = new Dictionary <string, string>()
            {
                ["management:endpoints:enabled"]      = "false",
                ["management:endpoints:path"]         = "/management",
                ["management:endpoints:info:enabled"] = "true",
                ["management:endpoints:info:id"]      = "/infomanagement"
            };
            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(appsettings);
            var config = configurationBuilder.Build();

            ManagementOptions opts = ManagementOptions.GetInstance(config);

            Assert.False(opts.Enabled);
            Assert.Equal("/management", opts.Path);
        }
Example #29
0
        public async void InfoHttpCall_ReturnsExpected()
        {
            // Note: This test pulls in from git.properties and appsettings created
            // in the Startup class
            ManagementOptions.Clear();
            using (var server = TestServer.Create <Startup>())
            {
                var client = server.HttpClient;
                var result = await client.GetAsync("http://localhost/cloudfoundryapplication/infomanagement");

                Assert.Equal(HttpStatusCode.OK, result.StatusCode);
                var json = await result.Content.ReadAsStringAsync();

                Assert.NotNull(json);
                var dict = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, object> > >(json);
                Assert.NotNull(dict);

                Assert.Equal(3, dict.Count);
                Assert.True(dict.ContainsKey("application"));
                Assert.True(dict.ContainsKey("NET"));
                Assert.True(dict.ContainsKey("git"));

                var appNode = dict["application"] as Dictionary <string, object>;
                Assert.NotNull(appNode);
                Assert.Equal("foobar", appNode["name"]);

                var netNode = dict["NET"] as Dictionary <string, object>;
                Assert.NotNull(netNode);
                Assert.Equal("Core", netNode["type"]);

                var gitNode = dict["git"] as Dictionary <string, object>;
                Assert.NotNull(gitNode);
                Assert.True(gitNode.ContainsKey("build"));
                Assert.True(gitNode.ContainsKey("branch"));
                Assert.True(gitNode.ContainsKey("commit"));
                Assert.True(gitNode.ContainsKey("closest"));
                Assert.True(gitNode.ContainsKey("dirty"));
                Assert.True(gitNode.ContainsKey("remote"));
                Assert.True(gitNode.ContainsKey("tags"));
            }
        }
        /// <summary>
        /// Add HealthCheck actuator endpoint to OWIN Pipeline
        /// </summary>
        /// <param name="builder">OWIN <see cref="IAppBuilder" /></param>
        /// <param name="config"><see cref="IConfiguration"/> of application for configuring health endpoint</param>
        /// <param name="loggerFactory">For logging within the middleware</param>
        /// <returns>OWIN <see cref="IAppBuilder" /> with Health Endpoint added</returns>
        public static IAppBuilder UseHealthActuator(this IAppBuilder builder, IConfiguration config, ILoggerFactory loggerFactory = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var mgmtOptions = ManagementOptions.Get(config);
            var options     = new HealthEndpointOptions(config);

            foreach (var mgmt in mgmtOptions)
            {
                mgmt.EndpointOptions.Add(options);
            }

            return(builder.UseHealthActuator(options, new DefaultHealthAggregator(), loggerFactory));
        }