Files
mtusi2026lab2/scripts/init-env.ps1
T
gamayunov2004 18b419cda2
Student application / application (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
ЛР 2: PostgreSQL, сессии и Valkey — на 4
2026-10-23 18:17:09 +03:00

18 lines
1017 B
PowerShell

$ErrorActionPreference = 'Stop'
Set-Location (Join-Path $PSScriptRoot '..')
$encoding = New-Object System.Text.UTF8Encoding($false)
New-Item -ItemType Directory -Force secrets | Out-Null
if (-not (Test-Path secrets/postgres_password)) {
$bytes = New-Object byte[] 32
$rng = [Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($bytes)
$rng.Dispose()
$password = [BitConverter]::ToString($bytes).Replace('-', '').ToLowerInvariant()
[IO.File]::WriteAllText((Join-Path $PWD 'secrets/postgres_password'), $password, $encoding)
}
$password = [IO.File]::ReadAllText((Join-Path $PWD 'secrets/postgres_password')).Trim()
[IO.File]::WriteAllText((Join-Path $PWD 'secrets/database_url'), "postgresql://messenger:${password}@postgres:5432/messenger", $encoding)
[IO.File]::WriteAllText((Join-Path $PWD 'secrets/cache_url'), 'redis://valkey:6379/0', $encoding)
if (-not (Test-Path .env)) { Copy-Item .env.example .env }
Write-Output 'Local configuration ready; secrets were not printed.'