mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Compare commits
7 Commits
copilot/ad
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb6e156e8a | ||
|
|
5ae1d8abf2 | ||
|
|
03c4275855 | ||
|
|
78f226f957 | ||
|
|
bec159a580 | ||
|
|
117671d959 | ||
|
|
8617c79da5 |
57
Cargo.lock
generated
57
Cargo.lock
generated
@@ -474,9 +474,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.18.0"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -653,9 +653,6 @@ name = "hashbrown"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51"
|
||||
dependencies = [
|
||||
"foldhash 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
@@ -869,9 +866,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.98"
|
||||
version = "0.3.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -881,9 +878,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -950,9 +947,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.18.0"
|
||||
version = "0.16.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -960,12 +957,6 @@ version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "micromap"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a86d3146ed3995b5913c414f6664344b9617457320782e64f0bb44afd49d74"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.9"
|
||||
@@ -1353,16 +1344,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -1410,7 +1399,7 @@ dependencies = [
|
||||
"dashmap",
|
||||
"data-encoding",
|
||||
"globset",
|
||||
"hashbrown 0.17.0",
|
||||
"hashbrown 0.16.1",
|
||||
"icu_casemap",
|
||||
"indexmap",
|
||||
"ipnet",
|
||||
@@ -1556,9 +1545,9 @@ checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.3"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1841,9 +1830,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1854,9 +1843,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
dependencies = [
|
||||
"quote 1.0.45",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1864,9 +1853,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2 1.0.106",
|
||||
@@ -1877,9 +1866,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@@ -1920,9 +1909,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.98"
|
||||
version = "0.3.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b572dff8bcf38bad0fa19729c89bb5748b2b9b1d8be70cf90df697e3a8f32aa"
|
||||
checksum = "2eadbac71025cd7b0834f20d1fe8472e8495821b4e9801eb0a60bd1f19827602"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
|
||||
@@ -99,7 +99,7 @@ rand = ["dep:rand"]
|
||||
anyhow = { version = "1.0.102", default-features = false }
|
||||
serde = {version = "1.0.150", default-features = false, features = ["derive", "rc", "alloc"] }
|
||||
serde_json = { version = "1.0.89", default-features = false, features = ["alloc"] }
|
||||
hashbrown = { version = "0.17", default-features = false, features = ["default-hasher"], optional = true }
|
||||
hashbrown = { version = "0.16", default-features = false, features = ["default-hasher"], optional = true }
|
||||
lazy_static = { version = "1.4.0", default-features = false }
|
||||
thiserror = { version = "2.0", default-features = false }
|
||||
|
||||
@@ -114,7 +114,7 @@ regex = {version = "1.12.3", optional = true, default-features = false }
|
||||
semver = {version = "1.0.28", optional = true, default-features = false }
|
||||
url = { version = "2.5.4", optional = true }
|
||||
uuid = { version = "1.22.0", default-features = false, features = ["v4", "fast-rng"], optional = true }
|
||||
jsonschema = { version = "0.46.4", default-features = false, optional = true }
|
||||
jsonschema = { version = "0.45.1", default-features = false, optional = true }
|
||||
chrono = { version = "0.4.44", optional = true }
|
||||
chrono-tz = { version = "0.10.1", optional = true }
|
||||
ipnet = { version = "2.12.0", optional = true, default-features = false }
|
||||
@@ -127,7 +127,7 @@ rand = { version = "0.10.0", default-features = false, features = ["thread_rng"]
|
||||
# Causes the project to link with the Spectre-mitigated CRT and libs.
|
||||
msvc_spectre_libs = { version = "0.1", features = ["error"], optional = true }
|
||||
dashmap = { version = "6.1", default-features = false, optional = true }
|
||||
lru = { version = "0.18", default-features = false, optional = true }
|
||||
lru = { version = "0.16", default-features = false, optional = true }
|
||||
mimalloc = { package = "regorus-mimalloc", path = "mimalloc", version = "2.2.6", optional = true }
|
||||
|
||||
# rvm related deps
|
||||
|
||||
@@ -80,10 +80,6 @@ namespace regorus {
|
||||
return std::unique_ptr<Engine>(new Engine(regorus_engine_clone(engine)));
|
||||
}
|
||||
|
||||
Result prepare() {
|
||||
return Result(regorus_engine_prepare(engine));
|
||||
}
|
||||
|
||||
Result set_rego_v0(bool enable) {
|
||||
return Result(regorus_engine_set_rego_v0(engine, enable));
|
||||
}
|
||||
|
||||
@@ -68,18 +68,6 @@ namespace Regorus
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepare internal evaluation structures without executing a query.
|
||||
/// This is optional: if skipped, the first evaluation pays this setup cost.
|
||||
/// </summary>
|
||||
public void Prepare()
|
||||
{
|
||||
UseHandle(enginePtr =>
|
||||
{
|
||||
CheckAndDropResult(Regorus.Internal.API.regorus_engine_prepare((Regorus.Internal.RegorusEngine*)enginePtr));
|
||||
});
|
||||
}
|
||||
|
||||
public void SetStrictBuiltinErrors(bool strict)
|
||||
{
|
||||
UseHandle(enginePtr =>
|
||||
|
||||
@@ -92,12 +92,6 @@ namespace Regorus.Internal
|
||||
[DllImport(LibraryName, EntryPoint = "regorus_engine_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
internal static extern RegorusEngine* regorus_engine_clone(RegorusEngine* engine);
|
||||
|
||||
/// <summary>
|
||||
/// Prepare a RegorusEngine for evaluation without executing a query.
|
||||
/// </summary>
|
||||
[DllImport(LibraryName, EntryPoint = "regorus_engine_prepare", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
internal static extern RegorusResult regorus_engine_prepare(RegorusEngine* engine);
|
||||
|
||||
/// <summary>
|
||||
/// Compile an RVM program from the engine state with entry points.
|
||||
/// </summary>
|
||||
|
||||
53
bindings/ffi/Cargo.lock
generated
53
bindings/ffi/Cargo.lock
generated
@@ -353,9 +353,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.18.0"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -511,9 +511,6 @@ name = "hashbrown"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51"
|
||||
dependencies = [
|
||||
"foldhash 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
@@ -712,9 +709,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.98"
|
||||
version = "0.3.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -724,9 +721,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -796,9 +793,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.18.0"
|
||||
version = "0.16.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -806,12 +803,6 @@ version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "micromap"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a86d3146ed3995b5913c414f6664344b9617457320782e64f0bb44afd49d74"
|
||||
|
||||
[[package]]
|
||||
name = "msvc_spectre_libs"
|
||||
version = "0.1.3"
|
||||
@@ -1082,16 +1073,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -1136,7 +1125,7 @@ dependencies = [
|
||||
"dashmap",
|
||||
"data-encoding",
|
||||
"globset",
|
||||
"hashbrown 0.17.0",
|
||||
"hashbrown 0.16.1",
|
||||
"icu_casemap",
|
||||
"indexmap",
|
||||
"ipnet",
|
||||
@@ -1296,9 +1285,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.3"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1535,9 +1524,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1548,9 +1537,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1558,9 +1547,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -1571,9 +1560,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
@@ -199,21 +199,6 @@ pub extern "C" fn regorus_engine_clone(engine: *mut RegorusEngine) -> *mut Regor
|
||||
}
|
||||
}
|
||||
|
||||
/// Prepare a [`RegorusEngine`] for evaluation without executing a query.
|
||||
///
|
||||
/// This is optional. If not called, first eval performs the same setup.
|
||||
/// If policy/data changes after preparation, setup is invalidated.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn regorus_engine_prepare(engine: *mut RegorusEngine) -> RegorusResult {
|
||||
with_unwind_guard(|| {
|
||||
to_regorus_result(|| -> Result<()> {
|
||||
let engine = to_ref(engine)?;
|
||||
let mut guard = engine.try_write()?;
|
||||
guard.prepare()
|
||||
}())
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn regorus_engine_drop(engine: *mut RegorusEngine) {
|
||||
if let Ok(e) = to_ref(engine) {
|
||||
|
||||
@@ -28,17 +28,6 @@ func (e *Engine) Clone() *Engine {
|
||||
return c
|
||||
}
|
||||
|
||||
func (e *Engine) Prepare() error {
|
||||
result := C.regorus_engine_prepare(e.e)
|
||||
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) SetRegoV0(enable bool) error {
|
||||
result := C.regorus_engine_set_rego_v0(e.e, C.bool(enable))
|
||||
defer C.regorus_result_drop(result)
|
||||
|
||||
48
bindings/java/Cargo.lock
generated
48
bindings/java/Cargo.lock
generated
@@ -237,9 +237,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.18.0"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -598,9 +598,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.98"
|
||||
version = "0.3.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -610,9 +610,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -676,9 +676,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.18.0"
|
||||
version = "0.16.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -686,12 +686,6 @@ version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "micromap"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a86d3146ed3995b5913c414f6664344b9617457320782e64f0bb44afd49d74"
|
||||
|
||||
[[package]]
|
||||
name = "msvc_spectre_libs"
|
||||
version = "0.1.3"
|
||||
@@ -954,16 +948,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -1176,9 +1168,9 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.3"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1360,9 +1352,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1373,9 +1365,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1383,9 +1375,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -1396,9 +1388,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
@@ -23,14 +23,6 @@ JNIEXPORT jlong JNICALL Java_com_microsoft_regorus_Engine_nativeNewEngine
|
||||
JNIEXPORT jlong JNICALL Java_com_microsoft_regorus_Engine_nativeClone
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_microsoft_regorus_Engine
|
||||
* Method: nativePrepare
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_microsoft_regorus_Engine_nativePrepare
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_microsoft_regorus_Engine
|
||||
* Method: nativeAddPolicy
|
||||
|
||||
@@ -27,30 +27,13 @@ pub extern "system" fn Java_com_microsoft_regorus_Engine_nativeNewEngine(
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_com_microsoft_regorus_Engine_nativeClone(
|
||||
env: EnvUnowned,
|
||||
_env: EnvUnowned,
|
||||
_class: JClass,
|
||||
engine_ptr: jlong,
|
||||
) -> jlong {
|
||||
let res = throw_err(env, |_env| {
|
||||
let engine = unsafe { &mut *get_engine_ptr(engine_ptr)? };
|
||||
let c = engine.clone();
|
||||
Ok(Box::into_raw(Box::new(c)) as jlong)
|
||||
});
|
||||
|
||||
res.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_com_microsoft_regorus_Engine_nativePrepare(
|
||||
env: EnvUnowned,
|
||||
_class: JClass,
|
||||
engine_ptr: jlong,
|
||||
) {
|
||||
let _ = throw_err(env, |_env| {
|
||||
let engine = unsafe { &mut *get_engine_ptr(engine_ptr)? };
|
||||
engine.prepare()?;
|
||||
Ok(())
|
||||
});
|
||||
let engine = unsafe { &mut *(engine_ptr as *mut Engine) };
|
||||
let c = engine.clone();
|
||||
Box::into_raw(Box::new(c)) as jlong
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -454,9 +437,6 @@ pub extern "system" fn Java_com_microsoft_regorus_Engine_nativeDestroyEngine(
|
||||
_class: JClass,
|
||||
engine_ptr: jlong,
|
||||
) {
|
||||
if engine_ptr == 0 {
|
||||
return;
|
||||
}
|
||||
unsafe {
|
||||
let _engine = Box::from_raw(engine_ptr as *mut Engine);
|
||||
}
|
||||
@@ -836,13 +816,6 @@ fn throw_err<T>(mut env: EnvUnowned, f: impl FnOnce(&mut Env) -> Result<T>) -> R
|
||||
}
|
||||
}
|
||||
|
||||
fn get_engine_ptr(engine_ptr: jlong) -> Result<*mut Engine> {
|
||||
if engine_ptr == 0 {
|
||||
return Err(anyhow::anyhow!("Engine is closed"));
|
||||
}
|
||||
Ok(engine_ptr as *mut Engine)
|
||||
}
|
||||
|
||||
fn get_string_array(env: &mut Env, array: jobjectArray) -> Result<Vec<String>> {
|
||||
if array.is_null() {
|
||||
return Ok(Vec::new());
|
||||
|
||||
@@ -21,7 +21,6 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
// if you update the native API.
|
||||
private static native long nativeNewEngine();
|
||||
private static native long nativeClone(long enginePtr);
|
||||
private static native void nativePrepare(long enginePtr);
|
||||
private static native void nativeSetRegoV0(long enginePtr, boolean enable);
|
||||
private static native String nativeAddPolicy(long enginePtr, String path, String rego);
|
||||
private static native String nativeAddPolicyFromFile(long enginePtr, String path);
|
||||
@@ -46,7 +45,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
|
||||
// Pointer to Engine allocated on Rust's heap, all native methods works on
|
||||
// engine expects this pointer. It is free'd in `close` method.
|
||||
private long enginePtr;
|
||||
private final long enginePtr;
|
||||
|
||||
/**
|
||||
* Creates a new Regorus Engine.
|
||||
@@ -64,15 +63,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* Efficiently clones an Engine.
|
||||
*/
|
||||
public Engine clone() {
|
||||
return new Engine(nativeClone(requireOpen()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares internal evaluation structures without executing a query.
|
||||
* Optional: if skipped, first evaluation performs the same setup.
|
||||
*/
|
||||
public void prepare() {
|
||||
nativePrepare(requireOpen());
|
||||
return new Engine(nativeClone(enginePtr));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +73,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public void setRegoV0(boolean enable) {
|
||||
nativeSetRegoV0(requireOpen(), enable);
|
||||
nativeSetRegoV0(enginePtr, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +85,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return Rego package defined in the policy.
|
||||
*/
|
||||
public String addPolicy(String filename, String rego) {
|
||||
return nativeAddPolicy(requireOpen(), filename, rego);
|
||||
return nativeAddPolicy(enginePtr, filename, rego);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +96,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return Rego package defined in the policy.
|
||||
*/
|
||||
public String addPolicyFromFile(String path) {
|
||||
return nativeAddPolicyFromFile(requireOpen(), path);
|
||||
return nativeAddPolicyFromFile(enginePtr, path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +105,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return List of Rego packages as a JSON array of strings.
|
||||
*/
|
||||
public String getPackages() {
|
||||
return nativeGetPackages(requireOpen());
|
||||
return nativeGetPackages(enginePtr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,14 +114,14 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return List of Rego policies as a JSON array of sources.
|
||||
*/
|
||||
public String getPolicies() {
|
||||
return nativeGetPolicies(requireOpen());
|
||||
return nativeGetPolicies(enginePtr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the data document.
|
||||
*/
|
||||
public void clearData() {
|
||||
nativeClearData(requireOpen());
|
||||
nativeClearData(enginePtr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +143,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @param data Inline data document.
|
||||
*/
|
||||
public void addDataJson(String data) throws RuntimeException {
|
||||
nativeAddDataJson(requireOpen(), data);
|
||||
nativeAddDataJson(enginePtr, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +160,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @param path Path to JSON data document.
|
||||
*/
|
||||
public void addDataJsonFromFile(String path) throws RuntimeException {
|
||||
nativeAddDataJsonFromFile(requireOpen(), path);
|
||||
nativeAddDataJsonFromFile(enginePtr, path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +169,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @param input inline JSON input.
|
||||
*/
|
||||
public void setInputJson(String input) {
|
||||
nativeSetInputJson(requireOpen(), input);
|
||||
nativeSetInputJson(enginePtr, input);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +178,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @param path Path to JSON input.
|
||||
*/
|
||||
public void setInputJsonFromFile(String path) {
|
||||
nativeSetInputJsonFromFile(requireOpen(), path);
|
||||
nativeSetInputJsonFromFile(enginePtr, path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,7 +189,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return Query results as a JSON string.
|
||||
*/
|
||||
public String evalQuery(String query) {
|
||||
return nativeEvalQuery(requireOpen(), query);
|
||||
return nativeEvalQuery(enginePtr, query);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +200,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return Value of the rule as a JSON string.
|
||||
*/
|
||||
public String evalRule(String rule) {
|
||||
return nativeEvalRule(requireOpen(), rule);
|
||||
return nativeEvalRule(enginePtr, rule);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +210,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public void setEnableCoverage(boolean enable) {
|
||||
nativeSetEnableCoverage(requireOpen(), enable);
|
||||
nativeSetEnableCoverage(enginePtr, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,7 +218,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public void clearCoverageData() {
|
||||
nativeClearCoverageData(requireOpen());
|
||||
nativeClearCoverageData(enginePtr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,7 +228,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public String getCoverageReport() {
|
||||
return nativeGetCoverageReport(requireOpen());
|
||||
return nativeGetCoverageReport(enginePtr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,7 +238,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public String getCoverageReportPretty() {
|
||||
return nativeGetCoverageReportPretty(requireOpen());
|
||||
return nativeGetCoverageReportPretty(enginePtr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,7 +248,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public void setGatherPrints(boolean b) {
|
||||
nativeSetGatherPrints(requireOpen(), b);
|
||||
nativeSetGatherPrints(enginePtr, b);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,7 +258,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public String takePrints() {
|
||||
return nativeTakePrints(requireOpen());
|
||||
return nativeTakePrints(enginePtr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,34 +267,24 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @param config Policy length configuration.
|
||||
*/
|
||||
public void setPolicyLengthConfig(PolicyLengthConfig config) {
|
||||
nativeSetPolicyLengthConfig(requireOpen(), config.maxCol, config.maxFileBytes, config.maxLines);
|
||||
nativeSetPolicyLengthConfig(enginePtr, config.maxCol, config.maxFileBytes, config.maxLines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the policy length configuration, reverting to defaults.
|
||||
*/
|
||||
public void clearPolicyLengthConfig() {
|
||||
nativeClearPolicyLengthConfig(requireOpen());
|
||||
nativeClearPolicyLengthConfig(enginePtr);
|
||||
}
|
||||
|
||||
long getPtr() {
|
||||
return requireOpen();
|
||||
}
|
||||
|
||||
private long requireOpen() {
|
||||
if (enginePtr == 0) {
|
||||
throw new IllegalStateException("Engine is closed");
|
||||
}
|
||||
return enginePtr;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (enginePtr != 0) {
|
||||
nativeDestroyEngine(enginePtr);
|
||||
enginePtr = 0;
|
||||
}
|
||||
nativeDestroyEngine(enginePtr);
|
||||
}
|
||||
|
||||
// Loading native library from JAR is adapted from:
|
||||
|
||||
@@ -22,19 +22,8 @@ public class EngineTest extends TestCase
|
||||
"package test\nmessage = concat(\", \", [input.message, data.message])"
|
||||
);
|
||||
engine.addDataJson("{\"message\":\"World!\"}");
|
||||
engine.prepare();
|
||||
engine.setInputJson("{\"message\":\"Hello\"}");
|
||||
resJson = engine.evalQuery("data.test.message");
|
||||
|
||||
try (Engine template = engine.clone()) {
|
||||
template.setInputJson("{\"message\":\"Hi\"}");
|
||||
String templateResJson = template.evalQuery("data.test.message");
|
||||
Map templateRes = new Gson().fromJson(templateResJson, Map.class);
|
||||
ArrayList templateResults = (ArrayList) templateRes.get("result");
|
||||
ArrayList templateExpressions = (ArrayList) ((Map) templateResults.get(0)).get("expressions");
|
||||
Map templateExpression = (Map) templateExpressions.get(0);
|
||||
Assert.assertEquals("Hi, World!", templateExpression.get("value"));
|
||||
}
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
@@ -44,28 +33,4 @@ public class EngineTest extends TestCase
|
||||
Map expression = (Map) expressions.get(0);
|
||||
Assert.assertEquals("Hello, World!", expression.get("value"));
|
||||
}
|
||||
|
||||
public void test_closed_engine_operations_throw()
|
||||
{
|
||||
Engine engine = new Engine();
|
||||
engine.close();
|
||||
|
||||
try {
|
||||
engine.prepare();
|
||||
fail("prepare should fail on closed engine");
|
||||
} catch (IllegalStateException expected) {
|
||||
}
|
||||
|
||||
try {
|
||||
engine.clone();
|
||||
fail("clone should fail on closed engine");
|
||||
} catch (IllegalStateException expected) {
|
||||
}
|
||||
|
||||
try {
|
||||
engine.evalQuery("data");
|
||||
fail("evalQuery should fail on closed engine");
|
||||
} catch (IllegalStateException expected) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
48
bindings/python/Cargo.lock
generated
48
bindings/python/Cargo.lock
generated
@@ -221,9 +221,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.18.0"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -533,9 +533,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.98"
|
||||
version = "0.3.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -545,9 +545,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -611,9 +611,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.18.0"
|
||||
version = "0.16.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -621,12 +621,6 @@ version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "micromap"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a86d3146ed3995b5913c414f6664344b9617457320782e64f0bb44afd49d74"
|
||||
|
||||
[[package]]
|
||||
name = "msvc_spectre_libs"
|
||||
version = "0.1.3"
|
||||
@@ -963,16 +957,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -1152,9 +1144,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.3"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1332,9 +1324,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1345,9 +1337,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1355,9 +1347,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -1368,9 +1360,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
@@ -463,13 +463,6 @@ impl Engine {
|
||||
self.engine.take_prints()
|
||||
}
|
||||
|
||||
/// Prepare internal evaluation structures without executing a query.
|
||||
///
|
||||
/// Optional: if skipped, first evaluation performs the same setup.
|
||||
pub fn prepare(&mut self) -> Result<()> {
|
||||
self.engine.prepare()
|
||||
}
|
||||
|
||||
/// Clone a [`Engine`]
|
||||
///
|
||||
/// To avoid having to parse same policy again, the engine can be cloned
|
||||
|
||||
@@ -87,7 +87,6 @@ report = engine.get_coverage_report_pretty()
|
||||
print(report)
|
||||
|
||||
# Clone engine
|
||||
engine.prepare()
|
||||
engine1 = engine.clone()
|
||||
|
||||
|
||||
|
||||
56
bindings/ruby/Cargo.lock
generated
56
bindings/ruby/Cargo.lock
generated
@@ -244,9 +244,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.18.0"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -571,9 +571,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.98"
|
||||
version = "0.3.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -583,9 +583,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -659,9 +659,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.18.0"
|
||||
version = "0.16.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
|
||||
[[package]]
|
||||
name = "magnus"
|
||||
@@ -692,12 +692,6 @@ version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "micromap"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a86d3146ed3995b5913c414f6664344b9617457320782e64f0bb44afd49d74"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
@@ -935,18 +929,18 @@ checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
||||
|
||||
[[package]]
|
||||
name = "rb-sys"
|
||||
version = "0.9.128"
|
||||
version = "0.9.127"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45ca28513560e56cfb79a62b1fce363c73af170a182024ce880c77ee9429920a"
|
||||
checksum = "d7d7c9560fe42dcffa576941394075f18a17dce89fcf718a2fa90b7dc2134d12"
|
||||
dependencies = [
|
||||
"rb-sys-build",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rb-sys-build"
|
||||
version = "0.9.128"
|
||||
version = "0.9.127"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce04b2c55eff3a21aaa623fcc655d94373238e72cac6b3e1a3641ff31649f99a"
|
||||
checksum = "f1688e8f32967ba48c89e4dfa283b57f901075f542fc7ee9c3d7c5f9091ca1d9"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"lazy_static",
|
||||
@@ -994,16 +988,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -1211,9 +1203,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.3"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1391,9 +1383,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1404,9 +1396,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1414,9 +1406,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -1427,9 +1419,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
@@ -115,13 +115,6 @@ impl Engine {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prepare(&self) -> Result<(), Error> {
|
||||
self.engine
|
||||
.borrow_mut()
|
||||
.prepare()
|
||||
.map_err(|e| Error::new(runtime_error(), format!("Failed to prepare engine: {e}")))
|
||||
}
|
||||
|
||||
fn get_packages(&self) -> Result<Vec<String>, Error> {
|
||||
self.engine
|
||||
.borrow()
|
||||
@@ -380,7 +373,6 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
|
||||
method!(Engine::add_data_from_json_file, 1),
|
||||
)?;
|
||||
engine_class.define_method("clear_data", method!(Engine::clear_data, 0))?;
|
||||
engine_class.define_method("prepare", method!(Engine::prepare, 0))?;
|
||||
|
||||
// input operations
|
||||
engine_class.define_method("set_input", method!(Engine::set_input, 1))?;
|
||||
|
||||
@@ -150,7 +150,6 @@ class TestRegorus < Minitest::Test
|
||||
end
|
||||
|
||||
def test_engine_cloning
|
||||
@engine.prepare
|
||||
cloned_engine = @engine.clone
|
||||
|
||||
assert_instance_of ::Regorus::Engine, cloned_engine
|
||||
|
||||
64
bindings/wasm/Cargo.lock
generated
64
bindings/wasm/Cargo.lock
generated
@@ -238,9 +238,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.18.0"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -565,9 +565,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.98"
|
||||
version = "0.3.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -577,9 +577,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -649,9 +649,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.18.0"
|
||||
version = "0.16.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -659,12 +659,6 @@ version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "micromap"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a86d3146ed3995b5913c414f6664344b9617457320782e64f0bb44afd49d74"
|
||||
|
||||
[[package]]
|
||||
name = "minicov"
|
||||
version = "0.3.8"
|
||||
@@ -953,16 +947,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.46.4"
|
||||
version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -1152,9 +1144,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.3"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1344,9 +1336,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1357,9 +1349,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.71"
|
||||
version = "0.4.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96492d0d3ffba25305a7dc88720d250b1401d7edca02cc3bcd50633b424673b8"
|
||||
checksum = "af934872acec734c2d80e6617bbb5ff4f12b052dd8e6332b0817bce889516084"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
@@ -1367,9 +1359,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1377,9 +1369,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -1390,18 +1382,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-test"
|
||||
version = "0.3.71"
|
||||
version = "0.3.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af5ec93229ad9ccd0a545a516dec76dc276613f278f6a91aa6b463d5b33d42d0"
|
||||
checksum = "29826f9d9ecaa314c480d376b276d1c790e6cb6a4681fab8532da69cbabf977d"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"cast",
|
||||
@@ -1421,9 +1413,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-test-macro"
|
||||
version = "0.3.71"
|
||||
version = "0.3.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c81b9fef827e575e0e54431736d1baa0d700315d8c62cfef1f61fa3aad0cbeb"
|
||||
checksum = "c610311887f9e6599a546d278d12d69dfd3a3e92639b2129e4b11ad6cf1961d6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -1432,9 +1424,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-test-shared"
|
||||
version = "0.2.121"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f4d8ae7ad5440360e9799dfd42857d126454a88441ddf72d288ef83fa47f527"
|
||||
checksum = "60238e5b4b1b295701d6f9a66d2a126fe19990348f5fb9dae3b623a370119d94"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
|
||||
@@ -55,7 +55,7 @@ getrandom03 = { package = "getrandom", version = "0.3.1", features = ["std", "wa
|
||||
getrandom = { version = "0.4.2", features = ["wasm_js"] }
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.71"
|
||||
wasm-bindgen-test = "0.3.67"
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }
|
||||
|
||||
@@ -21,9 +21,3 @@ Run `cargo xtask build-wasm` to invoke wasm-pack with sensible defaults, or `car
|
||||
## Usage
|
||||
|
||||
See [test.js](https://github.com/microsoft/regorus/blob/main/bindings/wasm/test.js) for example usage.
|
||||
|
||||
For best performance with large policies, call `engine.prepare()` after loading
|
||||
policy/data, then use `engine.clone()` to create per-request engines. If
|
||||
`prepare()` is skipped, the first `eval*` call performs the same one-time
|
||||
setup. Adding/changing policy or data after `prepare()` invalidates the
|
||||
prepared state.
|
||||
|
||||
@@ -138,17 +138,6 @@ impl Engine {
|
||||
self.engine.set_rego_v0(enable)
|
||||
}
|
||||
|
||||
/// Clone this engine.
|
||||
///
|
||||
/// Useful for creating per-request engines after loading policy/data once.
|
||||
///
|
||||
/// Clone is designed to avoid reparsing policy text and reloading immutable
|
||||
/// policy structures. Mutable evaluation state is copied for isolation.
|
||||
#[wasm_bindgen(js_name = "clone")]
|
||||
pub fn cloneEngine(&self) -> Engine {
|
||||
Clone::clone(self)
|
||||
}
|
||||
|
||||
/// Add a policy
|
||||
///
|
||||
/// The policy is parsed into AST.
|
||||
@@ -169,20 +158,6 @@ impl Engine {
|
||||
self.engine.add_data(data).map_err(error_to_jsvalue)
|
||||
}
|
||||
|
||||
/// Prepare the engine for evaluation.
|
||||
///
|
||||
/// The first evaluation on an unprepared engine performs one-time setup.
|
||||
/// Calling `prepare()` performs that setup eagerly.
|
||||
///
|
||||
/// This is optional for correctness. If omitted, the first `eval*` call
|
||||
/// implicitly performs preparation.
|
||||
///
|
||||
/// If policies/data are modified after `prepare()`, preparation is
|
||||
/// invalidated and must be performed again (explicitly or via first eval).
|
||||
pub fn prepare(&mut self) -> Result<(), JsValue> {
|
||||
self.engine.prepare().map_err(error_to_jsvalue)
|
||||
}
|
||||
|
||||
/// Get the list of packages defined by loaded policies.
|
||||
///
|
||||
/// See https://docs.rs/regorus/latest/regorus/struct.Engine.html#method.get_packages
|
||||
@@ -512,9 +487,6 @@ mod tests {
|
||||
)?;
|
||||
assert_eq!(pkg, "data.test");
|
||||
|
||||
// Prepare before first evaluation.
|
||||
engine.prepare()?;
|
||||
|
||||
let results = engine.evalQuery("data".to_string())?;
|
||||
let r = regorus::Value::from_json_str(&results).map_err(error_to_jsvalue)?;
|
||||
|
||||
|
||||
@@ -40,13 +40,6 @@ engine.addDataJson(`
|
||||
}
|
||||
`);
|
||||
|
||||
// Prepare internal evaluation structures once.
|
||||
engine.prepare();
|
||||
|
||||
// Clone a prepared template engine for reuse.
|
||||
var template = engine.clone();
|
||||
engine = template.clone();
|
||||
|
||||
// Set policy input
|
||||
engine.setInputJson(`
|
||||
{
|
||||
|
||||
@@ -505,47 +505,6 @@ impl Engine {
|
||||
self.add_data(Value::from_json_str(data_json)?)
|
||||
}
|
||||
|
||||
/// Prepare the engine for evaluation without executing a query or rule.
|
||||
///
|
||||
/// The first evaluation on an unprepared engine performs one-time setup
|
||||
/// (analysis, scheduling, imports/rules processing, and initialization of
|
||||
/// internal evaluation structures). Calling this method performs that work
|
||||
/// eagerly so a later call to [`Engine::eval_rule`] / [`Engine::eval_query`]
|
||||
/// does not pay that startup cost.
|
||||
///
|
||||
/// This method is optional for correctness. If omitted, the first
|
||||
/// evaluation will implicitly prepare the engine.
|
||||
///
|
||||
/// Preparation is invalidated when policy/data that affects evaluation is
|
||||
/// changed (for example: [`Engine::add_policy`], [`Engine::add_policy_from_file`],
|
||||
/// [`Engine::add_data`], [`Engine::clear_data`]). In those cases, the next
|
||||
/// evaluation (or another explicit call to `prepare`) performs setup again.
|
||||
///
|
||||
/// This is especially useful before cloning template engines used for
|
||||
/// repeated evaluations.
|
||||
///
|
||||
/// ```
|
||||
/// # use regorus::*;
|
||||
/// # fn main() -> anyhow::Result<()> {
|
||||
/// let mut engine = Engine::new();
|
||||
/// engine.add_policy("test.rego".to_string(), r#"
|
||||
/// package test
|
||||
/// import rego.v1
|
||||
/// allow if input.user == "alice"
|
||||
/// "#.to_string())?;
|
||||
///
|
||||
/// engine.prepare()?;
|
||||
/// let mut cloned = engine.clone();
|
||||
///
|
||||
/// cloned.set_input_json(r#"{"user":"alice"}"#)?;
|
||||
/// assert_eq!(cloned.eval_rule("data.test.allow".to_string())?, Value::from(true));
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn prepare(&mut self) -> Result<()> {
|
||||
self.prepare_for_eval(false, false)
|
||||
}
|
||||
|
||||
/// Set whether builtins should raise errors strictly or not.
|
||||
///
|
||||
/// Regorus differs from OPA in that by default builtins will
|
||||
@@ -1125,10 +1084,9 @@ impl Engine {
|
||||
limits::enforce_memory_limit().map_err(|err| anyhow!(err))?;
|
||||
|
||||
self.interpreter.set_traces(enable_tracing);
|
||||
let newly_prepared = !self.prepared;
|
||||
|
||||
// if the data/policies have changed or the interpreter has never been prepared
|
||||
if newly_prepared {
|
||||
if !self.prepared {
|
||||
// Analyze the modules and determine how statements must be scheduled.
|
||||
let analyzer = Analyzer::new();
|
||||
let schedule = Rc::new(analyzer.analyze(&self.modules)?);
|
||||
@@ -1158,28 +1116,23 @@ impl Engine {
|
||||
|
||||
// Set schedule after hoisting completes
|
||||
self.interpreter.set_schedule(Some(schedule));
|
||||
}
|
||||
|
||||
#[cfg(feature = "azure_policy")]
|
||||
{
|
||||
#[cfg(feature = "azure_policy")]
|
||||
if for_target {
|
||||
// Resolve and validate target specifications across all modules.
|
||||
// This must run for target-aware compilation even if generic prepare()
|
||||
// was already called.
|
||||
// Resolve and validate target specifications across all modules
|
||||
crate::interpreter::target::resolve::resolve_and_apply_target(
|
||||
&mut self.interpreter,
|
||||
)?;
|
||||
// Infer resource types
|
||||
crate::interpreter::target::infer::infer_resource_type(&mut self.interpreter)?;
|
||||
} else if newly_prepared {
|
||||
// Check if any module specifies a target and warn if so.
|
||||
}
|
||||
|
||||
if !for_target {
|
||||
// Check if any module specifies a target and warn if so
|
||||
#[cfg(feature = "azure_policy")]
|
||||
self.warn_if_targets_present();
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "azure_policy"))]
|
||||
let _ = for_target;
|
||||
|
||||
if newly_prepared {
|
||||
self.prepared = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
use crate::ast::*;
|
||||
use crate::builtins::{self, BuiltinFcn};
|
||||
use crate::compiled_policy::CompiledPolicyData;
|
||||
#[cfg(feature = "azure_policy")]
|
||||
use crate::compiled_policy::TargetInfo;
|
||||
use crate::compiled_policy::{CompiledPolicyData, DefaultRuleInfo};
|
||||
use crate::compiler::destructuring_planner::{
|
||||
AssignmentPlan, BindingPlan, DestructuringPlan, WildcardSide,
|
||||
};
|
||||
@@ -1724,6 +1724,9 @@ impl Interpreter {
|
||||
// For now, we restrict constant refs to those that contain only simple literals.
|
||||
fn is_constant_ref(mut expr: &Ref<Expr>) -> Result<bool> {
|
||||
loop {
|
||||
if Self::is_simple_literal(expr)? {
|
||||
return Ok(true);
|
||||
}
|
||||
match expr.as_ref() {
|
||||
Expr::Var { .. } => break,
|
||||
Expr::RefDot { refr, .. } => expr = refr,
|
||||
@@ -1747,6 +1750,30 @@ impl Interpreter {
|
||||
))
|
||||
}
|
||||
|
||||
fn is_constant_key_expr(&self, expr: &Ref<Expr>) -> Result<bool> {
|
||||
if Self::is_simple_literal(expr)? {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
match expr.as_ref() {
|
||||
Expr::Var { span, .. } => {
|
||||
// A variable that is not currently bound in any active local scope behaves like
|
||||
// a stable global/package reference for this evaluation.
|
||||
let is_bound = self
|
||||
.scopes
|
||||
.iter()
|
||||
.rev()
|
||||
.any(|scope| scope.contains_key(&span.source_str()));
|
||||
Ok(!is_bound)
|
||||
}
|
||||
Expr::RefDot { refr, .. } => self.is_constant_key_expr(refr),
|
||||
Expr::RefBrack { refr, index, .. } => {
|
||||
Ok(self.is_constant_key_expr(refr)? && self.is_constant_key_expr(index)?)
|
||||
}
|
||||
_ => Ok(false),
|
||||
}
|
||||
}
|
||||
|
||||
// A rule's output expression is constant if it does not contain local variables.
|
||||
// For now, we restrict output expressions to those that contain only simple literals.
|
||||
fn is_constant_output(key_expr: &Option<Ref<Expr>>, output_expr: &Ref<Expr>) -> Result<bool> {
|
||||
@@ -1797,7 +1824,12 @@ impl Interpreter {
|
||||
comps.pop();
|
||||
output
|
||||
} else {
|
||||
// Rule's constness is determined only by its ref.
|
||||
// Implicit-true partial object rules can vary with each successful key binding.
|
||||
if let Some(ke) = &key_expr {
|
||||
if !is_old_style_set && !self.is_constant_key_expr(ke)? {
|
||||
is_const_rule = false;
|
||||
}
|
||||
}
|
||||
Value::Bool(true)
|
||||
};
|
||||
|
||||
@@ -2942,6 +2974,41 @@ impl Interpreter {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn default_rules_for_path(&self, path: &str) -> Option<Vec<DefaultRuleInfo>> {
|
||||
if let Some(rules) = self.compiled_policy.default_rules.get(path) {
|
||||
return Some(rules.clone());
|
||||
}
|
||||
|
||||
let (parent_path, index) = path.rsplit_once('.')?;
|
||||
let rules = self.compiled_policy.default_rules.get(parent_path)?;
|
||||
let matches = rules
|
||||
.iter()
|
||||
.filter(|(_, rule_index)| Self::default_rule_index_matches(rule_index, index))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if matches.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(matches)
|
||||
}
|
||||
}
|
||||
|
||||
fn has_default_rules_for_path(&self, path: &str) -> bool {
|
||||
self.default_rules_for_path(path).is_some()
|
||||
}
|
||||
|
||||
fn default_rule_index_matches(index: &Option<String>, path_component: &str) -> bool {
|
||||
match index.as_deref() {
|
||||
Some(index) if index == path_component => true,
|
||||
Some(index) => index
|
||||
.strip_prefix('"')
|
||||
.and_then(|index| index.strip_suffix('"'))
|
||||
.is_some_and(|index| index == path_component),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_rule_evaluated(&mut self, path: String) -> Result<()> {
|
||||
self.check_execution_time()?;
|
||||
let mut matched = false;
|
||||
@@ -2956,9 +3023,9 @@ impl Interpreter {
|
||||
}
|
||||
|
||||
// Evaluate the associated default rules after non-default rules
|
||||
if let Some(rules) = self.compiled_policy.default_rules.get(&path) {
|
||||
if let Some(rules) = self.default_rules_for_path(&path) {
|
||||
matched = true;
|
||||
for (r, _) in rules.clone() {
|
||||
for (r, _) in rules {
|
||||
if !self.processed.contains(&r) {
|
||||
let module = self.get_rule_module(&r)?;
|
||||
let prev_module = self.set_current_module(Some(module))?;
|
||||
@@ -3049,10 +3116,7 @@ impl Interpreter {
|
||||
let prefix = fields.iter().take(i).copied().collect::<Vec<_>>();
|
||||
let prefix_path = format!("data.{}", prefix.join("."));
|
||||
if self.compiled_policy.rules.contains_key(&prefix_path)
|
||||
|| self
|
||||
.compiled_policy
|
||||
.default_rules
|
||||
.contains_key(&prefix_path)
|
||||
|| self.has_default_rules_for_path(&prefix_path)
|
||||
{
|
||||
self.ensure_rule_evaluated(prefix_path)?;
|
||||
break;
|
||||
@@ -3076,7 +3140,7 @@ impl Interpreter {
|
||||
|
||||
if !no_error
|
||||
&& !self.compiled_policy.rules.contains_key(&rule_path)
|
||||
&& !self.compiled_policy.default_rules.contains_key(&rule_path)
|
||||
&& !self.has_default_rules_for_path(&rule_path)
|
||||
&& !self.compiled_policy.imports.contains_key(&rule_path)
|
||||
{
|
||||
bail!(span.error(&format!(
|
||||
@@ -3099,7 +3163,7 @@ impl Interpreter {
|
||||
};
|
||||
|
||||
if self.compiled_policy.rules.contains_key(&path)
|
||||
|| self.compiled_policy.default_rules.contains_key(&path)
|
||||
|| self.has_default_rules_for_path(&path)
|
||||
{
|
||||
self.ensure_rule_evaluated(path)?;
|
||||
found = true;
|
||||
@@ -3646,7 +3710,7 @@ impl Interpreter {
|
||||
self.data = Value::Undefined;
|
||||
self.ensure_loop_var_values_capacity();
|
||||
|
||||
let default_rules = self.compiled_policy.default_rules.get(rule_path).cloned();
|
||||
let default_rules = self.default_rules_for_path(rule_path);
|
||||
|
||||
if let Some(rules) = default_rules {
|
||||
for (rule, _) in rules {
|
||||
|
||||
@@ -181,7 +181,7 @@ impl<'a> Compiler<'a> {
|
||||
}
|
||||
|
||||
fn evaluate_default_rule(&mut self, rule_path: &str) -> Option<u16> {
|
||||
if !self.policy.inner.default_rules.contains_key(rule_path) {
|
||||
if !self.may_have_default_rule(rule_path) {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -200,6 +200,33 @@ impl<'a> Compiler<'a> {
|
||||
None
|
||||
}
|
||||
|
||||
fn may_have_default_rule(&self, rule_path: &str) -> bool {
|
||||
if self.policy.inner.default_rules.contains_key(rule_path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let Some((parent_path, index)) = rule_path.rsplit_once('.') else {
|
||||
return false;
|
||||
};
|
||||
|
||||
self.policy
|
||||
.inner
|
||||
.default_rules
|
||||
.get(parent_path)
|
||||
.is_some_and(|rules| {
|
||||
rules
|
||||
.iter()
|
||||
.any(|(_, rule_index)| match rule_index.as_deref() {
|
||||
Some(rule_index) if rule_index == index => true,
|
||||
Some(rule_index) => rule_index
|
||||
.strip_prefix('"')
|
||||
.and_then(|rule_index| rule_index.strip_suffix('"'))
|
||||
.is_some_and(|rule_index| rule_index == index),
|
||||
None => false,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn extract_destructuring_blocks(&self, rule_index: u16) -> Vec<Option<u32>> {
|
||||
self.rule_definition_destructuring_patterns[rule_index as usize].clone()
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
)]
|
||||
|
||||
use super::{CompilationContext, Compiler, CompilerError, ContextType, Result, WorklistEntry};
|
||||
use crate::ast::{Expr, ExprRef, Rule, RuleHead};
|
||||
use crate::ast::{AssignOp, Expr, ExprRef, Rule, RuleHead};
|
||||
use crate::compiler::destructuring_planner::plans::BindingPlan;
|
||||
use crate::lexer::Span;
|
||||
use crate::rvm::program::{Program, RuleType};
|
||||
@@ -52,14 +52,29 @@ impl<'a> Compiler<'a> {
|
||||
let rule_types: BTreeSet<RuleType> = definitions
|
||||
.iter()
|
||||
.map(|def| {
|
||||
if let Rule::Spec { head, .. } = def.as_ref() {
|
||||
if let Rule::Spec { head, bodies, .. } = def.as_ref() {
|
||||
match head {
|
||||
RuleHead::Set { .. } => RuleType::PartialSet,
|
||||
RuleHead::Compr { refr, assign, .. } => match refr.as_ref() {
|
||||
crate::ast::Expr::RefBrack { .. } if assign.is_some() => {
|
||||
// Variable-key bracket heads emit one object entry per successful
|
||||
// binding, so they must compile as partial objects.
|
||||
crate::ast::Expr::RefBrack { index, .. }
|
||||
if super::expressions::try_eval_const(index.as_ref()).is_none() =>
|
||||
{
|
||||
RuleType::PartialObject
|
||||
}
|
||||
crate::ast::Expr::RefBrack { .. } => RuleType::PartialSet,
|
||||
crate::ast::Expr::RefBrack { .. }
|
||||
if matches!(
|
||||
assign.as_ref().map(|assign| &assign.op),
|
||||
Some(AssignOp::Eq)
|
||||
) =>
|
||||
{
|
||||
RuleType::PartialObject
|
||||
}
|
||||
crate::ast::Expr::RefBrack { .. } if bodies.is_empty() => {
|
||||
RuleType::PartialObject
|
||||
}
|
||||
crate::ast::Expr::RefBrack { .. } => RuleType::Complete,
|
||||
_ => RuleType::Complete,
|
||||
},
|
||||
_ => RuleType::Complete,
|
||||
|
||||
@@ -454,7 +454,19 @@ impl RegoVM {
|
||||
let mut obj_value = self.take_register(obj)?;
|
||||
|
||||
if let Ok(obj_mut) = obj_value.as_object_mut() {
|
||||
obj_mut.insert(key_value, value_value);
|
||||
match obj_mut.get(&key_value) {
|
||||
Some(existing_value) if existing_value != &value_value => {
|
||||
self.set_register(obj, obj_value)?;
|
||||
return Err(VmError::RuleMultipleOutputs { pc: self.pc });
|
||||
}
|
||||
Some(_) => {
|
||||
self.set_register(obj, obj_value)?;
|
||||
return Ok(InstructionOutcome::Continue);
|
||||
}
|
||||
None => {
|
||||
obj_mut.insert(key_value, value_value);
|
||||
}
|
||||
}
|
||||
self.set_register(obj, obj_value)?;
|
||||
} else {
|
||||
let offending = obj_value.clone();
|
||||
|
||||
@@ -209,6 +209,9 @@ pub enum VmError {
|
||||
#[error("Rule-data conflict: {message} (pc={pc})")]
|
||||
RuleDataConflict { message: String, pc: usize },
|
||||
|
||||
#[error("rules must not produce multiple outputs (pc={pc})")]
|
||||
RuleMultipleOutputs { pc: usize },
|
||||
|
||||
#[error("Arithmetic error: {message} (pc={pc})")]
|
||||
ArithmeticError { message: String, pc: usize },
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@ use super::execution_model::{
|
||||
use super::machine::RegoVM;
|
||||
|
||||
impl RegoVM {
|
||||
/// Returns true if the error represents a resource-limit violation that
|
||||
/// must never be silently absorbed by rule evaluation.
|
||||
/// Returns true if the error must never be silently absorbed by rule
|
||||
/// evaluation backtracking, including resource-limit failures and semantic
|
||||
/// rule consistency errors.
|
||||
pub(super) const fn is_fatal_vm_error(err: &VmError) -> bool {
|
||||
matches!(
|
||||
err,
|
||||
@@ -26,6 +27,7 @@ impl RegoVM {
|
||||
| VmError::MemoryLimitExceeded { .. }
|
||||
| VmError::RegexSizeLimitExceeded { .. }
|
||||
| VmError::InstructionLimitExceeded { .. }
|
||||
| VmError::RuleMultipleOutputs { .. }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -102,135 +102,6 @@ fn extension_with_state() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepare_then_clone_without_initial_eval() -> Result<()> {
|
||||
let mut engine = Engine::new();
|
||||
engine.add_policy(
|
||||
"test.rego".to_string(),
|
||||
r#"package test
|
||||
import rego.v1
|
||||
|
||||
default allow := false
|
||||
|
||||
allow if {
|
||||
input.user in data.allowed_users
|
||||
}
|
||||
"#
|
||||
.to_string(),
|
||||
)?;
|
||||
engine.add_data(Value::from_json_str(
|
||||
r#"{"allowed_users":["alice","bob"]}"#,
|
||||
)?)?;
|
||||
|
||||
// Prepare once and clone without running an initial evaluation.
|
||||
engine.prepare()?;
|
||||
|
||||
let mut alice_engine = engine.clone();
|
||||
alice_engine.set_input_json(r#"{"user":"alice"}"#)?;
|
||||
assert_eq!(
|
||||
alice_engine.eval_rule("data.test.allow".to_string())?,
|
||||
Value::from(true)
|
||||
);
|
||||
|
||||
let mut mallory_engine = engine.clone();
|
||||
mallory_engine.set_input_json(r#"{"user":"mallory"}"#)?;
|
||||
assert_eq!(
|
||||
mallory_engine.eval_rule("data.test.allow".to_string())?,
|
||||
Value::from(false)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "azure_policy")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "azure_policy")))]
|
||||
fn prepare_then_compile_for_target() -> Result<()> {
|
||||
if !registry::targets::contains("target.tests.sample_test_target") {
|
||||
let target = Target::from_json_str(include_str!(
|
||||
"../interpreter/cases/target/definitions/sample_target.json"
|
||||
))?;
|
||||
registry::targets::register(Rc::new(target))?;
|
||||
}
|
||||
|
||||
let mut engine = Engine::new();
|
||||
engine.add_policy(
|
||||
"test.rego".to_string(),
|
||||
r#"package test
|
||||
import rego.v1
|
||||
__target__ := "target.tests.sample_test_target"
|
||||
|
||||
default allow := false
|
||||
|
||||
allow if {
|
||||
input.type == "test_resource"
|
||||
}
|
||||
"#
|
||||
.to_string(),
|
||||
)?;
|
||||
|
||||
engine.prepare()?;
|
||||
let compiled = engine.compile_for_target()?;
|
||||
let info = compiled.get_policy_info()?;
|
||||
assert_eq!(
|
||||
info.target_name.as_deref(),
|
||||
Some("target.tests.sample_test_target")
|
||||
);
|
||||
|
||||
let result = compiled.eval_with_input(Value::from_json_str(
|
||||
r#"{"name":"resource-1","type":"test_resource"}"#,
|
||||
)?)?;
|
||||
assert_eq!(result, Value::from(true));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "azure_policy")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "azure_policy")))]
|
||||
fn prepare_then_compile_for_target_error_recovery() -> Result<()> {
|
||||
let target_name = "target.tests.prepare_recovery_test_target";
|
||||
|
||||
let mut engine = Engine::new();
|
||||
engine.add_policy(
|
||||
"test.rego".to_string(),
|
||||
format!(
|
||||
r#"package test
|
||||
import rego.v1
|
||||
__target__ := "{target_name}"
|
||||
|
||||
default allow := false
|
||||
|
||||
allow if {{
|
||||
input.type == "test_resource"
|
||||
}}
|
||||
"#
|
||||
),
|
||||
)?;
|
||||
|
||||
engine.prepare()?;
|
||||
assert!(engine.compile_for_target().is_err());
|
||||
|
||||
if !registry::targets::contains(target_name) {
|
||||
let target_json =
|
||||
include_str!("../interpreter/cases/target/definitions/sample_target.json")
|
||||
.replace("target.tests.sample_test_target", target_name);
|
||||
let target = Target::from_json_str(&target_json)?;
|
||||
registry::targets::register(Rc::new(target))?;
|
||||
}
|
||||
|
||||
let compiled = engine.compile_for_target()?;
|
||||
let info = compiled.get_policy_info()?;
|
||||
assert_eq!(info.target_name.as_deref(), Some(target_name));
|
||||
|
||||
let result = compiled.eval_with_input(Value::from_json_str(
|
||||
r#"{"name":"resource-1","type":"test_resource"}"#,
|
||||
)?)?;
|
||||
assert_eq!(result, Value::from(true));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "azure_policy")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "azure_policy")))]
|
||||
|
||||
@@ -341,6 +341,35 @@ cases:
|
||||
result: false
|
||||
reasons: []
|
||||
|
||||
- note: default_rule_with_object_key
|
||||
data: {}
|
||||
input: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
default config["timeout"] := 30
|
||||
config["timeout"] := val if {
|
||||
val := input.val
|
||||
}
|
||||
query: data.test.config.timeout
|
||||
want_result: 30
|
||||
|
||||
- note: default_rule_with_object_key_override
|
||||
data: {}
|
||||
input:
|
||||
val: 60
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
default config["timeout"] := 30
|
||||
config["timeout"] := val if {
|
||||
val := input.val
|
||||
}
|
||||
query: data.test.config.timeout
|
||||
want_result: 60
|
||||
|
||||
- note: default_only_rule_with_package_query
|
||||
data: {}
|
||||
modules:
|
||||
|
||||
242
tests/interpreter/cases/rule/partial_object_iteration.yaml
Normal file
242
tests/interpreter/cases/rule/partial_object_iteration.yaml
Normal file
@@ -0,0 +1,242 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: partial_object_iteration_some_in_object_v1
|
||||
data: {}
|
||||
input:
|
||||
x:
|
||||
FOO: 1
|
||||
BAR: 2
|
||||
BAZ: 3
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] if {
|
||||
some k, _ in input.x
|
||||
}
|
||||
query: data.test
|
||||
want_result:
|
||||
violations:
|
||||
BAR: true
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_iteration_some_in_array_v1
|
||||
data: {}
|
||||
input:
|
||||
arr: ["FOO", "BAR", "BAZ"]
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[v] if {
|
||||
some _, v in input.arr
|
||||
}
|
||||
query: data.test
|
||||
want_result:
|
||||
violations:
|
||||
BAR: true
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_iteration_with_filter_v1
|
||||
data: {}
|
||||
input:
|
||||
x:
|
||||
FOO: 1
|
||||
BAR: 2
|
||||
BAZ: 3
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] if {
|
||||
some k, _ in input.x
|
||||
k != "BAR"
|
||||
}
|
||||
query: data.test
|
||||
want_result:
|
||||
violations:
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_iteration_input_lookup_future_keywords
|
||||
data: {}
|
||||
input:
|
||||
x:
|
||||
FOO: 1
|
||||
BAR: 2
|
||||
BAZ: 3
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import future.keywords.if
|
||||
|
||||
violations[k] if {
|
||||
input.x[k]
|
||||
}
|
||||
query: data.test
|
||||
want_result:
|
||||
violations:
|
||||
BAR: true
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_multiple_bodies_collect_all_keys_v1
|
||||
data: {}
|
||||
input:
|
||||
primary:
|
||||
FOO: 1
|
||||
BAR: 2
|
||||
secondary:
|
||||
BAZ: 3
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] if {
|
||||
some k, _ in input.primary
|
||||
}
|
||||
|
||||
violations[k] if {
|
||||
some k, _ in input.secondary
|
||||
}
|
||||
query: data.test
|
||||
want_result:
|
||||
violations:
|
||||
BAR: true
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: constant_key_implicit_true_rule_is_complete_v1
|
||||
data: {}
|
||||
input:
|
||||
enabled: true
|
||||
other: false
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
p["x"] if {
|
||||
input.enabled
|
||||
}
|
||||
|
||||
p["x"] if {
|
||||
input.other
|
||||
}
|
||||
query: data.test.p.x
|
||||
want_result: true
|
||||
|
||||
- note: partial_object_duplicate_keys_same_value_are_ok_v1
|
||||
data: {}
|
||||
input:
|
||||
arr: ["FOO", "FOO", "BAR"]
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[v] if {
|
||||
some _, v in input.arr
|
||||
}
|
||||
query: data.test
|
||||
want_result:
|
||||
violations:
|
||||
BAR: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_duplicate_keys_different_values_error_v1
|
||||
data: {}
|
||||
input:
|
||||
entries:
|
||||
- k: "FOO"
|
||||
v: 1
|
||||
- k: "FOO"
|
||||
v: 2
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] := v if {
|
||||
some entry in input.entries
|
||||
k := entry.k
|
||||
v := entry.v
|
||||
}
|
||||
query: data.test.violations
|
||||
error: "rules must not produce multiple outputs"
|
||||
|
||||
- note: partial_object_and_partial_set_iteration_coexist_v1
|
||||
data: {}
|
||||
input:
|
||||
x:
|
||||
FOO: 1
|
||||
BAR: 2
|
||||
BAZ: 3
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] if {
|
||||
some k, _ in input.x
|
||||
}
|
||||
|
||||
seen contains k if {
|
||||
some k, _ in input.x
|
||||
}
|
||||
query: data.test
|
||||
want_result:
|
||||
seen:
|
||||
set!: ["BAR", "BAZ", "FOO"]
|
||||
violations:
|
||||
BAR: true
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_key_bound_in_outer_scope_v1
|
||||
data: {}
|
||||
input:
|
||||
outer:
|
||||
FOO: [1, 2]
|
||||
BAR: [3]
|
||||
BAZ: []
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] if {
|
||||
some k, arr in input.outer
|
||||
some _ in arr
|
||||
}
|
||||
query: data.test.violations
|
||||
want_result:
|
||||
BAR: true
|
||||
FOO: true
|
||||
|
||||
- note: complete_rule_same_value_definitions_still_work_v1
|
||||
data: {}
|
||||
input:
|
||||
role: "superuser"
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
allowed if {
|
||||
input.role == "admin"
|
||||
}
|
||||
|
||||
allowed if {
|
||||
input.role == "superuser"
|
||||
}
|
||||
query: data.test.allowed
|
||||
want_result: true
|
||||
@@ -48,18 +48,34 @@ cases:
|
||||
want_result: true
|
||||
|
||||
- note: default_rule_with_object_key
|
||||
skip: true # TODO: Fix rule type classification for config["timeout"] - should be Complete, not PartialObject
|
||||
data: {}
|
||||
input: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
default config["timeout"] := 30
|
||||
config["timeout"] := 60 if {
|
||||
false # This will fail
|
||||
config["timeout"] := val if {
|
||||
val := input.val
|
||||
}
|
||||
query: data.test.config.timeout
|
||||
want_result: 30
|
||||
|
||||
- note: default_rule_with_object_key_override
|
||||
data: {}
|
||||
input:
|
||||
val: 60
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
default config["timeout"] := 30
|
||||
config["timeout"] := val if {
|
||||
val := input.val
|
||||
}
|
||||
query: data.test.config.timeout
|
||||
want_result: 60
|
||||
|
||||
- note: default_rule_complex_value
|
||||
data: {}
|
||||
modules:
|
||||
|
||||
241
tests/rvm/rego/cases/partial_object_rules.yaml
Normal file
241
tests/rvm/rego/cases/partial_object_rules.yaml
Normal file
@@ -0,0 +1,241 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: partial_object_iteration_some_in_object_v1
|
||||
data: {}
|
||||
input:
|
||||
x:
|
||||
FOO: 1
|
||||
BAR: 2
|
||||
BAZ: 3
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] if {
|
||||
some k, _ in input.x
|
||||
}
|
||||
query: data.test.violations
|
||||
want_result:
|
||||
BAR: true
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_iteration_some_in_array_v1
|
||||
data: {}
|
||||
input:
|
||||
arr: ["FOO", "BAR", "BAZ"]
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[v] if {
|
||||
some _, v in input.arr
|
||||
}
|
||||
query: data.test.violations
|
||||
want_result:
|
||||
BAR: true
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_iteration_with_filter_v1
|
||||
data: {}
|
||||
input:
|
||||
x:
|
||||
FOO: 1
|
||||
BAR: 2
|
||||
BAZ: 3
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] if {
|
||||
some k, _ in input.x
|
||||
k != "BAR"
|
||||
}
|
||||
query: data.test.violations
|
||||
want_result:
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_iteration_input_lookup_future_keywords
|
||||
data: {}
|
||||
input:
|
||||
x:
|
||||
FOO: 1
|
||||
BAR: 2
|
||||
BAZ: 3
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import future.keywords.if
|
||||
|
||||
violations[k] if {
|
||||
input.x[k]
|
||||
}
|
||||
query: data.test.violations
|
||||
want_result:
|
||||
BAR: true
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_multiple_bodies_collect_all_keys_v1
|
||||
data: {}
|
||||
input:
|
||||
primary:
|
||||
FOO: 1
|
||||
BAR: 2
|
||||
secondary:
|
||||
BAZ: 3
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] if {
|
||||
some k, _ in input.primary
|
||||
}
|
||||
|
||||
violations[k] if {
|
||||
some k, _ in input.secondary
|
||||
}
|
||||
query: data.test.violations
|
||||
want_result:
|
||||
BAR: true
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: constant_key_implicit_true_rule_is_complete_v1
|
||||
data: {}
|
||||
input:
|
||||
enabled: true
|
||||
other: false
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
p["x"] if {
|
||||
input.enabled
|
||||
}
|
||||
|
||||
p["x"] if {
|
||||
input.other
|
||||
}
|
||||
query: data.test.p.x
|
||||
want_result: true
|
||||
|
||||
- note: partial_object_duplicate_keys_same_value_are_ok_v1
|
||||
data: {}
|
||||
input:
|
||||
arr: ["FOO", "FOO", "BAR"]
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[v] if {
|
||||
some _, v in input.arr
|
||||
}
|
||||
query: data.test.violations
|
||||
want_result:
|
||||
BAR: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_duplicate_keys_different_values_error_v1
|
||||
data: {}
|
||||
input:
|
||||
entries:
|
||||
- k: "FOO"
|
||||
v: 1
|
||||
- k: "FOO"
|
||||
v: 2
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] := v if {
|
||||
some entry in input.entries
|
||||
k := entry.k
|
||||
v := entry.v
|
||||
}
|
||||
query: data.test.violations
|
||||
want_error: "multiple outputs"
|
||||
|
||||
- note: partial_object_and_partial_set_iteration_coexist_v1
|
||||
data: {}
|
||||
input:
|
||||
x:
|
||||
FOO: 1
|
||||
BAR: 2
|
||||
BAZ: 3
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] if {
|
||||
some k, _ in input.x
|
||||
}
|
||||
|
||||
seen contains k if {
|
||||
some k, _ in input.x
|
||||
}
|
||||
|
||||
main := {
|
||||
"seen": seen,
|
||||
"violations": violations,
|
||||
}
|
||||
query: data.test.main
|
||||
want_result:
|
||||
seen:
|
||||
set!: ["BAR", "BAZ", "FOO"]
|
||||
violations:
|
||||
BAR: true
|
||||
BAZ: true
|
||||
FOO: true
|
||||
|
||||
- note: partial_object_key_bound_in_outer_scope_v1
|
||||
data: {}
|
||||
input:
|
||||
outer:
|
||||
FOO: [1, 2]
|
||||
BAR: [3]
|
||||
BAZ: []
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
violations[k] if {
|
||||
some k, arr in input.outer
|
||||
some _ in arr
|
||||
}
|
||||
query: data.test.violations
|
||||
want_result:
|
||||
BAR: true
|
||||
FOO: true
|
||||
|
||||
- note: complete_rule_same_value_definitions_still_work_v1
|
||||
data: {}
|
||||
input:
|
||||
role: "superuser"
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
import rego.v1
|
||||
|
||||
allowed if {
|
||||
input.role == "admin"
|
||||
}
|
||||
|
||||
allowed if {
|
||||
input.role == "superuser"
|
||||
}
|
||||
query: data.test.allowed
|
||||
want_result: true
|
||||
@@ -6,9 +6,9 @@
|
||||
# Covers dynamic keys, collisions, non-string keys, and template validation
|
||||
|
||||
cases:
|
||||
- note: object_key_collision_overwrite
|
||||
description: Setting same key twice should overwrite the value
|
||||
example_rego: "{\"key\": 1, \"key\": 2}"
|
||||
- note: object_key_collision_conflict
|
||||
description: Setting same key twice with different values should raise a rule output conflict
|
||||
example_rego: "p[\"key\"] = value { value := [1, 2][_] }"
|
||||
literals:
|
||||
- {}
|
||||
- "key"
|
||||
@@ -26,9 +26,31 @@ cases:
|
||||
- "Load { dest: 2, literal_idx: 2 }" # value 1
|
||||
- "ObjectSet { obj: 0, key: 1, value: 2 }"
|
||||
- "Load { dest: 3, literal_idx: 3 }" # value 2
|
||||
- "ObjectSet { obj: 0, key: 1, value: 3 }" # Overwrite
|
||||
- "ObjectSet { obj: 0, key: 1, value: 3 }" # Conflict
|
||||
- "Return { value: 0 }"
|
||||
want_result: {"key": 2}
|
||||
want_error: "multiple outputs"
|
||||
|
||||
- note: object_key_duplicate_same_value
|
||||
description: Setting same key twice with the same value should succeed
|
||||
example_rego: "p[\"key\"] := 1 if { some _ in [0, 1] }"
|
||||
literals:
|
||||
- {}
|
||||
- "key"
|
||||
- 1
|
||||
instruction_params:
|
||||
object_create_params:
|
||||
- dest: 0
|
||||
template_literal_idx: 0
|
||||
literal_key_fields: []
|
||||
fields: []
|
||||
instructions:
|
||||
- "ObjectCreate { params_index: 0 }"
|
||||
- "Load { dest: 1, literal_idx: 1 }" # key
|
||||
- "Load { dest: 2, literal_idx: 2 }" # value
|
||||
- "ObjectSet { obj: 0, key: 1, value: 2 }"
|
||||
- "ObjectSet { obj: 0, key: 1, value: 2 }"
|
||||
- "Return { value: 0 }"
|
||||
want_result: {"key": 1}
|
||||
|
||||
- note: object_dynamic_key_generation
|
||||
description: Generate object keys dynamically from loop iteration
|
||||
|
||||
Reference in New Issue
Block a user