Files
inquiry_robot/deploy/_remote_find_prod_redis_env.ps1
T

54 lines
2.3 KiB
PowerShell

$ErrorActionPreference = "Continue"
# prod java parent / cmdline full redis-related flags (mask password values)
$prod = Get-CimInstance Win32_Process -Filter "Name='java.exe'" | Where-Object { $_.CommandLine -like '*server.port=8080*' } | Select-Object -First 1
if ($prod) {
$cl = $prod.CommandLine
Write-Host ("prod_pid=" + $prod.ProcessId)
# mask --spring.redis.password=...
$masked = [regex]::Replace($cl, "(--spring\.redis\.password=)(\S+)", '${1}***')
$masked = [regex]::Replace($masked, "(password=)([^,\s]+)", '${1}***')
Write-Host ("prod_cmd_len=" + $cl.Length)
# extract redis-related tokens
$tokens = $cl.Split(" ") | Where-Object { $_ -match "redis|REDIS|YTD_REDIS" }
foreach ($t in $tokens) {
$m = $t
if ($m -match "password=") { $m = ($m -replace "(=).+","=`$1***") }
Write-Host (" token=" + $m)
}
}
# agent short redis url
$agentEnv = "C:\yutongda\apps\inquiry-agent\.env"
if (Test-Path $agentEnv) {
Get-Content $agentEnv | ForEach-Object {
if ($_ -match "REDIS") {
$line = $_
if ($line -match "REDIS_URL=(.+)") {
$u = $Matches[1].Trim().Trim('"')
$safe = $u -replace "://[^@]+@", "://***@"
if ($safe -eq $u -and $u.Length -gt 20) { $safe = $u.Substring(0,12) + "...(len=" + $u.Length + ")" }
Write-Host ("agent_REDIS_URL_safe=" + $safe + " len=" + $u.Length)
} else {
Write-Host ("agent_" + $line)
}
}
}
}
# Try AUTH without username using password from URL via System.Uri
$www = Get-Content "E:\wwwroot\.env" | Where-Object { $_ -match "^REDIS_URL=" }
$url = ($www -replace "^REDIS_URL=","").Trim().Trim('"')
try {
# redis URL is not always valid System.Uri because of scheme; hack
$tmp = $url -replace "^redis://","http://"
$uri = [Uri]$tmp
Write-Host ("uri_userinfo_len=" + $uri.UserInfo.Length + " host=" + $uri.Host + " port=" + $uri.Port)
$ui = $uri.UserInfo
$up = $ui.Split(":",2)
Write-Host ("uri_user=" + $up[0] + " uri_pw_len=" + $up[1].Length)
} catch {
Write-Host ("uri_err=" + $_.Exception.Message)
}
# Does empty username + password work? Check lettuce docs - try starting a one-off with only password
# Use jedis from a small java snippet if jdk present
$java = "C:\yutongda\tools\jdk8\bin\java.exe"
Write-Host ("java_exists=" + (Test-Path $java))
Write-Host "FIND_DONE"