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 Name | Data Type | Required | Description |
---|---|---|---|
name | string | Yes | Variable name, must be unique |
type | string | Yes | Variable type, possible values: string, enum, num, int, bool |
default | string | Yes | Default value of the variable |
values | array | Required only for enum type | List 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
Each user variable must have a unique name.
The variable type must be one of the valid types: string, enum, num, int, bool.
a
values
list must be provided for enum type variables, and the default value must be in this list.the default value must be a valid floating-point number for num-type variables.
the default value must be a valid integer for int-type variables.
For bool-type variables, the default value must be ’true’ or ‘false’ (case-insensitive).
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.
When importing the configuration, the tool first checks the validity of the configuration before performing add or update operations.
If a variable is deleted from the configuration, the tool will automatically remove it from the application.
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.