20 lines
862 B
PowerShell
20 lines
862 B
PowerShell
# Windows twin of scripts/init-secrets.sh. Existing files are kept.
|
|
$ErrorActionPreference = 'Stop'
|
|
Set-Location (Join-Path $PSScriptRoot '..')
|
|
New-Item -ItemType Directory -Force secrets | Out-Null
|
|
|
|
function New-Secret($name, $bytes) {
|
|
$path = Join-Path 'secrets' $name
|
|
if ((Test-Path $path) -and (Get-Item $path).Length -gt 0) { "kept secrets/$name"; return }
|
|
$buffer = New-Object byte[] $bytes
|
|
[Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($buffer)
|
|
$value = [Convert]::ToBase64String($buffer) -replace '[+/=]', ''
|
|
# ASCII, no BOM, no trailing newline.
|
|
[IO.File]::WriteAllText((Join-Path (Get-Location) $path), $value, [Text.Encoding]::ASCII)
|
|
"created secrets/$name"
|
|
}
|
|
|
|
New-Secret 'postgres_password' 32
|
|
New-Secret 'jwt_secret' 64
|
|
if (-not (Test-Path .env)) { Copy-Item .env.example .env; 'created .env' }
|