-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[confcom] Make dependency fetching more resilient #9441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DomAyre
wants to merge
5
commits into
Azure:main
Choose a base branch
from
DomAyre:fix-rate-limiting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,49 +3,50 @@ | |||||||||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||||||||||
| # -------------------------------------------------------------------------------------------- | ||||||||||
|
|
||||||||||
| import platform | ||||||||||
| import requests | ||||||||||
| import hashlib | ||||||||||
| import json | ||||||||||
| import os | ||||||||||
| from pathlib import Path | ||||||||||
| import platform | ||||||||||
| import subprocess | ||||||||||
| from typing import Iterable | ||||||||||
|
|
||||||||||
| import requests | ||||||||||
|
|
||||||||||
| from azext_confcom.lib.binaries import get_binaries_dir | ||||||||||
|
|
||||||||||
| _opa_path = os.path.abspath(os.path.join(get_binaries_dir(), "opa")) | ||||||||||
| _opa_url = { | ||||||||||
| "Linux": "https://github.com/open-policy-agent/opa/releases/download/v1.10.1/opa_linux_amd64", | ||||||||||
| "Windows": "https://github.com/open-policy-agent/opa/releases/download/v1.10.1/opa_windows_amd64.exe", | ||||||||||
| } | ||||||||||
| _expected_sha256 = { | ||||||||||
| "Linux": "fe8e191d44fec33db2a3d0ca788b9f83f866d980c5371063620c3c6822792877", | ||||||||||
| "Windows": "4c932053350eabca47681208924046fbf3ad9de922d6853fb12cddf59aef15ce", | ||||||||||
| from typing import Iterable | ||||||||||
| from pathlib import Path | ||||||||||
| from azext_confcom.lib.paths import get_binaries_dir | ||||||||||
|
|
||||||||||
|
|
||||||||||
| _binaries_dir = get_binaries_dir() | ||||||||||
| _opa_binaries = { | ||||||||||
| "Linux": { | ||||||||||
| "path": _binaries_dir / "opa", | ||||||||||
| "url": "https://github.com/open-policy-agent/opa/releases/download/v1.10.1/opa_linux_amd64", | ||||||||||
| "sha256": "fe8e191d44fec33db2a3d0ca788b9f83f866d980c5371063620c3c6822792877", | ||||||||||
| }, | ||||||||||
| "Windows": { | ||||||||||
| "path": _binaries_dir / "opa.exe", | ||||||||||
| "url": "https://github.com/open-policy-agent/opa/releases/download/v1.10.1/opa_windows_amd64.exe", | ||||||||||
| "sha256": "4c932053350eabca47681208924046fbf3ad9de922d6853fb12cddf59aef15ce", | ||||||||||
| }, | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def opa_get(): | ||||||||||
|
|
||||||||||
| if not all(platform.system() in mapping for mapping in [_opa_url, _expected_sha256]): | ||||||||||
| raise RuntimeError(f"OPA is not supported on platform: {platform.system()}") | ||||||||||
|
|
||||||||||
| opa_fetch_resp = requests.get(_opa_url[platform.system()], verify=True) | ||||||||||
| opa_fetch_resp.raise_for_status() | ||||||||||
| for binary_info in _opa_binaries.values(): | ||||||||||
| opa_fetch_resp = requests.get(binary_info["url"], verify=True) | ||||||||||
| opa_fetch_resp.raise_for_status() | ||||||||||
|
|
||||||||||
| assert hashlib.sha256(opa_fetch_resp.content).hexdigest() == _expected_sha256[platform.system()] | ||||||||||
| assert hashlib.sha256(opa_fetch_resp.content).hexdigest() == binary_info["sha256"] | ||||||||||
|
||||||||||
| assert hashlib.sha256(opa_fetch_resp.content).hexdigest() == binary_info["sha256"] | |
| actual_hash = hashlib.sha256(opa_fetch_resp.content).hexdigest() | |
| if actual_hash != binary_info["sha256"]: | |
| raise RuntimeError(f"Checksum verification failed for OPA binary. Expected: {binary_info['sha256']}, Got: {actual_hash}") |
DomAyre marked this conversation as resolved.
Show resolved
Hide resolved
DomAyre marked this conversation as resolved.
Show resolved
Hide resolved
DomAyre marked this conversation as resolved.
Show resolved
Hide resolved
DomAyre marked this conversation as resolved.
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The downloaded binary files are missing executable permissions on Linux. The
__init__method (lines 81-87) attempts to add executable permissions later, but it's better to set them immediately after download. Add this after writing the file: