feat(oidc): added in so we could use an oidc to login as well :D
This commit is contained in:
@@ -23,6 +23,8 @@ $password = $ADM_PASSWORD
|
||||
$securePass = ConvertTo-SecureString $password -AsPlainText -Force
|
||||
$credentials = New-Object System.Management.Automation.PSCredential($username, $securePass)
|
||||
|
||||
|
||||
|
||||
function Update-Server {
|
||||
param (
|
||||
[string]$Destination,
|
||||
@@ -84,6 +86,75 @@ function Update-Server {
|
||||
$AppUpdate = {
|
||||
param ($Server, $Token, $Destination, $BuildFile)
|
||||
|
||||
function Fix-Env {
|
||||
$envFile = ".env"
|
||||
|
||||
if (-not (Test-Path $envFile)) {
|
||||
Write-Host ".env not found, creating..."
|
||||
New-Item -ItemType File -Path $envFile | Out-Null
|
||||
}
|
||||
|
||||
$envContent = Get-Content $envFile -Raw
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($envContent)) {
|
||||
$envContent = ""
|
||||
}
|
||||
|
||||
$envVarsToAdd = @{
|
||||
"PROVIDER" = "voidauth"
|
||||
"CLIENT_ID" = "crIVcUilFWIS6ME3"
|
||||
"CLIENT_SECRET" = "zsJeyjMN2yDDqfyzSsh96OtlA2714F5d"
|
||||
"CLIENT_SCOPES" = "openid profile email groups"
|
||||
"DISCOVERY_URL" = "https://auth.tuffraid.net/oidc/.well-known/openid-configuration"
|
||||
}
|
||||
|
||||
$linesToAppend = @()
|
||||
|
||||
foreach ($key in $envVarsToAdd.Keys) {
|
||||
$escapedKey = [regex]::Escape($key)
|
||||
|
||||
if ($envContent -notmatch "(?m)^$escapedKey=") {
|
||||
$linesToAppend += "$key=$($envVarsToAdd[$key])"
|
||||
Write-Host "Adding missing env: $key"
|
||||
}
|
||||
else {
|
||||
Write-Host "Env exists, skipping add: $key"
|
||||
}
|
||||
}
|
||||
|
||||
###### to replace the values of mistakens or something fun where we need to fix across all 17 servers put it here.
|
||||
$envVarsToReplace = @{
|
||||
# "PORT" = "3000"
|
||||
#"URL" = "https://$($Token)prod.alpla.net/lst"
|
||||
}
|
||||
|
||||
foreach ($key in $envVarsToReplace.Keys) {
|
||||
$value = $envVarsToReplace[$key]
|
||||
$escapedKey = [regex]::Escape($key)
|
||||
|
||||
if ($envContent -match "(?m)^$escapedKey=") {
|
||||
Write-Host "Replacing env: $key -> $value"
|
||||
$envContent = $envContent -replace "(?m)^$escapedKey=.*", "$key=$value"
|
||||
}
|
||||
else {
|
||||
Write-Host "Env not found for replace, skipping: $key"
|
||||
}
|
||||
}
|
||||
|
||||
if ($linesToAppend.Count -gt 0) {
|
||||
if ($envContent.Length -gt 0 -and -not $envContent.EndsWith("`n")) {
|
||||
$envContent += "`r`n"
|
||||
}
|
||||
|
||||
$envContent += "`r`n# ---- VoidAuth Config ----`r`n"
|
||||
$envContent += ($linesToAppend -join "`r`n")
|
||||
Write-Host "Appending new env vars."
|
||||
}
|
||||
|
||||
Set-Content -Path $envFile -Value $envContent
|
||||
Write-Host "Env update completed."
|
||||
}
|
||||
|
||||
#convert everything to the server fun
|
||||
$LocalPath = $Destination -replace '\$', ':'
|
||||
$BuildFileLoc = "$LocalPath\$BuildFile"
|
||||
@@ -121,8 +192,12 @@ function Update-Server {
|
||||
Write-Host "Running install/update in: $LocalPath"
|
||||
npm install --omit=dev
|
||||
Start-Sleep -Seconds 3
|
||||
Write-Host "Install/update completed."
|
||||
# do the migrations
|
||||
Write-Host "Install/update completed."
|
||||
|
||||
# update the env to include the new and missing things silly people and wanting things fixed :(
|
||||
Fix-Env #-Path $LocalPath
|
||||
|
||||
# do the migrations
|
||||
# Push-Location $LocalPath
|
||||
Write-Host "Running migrations"
|
||||
npm run dev:db:migrate
|
||||
|
||||
Reference in New Issue
Block a user