Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6b8e0adfb |
@@ -2,11 +2,10 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
|
import http.client
|
||||||
import pathlib
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
import urllib.error
|
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
|
|
||||||
values = dict(line.strip().split("=", 1) for line in pathlib.Path(sys.argv[1]).read_text().splitlines()
|
values = dict(line.strip().split("=", 1) for line in pathlib.Path(sys.argv[1]).read_text().splitlines()
|
||||||
@@ -14,7 +13,9 @@ values = dict(line.strip().split("=", 1) for line in pathlib.Path(sys.argv[1]).r
|
|||||||
access = values["S3_ACCESS_KEY"]
|
access = values["S3_ACCESS_KEY"]
|
||||||
secret = values["S3_SECRET_KEY"]
|
secret = values["S3_SECRET_KEY"]
|
||||||
bucket = values.get("S3_BUCKET", "objects")
|
bucket = values.get("S3_BUCKET", "objects")
|
||||||
port = values.get("CLUSTER_HOST_PORT", "9001")
|
port = int(values.get("CLUSTER_HOST_PORT", "9001"))
|
||||||
|
if not 1 <= port <= 65535:
|
||||||
|
raise ValueError("CLUSTER_HOST_PORT must be between 1 and 65535")
|
||||||
host = f"127.0.0.1:{port}"
|
host = f"127.0.0.1:{port}"
|
||||||
|
|
||||||
|
|
||||||
@@ -40,14 +41,13 @@ def request(method, path, body=b"", extra=None):
|
|||||||
signature = hmac.new(key, to_sign.encode(), hashlib.sha256).hexdigest()
|
signature = hmac.new(key, to_sign.encode(), hashlib.sha256).hexdigest()
|
||||||
headers["authorization"] = (f"AWS4-HMAC-SHA256 Credential={access}/{scope},"
|
headers["authorization"] = (f"AWS4-HMAC-SHA256 Credential={access}/{scope},"
|
||||||
f"SignedHeaders={signed_names},Signature={signature}")
|
f"SignedHeaders={signed_names},Signature={signature}")
|
||||||
url = f"http://{host}{path}"
|
connection = http.client.HTTPConnection("127.0.0.1", port, timeout=30)
|
||||||
outgoing = urllib.request.Request(url, data=body if method == "PUT" else None,
|
|
||||||
method=method, headers=headers)
|
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(outgoing, timeout=30) as response:
|
connection.request(method, path, body=body if method == "PUT" else None, headers=headers)
|
||||||
return response.status, response.read(), response.headers
|
response = connection.getresponse()
|
||||||
except urllib.error.HTTPError as error:
|
return response.status, response.read(), response.headers
|
||||||
return error.code, error.read(), error.headers
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) > 2 and sys.argv[2] == "survivor":
|
if len(sys.argv) > 2 and sys.argv[2] == "survivor":
|
||||||
|
|||||||
Reference in new issue
Block a user