Working with global policies

Global policies are a set of policies that are associated globally with all APIs or the selected set of APIs.

Note: This section applies only to the IBM® webMethods API Gateway.

When you create an API, you can enforce a policy only at the API level. If an organization wants to enforce a policy for multiple APIs, IBM API Studio provides the capability of creating a global policy that can be applied across all APIs or a selected set of APIs depending on the requirement. By associating policies globally to all APIs or a selected set of APIs, as an administrator you can ensure that a set of policies is applied to the selected APIs by default. For example, you can apply a routing policy to all APIs by creating a Global policy that controls how requests route to backend services.

In IBM API Studio, this policy is identified by the kind GlobalPolicy.

Here is a sample code for a Global policy.

kind: GlobalPolicy
apiVersion: api.ibm.com\v1
metadata:
  name: global_policy
  version: 1.0
  namespace: sample
spec:
  filter-api-type:
    - REST
  filter-http-methods:
    - GET
    - PUT
  filter-attributes: |
    (${apiName} endsWith Sample) and
    (${apiVersion} equals 1.0) and
    (${apiDescription} contains [finance, shopping]) and
    (${apiTag} contains swagger)
  # operator maybe equals, notEquals, contains, notContains, startsWith, notStartsWith, endsWith
  policy-sequence:
    - $ref: sample:policy_sequence:1.0 #set kind: StagedPolicySequence when defining the policy sequence

The structure in the code view and what it denotes is as follows.

Type Description
kind GlobalPolicy.

This denotes the asset type, global policy.

metadata This denotes the metadata or details of the asset type.
It covers the following metadata:
  • name. Name of the policy.
  • version. Version of the policy.
  • namespace. The namespace identifier for the policy.
spec This denotes various policy properties you can configure for the policy.

You can configure the following policy properties:

  • filter-api-type. Specifies the API types to include. Supported API types are REST, SOAP, and ODATA.
  • filter-http-methods. Specifies the HTTP methods to include. Supported HTTP methods are GET, PUT, POST, DELETE, PATCH, and HEAD.
  • filter-attributes. Defines the filtering logic using supported operators such as equals, contains, and endsWith. The API must satisfy all of the following conditions:

    Only APIs that meet all the conditions pass the filter.

  • policy_sequence. Specifies the policy sequence to apply to APIs that match the filter. The $ref attribute refers to a policy sequence in the format namespace:name:version.
    Note: You must set kind: StagedPolicySequence when defining the policy sequence for the IBM webMethods API Gateway.