Skip to content

Commit aa4ca83

Browse files
authored
Merge pull request #10 from ticketmaster/fix-schema-files
fix opa_check rule when a list of files is passed
2 parents 889747c + 9d742fa commit aa4ca83

File tree

5 files changed

+56
-8
lines changed

5 files changed

+56
-8
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
load("@rules_opa//opa:defs.bzl", "opa_check", "opa_library")
2+
3+
opa_library(
4+
name = "multiple_schema_files",
5+
srcs = ["main.rego"],
6+
strip_prefix = package_name(),
7+
visibility = ["//examples:__subpackages__"],
8+
)
9+
10+
opa_check(
11+
name = "multiple_schema_files_check",
12+
size = "small",
13+
bundle = ":multiple_schema_files",
14+
schema_files = [
15+
"//examples/simple:schemas/input.json",
16+
":admins.json",
17+
],
18+
strict = True,
19+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "array",
3+
"items": {
4+
"type": "string"
5+
}
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# METADATA
2+
# scope: subpackages
3+
# schemas:
4+
# - input: schema.input
5+
# - data.admins: schema.admins
6+
package main
7+
8+
import future.keywords
9+
10+
allow if {
11+
input.name in data.admins
12+
}
13+
14+
#

examples/simple/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ opa_eval_binary(
4343
query = "data.main.allow",
4444
deps = [":simple"],
4545
)
46+
47+
exports_files(["schemas/input.json"])

opa/private/opa_check.bzl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ def _opa_check_test_impl(ctx):
1414
if ctx.files.schema_files:
1515
files.extend(ctx.files.schema_files)
1616

17-
runfiles = ctx.runfiles(
18-
files = files,
19-
)
20-
21-
args = []
17+
args = ["set -xe\n"]
2218

2319
args.append(toolchain.opa.short_path)
2420
args.append("check")
@@ -29,19 +25,27 @@ def _opa_check_test_impl(ctx):
2925
args.append("-s")
3026
args.append("%s/" % (ctx.file.schema_dir.short_path))
3127
elif ctx.files.schema_files:
32-
for f in ctx.files.schema_files:
33-
args.append("-s")
34-
args.append(f.short_path)
28+
args.insert(1, "schema_dir=`mktemp -d`\n")
29+
args.insert(2, "cp %s $schema_dir\n" % (" ".join([f.short_path for f in ctx.files.schema_files])))
30+
args.append("-s")
31+
args.append("$schema_dir")
3532

3633
if ctx.file.capabilities:
3734
args.append("--capabilities")
3835
args.append(ctx.file.capabilities.short_path)
3936

37+
if ctx.attr.strict:
38+
args.append("--strict")
39+
4040
ctx.actions.write(
4141
output = tester_file,
4242
content = " ".join(args),
4343
)
4444

45+
runfiles = ctx.runfiles(
46+
files = files,
47+
)
48+
4549
return [
4650
DefaultInfo(
4751
executable = tester_file,
@@ -71,6 +75,9 @@ _opa_check_test = rule(
7175
providers = [ProtoInfo],
7276
doc = "Protobuf definition to generate json schemas",
7377
),
78+
"strict": attr.bool(
79+
doc = "enable compiler strict mode",
80+
),
7481
"capabilities": attr.label(
7582
doc = "set capabilities.json file path",
7683
allow_single_file = True,

0 commit comments

Comments
 (0)