From 3c72d504597e27f4a04d566866f0d11726a850c8 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sat, 27 Jan 2024 23:26:31 +0100 Subject: [PATCH] Refactor controller OpenAPI tags --- .../Controllers/ActivityPubController.cs | 1 + .../Controllers/AuthController.cs | 1 + .../Controllers/Mastodon/AuthController.cs | 21 +++++++++++++++++++ .../Controllers/NodeInfoController.cs | 1 + .../Controllers/UserController.cs | 1 + .../Controllers/WellKnownController.cs | 1 + .../Core/Extensions/ServiceExtensions.cs | 1 + 7 files changed, 27 insertions(+) create mode 100644 Iceshrimp.Backend/Controllers/Mastodon/AuthController.cs diff --git a/Iceshrimp.Backend/Controllers/ActivityPubController.cs b/Iceshrimp.Backend/Controllers/ActivityPubController.cs index bf151c64..3635e886 100644 --- a/Iceshrimp.Backend/Controllers/ActivityPubController.cs +++ b/Iceshrimp.Backend/Controllers/ActivityPubController.cs @@ -15,6 +15,7 @@ using Newtonsoft.Json.Linq; namespace Iceshrimp.Backend.Controllers; [ApiController] +[Tags("ActivityPub")] [UseNewtonsoftJson] public class ActivityPubController : Controller { [HttpGet("/notes/{id}")] diff --git a/Iceshrimp.Backend/Controllers/AuthController.cs b/Iceshrimp.Backend/Controllers/AuthController.cs index 7da82325..422115eb 100644 --- a/Iceshrimp.Backend/Controllers/AuthController.cs +++ b/Iceshrimp.Backend/Controllers/AuthController.cs @@ -12,6 +12,7 @@ using Microsoft.EntityFrameworkCore; namespace Iceshrimp.Backend.Controllers; [ApiController] +[Tags("Authentication")] [EnableRateLimiting("sliding")] [Produces("application/json")] [Route("/api/iceshrimp/v1/auth")] diff --git a/Iceshrimp.Backend/Controllers/Mastodon/AuthController.cs b/Iceshrimp.Backend/Controllers/Mastodon/AuthController.cs new file mode 100644 index 00000000..6f490f98 --- /dev/null +++ b/Iceshrimp.Backend/Controllers/Mastodon/AuthController.cs @@ -0,0 +1,21 @@ +using System.Net; +using System.Net.Mime; +using Iceshrimp.Backend.Controllers.Schemas; +using Iceshrimp.Backend.Core.Database; +using Iceshrimp.Backend.Core.Database.Tables; +using Iceshrimp.Backend.Core.Helpers; +using Iceshrimp.Backend.Core.Services; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.RateLimiting; +using Microsoft.EntityFrameworkCore; + +namespace Iceshrimp.Backend.Controllers.Mastodon; + +[ApiController] +[Tags("Mastodon")] +[EnableRateLimiting("sliding")] +[Produces("application/json")] +[Route("/api/v1")] +public class MastodonAuthController() : Controller { + +} \ No newline at end of file diff --git a/Iceshrimp.Backend/Controllers/NodeInfoController.cs b/Iceshrimp.Backend/Controllers/NodeInfoController.cs index acf75c18..a4d784e4 100644 --- a/Iceshrimp.Backend/Controllers/NodeInfoController.cs +++ b/Iceshrimp.Backend/Controllers/NodeInfoController.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Options; namespace Iceshrimp.Backend.Controllers; [ApiController] +[Tags("Federation")] [Route("/nodeinfo")] public class NodeInfoController(IOptions config) : Controller { [HttpGet("2.1")] diff --git a/Iceshrimp.Backend/Controllers/UserController.cs b/Iceshrimp.Backend/Controllers/UserController.cs index a1615e6a..838f733d 100644 --- a/Iceshrimp.Backend/Controllers/UserController.cs +++ b/Iceshrimp.Backend/Controllers/UserController.cs @@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore; namespace Iceshrimp.Backend.Controllers; [ApiController] +[Tags("User")] [Produces("application/json")] [EnableRateLimiting("sliding")] [Route("/api/iceshrimp/v1/user/{id}")] diff --git a/Iceshrimp.Backend/Controllers/WellKnownController.cs b/Iceshrimp.Backend/Controllers/WellKnownController.cs index df2b2546..590fadd9 100644 --- a/Iceshrimp.Backend/Controllers/WellKnownController.cs +++ b/Iceshrimp.Backend/Controllers/WellKnownController.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Options; namespace Iceshrimp.Backend.Controllers; [ApiController] +[Tags("Federation")] [Route("/.well-known")] public class WellKnownController(IOptions config, DatabaseContext db) : Controller { [HttpGet("webfinger")] diff --git a/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs b/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs index d6a414af..3a58b87b 100644 --- a/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs +++ b/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs @@ -83,6 +83,7 @@ public static class ServiceExtensions { //TODO: separate limiter for authenticated users, partitioned by user id //TODO: ipv6 /64 subnet buckets //TODO: rate limit status headers - maybe switch to https://github.com/stefanprodan/AspNetCoreRateLimit? + //TODO: alternatively just write our own services.AddRateLimiter(options => { options.AddSlidingWindowLimiter("sliding", limiterOptions => { limiterOptions.PermitLimit = 500;