I have a use case to use single policy.xml for different environments however the rate-limit is applicable only for certain environment.
For eg:
Dev: rate-limit is applicable (hosted in dev azure subscription)
QA: rate-limit is not applicable (hosted in test azure subscription)
Prod: rate-limit is applicable (hosted in prod azure subscription)
Update: Tried this from one of the posts here post:
<choose>
<when condition="@(context.Subscription.Name=="abcd")">
<rate-limit-by-key calls="1" renewal-period="15" counter-key="@(context.Subscription.Id)" />
</when>
<when condition="@(context.Subscription.Name=="efgh")">
<rate-limit-by-key calls="2" renewal-period="15" counter-key="@(context.Subscription.Id)" />
</when>
<otherwise />
</choose>
Below snippet is from the inbound request and what i don't understand is the value of the first when element condition attribute is false even though it is executed from the "abcd" subscription.
choose (7.565 ms)
{
"message": "Expression was successfully evaluated.",
"expression": "context.Subscription.Name==\"abcd\"",
"value": false
}
choose (0.251 ms)
{
"message": "Expression was successfully evaluated.",
"expression": "context.Subscription.Name==\"efgh\"",
"value": false
}
Solution that worked for me from below approaches:
<choose>
<when condition="@(context.Request.Url.Host.Contains("dev"))">
<rate-limit-by-key calls="1" renewal-period="5" counter-key="@(context.Subscription.Id)" />
</when>
<when condition="@(context.Request.OriginalUrl.Host.Contains("prod")">
<rate-limit-by-key calls="2" renewal-period="10" counter-key="@(context.Subscription.Id)" />
</when>
<otherwise />
</choose>