Skip to content

Instantly share code, notes, and snippets.

@gunzip
Last active October 10, 2017 13:10
Show Gist options
  • Save gunzip/f29b7854020dfcfd2a298a8a9a56ec32 to your computer and use it in GitHub Desktop.
Save gunzip/f29b7854020dfcfd2a298a8a9a56ec32 to your computer and use it in GitHub Desktop.
<policies>
<inbound>
<base />
<set-variable name="Channel" value="
@{
try {
var request = context.Request.Body.As<JObject>();
return request["content"]["channel"].ToString();
}
catch (Exception e) {
return "none";
}
}" />
<set-variable name="IsTrial" value="@(context.User.Groups.Where(g => g.Name == "ApiTrial").Count() > 0)" />
<rate-limit-by-key calls="2" renewal-period="10"
increment-condition="@(context.Variables.GetValueOrDefault("IsTrial", false))"
counter-key="@(String.Join("_",
context.Subscription.Id,
"ApiTrial",
context.Variables.GetValueOrDefault("IsTrial", false).ToString(),
(string) context.Variables["Channel"]))" />
</inbound>
</policies>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment