You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
935 B
36 lines
935 B
using JetBrains.Annotations;
|
|
using Recyclarr.Common.FluentValidation;
|
|
|
|
namespace Recyclarr.TrashLib.Config.Parsing;
|
|
|
|
[UsedImplicitly]
|
|
public class ConfigValidationExecutor
|
|
{
|
|
private readonly ILogger _log;
|
|
private readonly IRuntimeValidationService _validationService;
|
|
|
|
public ConfigValidationExecutor(ILogger log, IRuntimeValidationService validationService)
|
|
{
|
|
_log = log;
|
|
_validationService = validationService;
|
|
}
|
|
|
|
public bool Validate(object config, params string[] ruleSets)
|
|
{
|
|
var result = _validationService.Validate(config, ruleSets);
|
|
if (result.IsValid)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
var numErrors = result.Errors.LogValidationErrors(_log, "Config Validation");
|
|
if (numErrors == 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
_log.Error("Config validation failed with {Count} errors", numErrors);
|
|
return false;
|
|
}
|
|
}
|