mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Compare commits
9 Commits
copilot/co
...
copilot/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
639bfe3246 | ||
|
|
4cc82e2fda | ||
|
|
196b6d68aa | ||
|
|
c65e844f63 | ||
|
|
730e6de75a | ||
|
|
72515f6d4c | ||
|
|
839933c933 | ||
|
|
093e50f0a1 | ||
|
|
47124623ab |
75
CHANGELOG.md
75
CHANGELOG.md
@@ -6,10 +6,85 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.10.0] - 2026-05-05
|
||||
|
||||
### Added
|
||||
|
||||
- *(copilot)* add multi-agent code review skills (#707)
|
||||
- *(azure_policy)* test runner, compiler fixes, and example program (#700)
|
||||
- *(azure-policy)* implement effect compilation and metadata population (#691)
|
||||
- *(azure-policy)* implement count/count.where compilation (#688)
|
||||
- *(azure-policy)* implement condition, expression, field, and template dispatch compilation (#686)
|
||||
- *(azure-policy)* add compiler skeleton with core types and stubs (#674)
|
||||
- *(rvm)* implement Azure Policy condition evaluation (#661)
|
||||
- *(rvm)* new instructions and loop semantics for Azure Policy support (#659)
|
||||
- *(azure-policy)* add policy rule and policy definition parsers (#660)
|
||||
- add Azure Policy constraint parser (#658)
|
||||
- *(rvm)* extend program metadata and bump serialization to v6 (#654)
|
||||
- add Azure Policy core JSON parser and expression parser (#655)
|
||||
- add Azure Policy AST types (#653)
|
||||
- *(azure-policy)* add alias normalization and denormalization (#635)
|
||||
- add Azure Policy builtins with YAML test suite (#630)
|
||||
- make policy length limits configurable per engine (#624)
|
||||
- implement add_extension in Python binding (#596)
|
||||
- *(rbac)* [**breaking**] add Azure RBAC engine, FFI API, and cross-language tests (#577)
|
||||
- Azure RBAC condition interpreter with builtin evaluation coverage and YAML test suite, including quantifier (ForAnyOfAnyValues/ForAllOfAllValues), datetime (DateTimeEquals), IP (IpInRange), GUID (GuidEquals), list (ListContains), and string (StringEquals) semantics.
|
||||
- FFI surface for Azure RBAC condition evaluation (see bindings changelog for language-specific wrappers).
|
||||
|
||||
### Fixed
|
||||
|
||||
- harden regex builtins with compiled-size limit (#705)
|
||||
- *(ci)* skip mimalloc FFI and disable isolation for Miri (#621)
|
||||
|
||||
### Other
|
||||
|
||||
- bump version to 0.10.0 across all bindings
|
||||
- *(deps)* update all Rust dependencies and fix lockfile refresh workflow (#704)
|
||||
- *(deps)* bump com.google.code.gson:gson (#702)
|
||||
- *(deps)* bump the github-actions group across 1 directory with 5 updates (#690)
|
||||
- *(deps)* bump the per-dependency group across 1 directory with 5 updates (#703)
|
||||
- Make `git rev-parse` in `build.rs` optional with graceful fallback (#701)
|
||||
- *(azure_policy)* add foundation test cases (#698)
|
||||
- *(azure_policy)* add end-to-end policy test cases (#699)
|
||||
- fix rand advisory and harden python CI caching (#675)
|
||||
- azure-policy parser: allow overriding the column-width limit (#673)
|
||||
- *(deps)* bump the rust-dependencies group across 5 directories with 6 updates (#671)
|
||||
- *(deps)* bump ruby/setup-ruby in the github-actions group (#670)
|
||||
- *(csharp)* prepare NuGet package for nuget.org publishing (#668)
|
||||
- Fix RVM evaluation of default-only rules (#664)
|
||||
- *(deps)* bump minitest in /bindings/ruby in the per-dependency group (#656)
|
||||
- *(deps)* bump the rust-dependencies group across 2 directories with 3 updates (#657)
|
||||
- consolidate RVM instruction variants and clean up VM internals (#651)
|
||||
- *(deps)* bump wasm-bindgen-test (#650)
|
||||
- *(deps)* bump rb_sys in /bindings/ruby in the per-dependency group (#649)
|
||||
- *(deps)* bump the rust-dependencies group across 3 directories with 4 updates (#647)
|
||||
- *(deps)* bump the github-actions group across 1 directory with 3 updates (#646)
|
||||
- *(dependabot)* restore cargo dependency grouping (#645)
|
||||
- Fix build break (#634)
|
||||
- *(deps)* bump the rust-dependencies group across 5 directories with 16 updates (#633)
|
||||
- *(dependabot)* fix cargo config quoting (#632)
|
||||
- *(dependabot)* fix cargo workspace updates and refresh lockfiles (#629)
|
||||
- *(deps)* bump rubocop in /bindings/ruby in the per-dependency group (#622)
|
||||
- *(deps)* bump the github-actions group with 11 updates (#628)
|
||||
- Consolidate Dependabot, fix #595 (mimalloc + indexmap), add feature-matrix CI (#627)
|
||||
- RVM compiler & runtime optimizations: caching, instruction fusion, constant hoisting, and correctness fixes (#626)
|
||||
- Rvm optimizations (#620)
|
||||
- *(deps)* bump rubocop in /bindings/ruby in the per-dependency group (#618)
|
||||
- *(ci)* add miri workflow (#581)
|
||||
- *(ci)* add cargo audit and deny (#580)
|
||||
- switch binary serialization to postcard (#582)
|
||||
- *(deps-dev)* bump org.apache.maven.plugins:maven-surefire-plugin (#605)
|
||||
- *(deps)* bump bytes (#569)
|
||||
- *(deps)* bump the per-dependency group with 2 updates (#603)
|
||||
- *(deps)* bump the per-dependency group across 1 directory with 3 updates (#607)
|
||||
- boolean mapping (#612)
|
||||
- Bump the per-dependency group with 1 update (#587)
|
||||
- *(deps)* bump the per-dependency group (#585)
|
||||
- *(deps)* bump the per-dependency group (#586)
|
||||
- *(deps-dev)* bump the per-dependency group (#583)
|
||||
- *(deps)* bump the per-dependency group with 12 updates (#593)
|
||||
- *(dependabot)* expand coverage and pin workflows (#579)
|
||||
|
||||
### Changed
|
||||
- [**breaking**] Switch RVM binary serialization to postcard, bump the format to v4, and mark v1-3 loads as partial (recompile required).
|
||||
|
||||
|
||||
59
Cargo.lock
generated
59
Cargo.lock
generated
@@ -474,9 +474,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.17.0"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -653,6 +653,9 @@ 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"
|
||||
@@ -866,9 +869,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.97"
|
||||
version = "0.3.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -878,9 +881,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -947,9 +950,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.16.4"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -957,6 +960,12 @@ 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"
|
||||
@@ -1344,14 +1353,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -1388,7 +1399,7 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
||||
|
||||
[[package]]
|
||||
name = "regorus"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cfg-if",
|
||||
@@ -1399,7 +1410,7 @@ dependencies = [
|
||||
"dashmap",
|
||||
"data-encoding",
|
||||
"globset",
|
||||
"hashbrown 0.16.1",
|
||||
"hashbrown 0.17.0",
|
||||
"icu_casemap",
|
||||
"indexmap",
|
||||
"ipnet",
|
||||
@@ -1545,9 +1556,9 @@ checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1830,9 +1841,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1843,9 +1854,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
dependencies = [
|
||||
"quote 1.0.45",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1853,9 +1864,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2 1.0.106",
|
||||
@@ -1866,9 +1877,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@@ -1909,9 +1920,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.97"
|
||||
version = "0.3.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2eadbac71025cd7b0834f20d1fe8472e8495821b4e9801eb0a60bd1f19827602"
|
||||
checksum = "4b572dff8bcf38bad0fa19729c89bb5748b2b9b1d8be70cf90df697e3a8f32aa"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
|
||||
@@ -8,7 +8,7 @@ members = [
|
||||
[package]
|
||||
name = "regorus"
|
||||
description = "A fast, lightweight Rego (OPA policy language) interpreter"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
edition = "2021"
|
||||
license = "MIT AND Apache-2.0 AND BSD-3-Clause"
|
||||
repository = "https://github.com/microsoft/regorus"
|
||||
@@ -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.16", default-features = false, features = ["default-hasher"], optional = true }
|
||||
hashbrown = { version = "0.17", 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.45.1", default-features = false, optional = true }
|
||||
jsonschema = { version = "0.46.4", 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.16", default-features = false, optional = true }
|
||||
lru = { version = "0.18", default-features = false, optional = true }
|
||||
mimalloc = { package = "regorus-mimalloc", path = "mimalloc", version = "2.2.6", optional = true }
|
||||
|
||||
# rvm related deps
|
||||
|
||||
@@ -80,6 +80,10 @@ 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));
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- If the environment variable is set (such as in a Github Action run), append the suffix to the version number -->
|
||||
<RegorusPackageVersionSuffix Condition="'$(VersionSuffix)' != ''">-$(VersionSuffix)</RegorusPackageVersionSuffix>
|
||||
<UsePackageReference Condition="'$(UsePackageReference)' == ''">false</UsePackageReference>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
<RegorusPackageVersion>0.9.1</RegorusPackageVersion>
|
||||
<RegorusPackageVersion>0.10.0</RegorusPackageVersion>
|
||||
<RegorusPackageVersionSuffix Condition="'$(VersionSuffix)' != ''">-$(VersionSuffix)</RegorusPackageVersionSuffix>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- If the environment variable is set (such as in a Github Action run), append the suffix to the version number -->
|
||||
<RegorusPackageVersionSuffix Condition="'$(VersionSuffix)' != ''">-$(VersionSuffix)</RegorusPackageVersionSuffix>
|
||||
<UsePackageReference Condition="'$(UsePackageReference)' == ''">false</UsePackageReference>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -68,6 +68,18 @@ 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,6 +92,12 @@ 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>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<LangVersion>10.0</LangVersion>
|
||||
|
||||
<!-- See https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-pack -->
|
||||
<VersionPrefix>0.9.1</VersionPrefix>
|
||||
<VersionPrefix>$(RegorusPackageVersion)</VersionPrefix>
|
||||
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageLicenseExpression>MIT AND Apache-2.0 AND BSD-3-Clause</PackageLicenseExpression>
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- If the environment variable is set (such as in a Github Action run), append the suffix to the version number -->
|
||||
<RegorusPackageVersionSuffix Condition="'$(VersionSuffix)' != ''">-$(VersionSuffix)</RegorusPackageVersionSuffix>
|
||||
<UsePackageReference Condition="'$(UsePackageReference)' == ''">false</UsePackageReference>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Allow CI to append the version suffix for locally built packages -->
|
||||
<RegorusPackageVersionSuffix Condition="'$(VersionSuffix)' != ''">-$(VersionSuffix)</RegorusPackageVersionSuffix>
|
||||
<UsePackageReference Condition="'$(UsePackageReference)' == ''">false</UsePackageReference>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
57
bindings/ffi/Cargo.lock
generated
57
bindings/ffi/Cargo.lock
generated
@@ -353,9 +353,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.17.0"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -511,6 +511,9 @@ 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"
|
||||
@@ -709,9 +712,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.97"
|
||||
version = "0.3.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -721,9 +724,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -793,9 +796,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.16.4"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -803,6 +806,12 @@ 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"
|
||||
@@ -1073,14 +1082,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -1117,7 +1128,7 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
||||
|
||||
[[package]]
|
||||
name = "regorus"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@@ -1125,7 +1136,7 @@ dependencies = [
|
||||
"dashmap",
|
||||
"data-encoding",
|
||||
"globset",
|
||||
"hashbrown 0.16.1",
|
||||
"hashbrown 0.17.0",
|
||||
"icu_casemap",
|
||||
"indexmap",
|
||||
"ipnet",
|
||||
@@ -1152,7 +1163,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regorus-ffi"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cbindgen",
|
||||
@@ -1285,9 +1296,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1524,9 +1535,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1537,9 +1548,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1547,9 +1558,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -1560,9 +1571,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[package]
|
||||
name = "regorus-ffi"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
edition = "2021"
|
||||
license = "MIT AND Apache-2.0 AND BSD-3-Clause"
|
||||
|
||||
|
||||
@@ -199,6 +199,21 @@ 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,6 +28,17 @@ 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)
|
||||
|
||||
52
bindings/java/Cargo.lock
generated
52
bindings/java/Cargo.lock
generated
@@ -237,9 +237,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.17.0"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -598,9 +598,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.97"
|
||||
version = "0.3.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -610,9 +610,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -676,9 +676,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.16.4"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -686,6 +686,12 @@ 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"
|
||||
@@ -948,14 +954,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -992,7 +1000,7 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
||||
|
||||
[[package]]
|
||||
name = "regorus"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@@ -1024,7 +1032,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regorus-java"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"jni",
|
||||
@@ -1168,9 +1176,9 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1352,9 +1360,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1365,9 +1373,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1375,9 +1383,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -1388,9 +1396,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[package]
|
||||
name = "regorus-java"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
edition = "2021"
|
||||
repository = "https://github.com/microsoft/regorus/bindings/java"
|
||||
description = "Java bindings for Regorus - a fast, lightweight Rego interpreter written in Rust"
|
||||
|
||||
@@ -23,6 +23,14 @@ 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
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<groupId>com.microsoft.regorus</groupId>
|
||||
<artifactId>regorus-java</artifactId>
|
||||
<version>0.9.1</version>
|
||||
<version>0.10.0</version>
|
||||
|
||||
<name>Regorus Java</name>
|
||||
<description>Java bindings for Regorus - a fast, lightweight Rego interpreter written in Rust</description>
|
||||
|
||||
@@ -27,13 +27,30 @@ 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 engine = unsafe { &mut *(engine_ptr as *mut Engine) };
|
||||
let c = engine.clone();
|
||||
Box::into_raw(Box::new(c)) as 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(())
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -437,6 +454,9 @@ 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);
|
||||
}
|
||||
@@ -816,6 +836,13 @@ 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,6 +21,7 @@ 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);
|
||||
@@ -45,7 +46,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 final long enginePtr;
|
||||
private long enginePtr;
|
||||
|
||||
/**
|
||||
* Creates a new Regorus Engine.
|
||||
@@ -63,7 +64,15 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* Efficiently clones an Engine.
|
||||
*/
|
||||
public Engine clone() {
|
||||
return new Engine(nativeClone(enginePtr));
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +82,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public void setRegoV0(boolean enable) {
|
||||
nativeSetRegoV0(enginePtr, enable);
|
||||
nativeSetRegoV0(requireOpen(), enable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +94,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return Rego package defined in the policy.
|
||||
*/
|
||||
public String addPolicy(String filename, String rego) {
|
||||
return nativeAddPolicy(enginePtr, filename, rego);
|
||||
return nativeAddPolicy(requireOpen(), filename, rego);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,7 +105,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return Rego package defined in the policy.
|
||||
*/
|
||||
public String addPolicyFromFile(String path) {
|
||||
return nativeAddPolicyFromFile(enginePtr, path);
|
||||
return nativeAddPolicyFromFile(requireOpen(), path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +114,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return List of Rego packages as a JSON array of strings.
|
||||
*/
|
||||
public String getPackages() {
|
||||
return nativeGetPackages(enginePtr);
|
||||
return nativeGetPackages(requireOpen());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,14 +123,14 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return List of Rego policies as a JSON array of sources.
|
||||
*/
|
||||
public String getPolicies() {
|
||||
return nativeGetPolicies(enginePtr);
|
||||
return nativeGetPolicies(requireOpen());
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the data document.
|
||||
*/
|
||||
public void clearData() {
|
||||
nativeClearData(enginePtr);
|
||||
nativeClearData(requireOpen());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,7 +152,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @param data Inline data document.
|
||||
*/
|
||||
public void addDataJson(String data) throws RuntimeException {
|
||||
nativeAddDataJson(enginePtr, data);
|
||||
nativeAddDataJson(requireOpen(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +169,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @param path Path to JSON data document.
|
||||
*/
|
||||
public void addDataJsonFromFile(String path) throws RuntimeException {
|
||||
nativeAddDataJsonFromFile(enginePtr, path);
|
||||
nativeAddDataJsonFromFile(requireOpen(), path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +178,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @param input inline JSON input.
|
||||
*/
|
||||
public void setInputJson(String input) {
|
||||
nativeSetInputJson(enginePtr, input);
|
||||
nativeSetInputJson(requireOpen(), input);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +187,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @param path Path to JSON input.
|
||||
*/
|
||||
public void setInputJsonFromFile(String path) {
|
||||
nativeSetInputJsonFromFile(enginePtr, path);
|
||||
nativeSetInputJsonFromFile(requireOpen(), path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,7 +198,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return Query results as a JSON string.
|
||||
*/
|
||||
public String evalQuery(String query) {
|
||||
return nativeEvalQuery(enginePtr, query);
|
||||
return nativeEvalQuery(requireOpen(), query);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,7 +209,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @return Value of the rule as a JSON string.
|
||||
*/
|
||||
public String evalRule(String rule) {
|
||||
return nativeEvalRule(enginePtr, rule);
|
||||
return nativeEvalRule(requireOpen(), rule);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +219,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public void setEnableCoverage(boolean enable) {
|
||||
nativeSetEnableCoverage(enginePtr, enable);
|
||||
nativeSetEnableCoverage(requireOpen(), enable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +227,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public void clearCoverageData() {
|
||||
nativeClearCoverageData(enginePtr);
|
||||
nativeClearCoverageData(requireOpen());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,7 +237,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public String getCoverageReport() {
|
||||
return nativeGetCoverageReport(enginePtr);
|
||||
return nativeGetCoverageReport(requireOpen());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +247,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public String getCoverageReportPretty() {
|
||||
return nativeGetCoverageReportPretty(enginePtr);
|
||||
return nativeGetCoverageReportPretty(requireOpen());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,7 +257,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public void setGatherPrints(boolean b) {
|
||||
nativeSetGatherPrints(enginePtr, b);
|
||||
nativeSetGatherPrints(requireOpen(), b);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,7 +267,7 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
*
|
||||
*/
|
||||
public String takePrints() {
|
||||
return nativeTakePrints(enginePtr);
|
||||
return nativeTakePrints(requireOpen());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,24 +276,34 @@ public class Engine implements AutoCloseable, Cloneable {
|
||||
* @param config Policy length configuration.
|
||||
*/
|
||||
public void setPolicyLengthConfig(PolicyLengthConfig config) {
|
||||
nativeSetPolicyLengthConfig(enginePtr, config.maxCol, config.maxFileBytes, config.maxLines);
|
||||
nativeSetPolicyLengthConfig(requireOpen(), config.maxCol, config.maxFileBytes, config.maxLines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the policy length configuration, reverting to defaults.
|
||||
*/
|
||||
public void clearPolicyLengthConfig() {
|
||||
nativeClearPolicyLengthConfig(enginePtr);
|
||||
nativeClearPolicyLengthConfig(requireOpen());
|
||||
}
|
||||
|
||||
long getPtr() {
|
||||
return requireOpen();
|
||||
}
|
||||
|
||||
private long requireOpen() {
|
||||
if (enginePtr == 0) {
|
||||
throw new IllegalStateException("Engine is closed");
|
||||
}
|
||||
return enginePtr;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
nativeDestroyEngine(enginePtr);
|
||||
if (enginePtr != 0) {
|
||||
nativeDestroyEngine(enginePtr);
|
||||
enginePtr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Loading native library from JAR is adapted from:
|
||||
|
||||
@@ -22,8 +22,19 @@ 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();
|
||||
@@ -33,4 +44,28 @@ 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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
52
bindings/python/Cargo.lock
generated
52
bindings/python/Cargo.lock
generated
@@ -221,9 +221,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.17.0"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -533,9 +533,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.97"
|
||||
version = "0.3.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -545,9 +545,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -611,9 +611,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.16.4"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -621,6 +621,12 @@ 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"
|
||||
@@ -957,14 +963,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -1001,7 +1009,7 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
||||
|
||||
[[package]]
|
||||
name = "regorus"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@@ -1047,7 +1055,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regoruspy"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"ordered-float",
|
||||
@@ -1144,9 +1152,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1324,9 +1332,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1337,9 +1345,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1347,9 +1355,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -1360,9 +1368,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[package]
|
||||
name = "regoruspy"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
edition = "2021"
|
||||
repository = "https://github.com/microsoft/regorus/bindings/python"
|
||||
description = "Python bindings for Regorus - a fast, lightweight Rego interpreter written in Rust"
|
||||
|
||||
@@ -463,6 +463,13 @@ 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,6 +87,7 @@ report = engine.get_coverage_report_pretty()
|
||||
print(report)
|
||||
|
||||
# Clone engine
|
||||
engine.prepare()
|
||||
engine1 = engine.clone()
|
||||
|
||||
|
||||
|
||||
60
bindings/ruby/Cargo.lock
generated
60
bindings/ruby/Cargo.lock
generated
@@ -244,9 +244,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.17.0"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -571,9 +571,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.97"
|
||||
version = "0.3.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -583,9 +583,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -659,9 +659,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.16.4"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
|
||||
[[package]]
|
||||
name = "magnus"
|
||||
@@ -692,6 +692,12 @@ 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"
|
||||
@@ -929,18 +935,18 @@ checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
||||
|
||||
[[package]]
|
||||
name = "rb-sys"
|
||||
version = "0.9.127"
|
||||
version = "0.9.128"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7d7c9560fe42dcffa576941394075f18a17dce89fcf718a2fa90b7dc2134d12"
|
||||
checksum = "45ca28513560e56cfb79a62b1fce363c73af170a182024ce880c77ee9429920a"
|
||||
dependencies = [
|
||||
"rb-sys-build",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rb-sys-build"
|
||||
version = "0.9.127"
|
||||
version = "0.9.128"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1688e8f32967ba48c89e4dfa283b57f901075f542fc7ee9c3d7c5f9091ca1d9"
|
||||
checksum = "ce04b2c55eff3a21aaa623fcc655d94373238e72cac6b3e1a3641ff31649f99a"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"lazy_static",
|
||||
@@ -988,14 +994,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -1032,7 +1040,7 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
||||
|
||||
[[package]]
|
||||
name = "regorus"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@@ -1077,7 +1085,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regorusrb"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"magnus",
|
||||
"regorus",
|
||||
@@ -1203,9 +1211,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1383,9 +1391,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1396,9 +1404,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1406,9 +1414,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -1419,9 +1427,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "regorusrb"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
edition = "2024"
|
||||
description = "Ruby bindings for Regorus - a fast, lightweight Rego interpreter written in Rust"
|
||||
license = "MIT AND Apache-2.0 AND BSD-3-Clause"
|
||||
|
||||
@@ -115,6 +115,13 @@ 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()
|
||||
@@ -373,6 +380,7 @@ 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))?;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Regorus
|
||||
VERSION = "0.9.1"
|
||||
VERSION = "0.10.0"
|
||||
end
|
||||
|
||||
@@ -150,6 +150,7 @@ class TestRegorus < Minitest::Test
|
||||
end
|
||||
|
||||
def test_engine_cloning
|
||||
@engine.prepare
|
||||
cloned_engine = @engine.clone
|
||||
|
||||
assert_instance_of ::Regorus::Engine, cloned_engine
|
||||
|
||||
68
bindings/wasm/Cargo.lock
generated
68
bindings/wasm/Cargo.lock
generated
@@ -238,9 +238,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.17.0"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8"
|
||||
checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
@@ -565,9 +565,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.97"
|
||||
version = "0.3.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf"
|
||||
checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -577,9 +577,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "257eb0e588b76827bbddc9e73945a9743693dd2adeaee9da26420f93cfedb798"
|
||||
checksum = "fc59d2432e047d6090ba1d83c782d0128bd6203857978218f5614dbd3287281f"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytecount",
|
||||
@@ -649,9 +649,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.16.4"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -659,6 +659,12 @@ 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"
|
||||
@@ -947,14 +953,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.45.1"
|
||||
version = "0.46.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2f38748ceca8d0b0013e60f534d94a6e23dfd89fd2a88318fc5a2d04fda1010"
|
||||
checksum = "cb674900ca31acd75c4aaf63f48e43e719631c0539ea5a9e64163d1296bcb730"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"getrandom 0.3.4",
|
||||
"hashbrown 0.16.1",
|
||||
"itoa",
|
||||
"micromap",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
@@ -991,7 +999,7 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
||||
|
||||
[[package]]
|
||||
name = "regorus"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@@ -1022,7 +1030,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regorusjs"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"getrandom 0.2.17",
|
||||
"getrandom 0.3.4",
|
||||
@@ -1144,9 +1152,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
|
||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
@@ -1336,9 +1344,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1"
|
||||
checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -1349,9 +1357,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.70"
|
||||
version = "0.4.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af934872acec734c2d80e6617bbb5ff4f12b052dd8e6332b0817bce889516084"
|
||||
checksum = "96492d0d3ffba25305a7dc88720d250b1401d7edca02cc3bcd50633b424673b8"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
@@ -1359,9 +1367,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103"
|
||||
checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1369,9 +1377,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41"
|
||||
checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -1382,18 +1390,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea"
|
||||
checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-test"
|
||||
version = "0.3.70"
|
||||
version = "0.3.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29826f9d9ecaa314c480d376b276d1c790e6cb6a4681fab8532da69cbabf977d"
|
||||
checksum = "af5ec93229ad9ccd0a545a516dec76dc276613f278f6a91aa6b463d5b33d42d0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"cast",
|
||||
@@ -1413,9 +1421,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-test-macro"
|
||||
version = "0.3.70"
|
||||
version = "0.3.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c610311887f9e6599a546d278d12d69dfd3a3e92639b2129e4b11ad6cf1961d6"
|
||||
checksum = "3c81b9fef827e575e0e54431736d1baa0d700315d8c62cfef1f61fa3aad0cbeb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -1424,9 +1432,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-test-shared"
|
||||
version = "0.2.120"
|
||||
version = "0.2.121"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60238e5b4b1b295701d6f9a66d2a126fe19990348f5fb9dae3b623a370119d94"
|
||||
checksum = "4f4d8ae7ad5440360e9799dfd42857d126454a88441ddf72d288ef83fa47f527"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[package]
|
||||
name = "regorusjs"
|
||||
version = "0.9.1"
|
||||
version = "0.10.0"
|
||||
edition = "2021"
|
||||
repository = "https://github.com/microsoft/regorus/bindings/wasm"
|
||||
description = "WASM bindings for Regorus - a fast, lightweight Rego interpreter written in Rust"
|
||||
@@ -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.67"
|
||||
wasm-bindgen-test = "0.3.71"
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }
|
||||
|
||||
@@ -21,3 +21,9 @@ 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,6 +138,17 @@ 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.
|
||||
@@ -158,6 +169,20 @@ 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
|
||||
@@ -487,6 +512,9 @@ 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,6 +40,13 @@ 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,6 +505,47 @@ 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
|
||||
@@ -1084,9 +1125,10 @@ 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 !self.prepared {
|
||||
if newly_prepared {
|
||||
// Analyze the modules and determine how statements must be scheduled.
|
||||
let analyzer = Analyzer::new();
|
||||
let schedule = Rc::new(analyzer.analyze(&self.modules)?);
|
||||
@@ -1116,23 +1158,28 @@ 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
|
||||
// Resolve and validate target specifications across all modules.
|
||||
// This must run for target-aware compilation even if generic prepare()
|
||||
// was already called.
|
||||
crate::interpreter::target::resolve::resolve_and_apply_target(
|
||||
&mut self.interpreter,
|
||||
)?;
|
||||
// Infer resource types
|
||||
crate::interpreter::target::infer::infer_resource_type(&mut self.interpreter)?;
|
||||
}
|
||||
|
||||
if !for_target {
|
||||
// Check if any module specifies a target and warn if so
|
||||
#[cfg(feature = "azure_policy")]
|
||||
} else if newly_prepared {
|
||||
// Check if any module specifies a target and warn if so.
|
||||
self.warn_if_targets_present();
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "azure_policy"))]
|
||||
let _ = for_target;
|
||||
|
||||
if newly_prepared {
|
||||
self.prepared = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,135 @@ 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")))]
|
||||
|
||||
@@ -124,7 +124,7 @@ struct Binding {
|
||||
manifest: Option<&'static str>,
|
||||
ruby_version: Option<&'static str>,
|
||||
pom_xml: Option<&'static str>,
|
||||
csharp_project: Option<&'static str>,
|
||||
csharp_version_file: Option<&'static str>,
|
||||
csharp_dependents: &'static [&'static str],
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ const BINDINGS: &[Binding] = &[
|
||||
manifest: Some("bindings/ffi/Cargo.toml"),
|
||||
ruby_version: None,
|
||||
pom_xml: None,
|
||||
csharp_project: None,
|
||||
csharp_version_file: None,
|
||||
csharp_dependents: EMPTY,
|
||||
},
|
||||
Binding {
|
||||
@@ -148,7 +148,7 @@ const BINDINGS: &[Binding] = &[
|
||||
manifest: Some("bindings/java/Cargo.toml"),
|
||||
ruby_version: None,
|
||||
pom_xml: Some("bindings/java/pom.xml"),
|
||||
csharp_project: None,
|
||||
csharp_version_file: None,
|
||||
csharp_dependents: EMPTY,
|
||||
},
|
||||
Binding {
|
||||
@@ -157,7 +157,7 @@ const BINDINGS: &[Binding] = &[
|
||||
manifest: Some("bindings/python/Cargo.toml"),
|
||||
ruby_version: None,
|
||||
pom_xml: None,
|
||||
csharp_project: None,
|
||||
csharp_version_file: None,
|
||||
csharp_dependents: EMPTY,
|
||||
},
|
||||
Binding {
|
||||
@@ -166,7 +166,7 @@ const BINDINGS: &[Binding] = &[
|
||||
manifest: Some("bindings/wasm/Cargo.toml"),
|
||||
ruby_version: None,
|
||||
pom_xml: None,
|
||||
csharp_project: None,
|
||||
csharp_version_file: None,
|
||||
csharp_dependents: EMPTY,
|
||||
},
|
||||
Binding {
|
||||
@@ -175,7 +175,7 @@ const BINDINGS: &[Binding] = &[
|
||||
manifest: Some("bindings/ruby/ext/regorusrb/Cargo.toml"),
|
||||
ruby_version: Some("bindings/ruby/lib/regorus/version.rb"),
|
||||
pom_xml: None,
|
||||
csharp_project: None,
|
||||
csharp_version_file: None,
|
||||
csharp_dependents: EMPTY,
|
||||
},
|
||||
Binding {
|
||||
@@ -184,14 +184,8 @@ const BINDINGS: &[Binding] = &[
|
||||
manifest: None,
|
||||
ruby_version: None,
|
||||
pom_xml: None,
|
||||
csharp_project: Some("bindings/csharp/Regorus/Regorus.csproj"),
|
||||
csharp_dependents: &[
|
||||
"bindings/csharp/Directory.Packages.props",
|
||||
"bindings/csharp/Regorus.Tests/Regorus.Tests.csproj",
|
||||
"bindings/csharp/Benchmarks/Benchmarks.csproj",
|
||||
"bindings/csharp/TargetExampleApp/TargetExampleApp.csproj",
|
||||
"bindings/csharp/TestApp/TestApp.csproj",
|
||||
],
|
||||
csharp_version_file: Some("bindings/csharp/Directory.Packages.props"),
|
||||
csharp_dependents: EMPTY,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -335,7 +329,7 @@ fn read_binding_version(root: &Path, binding: &Binding) -> Result<Version> {
|
||||
if let Some(manifest) = binding.manifest {
|
||||
return read_manifest_version(&root.join(manifest));
|
||||
}
|
||||
if let Some(project) = binding.csharp_project {
|
||||
if let Some(project) = binding.csharp_version_file {
|
||||
return read_csharp_version(root.join(project));
|
||||
}
|
||||
bail!("binding '{}' missing version source", binding.name)
|
||||
@@ -357,13 +351,18 @@ fn read_manifest_version(path: &Path) -> Result<Version> {
|
||||
fn read_csharp_version(path: PathBuf) -> Result<Version> {
|
||||
let contents =
|
||||
fs::read_to_string(&path).with_context(|| format!("failed to read {}", path.display()))?;
|
||||
let re = Regex::new(r#"(?s)<VersionPrefix>(?P<value>[^<]+)</VersionPrefix>"#)?;
|
||||
let re = Regex::new(r#"(?s)<RegorusPackageVersion>(?P<value>[^<]+)</RegorusPackageVersion>"#)?;
|
||||
let caps = re
|
||||
.captures(&contents)
|
||||
.ok_or_else(|| anyhow!("{} missing <VersionPrefix> entry", path.display()))?;
|
||||
let version = caps.name("value").unwrap().as_str();
|
||||
Version::parse(version)
|
||||
.with_context(|| format!("invalid VersionPrefix '{}' in {}", version, path.display()))
|
||||
.ok_or_else(|| anyhow!("{} missing <RegorusPackageVersion> entry", path.display()))?;
|
||||
let version = caps.name("value").unwrap().as_str().trim();
|
||||
Version::parse(version).with_context(|| {
|
||||
format!(
|
||||
"invalid RegorusPackageVersion '{}' in {}",
|
||||
version,
|
||||
path.display()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// Calculates the version to write, bumping the minor release when the binding
|
||||
@@ -420,8 +419,8 @@ fn apply_binding_version(
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(project) = binding.csharp_project {
|
||||
touched.extend(update_csharp_projects(
|
||||
if let Some(project) = binding.csharp_version_file {
|
||||
touched.extend(update_csharp_version_files(
|
||||
root,
|
||||
project,
|
||||
binding.csharp_dependents,
|
||||
@@ -502,60 +501,55 @@ fn update_java_pom(root: &Path, pom_path: &str, version: &str, check: bool) -> R
|
||||
}
|
||||
|
||||
/// Updates the NuGet packaging project and any sample/test consumers.
|
||||
fn update_csharp_projects(
|
||||
fn update_csharp_version_files(
|
||||
root: &Path,
|
||||
package_project: &str,
|
||||
version_file: &str,
|
||||
dependent_projects: &[&str],
|
||||
version: &str,
|
||||
check: bool,
|
||||
) -> Result<Vec<String>> {
|
||||
let mut touched = Vec::new();
|
||||
let version_prefix = Regex::new(
|
||||
r#"(?s)(?P<prefix><VersionPrefix>)(?P<value>[^<]+)(?P<suffix></VersionPrefix>)"#,
|
||||
)?;
|
||||
let pkg_ref = Regex::new(
|
||||
r#"(?i)(?P<prefix><Package(?:Reference|Version)[^>]*Include="microsoft\.regorus"[^>]*Version=")(?P<value>\d+\.\d+\.\d+)(?P<suffix>[^\"]*")"#,
|
||||
let version_prop = Regex::new(
|
||||
r#"(?s)(?P<prefix><RegorusPackageVersion>)(?P<value>[^<]+)(?P<suffix></RegorusPackageVersion>)"#,
|
||||
)?;
|
||||
|
||||
let package_path = root.join(package_project);
|
||||
let package_path = root.join(version_file);
|
||||
if !version_prop.is_match(
|
||||
&fs::read_to_string(&package_path)
|
||||
.with_context(|| format!("failed to read {}", package_path.display()))?,
|
||||
) {
|
||||
anyhow::bail!(
|
||||
"{} missing <RegorusPackageVersion> entry",
|
||||
package_path.display()
|
||||
);
|
||||
}
|
||||
if edit_file(&package_path, check, |contents| {
|
||||
let mut changed = false;
|
||||
let mut new_contents = contents.to_owned();
|
||||
let new_contents = version_prop
|
||||
.replace(contents, |caps: ®ex::Captures| {
|
||||
let current = caps.name("value").unwrap().as_str().trim();
|
||||
if current == version {
|
||||
caps[0].to_string()
|
||||
} else {
|
||||
changed = true;
|
||||
format!("{}{}{}", &caps["prefix"], version, &caps["suffix"])
|
||||
}
|
||||
})
|
||||
.into_owned();
|
||||
|
||||
if version_prefix.is_match(&new_contents) {
|
||||
new_contents = version_prefix
|
||||
.replace(&new_contents, |caps: ®ex::Captures| {
|
||||
let current = caps.name("value").unwrap().as_str();
|
||||
if current == version {
|
||||
caps[0].to_string()
|
||||
} else {
|
||||
changed = true;
|
||||
format!("{}{}{}", &caps["prefix"], version, &caps["suffix"])
|
||||
}
|
||||
})
|
||||
.into_owned();
|
||||
}
|
||||
|
||||
let replaced = pkg_ref.replace_all(&new_contents, |caps: ®ex::Captures| {
|
||||
let current = caps.name("value").unwrap().as_str();
|
||||
if current == version {
|
||||
caps[0].to_string()
|
||||
} else {
|
||||
changed = true;
|
||||
format!("{}{}{}", &caps["prefix"], version, &caps["suffix"])
|
||||
}
|
||||
});
|
||||
let final_contents = replaced.into_owned();
|
||||
|
||||
if changed && final_contents != *contents {
|
||||
Ok(Some(final_contents))
|
||||
if changed && new_contents != *contents {
|
||||
Ok(Some(new_contents))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
})? {
|
||||
touched.push(package_project.to_string());
|
||||
touched.push(version_file.to_string());
|
||||
}
|
||||
|
||||
let pkg_ref = Regex::new(
|
||||
r#"(?i)(?P<prefix><Package(?:Reference|Version)[^>]*Include="microsoft\.regorus"[^>]*Version=")(?P<value>\d+\.\d+\.\d+)(?P<suffix>[^\"]*")"#,
|
||||
)?;
|
||||
|
||||
for rel_path in dependent_projects {
|
||||
let path = root.join(rel_path);
|
||||
if edit_file(&path, check, |contents| {
|
||||
|
||||
Reference in New Issue
Block a user