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
1 change: 0 additions & 1 deletion opa/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
exports_files(["opa_eval.sh.tpl"])
4 changes: 0 additions & 4 deletions opa/private/opa_eval_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ opa_eval_binary = rule(
allow_single_file = True,
doc = "input",
),
"_template": attr.label(
default = Label("opa_eval.sh.tpl"),
allow_single_file = True,
),
},
toolchains = ["//tools:toolchain_type"],
)
4 changes: 1 addition & 3 deletions opa/private/opa_rules_dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ _OPA_SHA256 = {
"0.54.0": {
"opa_darwin_amd64": "a33e829306cd2210ed743da7f4f957588ea350a184bb6ecbb7cbfd77ae7ca401",
"opa_darwin_arm64_static": "74500746e5faf0deb60863f1a3d1e3eed96006ff8183940f1c13f1a47969059d",
"opa_linux_amd64": "63c29426db9cf1a2584fcb65c08519cb52077d832933a02c31292555ff6dc3b3",
"opa_linux_amd64_static": "633829141f8d6706ac24e0b84393d7730a975a17cc4a15790bf7fad959a28ec3",
"opa_linux_arm64_static": "883e22c082508e2f95ba25333559ba8a5c38c9c5ef667314e132c9d8451450d8",
"opa_windows_amd64": "25284b69e1dd7feaa17446e49b1085b61dca0b496dc868304153eb64b422c7eb",
Expand All @@ -17,7 +16,6 @@ _OPA_SHA256 = {
_SUPPORTED_PLATFORMS = [
"opa_darwin_amd64",
"opa_darwin_arm64_static",
"opa_linux_amd64",
"opa_linux_amd64_static",
"opa_linux_arm64_static",
"opa_windows_amd64",
Expand All @@ -40,7 +38,7 @@ def opa_rules_dependencies(
url = "https://github.com/open-policy-agent/opa/releases/download/v%s/%s%s" % (version, bin, extname),
sha256 = sha256,
executable = 1,
downloaded_file_path = "opa",
downloaded_file_path = "opa%s" % extname,
)

maybe(
Expand Down
1 change: 1 addition & 0 deletions tools/opa_ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def main():
if args.output:
file, alias = split_once_or_double(args.output, ":")
copy_file(os.path.join(args.wd, alias), file)
os.chmod(file, 0o644)


if __name__ == "__main__":
Expand Down
27 changes: 19 additions & 8 deletions tools/opa_signer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from argparse import ArgumentParser
from tarfile import TarFile, TarInfo, open as taropen
from subprocess import run, PIPE,STDOUT
from subprocess import run, PIPE, STDOUT
from dataclasses import dataclass
from io import BytesIO
import sys
import os


@dataclass
class Args:
bundle: str
Expand All @@ -14,8 +15,10 @@ class Args:
signing_alg: str
command: list[str]


def parse_args() -> Args:
parser = ArgumentParser(prog="rules_opa::opa_signer", description="Tool to re-bundle an opa bundle with a signature file")
parser = ArgumentParser(prog="rules_opa::opa_signer",
description="Tool to re-bundle an opa bundle with a signature file")

parser.add_argument("-b", "--bundle", required=True)
parser.add_argument("-o", "--output", required=True)
Expand All @@ -33,28 +36,34 @@ def parse_args() -> Args:
ns.command,
)


def perform_signature(args: Args) -> str:
expected_file = ".signatures.json"
completed_process = run(args.command + ['--signing-key', args.signing_key, "--signing-alg", args.signing_alg, "--bundle", args.bundle], stdout=PIPE, stderr=STDOUT)
completed_process = run(args.command + ['--signing-key', args.signing_key, "--signing-alg",
args.signing_alg, "--bundle", args.bundle], stdout=PIPE, stderr=STDOUT)
returncode = completed_process.returncode

if returncode != 0:
command = " ".join(completed_process.args)
stdout = completed_process.stdout.decode()
print(f"Command exited with non-zero return code {returncode}.\n{command}\n{stdout}", file=sys.stderr)
print(
f"Command exited with non-zero return code {returncode}.\n{command}\n{stdout}", file=sys.stderr)
sys.exit(1)

if not os.path.exists(expected_file):
command = " ".join(completed_process.args)
print(f"File {expected_file} not found after running command:\n{command}", file=sys.stderr)
print(
f"File {expected_file} not found after running command:\n{command}", file=sys.stderr)
sys.exit(1)

return expected_file


def transfer_files(output: TarFile, bundle: TarFile):
for member in bundle.getmembers():
output.addfile(member, bundle.extractfile(member))


def addfile(output: TarFile, file_name: str):
with open(file_name, mode="rb") as f:
data = f.read()
Expand All @@ -74,6 +83,8 @@ def main():
addfile(output, signature_file)
transfer_files(output, bundle)

os.chmod(args.output, 0o644)


if __name__ == "__main__":
main()