forked from mtusi2026/mtusi2026lab4
Лабораторная 4 - Гончаревская.Е.А. - БВТ2304 - На 3
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse, os, secrets
|
||||
from pathlib import Path
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
def main():
|
||||
ap=argparse.ArgumentParser()
|
||||
ap.add_argument('--force',action='store_true')
|
||||
a=ap.parse_args()
|
||||
d=ROOT/'secrets'; d.mkdir(mode=0o700,exist_ok=True)
|
||||
password=secrets.token_hex(24)
|
||||
values={
|
||||
'postgres_password':password+'\n',
|
||||
'database_url':f'postgresql://messenger:{password}@postgres:5432/messenger?connect_timeout=5\n',
|
||||
'redis_url':'redis://valkey:6379/0\n',
|
||||
's3_access_key_id':'messenger'+secrets.token_hex(8)+'\n',
|
||||
's3_secret_access_key':secrets.token_urlsafe(36)+'\n',
|
||||
'minio_root_user':'minioadmin'+secrets.token_hex(4)+'\n',
|
||||
'minio_root_password':secrets.token_urlsafe(32)+'\n'
|
||||
}
|
||||
if not a.force and any((d/n).exists() for n in values):
|
||||
raise SystemExit('Secret files already exist; use --force only to rotate all credentials.')
|
||||
for n,v in values.items():
|
||||
f=d/n; f.write_text(v,encoding='utf-8')
|
||||
try: os.chmod(f,0o600)
|
||||
except OSError: pass
|
||||
print('Local secrets created; values were not printed.')
|
||||
if __name__=='__main__': main()
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
cd "$ROOT"
|
||||
docker compose restart postgres valkey rustfs api
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
|
||||
case "$TARGET_INSTANCE_ID" in *[!a-fA-F0-9-]*|'') echo "Invalid API instance id" >&2; exit 2;; esac
|
||||
docker stop --time 5 "$TARGET_INSTANCE_ID" >/dev/null
|
||||
Reference in New Issue
Block a user