feat: provision private S3 storage and attachment schema
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Create local Compose secrets without printing or overwriting existing values."""
|
||||
|
||||
import os
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1] / "secrets"
|
||||
|
||||
|
||||
def write(name: str, value: str) -> None:
|
||||
fd = os.open(ROOT / name, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
||||
with os.fdopen(fd, "w") as out:
|
||||
out.write(value)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
ROOT.mkdir(mode=0o700, exist_ok=True)
|
||||
db_names = {"postgres_password", "database_url"}
|
||||
s3_names = {
|
||||
"minio_root_user", "minio_root_password", "s3_access_key_id", "s3_secret_access_key",
|
||||
"s3_maintenance_key_id", "s3_maintenance_secret_key",
|
||||
}
|
||||
for names in (db_names, s3_names):
|
||||
existing = {name for name in names if (ROOT / name).exists()}
|
||||
if existing and existing != names:
|
||||
raise SystemExit(f"Incomplete secret group: {', '.join(sorted(names - existing))}")
|
||||
if not (ROOT / "postgres_password").exists():
|
||||
password = secrets.token_urlsafe(32)
|
||||
write("postgres_password", password)
|
||||
write("database_url", f"postgresql://messenger:{password}@postgres:5432/messenger")
|
||||
if not (ROOT / "minio_root_user").exists():
|
||||
write("minio_root_user", "lab4admin")
|
||||
write("minio_root_password", secrets.token_urlsafe(32))
|
||||
write("s3_access_key_id", secrets.token_hex(10))
|
||||
write("s3_secret_access_key", secrets.token_urlsafe(32))
|
||||
write("s3_maintenance_key_id", secrets.token_hex(10))
|
||||
write("s3_maintenance_secret_key", secrets.token_urlsafe(32))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user