Loading

How To Enforce an API Policy via Anypoint Platform API

Fecha de publicación: Mar 2, 2024
Tarea

GOAL

Often when we have CI/CD process, we need to enforce API policies after creating an API on API Manager.

This article gives steps about how to enforce an API policy via Anypoint Platform API, therefore the procedure can be automated. 

PREREQUISITE

Before conducting the procedure below, a Mule Application needs to be registered to the API Instance via autodiscovery process.

Pasos
  1. Obtain Access Token, Organization ID, and Environment ID as per steps on the following KB:
  2. Find the API ID of the API on API Manager, it will be used on next step.
  3. Use the above information to make the following API call against https://anypoint.mulesoft.com/apimanager/api/v1/organizations/{organizationId}/environments/{environmentId}/apis/{environmentApiId}/policies .
    For example, the following commands add a Rate limiting policy:
    export accessToken={Access Token}
    export organizationId={Organization ID}
    export environmentId={Environment ID}
    export environmentApiId={API ID}
    
    curl "https://anypoint.mulesoft.com/apimanager/api/v1/organizations/$organizationId/environments/$environmentId/apis/$environmentApiId/policies" \
    	-H "Authorization: Bearer $accessToken" \
    	-H "Content-Type: application/json" \
    	-X POST \
    	-d '{
              "policyTemplateId": "throttling",
              "configurationData": {
                "rateLimits": [
                  {
                    "timePeriodInMilliseconds": 60000,
                    "maximumRequests": 10
                  }
                ]
              },
              "groupId": "68ef9520-24e9-4cf2-b2f5-620025690913",
              "assetId": "rate-limiting",
              "assetVersion": "1.3.1"
            }'
    
    Note: 68ef9520-24e9-4cf2-b2f5-620025690913 is MuleSoft group id owning out of box policies
  4. Depends on different Policies, you may want to find out the format and fields of configurationData. This can be done with steps below:
    a. Manually apply a policy on the API, then
    b. Fetch policy configurations with the following commands
    export accessToken={Access Token}
    export organizationId={Organization ID}
    export environmentId={Environment ID}
    export environmentApiId={API ID}
    
    curl "https://anypoint.mulesoft.com/apimanager/api/v1/organizations/$organizationId/environments/$environmentId/apis/$environmentApiId/policies" \
    	-H "Authorization: Bearer $accessToken"
 Disclaimer: These examples are provided as reference for your own usage and is not to be considered a MuleSoft product. These examples should be considered as a custom solution. The custom solution is not a Supported MuleSoft product.

REFERENCE

Número del artículo de conocimiento

001117037

 
Cargando
Salesforce Help | Article