Skip to content

Commit

Permalink
chocolatey-visualstudio.extension: extract Get-VSChannelManifestItem …
Browse files Browse the repository at this point in the history
…out of Get-VSChannelManifestItemUrl

GitHub-Issue: GH-7 GH-8 GH-10 GH-26
  • Loading branch information
jberezanski committed May 15, 2018
1 parent a26823a commit d0b1e41
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 40 deletions.
@@ -0,0 +1,53 @@
function Get-VSChannelManifestItem
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)] [System.Collections.IDictionary] $Manifest,
[ValidateSet('Bootstrapper', 'Manifest')] [Parameter(Mandatory = $true)] [string] $ChannelItemType
)

$result = $null
if ($Manifest -is [Collections.IDictionary] -and $Manifest.ContainsKey('channelItems'))
{
$channelItems = $Manifest['channelItems']
if ($channelItems -is [array])
{
$channelItem = $channelItems | Where-Object { $_ -is [Collections.IDictionary] -and $_.ContainsKey('type') -and $_['type'] -eq $ChannelItemType }
if (($channelItem | Measure-Object).Count -eq 1)
{
if ($channelItem -is [Collections.IDictionary])
{
$result = $channelItem
}
else
{
Write-Debug 'Manifest parsing error: channelItem is not IDictionary'
}
}
else
{
Write-Debug 'Manifest parsing error: zero or more than one channelItem objects found'
}
}
else
{
Write-Debug 'Manifest parsing error: channelItems is not an array'
}
}
else
{
Write-Debug 'Manifest parsing error: manifest is not IDictionary or does not contain channelItems'
}

if ($result -ne $null)
{
Write-Debug "Located channel manifest item of type $ChannelItemType"
}
else
{
Write-Debug "Could not locate the channel manifest item of type $ChannelItemType"
}

return $result
}
Expand Up @@ -3,76 +3,54 @@ function Get-VSChannelManifestItemUrl
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)] [hashtable] $Manifest,
[Parameter(Mandatory = $true)] [System.Collections.IDictionary] $Manifest,
[ValidateSet('Bootstrapper', 'Manifest')] [Parameter(Mandatory = $true)] [string] $ChannelItemType
)

$url = $null
$checksum = $null
$checksumType = $null
if ($Manifest -is [Collections.IDictionary] -and $Manifest.ContainsKey('channelItems'))
$channelItem = Get-VSChannelManifestItem -Manifest $Manifest -ChannelItemType $ChannelItemType
if ($channelItem -is [Collections.IDictionary] -and $channelItem.ContainsKey('payloads'))
{
$channelItems = $Manifest['channelItems']
if ($channelItems -is [array])
$payloads = $channelItem['payloads']
if ($payloads -is [array])
{
$channelItem = $channelItems | Where-Object { $_ -is [Collections.IDictionary] -and $_.ContainsKey('type') -and $_['type'] -eq $ChannelItemType }
if (($channelItem | Measure-Object).Count -eq 1)
if (($payloads | Measure-Object).Count -eq 1)
{
if ($channelItem -is [Collections.IDictionary] -and $channelItem.ContainsKey('payloads'))
$payload = $payloads[0]
if ($payload -is [Collections.IDictionary] -and $payload.ContainsKey('url'))
{
$payloads = $channelItem['payloads']
if ($payloads -is [array])
$url = $payload['url']
if (-not [string]::IsNullOrEmpty($url) -and $payload.ContainsKey('sha256'))
{
if (($payloads | Measure-Object).Count -eq 1)
{
$payload = $payloads[0]
if ($payload -is [Collections.IDictionary] -and $payload.ContainsKey('url'))
{
$url = $payload['url']
if (-not [string]::IsNullOrEmpty($url) -and $payload.ContainsKey('sha256'))
{
$checksum = $payload['sha256']
$checksumType = 'sha256'
}
else
{
Write-Debug 'Manifest parsing error: payload url is empty or payload does not contain sha256'
# url will still be returned; it might be useful even without the checksum
}
}
else
{
Write-Debug 'Manifest parsing error: payload is not IDictionary or does not contain url'
}
}
else
{
Write-Debug 'Manifest parsing error: zero or more than one payload objects found'
}
$checksum = $payload['sha256']
$checksumType = 'sha256'
}
else
{
Write-Debug 'Manifest parsing error: payloads is not an array'
Write-Debug 'Manifest parsing error: payload url is empty or payload does not contain sha256'
# url will still be returned; it might be useful even without the checksum
}
}
else
{
Write-Debug 'Manifest parsing error: channelItem is not IDictionary or does not contain payloads'
Write-Debug 'Manifest parsing error: payload is not IDictionary or does not contain url'
}
}
else
{
Write-Debug 'Manifest parsing error: zero or more than one channelItem objects found'
Write-Debug 'Manifest parsing error: zero or more than one payload objects found'
}
}
else
{
Write-Debug 'Manifest parsing error: channelItems is not an array'
Write-Debug 'Manifest parsing error: payloads is not an array'
}
}
else
{
Write-Debug 'Manifest parsing error: manifest is not IDictionary or does not contain channelItems'
Write-Debug 'Manifest parsing error: channelItem is not IDictionary or does not contain payloads'
}

if (-not [string]::IsNullOrEmpty($url))
Expand Down

0 comments on commit d0b1e41

Please sign in to comment.