Files
lingxi-web/telegram-gateway/docker/scripts/rotate-jwt.ps1
T
wmq 06112602ec feat(gateway): include production Telegram user gateway
Version the NestJS TDLib gateway with Docker deployment, migrations, automated tests and platform integration documentation while excluding all account sessions, credentials, runtime databases and backups.
2026-08-01 18:38:20 +08:00

39 lines
1.0 KiB
PowerShell

param(
[Parameter(Mandatory = $true)]
[string]$EnvironmentFile
)
$ErrorActionPreference = 'Stop'
$envPath = [System.IO.Path]::GetFullPath($EnvironmentFile)
if (-not (Test-Path -LiteralPath $envPath -PathType Leaf)) {
throw "Environment file not found"
}
$bytes = New-Object byte[] 48
$generator = [System.Security.Cryptography.RandomNumberGenerator]::Create()
try {
$generator.GetBytes($bytes)
} finally {
$generator.Dispose()
}
$newSecret = [Convert]::ToBase64String($bytes).TrimEnd('=').Replace('+', '-').Replace('/', '_')
$found = $false
$updated = foreach ($line in [System.IO.File]::ReadAllLines($envPath)) {
if ($line -match '^JWT_SECRET=') {
$found = $true
"JWT_SECRET=$newSecret"
} else {
$line
}
}
if (-not $found) {
$updated += "JWT_SECRET=$newSecret"
}
$temporaryPath = "$envPath.rotate.tmp"
$utf8WithoutBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllLines($temporaryPath, $updated, $utf8WithoutBom)
Move-Item -LiteralPath $temporaryPath -Destination $envPath -Force
Write-Output 'JWT_SECRET rotated'