param( [string]$BaseUrl = "http://localhost:8080", [string]$ApiToken = "" ) Write-Host "AZA Healthcheck" # Resolve token (param wins; otherwise ENV) $resolvedToken = $ApiToken if (-not $resolvedToken -or $resolvedToken.Trim().Length -eq 0) { $resolvedToken = $env:AZA_API_TOKEN } function Invoke-JsonGet([string]$Url) { $headers = @{} if ($resolvedToken -and $resolvedToken.Trim().Length -gt 0) { # IMPORTANT: Never print the token. $headers["Authorization"] = "Bearer $resolvedToken" } return Invoke-RestMethod -Uri $Url -Headers $headers -Method GET } try { Invoke-JsonGet "$BaseUrl/health" | Out-Null Write-Host "Health endpoint OK" } catch { Write-Host "Health endpoint not available" } try { $license = Invoke-JsonGet "$BaseUrl/license/status" # Must keep exact schema: { valid: bool, valid_until: number|null } $hasValid = $license.PSObject.Properties.Name -contains "valid" $hasValidUntil = $license.PSObject.Properties.Name -contains "valid_until" if (-not $hasValid -or -not $hasValidUntil) { throw "License schema invalid (missing keys)" } if ($license.valid -isnot [bool]) { throw "License schema invalid (valid must be boolean)" } if ($null -ne $license.valid_until -and ($license.valid_until -isnot [int] -and $license.valid_until -isnot [long] -and $license.valid_until -isnot [double])) { throw "License schema invalid (valid_until must be null or unix timestamp)" } Write-Host "License endpoint schema OK" } catch { Write-Host "License endpoint check failed" Write-Host $_.Exception.Message exit 1 } Write-Host "Healthcheck complete"