mirror of
https://github.com/Radarr/Radarr
synced 2026-02-05 06:14:28 +01:00
Log calls to deprecated endpoints
(cherry picked from commit aaaf18aec33dc0ae5075b53ab81812743608d6a6)
This commit is contained in:
parent
5d17f8e84d
commit
41b1ea553e
1 changed files with 14 additions and 0 deletions
|
|
@ -7,6 +7,8 @@
|
|||
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 @@ public abstract class RestController<TResource> : Controller
|
|||
where TResource : RestResource, new()
|
||||
{
|
||||
private static readonly List<Type> VALIDATE_ID_ATTRIBUTES = new List<Type> { typeof(RestPutByIdAttribute), typeof(RestDeleteByIdAttribute) };
|
||||
private static readonly Type DEPRECATED_ATTRIBUTE = typeof(ObsoleteAttribute);
|
||||
|
||||
private readonly Logger _logger;
|
||||
|
||||
protected ResourceValidator<TResource> PostValidator { get; private set; }
|
||||
protected ResourceValidator<TResource> PutValidator { get; private set; }
|
||||
|
|
@ -32,6 +37,8 @@ protected void ValidateId(int id)
|
|||
|
||||
protected RestController()
|
||||
{
|
||||
_logger = NzbDroneLogger.GetLogger(this);
|
||||
|
||||
PostValidator = new ResourceValidator<TResource>();
|
||||
PutValidator = new ResourceValidator<TResource>();
|
||||
SharedValidator = new ResourceValidator<TResource>();
|
||||
|
|
@ -90,6 +97,13 @@ public override void OnActionExecuting(ActionExecutingContext context)
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue