diff --git a/bindings/c/main.c b/bindings/c/main.c
index 887adc8..e9f01ee 100644
--- a/bindings/c/main.c
+++ b/bindings/c/main.c
@@ -11,6 +11,13 @@ int main() {
if (r.status != Ok)
goto error;
+ // Raise the default col limit to 2000
+ RegorusPolicyLengthConfig len_config = { .max_col = 2000, .max_file_bytes = 1048576, .max_lines = 20000 };
+ r = regorus_engine_set_policy_length_config(engine, len_config);
+ if (r.status != Ok)
+ goto error;
+ regorus_result_drop(r);
+
// Load policies.
r = regorus_engine_add_policy_from_file(engine, "../../../tests/aci/framework.rego");
if (r.status != Ok)
diff --git a/bindings/cpp/main.cpp b/bindings/cpp/main.cpp
index 2596d1c..63cd92e 100644
--- a/bindings/cpp/main.cpp
+++ b/bindings/cpp/main.cpp
@@ -8,6 +8,13 @@ void example()
engine.set_rego_v0(true);
engine.set_enable_coverage(true);
+
+ RegorusPolicyLengthConfig len_config;
+ // Raise the default col limit to 2000
+ len_config.max_col = 2000;
+ len_config.max_file_bytes = 1048576;
+ len_config.max_lines = 20000;
+ engine.set_policy_length_config(len_config);
// Add policies.
engine.add_policy("objects.rego",R"(package objects
diff --git a/bindings/cpp/regorus.hpp b/bindings/cpp/regorus.hpp
index 6cdfb1c..5d43d70 100644
--- a/bindings/cpp/regorus.hpp
+++ b/bindings/cpp/regorus.hpp
@@ -131,7 +131,15 @@ namespace regorus {
Result get_coverage_report_pretty() {
return Result(regorus_engine_get_coverage_report_pretty(engine));
}
-
+
+ Result set_policy_length_config(RegorusPolicyLengthConfig config) {
+ return Result(regorus_engine_set_policy_length_config(engine, config));
+ }
+
+ Result clear_policy_length_config() {
+ return Result(regorus_engine_clear_policy_length_config(engine));
+ }
+
~Engine() {
regorus_engine_drop(engine);
}
diff --git a/bindings/csharp/Regorus/Engine.cs b/bindings/csharp/Regorus/Engine.cs
index 613f8dc..78d14de 100644
--- a/bindings/csharp/Regorus/Engine.cs
+++ b/bindings/csharp/Regorus/Engine.cs
@@ -82,6 +82,24 @@ namespace Regorus
CheckAndDropResult(Regorus.Internal.API.regorus_engine_clear_execution_timer_config((Regorus.Internal.RegorusEngine*)enginePtr));
});
}
+
+ public void SetPolicyLengthConfig(PolicyLengthConfig config)
+ {
+ var nativeConfig = config.ToNative();
+ UseHandle(enginePtr =>
+ {
+ CheckAndDropResult(Regorus.Internal.API.regorus_engine_set_policy_length_config((Regorus.Internal.RegorusEngine*)enginePtr, nativeConfig));
+ });
+ }
+
+ public void ClearPolicyLengthConfig()
+ {
+ UseHandle(enginePtr =>
+ {
+ CheckAndDropResult(Regorus.Internal.API.regorus_engine_clear_policy_length_config((Regorus.Internal.RegorusEngine*)enginePtr));
+ });
+ }
+
public string? AddPolicy(string path, string rego)
{
return Utf8Marshaller.WithUtf8(path, pathPtr =>
diff --git a/bindings/csharp/Regorus/NativeMethods.cs b/bindings/csharp/Regorus/NativeMethods.cs
index 8042450..df2170d 100644
--- a/bindings/csharp/Regorus/NativeMethods.cs
+++ b/bindings/csharp/Regorus/NativeMethods.cs
@@ -428,6 +428,18 @@ namespace Regorus.Internal
[DllImport(LibraryName, EntryPoint = "regorus_engine_clear_execution_timer_config", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
internal static extern RegorusResult regorus_engine_clear_execution_timer_config(RegorusEngine* engine);
+ ///
+ /// Set the policy length limits for a specific engine instance.
+ ///
+ [DllImport(LibraryName, EntryPoint = "regorus_engine_set_policy_length_config", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ internal static extern RegorusResult regorus_engine_set_policy_length_config(RegorusEngine* engine, RegorusPolicyLengthConfig config);
+
+ ///
+ /// Clear the policy length configuration for a specific engine instance.
+ ///
+ [DllImport(LibraryName, EntryPoint = "regorus_engine_clear_policy_length_config", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ internal static extern RegorusResult regorus_engine_clear_policy_length_config(RegorusEngine* engine);
+
#endregion
#region Execution Timer Global Methods
@@ -772,6 +784,17 @@ namespace Regorus.Internal
public uint check_interval;
}
+ ///
+ /// FFI representation of the policy length configuration.
+ ///
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct RegorusPolicyLengthConfig
+ {
+ public uint max_col;
+ public UIntPtr max_file_bytes;
+ public UIntPtr max_lines;
+ }
+
///
/// Byte buffer returned from FFI.
///
diff --git a/bindings/csharp/Regorus/PolicyLengthConfig.cs b/bindings/csharp/Regorus/PolicyLengthConfig.cs
new file mode 100644
index 0000000..0b06a27
--- /dev/null
+++ b/bindings/csharp/Regorus/PolicyLengthConfig.cs
@@ -0,0 +1,53 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+
+using System;
+
+namespace Regorus
+{
+ ///
+ /// Policy source length limits enforced when loading policy files.
+ ///
+ public readonly struct PolicyLengthConfig
+ {
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// Maximum column width per line. Must be non-zero.
+ /// Maximum policy file size in bytes. Must be non-zero.
+ /// Maximum number of lines per policy file. Must be non-zero.
+ /// Thrown when any parameter is zero.
+ public PolicyLengthConfig(uint maxCol, nuint maxFileBytes, nuint maxLines)
+ {
+ if (maxCol == 0)
+ throw new ArgumentOutOfRangeException(nameof(maxCol), "Must be non-zero.");
+ if (maxFileBytes == 0)
+ throw new ArgumentOutOfRangeException(nameof(maxFileBytes), "Must be non-zero.");
+ if (maxLines == 0)
+ throw new ArgumentOutOfRangeException(nameof(maxLines), "Must be non-zero.");
+
+ MaxCol = maxCol;
+ MaxFileBytes = maxFileBytes;
+ MaxLines = maxLines;
+ }
+
+ /// Maximum column width per line (default: 1024).
+ public uint MaxCol { get; }
+
+ /// Maximum policy file size in bytes (default: 1 MiB).
+ public nuint MaxFileBytes { get; }
+
+ /// Maximum number of lines per policy file (default: 20000).
+ public nuint MaxLines { get; }
+
+ internal Regorus.Internal.RegorusPolicyLengthConfig ToNative()
+ {
+ return new Regorus.Internal.RegorusPolicyLengthConfig
+ {
+ max_col = MaxCol,
+ max_file_bytes = MaxFileBytes,
+ max_lines = MaxLines,
+ };
+ }
+ }
+}
diff --git a/bindings/csharp/TestApp/Program.cs b/bindings/csharp/TestApp/Program.cs
index c9b638c..1cfb42f 100644
--- a/bindings/csharp/TestApp/Program.cs
+++ b/bindings/csharp/TestApp/Program.cs
@@ -20,6 +20,8 @@ w.Restart();
var engine = new Regorus.Engine();
engine.SetRegoV0(true);
+// Raise the default col limit to 2000
+engine.SetPolicyLengthConfig(new Regorus.PolicyLengthConfig(maxCol: 2000, maxFileBytes: 1048576, maxLines: 20000));
w.Stop();
var newEngineTicks = w.ElapsedTicks;
diff --git a/bindings/ffi/src/engine.rs b/bindings/ffi/src/engine.rs
index 817d41e..8079b8e 100644
--- a/bindings/ffi/src/engine.rs
+++ b/bindings/ffi/src/engine.rs
@@ -6,6 +6,7 @@ use crate::common::{
};
use crate::compiled_policy::RegorusCompiledPolicy;
use crate::limits::RegorusExecutionTimerConfig;
+use crate::limits::RegorusPolicyLengthConfig;
use crate::lock::{new_handle, read, try_read, try_write, Handle, ReadGuard, WriteGuard};
use crate::panic_guard::with_unwind_guard;
use alloc::boxed::Box;
@@ -491,6 +492,37 @@ pub extern "C" fn regorus_engine_clear_execution_timer_config(
}())
}
+/// Set the policy length limits used when loading policies.
+#[no_mangle]
+pub extern "C" fn regorus_engine_set_policy_length_config(
+ engine: *mut RegorusEngine,
+ config: RegorusPolicyLengthConfig,
+) -> RegorusResult {
+ with_unwind_guard(|| {
+ to_regorus_result(|| -> Result<()> {
+ let engine = to_ref(engine)?;
+ let mut guard = engine.try_write()?;
+ guard.set_policy_length_config(config.to_policy_length_config()?);
+ Ok(())
+ }())
+ })
+}
+
+/// Clear the policy length configuration, reverting to defaults.
+#[no_mangle]
+pub extern "C" fn regorus_engine_clear_policy_length_config(
+ engine: *mut RegorusEngine,
+) -> RegorusResult {
+ with_unwind_guard(|| {
+ to_regorus_result(|| -> Result<()> {
+ let engine = to_ref(engine)?;
+ let mut guard = engine.try_write()?;
+ guard.clear_policy_length_config();
+ Ok(())
+ }())
+ })
+}
+
/// Get pretty printed coverage report.
///
/// See https://docs.rs/regorus/latest/regorus/coverage/struct.Report.html#method.to_string_pretty
diff --git a/bindings/ffi/src/limits.rs b/bindings/ffi/src/limits.rs
index f9ef407..18b74ff 100644
--- a/bindings/ffi/src/limits.rs
+++ b/bindings/ffi/src/limits.rs
@@ -4,7 +4,7 @@
use crate::common::{to_regorus_result, RegorusResult, RegorusStatus};
use alloc::format;
use anyhow::{anyhow, Result};
-use core::num::NonZeroU32;
+use core::num::{NonZeroU32, NonZeroUsize};
use core::time::Duration;
use regorus::utils::limits::{self, ExecutionTimerConfig};
@@ -158,6 +158,31 @@ impl RegorusExecutionTimerConfig {
}
}
+/// FFI representation of [`regorus::PolicyLengthConfig`].
+#[repr(C)]
+#[derive(Debug, Clone, Copy)]
+pub struct RegorusPolicyLengthConfig {
+ /// Maximum column width per line (must be non-zero).
+ pub max_col: u32,
+ /// Maximum policy file size in bytes (must be non-zero).
+ pub max_file_bytes: usize,
+ /// Maximum number of lines per policy file (must be non-zero).
+ pub max_lines: usize,
+}
+
+impl RegorusPolicyLengthConfig {
+ pub fn to_policy_length_config(self) -> Result {
+ Ok(regorus::PolicyLengthConfig {
+ max_col: NonZeroU32::new(self.max_col)
+ .ok_or_else(|| anyhow!("max_col must be non-zero"))?,
+ max_file_bytes: NonZeroUsize::new(self.max_file_bytes)
+ .ok_or_else(|| anyhow!("max_file_bytes must be non-zero"))?,
+ max_lines: NonZeroUsize::new(self.max_lines)
+ .ok_or_else(|| anyhow!("max_lines must be non-zero"))?,
+ })
+ }
+}
+
#[no_mangle]
pub extern "C" fn regorus_set_fallback_execution_timer_config(
config: RegorusExecutionTimerConfig,
diff --git a/bindings/go/main.go b/bindings/go/main.go
index 5cca2db..e59de0d 100644
--- a/bindings/go/main.go
+++ b/bindings/go/main.go
@@ -18,6 +18,8 @@ func main() {
defer engine.Close()
engine.SetRegoV0(true)
+ // Raise the default col limit to 2000
+ engine.SetPolicyLengthConfig(regorus.PolicyLengthConfig{MaxCol: 2000, MaxFileBytes: 1048576, MaxLines: 20000})
elapsed1 := time.Since(t)
diff --git a/bindings/go/pkg/regorus/mod.go b/bindings/go/pkg/regorus/mod.go
index 3e2a498..98aaf49 100644
--- a/bindings/go/pkg/regorus/mod.go
+++ b/bindings/go/pkg/regorus/mod.go
@@ -214,3 +214,32 @@ func (e *Engine) TakePrints() (string, error) {
return C.GoString(result.output), nil
}
+
+type PolicyLengthConfig struct {
+ MaxCol uint32
+ MaxFileBytes uint
+ MaxLines uint
+}
+
+func (e *Engine) SetPolicyLengthConfig(config PolicyLengthConfig) error {
+ c := C.RegorusPolicyLengthConfig{
+ max_col: C.uint32_t(config.MaxCol),
+ max_file_bytes: C.size_t(config.MaxFileBytes),
+ max_lines: C.size_t(config.MaxLines),
+ }
+ result := C.regorus_engine_set_policy_length_config(e.e, c)
+ defer C.regorus_result_drop(result)
+ if result.status != C.Ok {
+ return fmt.Errorf("%s", C.GoString(result.error_message))
+ }
+ return nil
+}
+
+func (e *Engine) ClearPolicyLengthConfig() error {
+ result := C.regorus_engine_clear_policy_length_config(e.e)
+ defer C.regorus_result_drop(result)
+ if result.status != C.Ok {
+ return fmt.Errorf("%s", C.GoString(result.error_message))
+ }
+ return nil
+}
diff --git a/bindings/java/Test.java b/bindings/java/Test.java
index af482e7..08f2371 100644
--- a/bindings/java/Test.java
+++ b/bindings/java/Test.java
@@ -2,6 +2,7 @@
// Licensed under the MIT License.
import com.microsoft.regorus.Engine;
+import com.microsoft.regorus.PolicyLengthConfig;
import com.microsoft.regorus.PolicyModule;
import com.microsoft.regorus.Program;
import com.microsoft.regorus.Rvm;
@@ -26,6 +27,9 @@ public class Test {
// Enable coverage.
engine.setEnableCoverage(true);
+ // Raise the default col limit to 2000
+ engine.setPolicyLengthConfig(new PolicyLengthConfig(2000, 1048576, 20000));
+
// Evaluate rule.
String valueJson = engine.evalRule("data.test.message");
System.out.println(valueJson);
diff --git a/bindings/java/src/lib.rs b/bindings/java/src/lib.rs
index 20e0672..6732c39 100644
--- a/bindings/java/src/lib.rs
+++ b/bindings/java/src/lib.rs
@@ -2,6 +2,7 @@
// Licensed under the MIT License.
use anyhow::Result;
+use core::num::{NonZeroU32, NonZeroUsize};
use jni::objects::{JBooleanArray, JByteArray, JClass, JObject, JObjectArray, JString};
use jni::sys::{jboolean, jbooleanArray, jbyteArray, jlong, jobjectArray, jstring};
use jni::JNIEnv;
@@ -365,6 +366,39 @@ pub extern "system" fn Java_com_microsoft_regorus_Engine_getAstAsJson(
}
}
+#[no_mangle]
+pub extern "system" fn Java_com_microsoft_regorus_Engine_nativeSetPolicyLengthConfig(
+ env: JNIEnv,
+ _class: JClass,
+ engine_ptr: jlong,
+ max_col: u32,
+ max_file_bytes: jlong,
+ max_lines: jlong,
+) {
+ let _ = throw_err(env, |_env| {
+ let engine = unsafe { &mut *(engine_ptr as *mut Engine) };
+ engine.set_policy_length_config(regorus::PolicyLengthConfig {
+ max_col: NonZeroU32::new(max_col)
+ .ok_or_else(|| anyhow::anyhow!("maxCol must be non-zero"))?,
+ max_file_bytes: NonZeroUsize::new(max_file_bytes as usize)
+ .ok_or_else(|| anyhow::anyhow!("maxFileBytes must be non-zero"))?,
+ max_lines: NonZeroUsize::new(max_lines as usize)
+ .ok_or_else(|| anyhow::anyhow!("maxLines must be non-zero"))?,
+ });
+ Ok(())
+ });
+}
+
+#[no_mangle]
+pub extern "system" fn Java_com_microsoft_regorus_Engine_nativeClearPolicyLengthConfig(
+ _env: JNIEnv,
+ _class: JClass,
+ engine_ptr: jlong,
+) {
+ let engine = unsafe { &mut *(engine_ptr as *mut Engine) };
+ engine.clear_policy_length_config();
+}
+
#[no_mangle]
pub extern "system" fn Java_com_microsoft_regorus_Engine_nativeDestroyEngine(
_env: JNIEnv,
diff --git a/bindings/java/src/main/java/com/microsoft/regorus/Engine.java b/bindings/java/src/main/java/com/microsoft/regorus/Engine.java
index 9ee6f47..765c1de 100644
--- a/bindings/java/src/main/java/com/microsoft/regorus/Engine.java
+++ b/bindings/java/src/main/java/com/microsoft/regorus/Engine.java
@@ -39,6 +39,8 @@ public class Engine implements AutoCloseable, Cloneable {
private static native void nativeClearCoverageData(long enginePtr);
private static native void nativeSetGatherPrints(long enginePtr, boolean b);
private static native String nativeTakePrints(long enginePtr);
+ private static native void nativeSetPolicyLengthConfig(long enginePtr, int maxCol, long maxFileBytes, long maxLines);
+ private static native void nativeClearPolicyLengthConfig(long enginePtr);
private static native void nativeDestroyEngine(long enginePtr);
// Pointer to Engine allocated on Rust's heap, all native methods works on
@@ -259,6 +261,22 @@ public class Engine implements AutoCloseable, Cloneable {
return nativeTakePrints(enginePtr);
}
+ /**
+ * Set the policy length limits used when loading policies.
+ *
+ * @param config Policy length configuration.
+ */
+ public void setPolicyLengthConfig(PolicyLengthConfig config) {
+ nativeSetPolicyLengthConfig(enginePtr, config.maxCol, config.maxFileBytes, config.maxLines);
+ }
+
+ /**
+ * Clear the policy length configuration, reverting to defaults.
+ */
+ public void clearPolicyLengthConfig() {
+ nativeClearPolicyLengthConfig(enginePtr);
+ }
+
long getPtr() {
return enginePtr;
}
diff --git a/bindings/java/src/main/java/com/microsoft/regorus/PolicyLengthConfig.java b/bindings/java/src/main/java/com/microsoft/regorus/PolicyLengthConfig.java
new file mode 100644
index 0000000..f99a350
--- /dev/null
+++ b/bindings/java/src/main/java/com/microsoft/regorus/PolicyLengthConfig.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ * Licensed under the MIT License.
+ **/
+
+package com.microsoft.regorus;
+
+/**
+ * Policy source length limits enforced when loading policy files.
+ *
+ * All values must be positive (non-zero).
+ */
+public final class PolicyLengthConfig {
+ /**
+ * Maximum column width per line (default: 1024).
+ */
+ public final int maxCol;
+
+ /**
+ * Maximum policy file size in bytes (default: 1 MiB).
+ */
+ public final long maxFileBytes;
+
+ /**
+ * Maximum number of lines per policy file (default: 20000).
+ */
+ public final long maxLines;
+
+ /**
+ * Create a new policy length configuration.
+ *
+ * @param maxCol Maximum column width per line.
+ * @param maxFileBytes Maximum policy file size in bytes.
+ * @param maxLines Maximum number of lines per policy file.
+ */
+ public PolicyLengthConfig(int maxCol, long maxFileBytes, long maxLines) {
+ if (maxCol <= 0) {
+ throw new IllegalArgumentException("maxCol must be positive");
+ }
+ if (maxFileBytes <= 0) {
+ throw new IllegalArgumentException("maxFileBytes must be positive");
+ }
+ if (maxLines <= 0) {
+ throw new IllegalArgumentException("maxLines must be positive");
+ }
+ this.maxCol = maxCol;
+ this.maxFileBytes = maxFileBytes;
+ this.maxLines = maxLines;
+ }
+}
diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs
index 0e327d3..e97362b 100644
--- a/bindings/python/src/lib.rs
+++ b/bindings/python/src/lib.rs
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use anyhow::{anyhow, Result};
+use core::num::{NonZeroU32, NonZeroUsize};
use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
use pyo3::types::*;
@@ -392,6 +393,35 @@ impl Engine {
.add_extension(path, nargs, Box::new(extension_impl))
}
+ /// Set the policy length limits used when loading policies.
+ ///
+ /// * `max_col`: Maximum column width per line.
+ /// * `max_file_bytes`: Maximum policy file size in bytes.
+ /// * `max_lines`: Maximum number of lines per policy file.
+ #[pyo3(signature = (*, max_col, max_file_bytes, max_lines))]
+ pub fn set_policy_length_config(
+ &mut self,
+ max_col: u32,
+ max_file_bytes: usize,
+ max_lines: usize,
+ ) -> Result<()> {
+ self.engine
+ .set_policy_length_config(::regorus::PolicyLengthConfig {
+ max_col: NonZeroU32::new(max_col)
+ .ok_or_else(|| anyhow!("max_col must be non-zero"))?,
+ max_file_bytes: NonZeroUsize::new(max_file_bytes)
+ .ok_or_else(|| anyhow!("max_file_bytes must be non-zero"))?,
+ max_lines: NonZeroUsize::new(max_lines)
+ .ok_or_else(|| anyhow!("max_lines must be non-zero"))?,
+ });
+ Ok(())
+ }
+
+ /// Clear the policy length configuration, reverting to defaults.
+ pub fn clear_policy_length_config(&mut self) {
+ self.engine.clear_policy_length_config();
+ }
+
/// Enable code coverage
///
/// * `enable`: Whether to enable coverage or not.
diff --git a/bindings/python/test.py b/bindings/python/test.py
index aef2e18..2f6262e 100644
--- a/bindings/python/test.py
+++ b/bindings/python/test.py
@@ -10,6 +10,8 @@ if hasattr(sys.stdout, "reconfigure"):
engine = regorus.Engine()
engine.set_rego_v0(True)
+# Raise the default col limit to 2000
+engine.set_policy_length_config(max_col=2000, max_file_bytes=1048576, max_lines=20000)
# Load policies
pkg = engine.add_policy_from_file('../../tests/aci/framework.rego')
diff --git a/bindings/ruby/Cargo.lock b/bindings/ruby/Cargo.lock
index 0cd8f85..92d4882 100644
--- a/bindings/ruby/Cargo.lock
+++ b/bindings/ruby/Cargo.lock
@@ -962,6 +962,7 @@ version = "0.9.1"
dependencies = [
"magnus",
"regorus",
+ "serde",
"serde_json",
"serde_magnus",
]
diff --git a/bindings/ruby/ext/regorusrb/Cargo.toml b/bindings/ruby/ext/regorusrb/Cargo.toml
index fac8f2e..7d7de82 100644
--- a/bindings/ruby/ext/regorusrb/Cargo.toml
+++ b/bindings/ruby/ext/regorusrb/Cargo.toml
@@ -18,5 +18,6 @@ coverage = ["regorus/coverage"]
[dependencies]
magnus = { version = "0.8.2" }
regorus = { path = "../../../..", default-features = false, features = ["arc"] }
+serde = { version = "1", features = ["derive"] }
serde_json = "1.0.140"
serde_magnus = "0.11.0"
diff --git a/bindings/ruby/ext/regorusrb/src/lib.rs b/bindings/ruby/ext/regorusrb/src/lib.rs
index 615ce0e..c4142a4 100644
--- a/bindings/ruby/ext/regorusrb/src/lib.rs
+++ b/bindings/ruby/ext/regorusrb/src/lib.rs
@@ -1,10 +1,19 @@
+use core::num::{NonZeroU32, NonZeroUsize};
use magnus::{Error, Ruby, exception::runtime_error, method, module, prelude::*};
use regorus::Engine as RegorusEngine;
+use serde::Deserialize;
use std::cell::RefCell;
use std::cmp::Ordering;
// `Value` exists under magnus, regorus, and serde_json, so be explicit
+#[derive(Deserialize)]
+struct PolicyLengthSpec {
+ max_col: u32,
+ max_file_bytes: usize,
+ max_lines: usize,
+}
+
#[derive(Default)]
#[magnus::wrap(class = "Regorus::Engine")]
pub struct Engine {
@@ -55,15 +64,17 @@ impl Engine {
.map_err(|e| Error::new(runtime_error(), format!("Failed to add policy: {e}")))
}
- fn add_data(&self, ruby_hash: magnus::RHash) -> Result<(), Error> {
- let data_value: regorus::Value = serde_magnus::deserialize(ruby_hash).map_err(|e| {
- Error::new(
- runtime_error(),
- format!("Failed to deserialize Ruby value: {e}"),
- )
- })?;
+ fn add_data(ruby: &Ruby, rb_self: &Self, ruby_hash: magnus::RHash) -> Result<(), Error> {
+ let data_value: regorus::Value =
+ serde_magnus::deserialize(ruby, ruby_hash).map_err(|e| {
+ Error::new(
+ runtime_error(),
+ format!("Failed to deserialize Ruby value: {e}"),
+ )
+ })?;
- self.engine
+ rb_self
+ .engine
.borrow_mut()
.add_data(data_value)
.map_err(|e| Error::new(runtime_error(), format!("Failed to add data: {e}")))
@@ -111,15 +122,16 @@ impl Engine {
.map_err(|e| Error::new(runtime_error(), format!("Failed to get policies: {e}")))
}
- fn set_input(&self, ruby_hash: magnus::RHash) -> Result<(), Error> {
- let input_value: regorus::Value = serde_magnus::deserialize(ruby_hash).map_err(|e| {
- Error::new(
- runtime_error(),
- format!("Failed to deserialize Ruby value: {e}"),
- )
- })?;
+ fn set_input(ruby: &Ruby, rb_self: &Self, ruby_hash: magnus::RHash) -> Result<(), Error> {
+ let input_value: regorus::Value =
+ serde_magnus::deserialize(ruby, ruby_hash).map_err(|e| {
+ Error::new(
+ runtime_error(),
+ format!("Failed to deserialize Ruby value: {e}"),
+ )
+ })?;
- self.engine.borrow_mut().set_input(input_value);
+ rb_self.engine.borrow_mut().set_input(input_value);
Ok(())
}
@@ -142,14 +154,14 @@ impl Engine {
Ok(())
}
- fn eval_query(&self, query: String) -> Result {
- let results = self
+ fn eval_query(ruby: &Ruby, rb_self: &Self, query: String) -> Result {
+ let results = rb_self
.engine
.borrow_mut()
.eval_query(query, false)
.map_err(|e| Error::new(runtime_error(), format!("Failed to evaluate query: {e}")))?;
- serde_magnus::serialize(&results).map_err(|e| {
+ serde_magnus::serialize(ruby, &results).map_err(|e| {
Error::new(
runtime_error(),
format!("Failed to serailzie query results: {e}"),
@@ -177,15 +189,19 @@ impl Engine {
})
}
- fn eval_rule(&self, query: String) -> Result