44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using System.Collections.Immutable;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using StellaOps.PolicyDsl;
|
|
using StellaOps.Policy.Engine.Evaluation;
|
|
|
|
namespace StellaOps.Policy.Engine.Services;
|
|
|
|
internal sealed partial class PolicyEvaluationService
|
|
{
|
|
private readonly PolicyEvaluator evaluator = new();
|
|
private readonly PathScopeMetrics _pathMetrics;
|
|
private readonly ILogger<PolicyEvaluationService> _logger;
|
|
|
|
public PolicyEvaluationService()
|
|
: this(new PathScopeMetrics(), NullLogger<PolicyEvaluationService>.Instance)
|
|
{
|
|
}
|
|
|
|
public PolicyEvaluationService(PathScopeMetrics pathMetrics, ILogger<PolicyEvaluationService> logger)
|
|
{
|
|
_pathMetrics = pathMetrics ?? throw new ArgumentNullException(nameof(pathMetrics));
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|
}
|
|
|
|
internal Evaluation.PolicyEvaluationResult Evaluate(PolicyIrDocument document, Evaluation.PolicyEvaluationContext context)
|
|
{
|
|
if (document is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(document));
|
|
}
|
|
|
|
if (context is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(context));
|
|
}
|
|
|
|
var request = new Evaluation.PolicyEvaluationRequest(document, context);
|
|
return evaluator.Evaluate(request);
|
|
}
|
|
|
|
// PathScopeSimulationService partial class relies on _pathMetrics.
|
|
}
|