1Open Policy Agent(1)                                      Open Policy Agent(1)
2
3
4

NAME

6       opa-eval - Evaluate a Rego query
7
8
9

SYNOPSIS

11       opa eval  [flags]
12
13
14

DESCRIPTION

16       Evaluate a Rego query and print the result.
17
18

Examples

20       To evaluate a simple query:
21
22
23              $ opa eval 'x = 1; y = 2; x < y'
24
25
26
27       To evaluate a query against JSON data:
28
29
30              $ opa eval --data data.json 'data.names[_] = name'
31
32
33
34       To evaluate a query against JSON data supplied with a file:// URL:
35
36
37              $ opa eval --data file:///path/to/file.json 'data'
38
39
40

File & Bundle Loading

42       The  --bundle flag will load data files and Rego files contained in the
43       bundle specified by the path. It can be either a compressed tar archive
44       bundle file or a directory tree.
45
46
47              $ opa eval --bundle /some/path 'data'
48
49
50
51       Where /some/path contains:
52
53
54              foo/
55                |
56                +-- bar/
57                |     |
58                |     +-- data.json
59                |
60                +-- baz.rego
61                |
62                +-- manifest.yaml
63
64
65
66       The  JSON  file  'foo/bar/data.json'  would  be loaded and rooted under
67       package path contained inside the file. Only data files named data.json
68       or  data.yaml  will  be  loaded. In the example above the manifest.yaml
69       would be ignored.
70
71
72       See https://www.openpolicyagent.org/docs/latest/bundles/ for  more  de‐
73       tails on bundle directory structures.
74
75
76       The --data flag can be used to recursively load ALL *.rego, *.json, and
77       *.yaml files under the specified directory.
78
79

Output Formats

81       Set the output format with the --format flag.
82
83
84              --format=json      : output raw query results as JSON
85              --format=values    : output line separated JSON arrays containing expression values
86              --format=bindings  : output line separated JSON objects containing variable bindings
87              --format=pretty    : output query results in a human-readable format
88
89
90

Schema

92       The -s/--schema flag provides one or more JSON Schemas used to validate
93       references  to  the input or data documents.  Loads a single JSON file,
94       applying it to the input document; or all the schema  files  under  the
95       specified directory.
96
97
98              $ opa eval --data policy.rego --input input.json --schema schema.json
99              $ opa eval --data policy.rego --input input.json --schema schemas/
100
101
102
103

OPTIONS

105       -b, --bundle=""      set bundle file(s) or directory path(s). This flag
106       can be repeated.
107
108
109       --count=1      number of times to repeat each benchmark
110
111
112       --coverage[=false]      report coverage
113
114
115       -d, --data=""      set policy or data file(s). This  flag  can  be  re‐
116       peated.
117
118
119       --disable-indexing[=false]      disable indexing optimizations
120
121
122       --disable-inlining=[]       set  paths of documents to exclude from in‐
123       lining
124
125
126       --explain=off      enable query explanations
127
128
129       --fail[=false]      exits with non-zero exit  code  on  undefined/empty
130       result and errors
131
132
133       --fail-defined[=false]       exits  with  non-zero  exit  code  on  de‐
134       fined/non-empty result and errors
135
136
137       -f, --format=json      set output format
138
139
140       -h, --help[=false]      help for eval
141
142
143       --ignore=[]      set file and directory names to ignore during  loading
144       (e.g., '.*' excludes hidden files)
145
146
147       --import=""      set query import(s). This flag can be repeated.
148
149
150       -i, --input=""      set input file path
151
152
153       --instrument[=false]      enable query instrumentation metrics (implies
154       --metrics)
155
156
157       --metrics[=false]      report query performance metrics
158
159
160       --package=""      set query package
161
162
163       -p, --partial[=false]      perform partial evaluation
164
165
166       --pretty-limit=80      set limit after which pretty output  gets  trun‐
167       cated
168
169
170       --profile[=false]      perform expression profiling
171
172
173       --profile-limit=10      set number of profiling results to show
174
175
176       --profile-sort=""      set sort order of expression profiler results
177
178
179       -s, --schema=""      set schema file path or directory path
180
181
182       --shallow-inlining[=false]       disable  inlining of rules that depend
183       on unknowns
184
185
186       --stdin[=false]      read query from stdin
187
188
189       -I, --stdin-input[=false]      read input document from stdin
190
191
192       --strict-builtin-errors[=false]      treat built-in function errors  as
193       fatal
194
195
196       -t, --target=rego      set the runtime to exercise
197
198
199       -u,  --unknowns=[input]       set paths to treat as unknown during par‐
200       tial evaluation
201
202
203

SEE ALSO

205       opa(1)
206
207
208
209                                   Jun 2022               Open Policy Agent(1)
Impressum