Add safe Windows desktop feed publication
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
[CmdletBinding(DefaultParameterSetName = "Url")]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Url
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "Url")]
|
||||
[string]$Url,
|
||||
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "Path")]
|
||||
[string]$Path
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -10,27 +14,42 @@ function Fail($Message) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
$parsedUrl = $null
|
||||
if (-not [System.Uri]::TryCreate($Url, [System.UriKind]::Absolute, [ref]$parsedUrl)) {
|
||||
Fail "Desktop update feed URL is not absolute: $Url"
|
||||
}
|
||||
$feedSource = $null
|
||||
$feedContent = $null
|
||||
|
||||
if ($parsedUrl.Scheme -ne "https") {
|
||||
Fail "Desktop update feed URL must use HTTPS: $Url"
|
||||
if ($PSCmdlet.ParameterSetName -eq "Url") {
|
||||
$parsedUrl = $null
|
||||
if (-not [System.Uri]::TryCreate($Url, [System.UriKind]::Absolute, [ref]$parsedUrl)) {
|
||||
Fail "Desktop update feed URL is not absolute: $Url"
|
||||
}
|
||||
|
||||
if ($parsedUrl.Scheme -ne "https") {
|
||||
Fail "Desktop update feed URL must use HTTPS: $Url"
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 30
|
||||
} catch {
|
||||
Fail "Desktop update feed request failed for ${Url}: $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
if ($response.StatusCode -ne 200) {
|
||||
Fail "Desktop update feed must return HTTP 200. Actual status: $($response.StatusCode)"
|
||||
}
|
||||
|
||||
$feedSource = $Url
|
||||
$feedContent = $response.Content
|
||||
} else {
|
||||
if (-not (Test-Path -LiteralPath $Path)) {
|
||||
Fail "Desktop update feed file was not found: $Path"
|
||||
}
|
||||
|
||||
$feedSource = (Resolve-Path -LiteralPath $Path).Path
|
||||
$feedContent = Get-Content -LiteralPath $feedSource -Raw
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 30
|
||||
} catch {
|
||||
Fail "Desktop update feed request failed for ${Url}: $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
if ($response.StatusCode -ne 200) {
|
||||
Fail "Desktop update feed must return HTTP 200. Actual status: $($response.StatusCode)"
|
||||
}
|
||||
|
||||
try {
|
||||
[xml]$xml = $response.Content
|
||||
[xml]$xml = $feedContent
|
||||
} catch {
|
||||
Fail "Desktop update feed is not valid XML: $($_.Exception.Message)"
|
||||
}
|
||||
@@ -82,4 +101,4 @@ if ([string]::IsNullOrWhiteSpace($version)) {
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "QSfera Desktop update feed validation passed: $Url"
|
||||
Write-Host "QSfera Desktop update feed validation passed: $feedSource"
|
||||
|
||||
Reference in New Issue
Block a user