MEDIUM: vars: add support for a "set-var" global directive
authorWilly Tarreau <w@1wt.eu>
Fri, 26 Mar 2021 10:38:08 +0000 (11:38 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 26 Mar 2021 15:34:53 +0000 (16:34 +0100)
commit13d2ba2a8215c2e3cd84b3cc96d8fbd26a734447
tree9fcea91a5f4371ad08413a7935e2618714d80e8a
parent01d580ae86c87cbb5d6db16efdfdc709de1b92b2
MEDIUM: vars: add support for a "set-var" global directive

While we do support process-wide variables ("proc.<name>"), there was
no way to preset them from the configuration. This was particularly
limiting their usefulness since configs involving them always had to
first check if the variable was set prior to performing an operation.

This patch adds a new "set-var" directive in the global section that
supports setting the proc.<name> variables from an expression, like
other set-var actions do. The syntax however follows what is already
being done for setenv, which consists in having one argument for the
variable name and another one for the expression.

Only "constant" expressions are allowed here, such as "int", "str"
etc, combined with arithmetic or string converters, and variable
lookups. A few extra sample fetch keywords like "date", "rand" and
"uuid" are also part of the constant expressions and may make sense
to allow to create a random key or differentiate processes.

The way it was done consists in parsing a dummy rule an executing the
expression in the CFG_PARSE context, then releasing the expression.
This is safe because the sample that variables store does not hold a
back pointer to expression that created them.
doc/configuration.txt
src/vars.c