summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--BUILD1
-rw-r--r--MODULE.bazel6
-rw-r--r--bazel_registry.json3
-rw-r--r--integrity.py34
5 files changed, 45 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4b30330
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+bazel-*/
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/BUILD
@@ -0,0 +1 @@
+
diff --git a/MODULE.bazel b/MODULE.bazel
new file mode 100644
index 0000000..4ac990a
--- /dev/null
+++ b/MODULE.bazel
@@ -0,0 +1,6 @@
+module(
+ name = "bazel_registry",
+ version = "0.0.0",
+ compatibility_level = 1,
+)
+
diff --git a/bazel_registry.json b/bazel_registry.json
new file mode 100644
index 0000000..ea3f94f
--- /dev/null
+++ b/bazel_registry.json
@@ -0,0 +1,3 @@
+{
+ "mirrors": []
+}
diff --git a/integrity.py b/integrity.py
new file mode 100644
index 0000000..14bfe66
--- /dev/null
+++ b/integrity.py
@@ -0,0 +1,34 @@
+import sys
+import hashlib
+import base64
+from pathlib import Path
+import requests
+
+def file_hash(file_path: Path) -> str:
+ sha256_hash = hashlib.sha256()
+ with open(file_path, "rb") as file:
+ while True:
+ data = file.read(65536)
+ if not data:
+ break
+ sha256_hash.update(data)
+ return "sha256-" + base64.b64encode(sha256_hash.digest()).decode()
+
+def url_hash(url: str) -> str:
+ sha256_hash = hashlib.sha256()
+ with requests.get(url, stream=True) as resp:
+ resp.raise_for_status()
+ while True:
+ data = resp.raw.read(65536)
+ if not data:
+ break
+ sha256_hash.update(data)
+ return "sha256-" + base64.b64encode(sha256_hash.digest()).decode()
+
+if __name__ == "__main__" and len(sys.argv) > 1:
+ path = Path(sys.argv[1])
+ if path.exists():
+ print(file_hash(path))
+ else:
+ print(url_hash(sys.argv[1]))
+