SteeltoeOSS / Steeltoe

.NET Components for Externalized Configuration, Database Connectors, Service Discovery, Logging and Distributed Tracing, Application Management, Security, and more.
https://steeltoe.io
Apache License 2.0
1.02k stars 163 forks source link

Mappings Actuator Should Return Razor Pages #155

Open TimHess opened 5 years ago

TimHess commented 5 years ago

/mappings currently doesn't know about razor pages, but it would be nice if it did

zHaytam commented 4 years ago

Hello, Mappings Actuator should also return the urls of razor pages? I would be happy to tackle this if you guys accept PRs.

TimHess commented 4 years ago

We'd love to have your contribution on this issue, please let us know if you need any assistance getting started

zHaytam commented 4 years ago

Of course! I'm currently looking at how to get a list of all the registered razor pages, apparently it's not as "easy" as controller actions.

TimHess commented 3 years ago

This starting point

Led me to some rough (and incomplete) code:

        private readonly IEnumerable<EndpointDataSource> _endpointDataSources;
        ....

        public MappingsEndpointMiddleware(
            ...
            IEnumerable<EndpointDataSource> endpointDataSources = null,
            ILogger<MappingsEndpointMiddleware> logger = null)
            : base(endpoint, mgmtOptions, logger: logger)
        {
            ...
            _endpointDataSources = endpointDataSources;
        }
       ...
        protected internal ApplicationMappings GetApplicationMappings(HttpContext context)
        {
            ...
            if (_endpointDataSources != null)
            {
                // https://stackoverflow.com/questions/28435734/how-to-get-a-list-of-all-routes-in-asp-net-core
                var endpoints = _endpointDataSources.SelectMany(es => es.Endpoints).OfType<RouteEndpoint>();
                var output = endpoints.Select(
                    e =>
                    {
                        var controller = e.Metadata
                            .OfType<ControllerActionDescriptor>()
                            .FirstOrDefault();
                        var action = controller != null
                            ? $"{controller.ControllerName}.{controller.ActionName}"
                            : null;
                        var controllerMethod = controller != null
                            ? $"{controller.ControllerTypeInfo.FullName}:{controller.MethodInfo.Name}"
                            : null;
                        return new
                        {
                            Method = e.Metadata.OfType<HttpMethodMetadata>().FirstOrDefault()?.HttpMethods?[0],
                            Route = $"/{e.RoutePattern.RawText.TrimStart('/')}",
                            Action = action,
                            ControllerMethod = controllerMethod
                        };
                    });
                foreach (var r in output)
                {
                   // desc.Add(r.Route, new () { new () { Key = r.Route, Value = null } });
                }
            }

            var contextMappings = new ContextMappings(desc);
            return new ApplicationMappings(contextMappings);
        }