Skip to content

Commit cc917ea

Browse files
authored
feat: Complete target system with C# bindings and resource inference (microsoft#458)
* feat: Add Schema Registry and Validation Framework This commit introduces a comprehensive schema registry and validation framework, providing schema-based validation of resources and policy effects. - Thread-safe, in-memory registry for schema storage and management - Global registry patterns for effects and resources - Concurrent access with proper error handling - Unicode schema names support - JSON Schema-compliant validation for all primitive types - Advanced constraint validation (patterns, ranges, length limits) - Discriminated union support with anyOf schemas - Detailed error reporting with nested validation paths - Discriminated subobject validation for polymorphic schemas - **Registry Tests**: All registry operations - **Effect Tests**: Policy effect validation - **Resource Tests**: Resource validation - **Validation Tests**: Core validation engine - Thread-safety, error handling, integration scenarios, edge cases - **Dependencies**: dashmap, once_cell, regex - **Thread Safety**: Minimal locking with Rc<Schema> sharing - **Error Types**: TypeMismatch, OutOfRange, PatternMismatch, etc. - Complete schema registry and validation subsystem - Comprehensive test coverage - Foundation for policy validation in Regorus Benchmarks: - Criterion benchmarks for basic types, effects and Azure resources - Performance range: 3.22ns (string) to 34.74µs (Azure VM resource schema validation) - String withs patterns validation: 30.2µs. Need to explore whether regex caching helps bring this down. - Azure policy effects: 188ns-1.4µs Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> * feat: Complete target system with C# bindings and resource inference - Add comprehensive target system with TargetRegistry and target-aware compilation - Implement resource type inference from policy equality expressions - Create modular C# bindings with separate wrapper classes for each concept - Add thread-safe CompiledPolicy with reference counting for safe disposal - Enhance FFI with detailed error propagation and target functionality - Create TargetExampleApp demonstrating Azure Policy integration - Add CI/CD pipeline testing for all C# applications - Support target definitions with schema validation and resource selectors - Implement PolicyModule struct and target-aware compilation methods - Add comprehensive test coverage for target functionality Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> --------- Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
1 parent 3c33d31 commit cc917ea

71 files changed

Lines changed: 10278 additions & 1000 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-csharp.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,38 @@ jobs:
140140
uses: actions/download-artifact@v4
141141
with:
142142
name: regorus-nuget
143-
path: ./bindings/csharp/Regorus.Tests/regorus-nuget/
143+
path: ./bindings/csharp/regorus-nuget/
144144

145145
- name: Restore Regorus.Tests
146-
run: dotnet restore /p:RestoreAdditionalProjectSources=./regorus-nuget
146+
run: dotnet restore /p:RestoreAdditionalProjectSources=../regorus-nuget
147147
working-directory: ./bindings/csharp/Regorus.Tests
148148

149149
- name: Run Regorus.Tests
150150
run: dotnet test --no-restore
151151
working-directory: ./bindings/csharp/Regorus.Tests
152+
153+
- name: Restore TestApp
154+
run: dotnet restore /p:RestoreAdditionalProjectSources=../regorus-nuget
155+
working-directory: ./bindings/csharp/TestApp
156+
157+
- name: Build TestApp
158+
run: dotnet build --no-restore
159+
working-directory: ./bindings/csharp/TestApp
160+
161+
- name: Run TestApp
162+
run: dotnet run --no-build --framework net8.0
163+
working-directory: ./bindings/csharp/TestApp
164+
165+
- name: Restore TargetExampleApp
166+
run: dotnet restore /p:RestoreAdditionalProjectSources=../regorus-nuget
167+
working-directory: ./bindings/csharp/TargetExampleApp
168+
169+
- name: Build TargetExampleApp
170+
run: dotnet build --no-restore
171+
working-directory: ./bindings/csharp/TargetExampleApp
172+
173+
- name: Run TargetExampleApp
174+
run: dotnet run --no-build --framework net8.0
175+
working-directory: ./bindings/csharp/TargetExampleApp
176+
177+

Cargo.lock

Lines changed: 61 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ anyhow = { version = "1.0.45", default-features = false }
9393
serde = {version = "1.0.150", default-features = false, features = ["derive", "rc"] }
9494
serde_json = { version = "1.0.89", default-features = false, features = ["alloc"] }
9595
lazy_static = { version = "1.4.0", default-features = false }
96+
thiserror = { version = "2.0", default-features = false }
9697

9798
data-encoding = { version = "2.8.0", optional = true, default-features=false, features = ["alloc"] }
9899
scientific = { version = "0.5.3" }

bindings/c-nostd/main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,48 +43,48 @@ int main() {
4343

4444
// Turn on rego v0 since policy uses v0.
4545
r = regorus_engine_set_rego_v0(engine, true);
46-
if (r.status != RegorusStatusOk)
46+
if (r.status != Ok)
4747
goto error;
4848

4949
// Load policies.
5050
r = regorus_engine_add_policy(engine, "framework.rego", (buffer = file_to_string("../../../tests/aci/framework.rego")));
5151
free(buffer);
52-
if (r.status != RegorusStatusOk)
52+
if (r.status != Ok)
5353
goto error;
5454
printf("Loaded package %s\n", r.output);
5555
regorus_result_drop(r);
5656

5757
r = regorus_engine_add_policy(engine, "api.rego", (buffer = file_to_string("../../../tests/aci/api.rego")));
5858
free(buffer);
59-
if (r.status != RegorusStatusOk)
59+
if (r.status != Ok)
6060
goto error;
6161
printf("Loaded package %s\n", r.output);
6262
regorus_result_drop(r);
6363

6464
r = regorus_engine_add_policy(engine, "policy.rego", (buffer = file_to_string("../../../tests/aci/policy.rego")));
6565
free(buffer);
66-
if (r.status != RegorusStatusOk)
66+
if (r.status != Ok)
6767
goto error;
6868
printf("Loaded package %s\n", r.output);
6969
regorus_result_drop(r);
7070

7171
// Add data
7272
r = regorus_engine_add_data_json(engine, (buffer = file_to_string("../../../tests/aci/data.json")));
7373
free(buffer);
74-
if (r.status != RegorusStatusOk)
74+
if (r.status != Ok)
7575
goto error;
7676
regorus_result_drop(r);
7777

7878
// Set input
7979
r = regorus_engine_set_input_json(engine, (buffer = file_to_string("../../../tests/aci/input.json")));
8080
free(buffer);
81-
if (r.status != RegorusStatusOk)
81+
if (r.status != Ok)
8282
goto error;
8383
regorus_result_drop(r);
8484

8585
// Eval rule.
8686
r = regorus_engine_eval_rule(engine, "data.framework.mount_overlay");
87-
if (r.status != RegorusStatusOk)
87+
if (r.status != Ok)
8888
goto error;
8989

9090
// Print output

0 commit comments

Comments
 (0)