Using App Attributes to Configure Policies

3 3 1,448

During API proxy development, you will probably set, reset, and set again the configuration properties of a policy until you have the properties set to the correct value for your requirements. However, every time you change a policy setting, you have to redeploy the API proxy.

For example, if you are using the Edge UI, saving the API proxy automatically redeploys it. If you are developing your API proxies in XML, then you have to upload your changes to Edge and then redeploy the proxy manually or through Edge management API calls.

Alternatively, you can configure policies using variables. Then, you only need to change the value of a variable to reconfigure the policy. That means no redeploy needed and, if you are developing proxies in XML, no upload required either.

There are many ways to set variables in Edge. You can:

  • Pass query params, headers, form parameters, the HTTP message body, and other information in a request to an API proxy and then access that information as flow variables.
  • Use the ExtractVariables policy to extract the settings from a request.
  • Use Key/Value maps, which are collections of arbitrary name/value pairs that can be accessed at runtime by API proxies.
  • Set attributes on an app, API product, or individual developer and use those attributes to configure a proxy.

For this article, I used app attributes because they don't require me to add any extra information to a request, as required by flow variables and the ExtractVariables property, or add any logic to the proxy to extract a Key/Value map entry. Also, I can set them once for an app, instead of setting them for every developer or API product.

You can edit app attributes in the Edge UI, or using the Update an App Attribute API. In the Edge UI:

  1. Select Publish > Developer Apps.
  2. Select the app from the list, and the select Edit to edit the app attributes or add new ones.

Shown below are the attributes for an app named "QuotaTest":

1685-screen-shot-2015-12-17-at-91954-am.png

These attributes let me configure a Quota policy for my API proxy. In this scenario, I want to try different quota settings to see which work best in my test environment. I can quickly change the values of the app attributes to configure my Quota policy without having to redeploy my API proxy for every change. After I determine the correct values for my requirements, I can either set them directly in the Quota policy, or leave them as app attributes.

Shown below is my Quota policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="Quota-ProductExtract">
    <DisplayName>Quota-ProductExtract</DisplayName>
     <!-- Get from app attribute -->
    <Allow count="2000" countRef="verifyapikey.verify-api-key.app.appLimit"/>
    <Interval ref="verifyapikey.verify-api-key.app.appInterval">1</Interval> 
    <TimeUnit ref="verifyapikey.verify-api-key.app.appTimeUnit">hour</TimeUnit>
</Quota> 

The only requirement is that the API proxy uses an APIKey policy. It is through the VerifyAPI key policy that you reference the app attributes:

verifyapikey.<verifyApiKeyPolicyName>.app.<appAttributeName> 

Notice how the policy also specifies default values for the properties. These values are used if the app attributes are not accessible for some reason.

Alternatively, you could extract attributes from the API product:

<!-- extract from product based on key 
<Allow count="2000" countRef="verifyapikey.verify-api-key.apiproduct.developer.quota.limit"/>
<Interval ref="verifyapikey.verify-api-key.apiproduct.developer.quota.interval">1</Interval>
<TimeUnit ref="verifyapikey.verify-api-key.apiproduct.developer.quota.timeunit">hour</TimeUnit> 

Or developer:

<!-- get from developer attribute    
<Allow count="2000" countRef="verifyapikey.verify-api-key.developer.limit"/>
<Interval ref="verifyapikey.verify-api-key.developer.timeInterval">1</Interval>
<TimeUnit ref="verifyapikey.verify-api-key.developer.timeUnit">hour</TimeUnit>
Comments
Not applicable

Hi @sgilson,

Can you detail the solution you refer to in these lines:

Alternatively, you could extract attributes from the API product:

<!-- extract from product based on key 
<Allow count="2000" countRef="verifyapikey.verify-api-key.apiproduct.developer.quota.limit"/>
<Interval ref="verifyapikey.verify-api-key.apiproduct.developer.quota.interval">1</Interval>
<TimeUnit ref="verifyapikey.verify-api-key.apiproduct.developer.quota.timeunit">hour</TimeUnit> 

I looks to me that verifyapikey.verify-api-key.apiproduct.developer.quota.* are not custom attributes. If I am right, then where are they set up exactly and how? I am trying to set them up using the Edge UI, but I do not manage it.

Thank you,

Emilia

Not applicable

Thank you, this was a very helpful article! I would like to take your Quota example one step further.

I have the case where I have product with a defined quota. And this quota is what I want to apply to all applications within the product. Then along comes an application that requires a quota that is much higher than what is defined by the product. So how can define a different quota policy for this application without changing the quota for all other applications associated to the product. Without requiring me to update all applications.

Where and how do I define the followin conditional logic? First I'd like it to look for the quota values for the application, then the product, and then a default value if nothing else exists.

@swilliams, thoughts?

williamssean
Staff

Great question @Stacey Frett. I actually think this should be a new question on the community.

There are two approaches: 1) Create a new product with the new quota and grant the application access to the new product that you created.

2) Add a custom attribute on the App which will override the quota defined on the product. So in this case you would need a JavaScript callout that checks for the custom attribute on the App and if it exists then set a flow variable with the App limit. If the App custom attribute does not exist then set the flow variable with the product quota limit. In the Quota policy, refer to the flow variable as opposed to the Apigee defined quota limit.

Version history
Last update:
‎12-17-2015 06:44 AM
Updated by: