Packaging and importing your policies into IBM API Connect
Make your user-defined policy available to API developers by packaging it and importing it into an IBM® API Connect Catalog.
Before you begin
Before you can package a user-defined policy and import it into IBM API Connect, you must complete the following tasks:
- Describe your policy in a YAML file.
- Implement your policy by using DataPower processing rules and actions.
To package and import your user-defined policy, complete the following steps:
Create a .zip file that contains the following folder structure:
<policy-name>.yaml implementation/ policy-name.zip
- <policy-name>.yaml is your policy definition file.
The YAML file must use the name that is specified in its
- implementation/policy-name.zip is your policy implementation for a policy that is deployed to the DataPower Gateway. The policy implementation file contains the DataPower processing rules and actions that were exported from DataPower in step 2.
The name of the .zip file must start with the name of the user-defined policy (as defined in the policy YAML file). If the implementation requires certificate and key files, these files must be added to the implementation directory.Note: Your package .zip file must contain a .zip policy implementation file.
- <policy-name>.yaml is your policy definition file. The YAML file must use the name that is specified in its
Use the API Manager user
interface to import your policy into a Catalog. For more information, see
user-defined policy into a Catalog.
- You must import your user-defined policy into every Catalog in API Manager that you require your policy to run in.
- For the policy to be displayed on the palette in the API assembly editor, you must import the user-defined policy into the Sandbox Catalog.
What to do next
Make your user-defined policy package accessible to the API Designer UI. To display user-defined policies in the API Designer UI, edit the .apiconnect/config file to point to the directory containing the policy.yaml file. You can edit the global config file (~/.apiconnect/config) or a project-specific config file (~/ProjectA/.apiconnect/config). Follow these steps:
- Create one or more directories to hold your policy.yaml files that are accessible to Node.js, and copy the user-defined policy package into this directory. For example, create directories named /ProjectA/Policies and /ProjectB/Policies.
- Extract the policy package so that the folder structure is visible, for example policy.yaml and implementation/policy-name.zip. The file containing the custom policies must be named policy.yaml.
- Add the
userPolicies: [ ]array object to the config file in ~/ProjectA/.apiconnect/ or ~/.apiconnect/, and edit the array object so it contains the absolute path to the director(ies) containing the policy.yaml file.
Following is an example of an ~/.apiconnect/config file showing the userPolicies entry pointing to the directory containing the policy.yaml file:
apim_server: us.apiconnect.ibmcloud.com us.apiconnect.ibmcloud.com.meta: formFactor: BLUEMIX_PUBLIC serverCapabilities: authTypes: - basic - token toolkit: version_recommended: 2.1.30 version_minimum: 2.1.30 catalog: >- apic-catalog://us.apiconnect.ibmcloud.com/orgs/sampleorg-myspace2/catalogs/sb app: >- apic-app://us.apiconnect.ibmcloud.com/orgs/sampleorg-myspace2/apps/acme-bank userPolicies: - /ProjectA/PoliciesNote:
userPolicies: array object contains a list of absolute paths to the policy director(ies). The values can point to a parent location, for example
userPolicies: ["~/mypolicies"]. Alternatively, each policy location can be specified in the array, for example
userPolicies: ["~/mypolicies/policya", ~/mypolicies/policyb"]. However, do not use both of these approaches in the same directory. For example, do not create policies in a directory structure like this ~/mypolicies, ~/mypolicies/policya, and ~/mypolicies/policyb.
- Open the API Designer UI. The user-defined policy is available on the policy assembly palette, and you can add the policy to your API definition.