Skip to content

Commit

Permalink
Change route approvals to new way and approve routes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach committed Feb 8, 2024
1 parent 0a99a1a commit 8b95e1c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
34 changes: 21 additions & 13 deletions src/ServiceControl.Audit.UnitTests/API/APIApprovals.cs
@@ -1,5 +1,11 @@
namespace ServiceControl.UnitTests.API
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Audit;
using Audit.Infrastructure.Settings;
using Audit.Infrastructure.WebApi;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -44,26 +50,28 @@ public void HttpApiRoutes()
var httpApiMethods = GetControllerRoutes()
.Select(pair =>
{
var type = pair.Method.DeclaringType;
var httpMethods = pair.Method.GetCustomAttributes(true)
(MethodInfo method, RouteAttribute route) = pair;
var type = method.DeclaringType;
var httpMethods = method.GetCustomAttributes(true)
.OfType<IActionHttpMethodProvider>()
.SelectMany(att => att.HttpMethods.Select(m => m.Method))
.SelectMany(att => att.HttpMethods.Select(m => m))
.Distinct()
.OrderBy(httpMethod => httpMethod);
.OrderBy(httpMethod => httpMethod)
.ToArray();
if (!httpMethods.Any())
{
throw new Exception($"Method {type.FullName}:{pair.Method.Name} has Route attribute but no method attribute like HttpGet.");
throw new Exception($"Method {type.FullName}:{method.Name} has Route attribute but no method attribute like HttpGet.");
}
var parametersString = string.Join(", ", pair.Method.GetParameters().Select(p => $"{PrettyTypeName(p.ParameterType)} {p.Name}"));
var methodSignature = $"{type.FullName}:{pair.Method.Name}({parametersString})";
var parametersString = string.Join(", ", method.GetParameters().Select(p => $"{PrettyTypeName(p.ParameterType)} {p.Name}"));
var methodSignature = $"{type.FullName}:{method.Name}({parametersString})";
return new
{
MethodSignature = methodSignature,
HttpMethods = string.Join("/", httpMethods),
Route = pair.Route.Template
Route = route.Template
};
})
.OrderBy(x => x.Route).ThenBy(x => x.HttpMethods)
Expand All @@ -80,19 +88,19 @@ public void HttpApiRoutes()
Approver.Verify(httpApi);
}

IEnumerable<(MethodInfo Method, IHttpRouteInfoProvider Route)> GetControllerRoutes()
IEnumerable<(MethodInfo Method, RouteAttribute Route)> GetControllerRoutes()
{
var controllers = typeof(Program).Assembly.GetTypes()
.Where(t => typeof(IHttpController).IsAssignableFrom(t));
.Where(t => typeof(ControllerBase).IsAssignableFrom(t));

foreach (var type in controllers)
{
foreach (var methodInfo in type.GetMethods())
foreach (var method in type.GetMethods())
{
var routeAtts = methodInfo.GetCustomAttributes(true).OfType<IHttpRouteInfoProvider>();
var routeAtts = method.GetCustomAttributes(true).OfType<RouteAttribute>();
foreach (var routeAtt in routeAtts)
{
yield return (methodInfo, routeAtt);
yield return (method, routeAtt);
}
}
}
Expand Down
@@ -1,16 +1,16 @@
GET / => ServiceControl.Audit.Infrastructure.WebApi.RootController:Urls()
GET /configuration => ServiceControl.Audit.Infrastructure.WebApi.RootController:Config()
GET /connection => ServiceControl.Audit.Connection.ConnectionController:GetConnectionDetails()
GET /conversations/{conversationid} => ServiceControl.Audit.Auditing.MessagesView.MessagesConversationController:Get(String conversationid)
GET /endpoints/{endpoint}/audit-count => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:GetEndpointAuditCounts(String endpoint)
GET /endpoints/{endpoint}/messages => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:GetEndpointMessages(String endpoint)
GET /endpoints/{endpoint}/messages/search => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:Search(String endpoint, String q)
GET /endpoints/{endpoint}/messages/search/{keyword} => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:SearchByKeyword(String endpoint, String keyword)
GET /endpoints/known => ServiceControl.Audit.Monitoring.KnownEndpointsController:GetAll()
GET /conversations/{conversationId} => ServiceControl.Audit.Auditing.MessagesView.MessagesConversationController:Get(PagingInfo pagingInfo, SortInfo sortInfo, String conversationId)
GET /endpoints/{endpoint}/audit-count => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:GetEndpointAuditCounts(PagingInfo pagingInfo, String endpoint)
GET /endpoints/{endpoint}/messages => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:GetEndpointMessages(PagingInfo pagingInfo, SortInfo sortInfo, Boolean includeSystemMessages, String endpoint)
GET /endpoints/{endpoint}/messages/search => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:Search(PagingInfo pagingInfo, SortInfo sortInfo, String endpoint, String q)
GET /endpoints/{endpoint}/messages/search/{keyword} => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:SearchByKeyword(PagingInfo pagingInfo, SortInfo sortInfo, String endpoint, String keyword)
GET /endpoints/known => ServiceControl.Audit.Monitoring.KnownEndpointsController:GetAll(PagingInfo pagingInfo)
GET /instance-info => ServiceControl.Audit.Infrastructure.WebApi.RootController:Config()
GET /messages => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:GetAllMessages()
GET /messages => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:GetAllMessages(PagingInfo pagingInfo, SortInfo sortInfo, Boolean includeSystemMessages)
GET /messages/{*catchAll} => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:CatchAll(String catchAll)
GET /messages/{id}/body => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:Get(String id)
GET /messages/search => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:Search(String q)
GET /messages/search/{keyword} => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:SearchByKeyWord(String keyword)
GET /sagas/{id} => ServiceControl.Audit.SagaAudit.SagasController:Sagas(Guid id)
GET /messages/search => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:Search(PagingInfo pagingInfo, SortInfo sortInfo, String q)
GET /messages/search/{keyword} => ServiceControl.Audit.Auditing.MessagesView.GetMessagesController:SearchByKeyWord(PagingInfo pagingInfo, SortInfo sortInfo, String keyword)
GET /sagas/{id} => ServiceControl.Audit.SagaAudit.SagasController:Sagas(PagingInfo pagingInfo, Guid id)

0 comments on commit 8b95e1c

Please sign in to comment.