Log calls to deprecated endpoints

(cherry picked from commit aaaf18aec33dc0ae5075b53ab81812743608d6a6)
pull/10296/head
Qstick 2 years ago committed by Bogdan
parent 5d17f8e84d
commit 41b1ea553e

@ -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<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 @@ namespace Radarr.Http.REST
protected RestController()
{
_logger = NzbDroneLogger.GetLogger(this);
PostValidator = new ResourceValidator<TResource>();
PutValidator = new ResourceValidator<TResource>();
SharedValidator = new ResourceValidator<TResource>();
@ -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);
}

Loading…
Cancel
Save