From fda2a4cf61efa3bb3bb15b3484f8ee3d0f90948d Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 16 Jun 2020 11:04:42 +0300 Subject: [PATCH 1/4] Create manifest-validator.ps1 --- packages-generation/manifest-validator.ps1 | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 packages-generation/manifest-validator.ps1 diff --git a/packages-generation/manifest-validator.ps1 b/packages-generation/manifest-validator.ps1 new file mode 100644 index 0000000..4b7dbe4 --- /dev/null +++ b/packages-generation/manifest-validator.ps1 @@ -0,0 +1,62 @@ +param ( + [Parameter(Mandatory)][string] $ManifestUrl, + [string] $AccessToken +) + +$authorizationHeaderValue = "Basic $AccessToken" +$webRequestHeaders = @{} +if ($AccessToken) { + $webRequestHeaders.Add("Authorization", $authorizationHeaderValue) +} + +function Publish-Error { + param( + [string] $ErrorDescription, + [object] $Exception + ) + Write-Host "##vso[task.logissue type=error]ERROR: $ErrorDescription." + Write-Host "##vso[task.logissue type=error] $Exception" +} + +function Test-DownloadUrl { + param([string] $DownloadUrl) + $request = [System.Net.WebRequest]::Create($DownloadUrl) + if ($AccessToken) { + $request.Headers.Add("Authorization", $authorizationHeaderValue) + } + try { + $response = $request.GetResponse() + return ([int]$response.StatusCode -eq 200) + } catch { + return $false + } +} + +Write-Host "Downloading manifest json from '$ManifestUrl'..." +try { + $manifestResponse = Invoke-WebRequest -Method Get -Uri $ManifestUrl -Headers $webRequestHeaders +} catch { + Publish-Error "Unable to download manifest json from '$ManifestUrl'" $_ + exit 1 +} + +Write-Host "Parsing manifest json content from '$ManifestUrl'..." +try { + $manifestJson = $manifestResponse.Content | ConvertFrom-Json +} catch { + Publish-Error "Unable to parse manifest json content '$ManifestUrl'" $_ + exit 1 +} + +$versionsList = $manifestJson.version +Write-Host "Found versions: $($versionsList -join ', ')" + +$manifestJson | ForEach-Object { + Write-Host "Validating version '$($_.version)'..." + $_.files | ForEach-Object { + Write-Host " Validating '$($_.download_url)'..." + if (-not (Test-DownloadUrl $_.download_url)) { + Publish-Error "Url '$($_.download_url)' is invalid" + } + } +} From b10b90bd3c969f2f05f66e08c6a6d1184adaf2e4 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 16 Jun 2020 11:21:35 +0300 Subject: [PATCH 2/4] Update manifest-validator.ps1 --- packages-generation/manifest-validator.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/packages-generation/manifest-validator.ps1 b/packages-generation/manifest-validator.ps1 index 4b7dbe4..1103a89 100644 --- a/packages-generation/manifest-validator.ps1 +++ b/packages-generation/manifest-validator.ps1 @@ -20,6 +20,7 @@ function Publish-Error { function Test-DownloadUrl { param([string] $DownloadUrl) + $DownloadUrl = $DownloadUrl + "w" $request = [System.Net.WebRequest]::Create($DownloadUrl) if ($AccessToken) { $request.Headers.Add("Authorization", $authorizationHeaderValue) From 393744251091981a9d56f08bcfc33d0e1bb53168 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 16 Jun 2020 11:24:14 +0300 Subject: [PATCH 3/4] Update manifest-validator.ps1 --- packages-generation/manifest-validator.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/packages-generation/manifest-validator.ps1 b/packages-generation/manifest-validator.ps1 index 1103a89..0ee4976 100644 --- a/packages-generation/manifest-validator.ps1 +++ b/packages-generation/manifest-validator.ps1 @@ -16,6 +16,7 @@ function Publish-Error { ) Write-Host "##vso[task.logissue type=error]ERROR: $ErrorDescription." Write-Host "##vso[task.logissue type=error] $Exception" + Write-Host "##vso[task.complete result=Failed;]" } function Test-DownloadUrl { From a3c9b8be132d72f7b64ae0e3a7df369bc5878599 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 16 Jun 2020 11:41:15 +0300 Subject: [PATCH 4/4] Update manifest-validator.ps1 --- packages-generation/manifest-validator.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/packages-generation/manifest-validator.ps1 b/packages-generation/manifest-validator.ps1 index 0ee4976..7266e11 100644 --- a/packages-generation/manifest-validator.ps1 +++ b/packages-generation/manifest-validator.ps1 @@ -21,7 +21,6 @@ function Publish-Error { function Test-DownloadUrl { param([string] $DownloadUrl) - $DownloadUrl = $DownloadUrl + "w" $request = [System.Net.WebRequest]::Create($DownloadUrl) if ($AccessToken) { $request.Headers.Add("Authorization", $authorizationHeaderValue)