Examples
Basic rule usage
This first example show the simplest possible rule.
First we need to generate a rule:
$ echo "pattern nr = 18" > nr-rule.dog
And we also need have an input file:
$ echo 18 > input.txt
$ cargo r -q -- \
eval \
--policy nr-rule.dog \
--input input.txt \
--name nr-rule::nr
evaluate pattern: nr-rule::nr
Pattern: nr-rule::nr
Satisfied: true
Value:
18
Rationale:
primordial(true)
ok!
JSON input format
First we create our rule, and save it in a file named json-rule.dog
:
$ echo "pattern nr = {
nr: integer,
}" > json-rule.dog
And then we create an input file, and save it in a file named input.json
:
$ echo "{
"nr": 18
}" > input.json
And we can run the eval
command:
$ cargo r -q -- \
eval \
--policy json-rule.dog \
--input input.json \
--name json-rule::nr
YAML input format
First we create our rule, and save it in a file named yaml-rule.dog
:
$ echo "pattern nr = {
nr: integer,
}" > yaml-rule.dog
And then we create an input file, and save it in a file named input.yaml
:
$ echo "---
nr: 18" > input.yaml
And then we specify the -t
option to the eval
command and specify the format
as yaml
:
$ cargo r -q -- \
eval -t yaml \
--policy yaml-rule.dog \
--input input.yaml \
--name yaml-rule::nr
evaluate pattern: yaml-rule::nr
Pattern: yaml-rule::nr
Satisfied: true
Value:
nr: <<integer>>
Rationale:
field: nr
Pattern: <none>
Satisfied: true
Value:
18
Rationale:
primordial(true)
ok!
Server
The swio
command can also be used to run the policy server:
$ cargo r -q -- \
serve \
--policy json-rule.dog
You can then open http://localhost:8080 in your browser and navigate using the web UI.