mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
fixed input validation for indexers
This commit is contained in:
parent
147bb5476b
commit
438e3199de
@ -64,7 +64,7 @@ private IndexerResource UpdateIndexer(IndexerResource indexerResource)
|
||||
indexer.InjectFrom(indexerResource);
|
||||
indexer.Settings = SchemaDeserializer.DeserializeSchema(indexer.Settings, indexerResource.Fields);
|
||||
|
||||
ValidateSetting(indexer.Settings);
|
||||
ValidateIndexer(indexer);
|
||||
|
||||
indexer = _indexerService.Update(indexer);
|
||||
|
||||
@ -75,15 +75,18 @@ private IndexerResource UpdateIndexer(IndexerResource indexerResource)
|
||||
}
|
||||
|
||||
|
||||
private static void ValidateSetting(IIndexerSetting setting)
|
||||
private static void ValidateIndexer(Indexer indexer)
|
||||
{
|
||||
var validationResult = setting.Validate();
|
||||
if (indexer.Enable)
|
||||
{
|
||||
var validationResult = indexer.Settings.Validate();
|
||||
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
throw new ValidationException(validationResult.Errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Indexer GetIndexer(IndexerResource indexerResource)
|
||||
{
|
||||
@ -100,7 +103,7 @@ private Indexer GetIndexer(IndexerResource indexerResource)
|
||||
indexer.InjectFrom(indexerResource);
|
||||
indexer.Settings = SchemaDeserializer.DeserializeSchema(indexer.Settings, indexerResource.Fields);
|
||||
|
||||
ValidateSetting(indexer.Settings);
|
||||
ValidateIndexer(indexer);
|
||||
|
||||
return indexer;
|
||||
}
|
||||
|
@ -6,15 +6,4 @@ public interface IIndexerSetting
|
||||
{
|
||||
ValidationResult Validate();
|
||||
}
|
||||
|
||||
|
||||
public class NullSetting : IIndexerSetting
|
||||
{
|
||||
public static readonly NullSetting Instance = new NullSetting();
|
||||
|
||||
public ValidationResult Validate()
|
||||
{
|
||||
return new ValidationResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,22 @@
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Newznab
|
||||
{
|
||||
public class NewznabSettingsValidator : AbstractValidator<NewznabSettings>
|
||||
{
|
||||
public NewznabSettingsValidator()
|
||||
{
|
||||
RuleFor(c => c.Url).ValidRootUrl();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class NewznabSettings : IIndexerSetting
|
||||
{
|
||||
private static readonly NewznabSettingsValidator Validator = new NewznabSettingsValidator();
|
||||
|
||||
public NewznabSettings()
|
||||
{
|
||||
Categories = new[] { 5030, 5040 };
|
||||
//RuleFor(c => c.Url).ValidRootUrl();
|
||||
}
|
||||
|
||||
[FieldDefinition(0, Label = "URL")]
|
||||
@ -23,18 +33,9 @@ public NewznabSettings()
|
||||
|
||||
public IEnumerable<Int32> Categories { get; set; }
|
||||
|
||||
public bool IsValid
|
||||
{
|
||||
get
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(Url);
|
||||
}
|
||||
}
|
||||
|
||||
public ValidationResult Validate()
|
||||
{
|
||||
return new ValidationResult();
|
||||
//return Validate(this);
|
||||
return Validator.Validate(this);
|
||||
}
|
||||
}
|
||||
}
|
14
NzbDrone.Core/Indexers/NullSetting.cs
Normal file
14
NzbDrone.Core/Indexers/NullSetting.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using FluentValidation.Results;
|
||||
|
||||
namespace NzbDrone.Core.Indexers
|
||||
{
|
||||
public class NullSetting : IIndexerSetting
|
||||
{
|
||||
public static readonly NullSetting Instance = new NullSetting();
|
||||
|
||||
public ValidationResult Validate()
|
||||
{
|
||||
return new ValidationResult();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,22 @@
|
||||
using System;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Results;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Core.Annotations;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Omgwtfnzbs
|
||||
{
|
||||
public class OmgwtfnzbsSettingsValidator : AbstractValidator<OmgwtfnzbsSettings>
|
||||
{
|
||||
public OmgwtfnzbsSettingsValidator()
|
||||
{
|
||||
RuleFor(c => c.Username).NotEmpty();
|
||||
RuleFor(c => c.ApiKey).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class OmgwtfnzbsSettings : IIndexerSetting
|
||||
{
|
||||
// public OmgwtfnzbsSettings()
|
||||
// {
|
||||
// RuleFor(c => c.Username).NotEmpty();
|
||||
// RuleFor(c => c.ApiKey).NotEmpty();
|
||||
// }
|
||||
private static readonly OmgwtfnzbsSettingsValidator Validator = new OmgwtfnzbsSettingsValidator();
|
||||
|
||||
[FieldDefinition(0, Label = "Username")]
|
||||
public String Username { get; set; }
|
||||
@ -22,8 +26,7 @@ public class OmgwtfnzbsSettings : IIndexerSetting
|
||||
|
||||
public ValidationResult Validate()
|
||||
{
|
||||
return new ValidationResult();
|
||||
//return Validate(this);
|
||||
return Validator.Validate(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -210,6 +210,7 @@
|
||||
<Compile Include="Indexers\IndexerSettingUpdatedEvent.cs" />
|
||||
<Compile Include="Indexers\IndexerWithSetting.cs" />
|
||||
<Compile Include="Indexers\Newznab\SizeParsingException.cs" />
|
||||
<Compile Include="Indexers\NullSetting.cs" />
|
||||
<Compile Include="Indexers\RssSyncCommand.cs" />
|
||||
<Compile Include="Indexers\XElementExtensions.cs" />
|
||||
<Compile Include="Instrumentation\Commands\ClearLogCommand.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user