Public Access
Validate FTPS/SFTP config fields and name what's missing before connecting
CAMBS's run showed host= blank, an empty upload path, and WinSCP's "Password is set, but UserName is not" - i.e. entity.json's ftps section had a readable password but host/username/insurance_path came up empty, which points at misspelled or misplaced keys. Instead of letting WinSCP throw a cryptic connect error per practice, check the merged config up front and print exactly which entity.json fields are missing or blank.
This commit is contained in:
+26
@@ -110,6 +110,16 @@ function Expand-Path($template, $practice) {
|
|||||||
return $template -replace '\{practice\}', $practice
|
return $template -replace '\{practice\}', $practice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-MissingFields($section, $sectionName, $fieldNames) {
|
||||||
|
$missing = @()
|
||||||
|
foreach ($f in $fieldNames) {
|
||||||
|
if (-not $section -or [string]::IsNullOrWhiteSpace([string]$section.$f)) {
|
||||||
|
$missing += "$sectionName.$f"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $missing
|
||||||
|
}
|
||||||
|
|
||||||
function Get-ArchiveDir($parent, $name) {
|
function Get-ArchiveDir($parent, $name) {
|
||||||
$found = Get-ChildItem -Path $parent -Directory |
|
$found = Get-ChildItem -Path $parent -Directory |
|
||||||
Where-Object { $_.Name -ieq $name } | Select-Object -First 1
|
Where-Object { $_.Name -ieq $name } | Select-Object -First 1
|
||||||
@@ -245,6 +255,16 @@ foreach ($practice in $practices) {
|
|||||||
$pdfPath = Expand-Path $config.ftps.pdf_path $pracName
|
$pdfPath = Expand-Path $config.ftps.pdf_path $pracName
|
||||||
$insResult = @{ Ok = 0; Fail = 0 }
|
$insResult = @{ Ok = 0; Fail = 0 }
|
||||||
|
|
||||||
|
$missing = Get-MissingFields $config.ftps "ftps" @("host", "username", "password", "insurance_path", "pdf_path")
|
||||||
|
if (($insFiles.Count -gt 0 -or $ptStmts.Count -gt 0) -and $missing.Count -gt 0) {
|
||||||
|
Write-Host " CONFIG ERROR: entity.json is missing or has blank: $($missing -join ', ')" -ForegroundColor Red
|
||||||
|
Write-Host " Check spelling of those keys in entity.json (and practice.json if present)." -ForegroundColor Yellow
|
||||||
|
Write-Log "error" "CONFIG entity=$entityName practice=$pracName missing=$($missing -join ',')"
|
||||||
|
$totalFail += $insFiles.Count + $ptStmts.Count
|
||||||
|
Write-Host " $today\ left for retry." -ForegroundColor Yellow
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if ($insFiles.Count -gt 0) {
|
if ($insFiles.Count -gt 0) {
|
||||||
Write-Host " Insurance ($($insFiles.Count)) -> $insPath" -ForegroundColor White
|
Write-Host " Insurance ($($insFiles.Count)) -> $insPath" -ForegroundColor White
|
||||||
$r = Invoke-FTPSUpload $config.ftps $insFiles $insPath $entityName $pracName
|
$r = Invoke-FTPSUpload $config.ftps $insFiles $insPath $entityName $pracName
|
||||||
@@ -293,6 +313,12 @@ foreach ($practice in $practices) {
|
|||||||
if ($patFiles.Count -eq 0) {
|
if ($patFiles.Count -eq 0) {
|
||||||
Write-Host " No txt/tif files in $($ptFolder.Name)\ - skipping." -ForegroundColor Gray
|
Write-Host " No txt/tif files in $($ptFolder.Name)\ - skipping." -ForegroundColor Gray
|
||||||
Write-Info "SKIP entity=$entityName practice=$pracName reason=no txt/tif files"
|
Write-Info "SKIP entity=$entityName practice=$pracName reason=no txt/tif files"
|
||||||
|
} elseif (($sftpMissing = Get-MissingFields $config.sftp "sftp" @("host", "username", "password", "patient_path")).Count -gt 0) {
|
||||||
|
Write-Host " CONFIG ERROR: entity.json is missing or has blank: $($sftpMissing -join ', ')" -ForegroundColor Red
|
||||||
|
Write-Host " Check spelling of those keys in entity.json (and practice.json if present)." -ForegroundColor Yellow
|
||||||
|
Write-Log "error" "CONFIG entity=$entityName practice=$pracName missing=$($sftpMissing -join ',')"
|
||||||
|
$totalFail += $patFiles.Count
|
||||||
|
Write-Host " $($ptFolder.Name)\ left for retry." -ForegroundColor Yellow
|
||||||
} else {
|
} else {
|
||||||
$patPath = Expand-Path $config.sftp.patient_path $pracName
|
$patPath = Expand-Path $config.sftp.patient_path $pracName
|
||||||
Write-Host " Patient ($($patFiles.Count)) -> $patPath" -ForegroundColor White
|
Write-Host " Patient ($($patFiles.Count)) -> $patPath" -ForegroundColor White
|
||||||
|
|||||||
Reference in New Issue
Block a user