Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.13k stars 3.77k forks source link

Az.EventGrid 2.0.0 Update-AzEventGridSubscription -FilterAdvancedFilter #25342

Open catalingurgu opened 3 weeks ago

catalingurgu commented 3 weeks ago

Description

Could not find a way to pass the value to search for in the key when using the new -FilterAdvancedFilter parameter, IAdvancedFilter type seems to contain only Key and operatorType properties In the previous version (1.6.1) it was possible to specify the string value to look for when using operators like "StringBeginsWith". Some examples on how to pass the value(s) needed for searching inside the key value would be welcomed. e.g.:

Update-AzEventGridSubscription -Name $data.eventName -Scope "subscriptions/$subscriptionId" -Destination $DestinationObject -FilterIncludedEventType $data.includeEventType -FilterAdvancedFilter $data.filter1

The question is, how to build the $data.filter1 object to include the text to search for.

Thanks.

Script or Debug output

No response

Environment data

No response

Module versions

No response

Error output

No response

isra-fel commented 2 weeks ago

Hi thanks for reporting! I'll loop in the developers of the module but it seems New-AzEventGridAdvancedFilterObject is the way to go. Pass its returned value to -FilterAdvancedFilter

microsoft-github-policy-service[bot] commented 2 weeks ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jfggdl.

catalingurgu commented 2 weeks ago

Hi thanks for reporting! I'll loop in the developers of the module but it seems New-AzEventGridAdvancedFilterObject is the way to go. Pass its returned value to -FilterAdvancedFilter

Thanks for the reply, indeed, I thought that I can use New-AzEventGridAdvancedFilterObject to define the filter, but its output is of type AdvancedFilter, which has only Key and OperatorType properties, see AdvancedFilter Class In the previous version (1.6.1) the filter definition was a hashtable array, the keys from a hashtable element being Operator, Key and Value(s) Learn Link So the problem with the 2.0.0 version for me is the missing "value" or "values" property from the AdvancedFilter class. I think it needs to be there, in my understanding the purpose of the advanced filter is to look for values in the Key using the operator specified with the OperationType property. Or maybe there's an alternative method to do this, but I didn't find one in the documentation. Thanks!

isra-fel commented 1 week ago

Hi @catalingurgu after checking with team member we believe this was a code defect. There should have been cmdlets for you to create filter objects and pass them to Update-AzEventGridSubscription. Use this as a workaround - create the filter objects with .NET APIs

$filter = New-Object -TypeName "Microsoft.Azure.PowerShell.Cmdlets.EventGrid.Models.StringBeginsWithAdvancedFilter" -Property @{Key = "KEY"; Value = @("VALUE1", "VALUE2")}

For a complete list of filter types please refer to the "Derived" part of IAdvancedFilter Interface

isra-fel commented 1 week ago

@jfggdl please note that the root cause was polymorphism wasn't handled correctly. According to the development guide, model classes should be created from the child classes, i.e. the concrete Filter classes instead of AdvancedFilter.

catalingurgu commented 1 week ago

@isra-fel, Thanks for the solution! For anyone trying to implement the .NET API workaround in an Azure Automation Account PowerShell Runbook: I had to explicitly import the Az.EventGrid module in the runbook (Import-Module -Name Az.EventGrid), without this the .NET assembly doesn't seem to be available and the type is not recognized.