forked from mtusi2026/mtusi2026lab3
lab3: выполнение и доказательтсва
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SECRETS = ROOT / "secrets"
|
||||
|
||||
|
||||
def write(name: str, value: str) -> None:
|
||||
with open(SECRETS / name, "w", encoding="utf-8", newline="") as file:
|
||||
file.write(value)
|
||||
(SECRETS / name).chmod(0o644)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if (SECRETS / "postgres_password").exists():
|
||||
print("secrets/ already exists, nothing changed.")
|
||||
return
|
||||
SECRETS.mkdir(exist_ok=True)
|
||||
db_password = secrets.token_hex(24)
|
||||
redis_password = secrets.token_hex(24)
|
||||
|
||||
write("postgres_password", db_password)
|
||||
write("database_url", f"postgresql://messenger:{db_password}@postgres:5432/messenger")
|
||||
write("cache_url", f"redis://:{redis_password}@redis:6379/0")
|
||||
write("redis_auth", f"requirepass {redis_password}\n")
|
||||
print("Created secrets/: postgres_password, database_url, cache_url, redis_auth (values are not printed).")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user