Application User Variables

Directory Structure

|-- user_variables/
  |-- user_variables.yaml
  |-- ...

The YAML files can contain one or more user variables of the application.

Configuration Description

Each user variable is an object containing the following parameters:

Parameter NameData TypeRequiredDescription
namestringYesVariable name, must be unique
typestringYesVariable type, possible values: string, enum, num, int, bool
defaultstringYesDefault value of the variable
valuesarrayRequired only for enum typeList of possible values for enum type

Configuration Example

- name: var1
  type: string
  default: '-'
- name: var2
  type: enum
  default: abc
  values:
  - abc
  - bcd
- name: var3
  type: num
  default: '1'
- name: var4
  type: int
  default: '1'
- name: var5
  type: bool
  default: 'true'

This configuration defines five different user variables.

Usage Example

Update configuration to OpenResty Edge:

edge-config https://192.168.1.1 -s -t 2051e780-1897-4ea0-92b4-2c2f0169aa94 -l user_variables -i /root/oredge-configs -d test.com

Export configuration from OpenResty Edge:

edge-config -u https://192.168.1.1 -s -t 2051e780-1897-4ea0-92b4-2c2f0169aa94 -E -l user_variables -d test.com

Cleanup user variables from OpenResty Edge:

edge-config -u https://192.168.1.1 -s -t 2051e780-1897-4ea0-92b4-2c2f0169aa94 -c -l user_variables -d test.com

The above examples all use -l user_variables to specify that the command-line tool will operate only on configurations related to the user variables.

Notes

  1. Each user variable must have a unique name.

  2. The variable type must be one of the valid types: string, enum, num, int, bool.

  3. a values list must be provided for enum type variables, and the default value must be in this list.

  4. the default value must be a valid floating-point number for num-type variables.

  5. the default value must be a valid integer for int-type variables.

  6. For bool-type variables, the default value must be ’true’ or ‘false’ (case-insensitive).

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

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

  9. If a variable is deleted from the configuration, the tool will automatically remove it from the application.

  10. If an error occurs during configuration processing, the tool will automatically clear the changes made to maintain configuration consistency.

Variable Usage

User variables can be used in Edgelang rules in the format $or_user_variable_<variable_name>. For example:

$or_user_variable_var1

The system automatically handles variable replacement and restoration during configuration import and export.