Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/multiple_schema_files/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@rules_opa//opa:defs.bzl", "opa_check", "opa_library")

opa_library(
name = "multiple_schema_files",
srcs = ["main.rego"],
strip_prefix = package_name(),
visibility = ["//examples:__subpackages__"],
)

opa_check(
name = "multiple_schema_files_check",
size = "small",
bundle = ":multiple_schema_files",
schema_files = [
"//examples/simple:schemas/input.json",
":admins.json",
],
strict = True,
)
6 changes: 6 additions & 0 deletions examples/multiple_schema_files/admins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "array",
"items": {
"type": "string"
}
}
14 changes: 14 additions & 0 deletions examples/multiple_schema_files/main.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# METADATA
# scope: subpackages
# schemas:
# - input: schema.input
# - data.admins: schema.admins
package main

import future.keywords

allow if {
input.name in data.admins
}

#
2 changes: 2 additions & 0 deletions examples/simple/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ opa_eval_binary(
query = "data.main.allow",
deps = [":simple"],
)

exports_files(["schemas/input.json"])
23 changes: 15 additions & 8 deletions opa/private/opa_check.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ def _opa_check_test_impl(ctx):
if ctx.files.schema_files:
files.extend(ctx.files.schema_files)

runfiles = ctx.runfiles(
files = files,
)

args = []
args = ["set -xe\n"]

args.append(toolchain.opa.short_path)
args.append("check")
Expand All @@ -29,19 +25,27 @@ def _opa_check_test_impl(ctx):
args.append("-s")
args.append("%s/" % (ctx.file.schema_dir.short_path))
elif ctx.files.schema_files:
for f in ctx.files.schema_files:
args.append("-s")
args.append(f.short_path)
args.insert(1, "schema_dir=`mktemp -d`\n")
args.insert(2, "cp %s $schema_dir\n" % (" ".join([f.short_path for f in ctx.files.schema_files])))
args.append("-s")
args.append("$schema_dir")

if ctx.file.capabilities:
args.append("--capabilities")
args.append(ctx.file.capabilities.short_path)

if ctx.attr.strict:
args.append("--strict")

ctx.actions.write(
output = tester_file,
content = " ".join(args),
)

runfiles = ctx.runfiles(
files = files,
)

return [
DefaultInfo(
executable = tester_file,
Expand Down Expand Up @@ -71,6 +75,9 @@ _opa_check_test = rule(
providers = [ProtoInfo],
doc = "Protobuf definition to generate json schemas",
),
"strict": attr.bool(
doc = "enable compiler strict mode",
),
"capabilities": attr.label(
doc = "set capabilities.json file path",
allow_single_file = True,
Expand Down