From 79e1ff53cd733dd5b3a988f3b988d46e00a50536 Mon Sep 17 00:00:00 2001 From: Arjun Aditya Date: Tue, 3 Dec 2024 02:45:26 +0530 Subject: [PATCH] Update pre-processor.mdx --- .../references/importyml/pre-processor.mdx | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/apps/docs/content/references/importyml/pre-processor.mdx b/apps/docs/content/references/importyml/pre-processor.mdx index c9be8d88..da593ddc 100644 --- a/apps/docs/content/references/importyml/pre-processor.mdx +++ b/apps/docs/content/references/importyml/pre-processor.mdx @@ -106,21 +106,34 @@ Functions generally support 2 types of parameters. - Spaces between `<` and `>` are NOT trimmed. - When the value is passed as a function parameter, it's always a string. -Used in [generateRandomString](#generaterandomstring), [generateRandomInt](#generaterandomint), and [pickRandom](#pickrandom) functions: eg. `<10>`, `512`, `<1024>`, etc. +**Simple examples:** +```yaml +SECRET_KEY: <@generateRandomString(<16>)> # String expression: <16> +RANDOM_RANGE: <@generateRandomInt(<1>, <100>)> # String expressions: <1> and <100> +PICK_VALUE: <@pickRandom(, , )> # String expressions: , , +``` + +### Variable reference names -### Variable reference names (previously stored as internal variables) +Variables are used to store and reuse values across your configuration. They can be created using functions like `setVar` and retrieved using `getVar`. -- Internal variables can be stored using [setVar](#setvar), [generateRandomStringVar](#generaterandomstringvar), [generateED25519Key](#generateed25519key), [generateRSA2048Key](#generatersa2048key), and [generateRSA4096Key](#generatersa4096key) functions. -- Variable reference name is a string constant NOT enclosed in `<` and `>` characters. -- Variable reference names are case-sensitive. -- Spaces before and after the reference name are trimmed. -- Stored value under an internal variable name is looked up and passed into the function as a string. -- If no value is found, an error is returned. +- Variable references are NOT enclosed in `<` and `>` when used with `getVar` +- Variable names are case-sensitive +- Spaces before and after the reference name are trimmed +- Returns an error if the variable doesn't exist -Used in [setVar](#setvar), [getVar](#getvar), [generateRandomStringVar](#generaterandomstringvar), [generateED25519Key](#generateed25519key), [generateRSA2048Key](#generatersa2048key), and [generateRSA4096Key](#generatersa4096key) functions: eg. ``, ``, etc. +**Simple examples:** +```yaml +# Store a value in a variable +PASSWORD: <@setVar(, <@generateRandomString(<30>)>)> + +# Use the stored value +HASHED_PASSWORD: <@getVar(myPassword)|sha256> # Note: no <> around myPassword +SAME_PASSWORD_AGAIN: <@getVar(myPassword)> # Reuse the same value +``` :::tip Internal processing of function parameters -The **string** is the only data type of all input parameters. Those input parameters that logically represent numbers, as in the case of the [generateRandomString](#generaterandomstring) function, are internally converted to numbers. +All parameters are handled as strings internally. For functions that expect numbers (like `generateRandomString`), the string values are automatically converted to numbers during processing. ::: ---