How to Define, Package and publish a Catalog scoped user-defined policy in IBM Datapower API Gateway?
1. User Defined policy
A policy is a piece of code that implements a specific aspect of processing in the IBM Datapower API Gateway during the handling of an API invocation at Run time.
A User defined policy is a feature of API Connect that lets us create our own policy executed in Datapower Gateway to achieve specific functionality like security, routing, logging, etc. A user-defined policy is of two types
- Catalog-scoped user-defined policy – A catalog-scoped user-defined policy is available to the APIS in the specific catalog to which the policy is published.
- Global scoped user-defined policy – A global scoped policy is available to all the APIS published in any catalog.
2. Defining Catalog scoped user-defined policy
2.1 Structure of user-defined policy yaml file
|Specification version.||The YAML file policy version.|
|Information section.||The title, name, version, description, and contact info for the policy.|
|Attach section.||Whether the policy is applied for REST/SOAP APIs.|
|Properties section.||Input properties for the policy as seen in the diagram below.
The properties section contains the list of properties the policy will declare as required input.
The JSON schema defines a root object containing the following JSON properties:
o label: The name value displayed for the property
o description: description of the property.
o type: integer, string, number, boolean, or array
o default (optional): default value.
o enum (for properties with a type of string): array of valid values.
|Gateways section.||Specify whether the policy is used with the DataPower gateway or any microservices gateway.|
|Assembly Section||XSLT/Gateway script that needs to be executed will be defined in this section|
*Note – Assembly section and properties section are optional sections of the yaml file
3. Packaging Catalog scope user-defined policy
- To Package, a catalog scope user-defined policy we need to create a zip file and import the policy into the zip file.
- A zip file can contain only 1 yaml file.
4. Publishing Catalog scoped user-defined policy
- Login to API Manager
- Click Manage Catalogs
- Select catalogs
- Then select the catalog you want to deploy the custom policy
- Gateways -> Selected Gateways
- Click on -> view policies -> Upload the newly created zip file.
- Verify if the custom policy is displayed in the assembly