Files
mtusi2026lab7/scripts/operator_task.py

58 lines
1.5 KiB
Python

"""Prepare a 60-second operator-only snapshot and run the audited pipeline CLI."""
import json
import sys
import time
from urllib.parse import quote
from scripts.bootstrap_security import OPERATOR, SECRET, write_private
from scripts.stand import compose
def prepare():
raw = json.loads((OPERATOR / "service-secrets.json").read_text())
directory = SECRET / "operator-task"
directory.mkdir(mode=0o755, exist_ok=True)
for name in ["cert.pem", "key.pem"]:
write_private(
directory / "current" / name,
(OPERATOR / "client" / name).read_bytes(),
mode=0o644,
)
values = {
"DATABASE_URL": "postgresql://messenger:"
+ quote(raw["postgres_password"], safe="")
+ "@postgres:5443/messenger?sslmode=verify-full&gssencmode=disable&sslrootcert=/trust/ca.pem&sslcert=/run/identity/current/cert.pem&sslkey=/run/identity/current/key.pem",
"BROKER_URL": "rediss://admin:"
+ raw["broker_admin"]
+ "@broker:6380/0",
"S3_ACCESS_KEY": raw["s3_root_user"],
"S3_SECRET_KEY": raw["s3_root_password"],
}
write_private(
directory / "secrets.json",
json.dumps({"valid_until": time.time() + 60, "values": values}) + "\n",
mode=0o644,
)
def run(*args):
prepare()
return compose(
"--profile",
"operator",
"run",
"--rm",
"--no-deps",
"operator-task",
*args,
)
def main():
print(run(*sys.argv[1:]))
if __name__ == "__main__":
main()