выполнение lab3, track-1

This commit is contained in:
R0flyan
2026-10-23 16:16:50 +03:00
parent 0ab3a341aa
commit f5d79d1886
64 changed files with 35863 additions and 58 deletions
+31
View File
@@ -0,0 +1,31 @@
"""Create local secrets once. Never print values or overwrite existing secrets."""
from pathlib import Path
import secrets
import shutil
root = Path(__file__).resolve().parents[1]
folder = root / 'secrets'
folder.mkdir(exist_ok=True)
folder.chmod(0o700)
def put(name, value):
path = folder / name
if not path.exists():
with path.open('x', encoding='utf-8', newline='\n') as f:
f.write(value + '\n')
# Parent directory is private; Compose mounts individual files for non-root services.
path.chmod(0o644)
return path.read_text(encoding='utf-8').strip()
pg = put('postgres_password', secrets.token_hex(32))
vk = put('valkey_password', secrets.token_hex(32))
put('database_url', f'postgres://messenger:{pg}@db:5432/messenger?sslmode=disable')
put('cache_url', f'redis://:{vk}@valkey:6379/0')
put('cursor_secret', secrets.token_hex(32))
put('valkey.conf', '\n'.join(['bind 0.0.0.0', 'protected-mode yes', f'requirepass {vk}',
'dir /data', 'appendonly yes', 'appendfsync always', 'maxmemory 128mb',
'maxmemory-policy noeviction', 'save 60 1000']))
if not (root / '.env').exists():
shutil.copyfile(root / '.env.example', root / '.env')
for name in ('restart.sh', 'stop-one.sh'):
(root / 'scripts' / name).chmod(0o755)
print('Local .env and secrets ready; existing values preserved.')