-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get-EvergreenAppItem fails when applications has no filter options #18
Labels
enhancement
New feature or request
Comments
I've got it working by modifying the function Get-EvergreenAppItem (line #63-ish): function Get-EvergreenAppItem {
param (
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$AppId,
[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[System.Object[]]$FilterOptions
)
# Construct array list to build the dynamic filter list
if ( $FilterOptions ) {
$FilterList = New-Object -TypeName "System.Collections.ArrayList"
# Process known filter properties and add them to array list if present on current object
if ( $FilterOptions.Architecture) {
$null = $FilterList.Add("`$PSItem.Architecture -eq ""$($FilterOptions.Architecture)""")
}
if ( $FilterOptions.Platform) {
$null = $FilterList.Add("`$PSItem.Platform -eq ""$($FilterOptions.Platform)""")
}
if ( $FilterOptions.Channel) {
$null = $FilterList.Add("`$PSItem.Channel -eq ""$($FilterOptions.Channel)""")
}
if ( $FilterOptions.Type) {
$null = $FilterList.Add("`$PSItem.Type -eq ""$($FilterOptions.Type)""")
}
if ( $FilterOptions.InstallerType) {
$null = $FilterList.Add("`$PSItem.InstallerType -eq ""$($FilterOptions.InstallerType)""")
}
if ( $FilterOptions.Language) {
$null = $FilterList.Add("`$PSItem.Language -eq ""$($FilterOptions.Language)""")
}
if ( $FilterOptions.Edition ) {
$null = $FilterList.Add("`$PSItem.Edition -eq ""$($FilterOptions.Edition )""")
}
if ( $FilterOptions.Release ) {
$null = $FilterList.Add("`$PSItem.Release -eq ""$($FilterOptions.Release )""")
}
if ( $FilterOptions.ImageType ) {
$null = $FilterList.Add("`$PSItem.ImageType -eq ""$($FilterOptions.ImageType )""")
}
# Construct script block from filter list array
$FilterExpression = [scriptblock]::Create(($FilterList -join " -and "))
# Get the evergreen app based on dynamic filter list
$EvergreenApp = Get-EvergreenApp -Name $AppId | Where-Object -FilterScript $FilterExpression
} else {
$EvergreenApp = Get-EvergreenApp -Name $AppId
}
# Handle return value
return $EvergreenApp
} and then on line #279-ish in Get-EvergreenAppItem.ps1: switch ($App.AppSource) {
"Winget" {
$AppItem = Get-WindowsPackageManagerItem -AppId $App.AppId
}
"Evergreen" {
if ( $null -ne $($App.FilterOptions) ) {
$AppItem = Get-EvergreenAppItem -AppId $App.AppId -FilterOptions $App.FilterOptions
} else {
$AppItem = Get-EvergreenAppItem -AppId $App.AppId
}
}
"StorageAccount" {
$AppItem = Get-StorageAccountAppItem -StorageAccountName $App.StorageAccountName -ContainerName $App.StorageAccountContainerName
}
} |
Cool - good catch! This makes total sense. I'll add this to the upcoming 1.1.0 version that I've been working on in the past months. Thanks for sharing! |
Coded into 1.1.0 now, awaiting further testing. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to package GIMP, but there's only one installer available for download in Evergreen and hence has no need for filtering.
Get-EvergreenAppItem has the FilterOptions parameter set to mandatory and therefore will fail when attempting to retrieve GIMP data. Edit: Or actually when I think of it, it would rather be the ValidateNotNullOrEmpty attribute that's causing the failure, as the pipeline would actually supply an empty value for the parameter input.
Perhaps you should add some logics to the function in order to make it work in this scenario as well and allow for FilterOptions to be voluntary.
The text was updated successfully, but these errors were encountered: