New: Add minimum version checks for applications

This commit is contained in:
Bogdan
2023-05-19 00:30:09 +03:00
parent b3bc92e60e
commit dcb19a66b0
6 changed files with 64 additions and 15 deletions

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using FluentValidation.Results; using FluentValidation.Results;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NLog; using NLog;
@@ -49,10 +48,10 @@ namespace NzbDrone.Core.Applications.Lidarr
{ {
failures.AddIfNotNull(_lidarrV1Proxy.TestConnection(BuildLidarrIndexer(testIndexer, DownloadProtocol.Usenet), Settings)); failures.AddIfNotNull(_lidarrV1Proxy.TestConnection(BuildLidarrIndexer(testIndexer, DownloadProtocol.Usenet), Settings));
} }
catch (WebException ex) catch (Exception ex)
{ {
_logger.Error(ex, "Unable to send test message"); _logger.Error(ex, "Unable to send test message");
failures.AddIfNotNull(new ValidationFailure("BaseUrl", "Unable to complete application test, cannot connect to Lidarr")); failures.AddIfNotNull(new ValidationFailure("BaseUrl", $"Unable to complete application test, cannot connect to Lidarr. {ex.Message}"));
} }
return new ValidationResult(failures); return new ValidationResult(failures);
@@ -61,7 +60,7 @@ namespace NzbDrone.Core.Applications.Lidarr
public override List<AppIndexerMap> GetIndexerMappings() public override List<AppIndexerMap> GetIndexerMappings()
{ {
var indexers = _lidarrV1Proxy.GetIndexers(Settings) var indexers = _lidarrV1Proxy.GetIndexers(Settings)
.Where(i => i.Implementation == "Newznab" || i.Implementation == "Torznab"); .Where(i => i.Implementation is "Newznab" or "Torznab");
var mappings = new List<AppIndexerMap>(); var mappings = new List<AppIndexerMap>();

View File

@@ -23,8 +23,11 @@ namespace NzbDrone.Core.Applications.Lidarr
public class LidarrV1Proxy : ILidarrV1Proxy public class LidarrV1Proxy : ILidarrV1Proxy
{ {
private static Version MinimumApplicationVersion => new (1, 0, 2, 0);
private const string AppApiRoute = "/api/v1"; private const string AppApiRoute = "/api/v1";
private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer"; private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer";
private readonly IHttpClient _httpClient; private readonly IHttpClient _httpClient;
private readonly Logger _logger; private readonly Logger _logger;
@@ -102,7 +105,17 @@ namespace NzbDrone.Core.Applications.Lidarr
try try
{ {
Execute<LidarrIndexer>(request); var applicationVersion = _httpClient.Post<LidarrIndexer>(request).Headers.GetSingleValue("X-Application-Version");
if (applicationVersion == null)
{
return new ValidationFailure(string.Empty, "Failed to fetch Lidarr version");
}
if (new Version(applicationVersion) < MinimumApplicationVersion)
{
return new ValidationFailure(string.Empty, $"Lidarr version should be at least {MinimumApplicationVersion.ToString(3)}. Version reported is {applicationVersion}", applicationVersion);
}
} }
catch (HttpException ex) catch (HttpException ex)
{ {

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using FluentValidation.Results; using FluentValidation.Results;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NLog; using NLog;
@@ -49,10 +48,10 @@ namespace NzbDrone.Core.Applications.Radarr
{ {
failures.AddIfNotNull(_radarrV3Proxy.TestConnection(BuildRadarrIndexer(testIndexer, DownloadProtocol.Usenet), Settings)); failures.AddIfNotNull(_radarrV3Proxy.TestConnection(BuildRadarrIndexer(testIndexer, DownloadProtocol.Usenet), Settings));
} }
catch (WebException ex) catch (Exception ex)
{ {
_logger.Error(ex, "Unable to send test message"); _logger.Error(ex, "Unable to send test message");
failures.AddIfNotNull(new ValidationFailure("BaseUrl", "Unable to complete application test, cannot connect to Radarr")); failures.AddIfNotNull(new ValidationFailure("BaseUrl", $"Unable to complete application test, cannot connect to Radarr. {ex.Message}"));
} }
return new ValidationResult(failures); return new ValidationResult(failures);
@@ -61,7 +60,7 @@ namespace NzbDrone.Core.Applications.Radarr
public override List<AppIndexerMap> GetIndexerMappings() public override List<AppIndexerMap> GetIndexerMappings()
{ {
var indexers = _radarrV3Proxy.GetIndexers(Settings) var indexers = _radarrV3Proxy.GetIndexers(Settings)
.Where(i => i.Implementation == "Newznab" || i.Implementation == "Torznab"); .Where(i => i.Implementation is "Newznab" or "Torznab");
var mappings = new List<AppIndexerMap>(); var mappings = new List<AppIndexerMap>();

View File

@@ -23,8 +23,12 @@ namespace NzbDrone.Core.Applications.Radarr
public class RadarrV3Proxy : IRadarrV3Proxy public class RadarrV3Proxy : IRadarrV3Proxy
{ {
private static Version MinimumApplicationV4Version => new (4, 0, 4, 0);
private static Version MinimumApplicationV3Version => new (3, 1, 1, 0);
private const string AppApiRoute = "/api/v3"; private const string AppApiRoute = "/api/v3";
private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer"; private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer";
private readonly IHttpClient _httpClient; private readonly IHttpClient _httpClient;
private readonly Logger _logger; private readonly Logger _logger;
@@ -102,7 +106,29 @@ namespace NzbDrone.Core.Applications.Radarr
try try
{ {
Execute<RadarrIndexer>(request); var applicationVersion = _httpClient.Post<RadarrIndexer>(request).Headers.GetSingleValue("X-Application-Version");
if (applicationVersion == null)
{
return new ValidationFailure(string.Empty, "Failed to fetch Radarr version");
}
var version = new Version(applicationVersion);
if (version.Major == 3)
{
if (version < MinimumApplicationV3Version)
{
return new ValidationFailure(string.Empty, $"Radarr version should be at least {MinimumApplicationV3Version.ToString(3)}. Version reported is {applicationVersion}", applicationVersion);
}
}
else
{
if (version < MinimumApplicationV4Version)
{
return new ValidationFailure(string.Empty, $"Radarr version should be at least {MinimumApplicationV4Version.ToString(3)}. Version reported is {applicationVersion}", applicationVersion);
}
}
} }
catch (HttpException ex) catch (HttpException ex)
{ {

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using FluentValidation.Results; using FluentValidation.Results;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using NLog; using NLog;
@@ -49,10 +48,10 @@ namespace NzbDrone.Core.Applications.Sonarr
{ {
failures.AddIfNotNull(_sonarrV3Proxy.TestConnection(BuildSonarrIndexer(testIndexer, DownloadProtocol.Usenet), Settings)); failures.AddIfNotNull(_sonarrV3Proxy.TestConnection(BuildSonarrIndexer(testIndexer, DownloadProtocol.Usenet), Settings));
} }
catch (WebException ex) catch (Exception ex)
{ {
_logger.Error(ex, "Unable to send test message"); _logger.Error(ex, "Unable to send test message");
failures.AddIfNotNull(new ValidationFailure("BaseUrl", "Unable to complete application test, cannot connect to Sonarr")); failures.AddIfNotNull(new ValidationFailure("BaseUrl", $"Unable to complete application test, cannot connect to Sonarr. {ex.Message}"));
} }
return new ValidationResult(failures); return new ValidationResult(failures);
@@ -61,7 +60,7 @@ namespace NzbDrone.Core.Applications.Sonarr
public override List<AppIndexerMap> GetIndexerMappings() public override List<AppIndexerMap> GetIndexerMappings()
{ {
var indexers = _sonarrV3Proxy.GetIndexers(Settings) var indexers = _sonarrV3Proxy.GetIndexers(Settings)
.Where(i => i.Implementation == "Newznab" || i.Implementation == "Torznab"); .Where(i => i.Implementation is "Newznab" or "Torznab");
var mappings = new List<AppIndexerMap>(); var mappings = new List<AppIndexerMap>();

View File

@@ -23,8 +23,11 @@ namespace NzbDrone.Core.Applications.Sonarr
public class SonarrV3Proxy : ISonarrV3Proxy public class SonarrV3Proxy : ISonarrV3Proxy
{ {
private static Version MinimumApplicationVersion => new (3, 0, 5, 0);
private const string AppApiRoute = "/api/v3"; private const string AppApiRoute = "/api/v3";
private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer"; private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer";
private readonly IHttpClient _httpClient; private readonly IHttpClient _httpClient;
private readonly Logger _logger; private readonly Logger _logger;
@@ -102,7 +105,17 @@ namespace NzbDrone.Core.Applications.Sonarr
try try
{ {
Execute<SonarrIndexer>(request); var applicationVersion = _httpClient.Post<SonarrIndexer>(request).Headers.GetSingleValue("X-Application-Version");
if (applicationVersion == null)
{
return new ValidationFailure(string.Empty, "Failed to fetch Sonarr version");
}
if (new Version(applicationVersion) < MinimumApplicationVersion)
{
return new ValidationFailure(string.Empty, $"Sonarr version should be at least {MinimumApplicationVersion.ToString(3)}. Version reported is {applicationVersion}", applicationVersion);
}
} }
catch (HttpException ex) catch (HttpException ex)
{ {