Global Custom Actions

Directory Structure

|-- global_custom_actions/
  |-- global_custom_actions.yaml
  |-- ...

The YAML files can contain one or more global custom actions.

Configuration Description

Parameter NameData TypeRequiredDescription
namestringYesThe name of the global custom action, which is also its unique identifier
conditionsarrayYesList of conditions that trigger this action
actionsarrayYesList of actions to be executed when the conditions are met

Conditions Configuration

Please refer to Page Rules - Conditions

Actions Configuration

Please refer to Page Rules - Actions

Configuration Example

- name: global-action-1
  conditions:
  - var: uri
    op: eq
    val: /hello
  actions:
  - limit-req-rate:
      rate_shape_unit: r/s
      rate_reject: 20
      rate_reject_unit: r/s
      error_page_status_code: 429
      reject_action: error_page
      limit_key: uri
      rate_shape: 10
- name: global-action-2
  conditions:
  - var: uri
    op: eq
    val: /bad/request
  actions:
  - exit:
      code: 403
- name: global-action-3
  conditions:
  - var: uri
    op: eq
    val: /el
  actions:
  - user-code:
      el: |-
        {
        true =>
          set-upstream-name("hello $or_global_user_variable_uuid"),
          done;
        }

This configuration defines three global custom actions, each with specific conditions and actions to be executed.

Usage Example

Update configuration to OpenResty Edge:

edge-config https://192.168.1.1 -s -t 2051e780-1897-4ea0-92b4-2c2f0169aa94 -l global_custom_actions -i /root/oredge-configs

Export configuration from OpenResty Edge:

edge-config -u https://192.168.1.1 -s -t 2051e780-1897-4ea0-92b4-2c2f0169aa94 -E -l global_custom_actions

In both examples, -l global_custom_actions is used to specify that only global custom action related configurations are to be imported/exported.

Notes

  1. Global custom actions are a global configuration. Delete operations are not performed when updating configurations to maintain compatibility with multiple local configurations.

  2. Each global custom action must have a unique name.

  3. Action configurations must be valid action types with corresponding configuration parameters.

  4. When updating configurations, the tool compares the new and old configurations to determine if an update is necessary. If there are changes, an update operation will be performed.

  5. When importing configurations, the tool first checks the validity of the configuration before performing add or update operations.

  6. the tool formats the YAML content when exporting configurations, especially for the el field in user-code actions.