From 41b1ea553ede167638f5fafbbc1cb816ce240e48 Mon Sep 17 00:00:00 2001 From: Qstick Date: Wed, 30 Nov 2022 19:46:27 -0600 Subject: [PATCH] Log calls to deprecated endpoints (cherry picked from commit aaaf18aec33dc0ae5075b53ab81812743608d6a6) --- src/Radarr.Http/REST/RestController.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Radarr.Http/REST/RestController.cs b/src/Radarr.Http/REST/RestController.cs index 38d9f5e78..109a05430 100644 --- a/src/Radarr.Http/REST/RestController.cs +++ b/src/Radarr.Http/REST/RestController.cs @@ -7,6 +7,8 @@ using FluentValidation.Results; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; +using NLog; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Datastore; using Radarr.Http.REST.Attributes; using Radarr.Http.Validation; @@ -17,6 +19,9 @@ namespace Radarr.Http.REST where TResource : RestResource, new() { private static readonly List VALIDATE_ID_ATTRIBUTES = new List { typeof(RestPutByIdAttribute), typeof(RestDeleteByIdAttribute) }; + private static readonly Type DEPRECATED_ATTRIBUTE = typeof(ObsoleteAttribute); + + private readonly Logger _logger; protected ResourceValidator PostValidator { get; private set; } protected ResourceValidator PutValidator { get; private set; } @@ -32,6 +37,8 @@ namespace Radarr.Http.REST protected RestController() { + _logger = NzbDroneLogger.GetLogger(this); + PostValidator = new ResourceValidator(); PutValidator = new ResourceValidator(); SharedValidator = new ResourceValidator(); @@ -90,6 +97,13 @@ namespace Radarr.Http.REST } } + var controllerAttributes = descriptor.ControllerTypeInfo.CustomAttributes; + if (controllerAttributes.Any(x => x.AttributeType == DEPRECATED_ATTRIBUTE) || attributes.Any(x => x.AttributeType == DEPRECATED_ATTRIBUTE)) + { + _logger.Warn("API call made to deprecated endpoint from {0}", Request.Headers.UserAgent.ToString()); + Response.Headers["Deprecation"] = "true"; + } + base.OnActionExecuting(context); }