Layer7 API Management

  • 1.  how to do "or" comparison on muti-valued variable

    Posted Nov 30, 2015 11:02 AM

    Hi All,

     

    This might seem as a beginner question but i was wondering on the best way to do an "OR" expression on a multivalued variable. to illustrate this i tried adding a simple comparer but that produces an "and" expression (sample attached), so should i go for a loop with an at least check with many compares or do a reg ext inside the loop since I'm looking at this from a performance/best practice point of view.

     

    Thanks in advance,



  • 2.  Re: how to do "or" comparison on muti-valued variable

    Posted Nov 30, 2015 03:27 PM

    Hey Lepird,

     

    Take a look at the 'Compare Properties'. there is a section called 'If Multivalued'. i think you can achieve what you are looking for here. the default setting is 'all values must pass' ( Logical 'AND' ).

    compare.png

     

    Here are the different options you can use with the 'Compare Assertion and Multivalued Context Variable'.

     

    I think you may be interested in the 'Any Value Must Pass', which is more of a Logical 'OR' .

     

    multi_options.png



  • 3.  Re: how to do "or" comparison on muti-valued variable

    Posted Dec 01, 2015 03:47 AM
      |   view attached

    Hey Doyle,

     

    I Have tried all the values in the drop down and it is always failing. it seems that what i need to do is the inverse of what the assertion does. to highlight the point i created a sample policy (attached) where i need to validated a repeatable query string against a set of values.

     

    so assuming the valid values are (f1, f2, f3, f4)

     

    so the below hits should be valid:

     

    /multivalue_test?filter=f1&filter=f2

    /multivalue_test?filter=f1

    /multivalue_test?filter=f1&filter=f3

     

    and the below should be invalid

     

    /multivalue_test?filter=f6

    /multivalue_test?filter=f1&filter=f7

     

    using the compare assertion as indicated all requests fail.

    Attachment(s)

    zip
    multivalue_test.xml.zip   856 B 1 version


  • 4.  Re: how to do "or" comparison on muti-valued variable

    Posted Dec 01, 2015 10:05 AM

    Hey Fahad,

     

    I think there is some slight confusion on how the 'Compare Assertion' works. As used in the policy you attached, the rules apply to each 'Multivalued index', so each rule would need to to pass for each index, which in your case, it won't, as an index can't be equal to more than 1 value. The logical 'Or' doesn't apply to the rules, but to the multivalued variable, if that makes sense.

     

    Compare_Orig.png

     

    To accomplish what you're looking for, you'd use something like the following, this requires that there is a parameter that have each of these values at a minimum.

     

    filterPolicy_all.png



  • 5.  Re: how to do "or" comparison on muti-valued variable

    Posted Dec 01, 2015 11:03 AM

    Hey Doyle,

     

    Thanks for the reply and clarifications. Though it seems we got a bit sidetracked from my original question. as I indicated the requirement was achievable using a loop as follows

     

     

    this is doable as well using regex

     

     

    also an XSLT can work though i don't have an example right now.

     

    My question was related to which of these approaches would be considered as best practice and yield better performance results for doing a logical "OR".

     

    Thanks in advance,



  • 6.  Re: how to do "or" comparison on muti-valued variable
    Best Answer

    Posted Dec 01, 2015 11:09 AM

    Off the top of my head I don't know which one is faster, but this can easily be tested using the ${assertion.latency.ms} context variable. This guy will give you the latency in milliseconds of the last assertion that executed, so if you put all the logic you want to test in an 'All Assertions' folder and then set a context variable Logic1_Latency=${assertion.latency.ms}, this variable will now contain the time it took to execute the previous All assertion.

     

    From here, you should be able to get an idea of how fast the logic is.



  • 7.  Re: how to do "or" comparison on muti-valued variable

    Posted Dec 01, 2015 11:22 AM

    Thanks for the update and fast response I will be doing that in my testing.