-
Notifications
You must be signed in to change notification settings - Fork 0
09 CLI and Policy Lifecycle
The RuleGate CLI turns policy work into a repeatable development and CI workflow.
flowchart LR
A[Edit rulegate.yaml] --> B[validate]
B --> C[lint]
C --> D[test fixtures]
D --> E[explain selected failures]
E --> F[generate C# and TypeScript]
F --> G[check generated output]
G --> H[Build and integration tests]
dotnet new tool-manifest
dotnet tool install Fotbiler.RuleGate.Cli --version 1.0.0
dotnet tool run rulegate infoThe examples below use rulegate for readability. Replace it with
dotnet tool run rulegate for a local tool manifest.
rulegate validate
rulegate validate ./policies/rulegate.yaml
rulegate validate ./policies/rulegate.yaml --format jsonValidation checks YAML loading, schema, policy IDs/routes, every requirement, typed value/operator compatibility, logical structure, time/context rules, and resource limits. Invalid input activates nothing.
Use JSON fields and exit codes in automation; do not parse human-readable text.
rulegate generate csharp \
./rulegate.yaml \
--namespace DocumentService.Authorization \
--output Generated/RuleGate.g.csCheck committed output without modifying files:
rulegate generate csharp \
./rulegate.yaml \
--namespace DocumentService.Authorization \
--output Generated/RuleGate.g.cs \
--checkUse generated identifiers instead of repeating strings in backend code. Generation is deterministic, sorts identifiers, detects name collisions, and writes atomically.
pnpm exec rulegate-angular generate \
./rulegate.yaml \
--output ./src/app/generated/rulegate.tspnpm exec rulegate-angular generate \
./rulegate.yaml \
--output ./src/app/generated/rulegate.ts \
--checkC# and TypeScript generation reduce string drift. They do not authorize a user and do not replace manifest validation.
Create authorization.tests.yaml:
schemaVersion: 1
manifest: rulegate.yaml
tests:
- id: reader-is-allowed
request:
subject:
id: alice
permissions: [DOC.READ]
resource:
type: document
id: doc-1
action: read
context:
evaluationTime: '2026-08-01T09:00:00+03:00'
expect:
outcome: allow
- id: missing-permission-is-denied
request:
subject:
id: bob
resource:
type: document
id: doc-1
action: read
context:
evaluationTime: '2026-08-01T09:00:00+03:00'
expect:
outcome: deny
failureCodes:
- RULEGATE_MISSING_PERMISSION
- RULEGATE_MISSING_ROLERun:
rulegate test
rulegate test authorization.tests.yaml --filter organization
rulegate test authorization.tests.yaml --format jsonEvery test supplies explicit subject, resource, action, evaluation time, and optional typed attributes. Fixed time keeps time/MFA tests deterministic.
Typed fixture attributes use entries:
attributes:
- name: organizationId
valueType: string
value: records
- name: clearanceLevel
valueType: number
value: '4'
- name: trustedDevice
valueType: boolean
value: 'true'
- name: groups
valueType: stringCollection
values: [records, legal]
- name: archivedAt
valueType: nullValueAdd tests for allow, deny, indeterminate, no matching policy, exact casing, missing data, wrong types, logical branches, boundary times, ownership, organization, and context.
rulegate explain \
authorization.tests.yaml \
--test missing-permission-is-deniedJSON mode:
rulegate explain \
authorization.tests.yaml \
--test missing-permission-is-denied \
--format jsonExplanation uses the runtime evaluator and reports outcome, stable failure codes, and the evaluated requirement tree. It omits subject/resource IDs, roles, permissions, attribute values, policy literals, descriptions, random IDs, and durations. Do not expose CLI explanations directly to untrusted HTTP clients.
rulegate lint rulegate.yaml
rulegate lint rulegate.yaml --format jsonLint detects duplicate or contradictory requirements, absorbed branches,
excessive depth/complexity, unnecessary logic, ID collisions, and risky
negative operators. Findings return exit code 1, including warnings, so CI
can use a strict quality gate.
| Code | Meaning |
|---|---|
0 |
Command completed successfully |
1 |
Invalid input, failed expectation, lint finding, generation failure, or stale output |
2 |
Invalid command-line usage |
3 |
Unexpected internal failure |
130 |
Cancelled |
set -euo pipefail
dotnet tool restore
dotnet tool run rulegate validate ./rulegate.yaml --format json
dotnet tool run rulegate lint ./rulegate.yaml --format json
dotnet tool run rulegate test ./authorization.tests.yaml --format json
dotnet tool run rulegate generate csharp \
./rulegate.yaml \
--namespace DocumentService.Authorization \
--output Generated/RuleGate.g.cs \
--check
pnpm exec rulegate-angular generate \
./rulegate.yaml \
--output ./web/src/app/generated/rulegate.ts \
--checkRun policy gates before application builds so failures are focused and fast.
Previous: Frontend integration · Next: Testing and diagnostics
Canonical source: docs/guide · Documentation index · RuleGate 1.0.0
- Home
- 1. Authorization foundations
- 2. Packages and installation
- 3. First protected API
- 4. Policy language
- 5. ASP.NET Core integration
- 6. Trusted attributes and context
- 7. Identity and Keycloak
- 8. Frontend integration
- 9. CLI and policy lifecycle
- 10. Testing and diagnostics
- 11. Policy sources and reload
- 12. Extensibility
- 13. Real-world recipes
- 14. Production checklist
- Glossary