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

SEE ALSO

202       opa(1)
203
204
205
206                                   May 2021               Open Policy Agent(1)
Impressum