Skip to content

Commit 48d9032

Browse files
authored
[confcom] Fix opa installation on windows and in strict networking environments (#9440)
* [confcom] Fix opa installation on windows and in strict networking environments * Bump version and history * Fix merge conflict from previous commits * Add clear error if user on unsupported platform * .
1 parent 8b6ea4b commit 48d9032

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

src/confcom/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Release History
44
===============
55

6+
1.4.3
7+
++++++
8+
* Fix installing OPA on Windows and in strict networking environments
9+
610
1.4.2
711
++++++
812
* Update policy model to use pydantic and explicitly declare collections where order doesn't affect function. These fields will serialize in alphabetical order and comparisons will ignore order.

src/confcom/azext_confcom/lib/opa.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@
1616
from azext_confcom.lib.binaries import get_binaries_dir
1717

1818
_opa_path = os.path.abspath(os.path.join(get_binaries_dir(), "opa"))
19-
_expected_sha256 = "fe8e191d44fec33db2a3d0ca788b9f83f866d980c5371063620c3c6822792877"
19+
_opa_url = {
20+
"Linux": "https://github.com/open-policy-agent/opa/releases/download/v1.10.1/opa_linux_amd64",
21+
"Windows": "https://github.com/open-policy-agent/opa/releases/download/v1.10.1/opa_windows_amd64.exe",
22+
}
23+
_expected_sha256 = {
24+
"Linux": "fe8e191d44fec33db2a3d0ca788b9f83f866d980c5371063620c3c6822792877",
25+
"Windows": "4c932053350eabca47681208924046fbf3ad9de922d6853fb12cddf59aef15ce",
26+
}
2027

2128

2229
def opa_get():
2330

24-
opa_fetch_resp = requests.get(
25-
f"https://openpolicyagent.org/downloads/v1.10.1/opa_{platform.system().lower()}_amd64",
26-
verify=True,
27-
)
31+
if not all(platform.system() in mapping for mapping in [_opa_url, _expected_sha256]):
32+
raise RuntimeError(f"OPA is not supported on platform: {platform.system()}")
33+
34+
opa_fetch_resp = requests.get(_opa_url[platform.system()], verify=True)
2835
opa_fetch_resp.raise_for_status()
2936

30-
assert hashlib.sha256(opa_fetch_resp.content).hexdigest() == _expected_sha256
37+
assert hashlib.sha256(opa_fetch_resp.content).hexdigest() == _expected_sha256[platform.system()]
3138

3239
with open(_opa_path, "wb") as f:
3340
f.write(opa_fetch_resp.content)

src/confcom/azext_confcom/tests/conftest.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import shutil
1515

1616
from pathlib import Path
17+
import zipfile
1718

1819

1920
# This fixture ensures tests are run against final built wheels of the extension
@@ -57,9 +58,9 @@ def run_on_wheel(request):
5758
if (extension_dir / "build").exists():
5859
shutil.rmtree((extension_dir / "build").as_posix(), ignore_errors=True)
5960

60-
if not any(build_dir.glob(f"{extension_name}*.whl")):
61+
if not any(build_dir.glob(f"*{extension_name}*.whl")):
6162
subprocess.run(
62-
["azdev", "extension", "build", extension.replace("azext_", ""), "--dist-dir", build_dir.as_posix()],
63+
["azdev", "extension", "build", extension_name, "--dist-dir", build_dir.as_posix()],
6364
check=True,
6465
)
6566

@@ -68,7 +69,15 @@ def run_on_wheel(request):
6869

6970
# Add the wheel to the path and reload extension modules so the
7071
# tests pick up the wheel code over the unbuilt code
71-
sys.path.insert(0, build_dir.glob("*.whl").__next__().as_posix())
72+
wheel_path = next(build_dir.glob("*.whl"))
73+
74+
expanded_dir = build_dir / f"{wheel_path.stem}_expanded"
75+
if not expanded_dir.exists():
76+
expanded_dir.mkdir(exist_ok=True)
77+
with zipfile.ZipFile(wheel_path, "r") as z:
78+
z.extractall(expanded_dir)
79+
80+
sys.path.insert(0, expanded_dir.resolve().as_posix())
7281
for module in list(sys.modules.values()):
7382
if extension in module.__name__ and module not in modules_to_test:
7483
del sys.modules[module.__name__]

src/confcom/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
logger.warn("Wheel is not available, disabling bdist_wheel hook")
2222

23-
VERSION = "1.4.2"
23+
VERSION = "1.4.3"
2424

2525
# The full list of classifiers is available at
2626
# https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)