Выполнение lab4 на 4
This commit is contained in:
+19
-18
@@ -10,26 +10,27 @@ if (-not (Test-Path -LiteralPath $envPath)) {
|
||||
}
|
||||
|
||||
$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.'
|
||||
function Ensure-LocalSecret([string] $name, [string] $prefix = '', [int] $byteCount = 32) {
|
||||
$secretPath = Join-Path $secretsDirectory "$name.txt"
|
||||
if (Test-Path -LiteralPath $secretPath) {
|
||||
if ([string]::IsNullOrWhiteSpace([IO.File]::ReadAllText($secretPath))) {
|
||||
throw "Existing secret file is empty: $name"
|
||||
}
|
||||
Write-Output "Existing secret preserved: $name"
|
||||
return
|
||||
}
|
||||
Write-Output 'Existing PostgreSQL password preserved.'
|
||||
exit 0
|
||||
$randomBytes = New-Object byte[] $byteCount
|
||||
$generator = [System.Security.Cryptography.RandomNumberGenerator]::Create()
|
||||
try { $generator.GetBytes($randomBytes) } finally { $generator.Dispose() }
|
||||
$secretValue = $prefix + ([BitConverter]::ToString($randomBytes).Replace('-', '').ToLowerInvariant())
|
||||
[IO.File]::WriteAllText($secretPath, $secretValue, [Text.Encoding]::ASCII)
|
||||
Write-Output "Local secret created: $name (value not printed)."
|
||||
}
|
||||
|
||||
$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).'
|
||||
Ensure-LocalSecret 'postgres_password'
|
||||
Ensure-LocalSecret 's3_root_user' 'root' 8
|
||||
Ensure-LocalSecret 's3_root_password'
|
||||
Ensure-LocalSecret 's3_access_key_id' 'api-' 8
|
||||
Ensure-LocalSecret 's3_secret_access_key'
|
||||
|
||||
Reference in New Issue
Block a user