Skip to content

Commit 7c6deb5

Browse files
committed
chore: upgrade opa to 0.63.0
1 parent 75a7ee5 commit 7c6deb5

File tree

2 files changed

+50
-30
lines changed

2 files changed

+50
-30
lines changed

opa/private/opa_rules_dependencies.bzl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
22
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
33

4-
DEFAULT_VERSION = "0.60.0"
4+
DEFAULT_VERSION = "0.63.0"
55

66
_OPA_SHA256 = {
7+
"0.63.0": {
8+
"opa_darwin_amd64": "236b2644541021aa7f0995fb0a0792bfb427e9a2d5417626f7c17d875f433ca6",
9+
"opa_darwin_arm64_static": "5c707597ce6e65e74f3a01fafee0f98e6276f0f66dd3d459ebc52997adac2b0e",
10+
"opa_linux_amd64": "20ab8e7ea816f9abd89d850656ff4ea08e5b7f2929720d6f5f20770d79800117",
11+
"opa_linux_amd64_static": "af1a9d13611974ff18c529dea3592512dd46f80a4fba95969cebccd2b0ddca64",
12+
"opa_linux_arm64_static": "0162d324e6578279072fda4a3eb69cd935a73512289135bef0c3bfe7aa1aaa2f",
13+
"opa_windows_amd64": "eb49d9bf98ca21be55c71bf033ed4b058aa1ffdec9b182cb66ae42c007e43074",
14+
"opa_capabilities_json": "4e43bd196f78e2210097e2e3bbce25512ef7783c48922be9e2ac0af8ad2fa7c8",
15+
"opa_builtin_metadata_json": "3c3bee9988c8d1d7784969a68eadd365fa9e56dd4cefe5b083de9e96f0ab431e",
16+
},
717
"0.60.0": {
818
"opa_darwin_amd64": "1b96cb23a63700b75f670e6bca1e3f8e9e7930c29b095753a9f978ce88828fa0",
919
"opa_darwin_arm64_static": "27c1209fda3a5b8d7ec158b3696246ce7d1bf3f0f08f3698a23bf7dada5a618b",

tools/opa_upgrade.py

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"opa_windows_amd64",
1616
]
1717

18-
T = TypeVar('T')
18+
T = TypeVar("T")
1919

2020

2121
def required(value: Optional[T], name: str) -> T:
@@ -28,55 +28,65 @@ def required(value: Optional[T], name: str) -> T:
2828
def get_sha256(artifact_name: str, version: str) -> str:
2929
ext = ".exe" if "windows" in artifact_name else ""
3030

31-
with urlopen(f"https://github.com/open-policy-agent/opa/releases/download/v{version}/{artifact_name}{ext}.sha256") as res:
32-
return res.read().decode().split(' ')[0]
31+
with urlopen(
32+
f"https://github.com/open-policy-agent/opa/releases/download/v{version}/{artifact_name}{ext}.sha256"
33+
) as res:
34+
return res.read().decode().split(" ")[0]
3335

3436

3537
def get_sha256_file(file: str, version: str) -> str:
36-
file_url = f"https://raw.githubusercontent.com/open-policy-agent/opa/v{version}/{file}"
38+
file_url = (
39+
f"https://raw.githubusercontent.com/open-policy-agent/opa/v{version}/{file}"
40+
)
3741

3842
with urlopen(file_url) as res:
3943
return sha256(res.read()).hexdigest()
4044

4145

4246
def main(args: Namespace):
43-
d = dict([
44-
(artifact_name, get_sha256(artifact_name, args.version))
45-
for artifact_name in ARTIFACTS
46-
])
47+
d = dict(
48+
[
49+
(artifact_name, get_sha256(artifact_name, args.version))
50+
for artifact_name in ARTIFACTS
51+
]
52+
)
4753

48-
bzl_path = WORKSPACE_ROOT.joinpath(
49-
'opa', 'private', 'opa_rules_dependencies.bzl')
54+
bzl_path = WORKSPACE_ROOT.joinpath("opa", "private", "opa_rules_dependencies.bzl")
5055

5156
with open(bzl_path) as bzl_file:
5257
bzl_content = bzl_file.read()
5358

54-
version_match = re.search(
55-
r"DEFAULT_VERSION\s*=\s*[\"'](.*?)[\"']", bzl_content)
59+
version_match = re.search(r"DEFAULT_VERSION\s*=\s*[\"'](.*?)[\"']", bzl_content)
5660

5761
if version_match is None:
5862
raise ValueError(f"Could not find DEFAULT_VERSION in file {bzl_path}")
5963

6064
start_version = version_match.start(1)
6165
end_version = version_match.end(1)
6266

63-
bzl_content = bzl_content[:start_version] + \
64-
args.version + bzl_content[end_version:]
67+
bzl_content = bzl_content[:start_version] + args.version + bzl_content[end_version:]
6568

66-
dict_match = re.search(
67-
r"^_OPA_SHA256\s*=\s*{\s*$", bzl_content, re.MULTILINE)
69+
dict_match = re.search(r"^_OPA_SHA256\s*=\s*{\s*$", bzl_content, re.MULTILINE)
6870

6971
if dict_match is None:
7072
raise ValueError(f"Could not find _OPA_SHA256 in file {bzl_path}")
7173

72-
bzl_content = bzl_content[:dict_match.end(
73-
)] + f"\n \"{args.version}\": {{\n" + '\n'.join([
74-
f" \"{artifact_name}\": \"{sha256}\","
75-
for artifact_name, sha256 in d.items()
76-
] + [
77-
f" \"opa_capabilities_json\": \"{get_sha256_file('capabilities.json', args.version)}\",",
78-
f" \"opa_builtin_metadata_json\": \"{get_sha256_file('builtin_metadata.json', args.version)}\",",
79-
]) + "\n }," + bzl_content[dict_match.end():]
74+
bzl_content = (
75+
bzl_content[: dict_match.end()]
76+
+ f'\n "{args.version}": {{\n'
77+
+ "\n".join(
78+
[
79+
f' "{artifact_name}": "{sha256}",'
80+
for artifact_name, sha256 in d.items()
81+
]
82+
+ [
83+
f" \"opa_capabilities_json\": \"{get_sha256_file('capabilities.json', args.version)}\",",
84+
f" \"opa_builtin_metadata_json\": \"{get_sha256_file('builtin_metadata.json', args.version)}\",",
85+
]
86+
)
87+
+ "\n },"
88+
+ bzl_content[dict_match.end() :]
89+
)
8090

8191
with open(bzl_path, "w", encoding="utf-8") as bzl_file:
8292
bzl_file.write(bzl_content)
@@ -89,13 +99,13 @@ def get_workspace_root(wd: Path) -> Path:
8999
return wd
90100

91101

92-
BUILD_WORKING_DIRECTORY = Path(
93-
required(os.getenv("BUILD_WORKING_DIRECTORY"), "BUILD_WORKING_DIRECTORY"))
94-
WORKSPACE_ROOT = get_workspace_root(BUILD_WORKING_DIRECTORY)
102+
WORKSPACE_ROOT = Path(
103+
required(os.getenv("BUILD_WORKSPACE_DIRECTORY"), "BUILD_WORKSPACE_DIRECTORY")
104+
)
95105

96-
if __name__ == '__main__':
106+
if __name__ == "__main__":
97107

98108
parser = ArgumentParser()
99-
parser.add_argument('--version', '-v', required=True)
109+
parser.add_argument("--version", "-v", required=True)
100110

101111
main(parser.parse_args())

0 commit comments

Comments
 (0)