mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
- add Azure RBAC condition interpreter and builtin evaluation in core (expressions, parser updates, evaluator, and test harness) - introduce comprehensive RBAC YAML test suites and coverage for i - action/suboperation - strings - numbers - bools - IP - GUID - dates - times - lists - quantifiers (ForAnyOfAnyValues, ForAllOfAllValues) - expose RBAC evaluation through FFI with an `rbac` feature flag enabled by default - add C# `RbacEngine` wrapper + P/Invoke entrypoint and document usage in C# README - expand C# tests to execute all RBAC YAML cases with per-case logging - wire test assets into C# test output and centralize YAML dependency versions Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
using System;
|
|
using Regorus.Internal;
|
|
|
|
#nullable enable
|
|
namespace Regorus
|
|
{
|
|
/// <summary>
|
|
/// Provides helpers for evaluating Azure RBAC condition expressions.
|
|
/// </summary>
|
|
public static unsafe class RbacEngine
|
|
{
|
|
/// <summary>
|
|
/// Evaluate an Azure RBAC condition expression against a JSON evaluation context.
|
|
/// </summary>
|
|
/// <param name="condition">Azure RBAC condition expression.</param>
|
|
/// <param name="contextJson">JSON encoded EvaluationContext.</param>
|
|
/// <returns>True if the condition evaluates to true; otherwise false.</returns>
|
|
/// <exception cref="Exception">Thrown when evaluation fails.</exception>
|
|
public static bool EvaluateCondition(string condition, string contextJson)
|
|
{
|
|
if (condition is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(condition));
|
|
}
|
|
|
|
if (contextJson is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(contextJson));
|
|
}
|
|
|
|
return Utf8Marshaller.WithUtf8(condition, conditionPtr =>
|
|
Utf8Marshaller.WithUtf8(contextJson, contextPtr =>
|
|
{
|
|
unsafe
|
|
{
|
|
var result = Internal.API.regorus_rbac_engine_eval_condition((byte*)conditionPtr, (byte*)contextPtr);
|
|
return ResultHelpers.GetBoolResult(result);
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
}
|