trustgraph/trustgraph_configurator/templates/2.2/runtime-config/parameter-processor.jsonnet
elpresidank 74cc8a4685 Squashed 'ai-context/trustgraph-templates/' content from commit 42a5fd1b
git-subtree-dir: ai-context/trustgraph-templates
git-subtree-split: 42a5fd1b678f32be378062e30451e2052ccb95dd
2026-04-05 21:09:49 -05:00

38 lines
No EOL
1.5 KiB
Jsonnet

// Parameter Processing Module
// Handles dynamic parameter replacement in configuration values
// Replaces {parameter_name} placeholders with actual parameter values
{
// Applies parameter substitutions to string values
// Only processes strings - leaves other types unchanged
substitute_parameters: function(value, parameters)
if std.isString(value) then
std.foldl(
function(acc, param)
// Only do string replacement if param.value is a string
if std.isString(param.value) then
std.strReplace(acc, "{" + param.key + "}", param.value)
else
acc, // Skip replacement for non-string parameter values
std.objectKeysValuesAll(parameters),
value
)
else
value,
// Applies parameter substitutions to all values in an object
// Recursively processes nested objects and arrays
substitute_parameters_in_object: function(obj, parameters)
if std.isObject(obj) then
{
[key]: $.substitute_parameters_in_object(obj[key], parameters)
for key in std.objectFields(obj)
}
else if std.isArray(obj) then
[
$.substitute_parameters_in_object(item, parameters)
for item in obj
]
else
$.substitute_parameters(obj, parameters),
}