0
我非常希望能夠根據用戶的Jwt聲明數據設置Azure API策略屬性。我已經能夠設置字符串值,如計數器鍵和遞增條件,但我無法設置所有屬性。我想象着做一些這樣的:Azure APIM策略編輯器
<rate-limit-by-key
calls="@((int) context.Variables["IdentityToken"].AsJwt().Claims.GetValueOrDefault("/LimitRate/Limit", "5"))"
renewal-period="@((int) context.Variables["IdentityToken"].AsJwt().Claims.GetValueOrDefault("/LimitRate/Duration/InSeconds", "60"))"
counter-key="@((string)context.Variables["Subject"])"
increment-condition="@(context.Response.StatusCode == 200)"
/>
但是似乎有一些驗證發生的事情,當我保存政策,我收到以下錯誤:
Error in element 'rate-limit-by-key' on line 98, column 10: The 'calls' attribute is invalid - The value '@((int) context.Variables["IdentityToken"].AsJwt().Claims.GetValueOrDefault("/LimitRate/Limit", "5"))' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:int' - The string '@((int) context.Variables["IdentityToken"].AsJwt().Claims.GetValueOrDefault("/LimitRate/Limit", "5"))' is not a valid Int32 value.
我甚至無法順利設定一個字符串參數(雖然一個有嚴格的格式)
<quota-by-key
calls="10"
bandwidth="100"
renewal-period="@((string) context.Variables["IdentityToken"].AsJwt().Claims.GetValueOrDefault("/Quota/RenewalPeriod", "P00Y00M01DT00H00M00S"))"
counter-key="@((string)context.Variables["Subject"])"
/>
當我嘗試挽救政策,給出了以下幾點:
Error in element 'quota-by-key' on line 99, column 6: @((string) context.Variables["IdentityToken"].AsJwt().Claims.GetValueOrDefault("/Quota/RenewalPeriod", "P00Y00M01DT00H00M00S")) is not in a valid format. Provide number of seconds or use 'PxYxMxDTxHxMxS' format where 'x' is a number.
我已經嘗試了一大組變體cast,Convert.ToInt32,聲明不是字符串,@ {return 5},@(5)等,但似乎有一些驗證發生在保存時間阻止它。
圍繞這個問題,我認爲這將是一個有用的功能添加到我的API?