使用 opa eval 命令评估文件夹中的多个文件
Evaluating multiple files from a folder using opa eval command
我在 OPA 网站上看到了这个,我可以使用以下内容:
在命令行上评估策略。
./opa eval -i input.json -d example.rego
就我而言,我有多个输入文件,我已将其修改为
./opa eval -i /tmp/tfplan.json -d /tmp/example.rego -d /tmp/input1.json - d /tmp/input2.json
我可以直接修改它以读取 tmp 文件夹中存在的所有 json 个文件,而不是单独将文件指定为 input1、input2 等吗?
是的! CLI 将接受 -d
/--data
和 -b
/--bundle
参数的目录并从中递归加载文件。
例如:
/tmp/foo/input1.json
/tmp/foo/input2.json
opa eval -d /tmp/foo/input1.json -d /tmp/foo/input2.json ..
与
相同
opa eval -d /tmp/foo ..
请记住 -d
/--data
将尝试加载目录中找到的 任何 文件,这有时会导致冲突(例如,数据文档中的重复键)或加载不正确的文件。所以在指向 /tmp
时要小心,因为它可能包含您不需要的其他文件(请注意上面的示例使用了 sub-directory)。通常我们建议使用 -b
/--bundle
并提供 data.json
文件,其目录结构遵循捆绑规范 https://www.openpolicyagent.org/docs/latest/management/#bundle-file-format,这有助于避免大多数常见问题。
我在 OPA 网站上看到了这个,我可以使用以下内容:
在命令行上评估策略。 ./opa eval -i input.json -d example.rego
就我而言,我有多个输入文件,我已将其修改为
./opa eval -i /tmp/tfplan.json -d /tmp/example.rego -d /tmp/input1.json - d /tmp/input2.json
我可以直接修改它以读取 tmp 文件夹中存在的所有 json 个文件,而不是单独将文件指定为 input1、input2 等吗?
是的! CLI 将接受 -d
/--data
和 -b
/--bundle
参数的目录并从中递归加载文件。
例如:
/tmp/foo/input1.json
/tmp/foo/input2.json
opa eval -d /tmp/foo/input1.json -d /tmp/foo/input2.json ..
与
相同opa eval -d /tmp/foo ..
请记住 -d
/--data
将尝试加载目录中找到的 任何 文件,这有时会导致冲突(例如,数据文档中的重复键)或加载不正确的文件。所以在指向 /tmp
时要小心,因为它可能包含您不需要的其他文件(请注意上面的示例使用了 sub-directory)。通常我们建议使用 -b
/--bundle
并提供 data.json
文件,其目录结构遵循捆绑规范 https://www.openpolicyagent.org/docs/latest/management/#bundle-file-format,这有助于避免大多数常见问题。