Выполнение lab4 на 4

This commit is contained in:
Daria0w0
2026-11-06 17:35:48 +03:00
parent 9197e151ba
commit 879463c947
89 changed files with 5551 additions and 108 deletions
+19 -18
View File
@@ -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'