Implement PostgreSQL storage, sessions and persistence checks
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$secretsDirectory = Join-Path $repoRoot 'secrets'
|
||||
$passwordPath = Join-Path $secretsDirectory 'postgres_password.txt'
|
||||
|
||||
New-Item -ItemType Directory -Path $secretsDirectory -Force | Out-Null
|
||||
|
||||
if (Test-Path -LiteralPath $passwordPath) {
|
||||
if ((Get-Item -LiteralPath $passwordPath).Length -eq 0) {
|
||||
throw 'Existing password file is empty. Supply a local password before starting PostgreSQL.'
|
||||
}
|
||||
Write-Output 'Existing PostgreSQL password preserved.'
|
||||
exit 0
|
||||
}
|
||||
|
||||
$randomBytes = New-Object byte[] 32
|
||||
$generator = [System.Security.Cryptography.RandomNumberGenerator]::Create()
|
||||
try {
|
||||
$generator.GetBytes($randomBytes)
|
||||
} finally {
|
||||
$generator.Dispose()
|
||||
}
|
||||
|
||||
$password = [Convert]::ToBase64String($randomBytes)
|
||||
[System.IO.File]::WriteAllText($passwordPath, $password, [System.Text.Encoding]::ASCII)
|
||||
Write-Output 'Local PostgreSQL password created in secrets/ (value not printed).'
|
||||
Reference in New Issue
Block a user