Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions st2common/st2common/util/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _create_graph(action_context, config):
return G


def _process(G, name, value):
def _process(G, name, value, parameter_schemas=None):
"""
Determines whether parameter is a template or a value. Adds graph nodes and edges accordingly.
"""
Expand All @@ -130,9 +130,20 @@ def _process(G, name, value):
if isinstance(value, list) or isinstance(value, dict):
complex_value_str = str(value)

is_jinja_expr = jinja_utils.is_jinja_expression(
value
) or jinja_utils.is_jinja_expression(complex_value_str)
# Check if the parameter is of type raw_string
is_raw_string = False
if parameter_schemas:
for schema in parameter_schemas:
if name in schema and schema[name].get("type") == "raw_string":
is_raw_string = True
break

# Skip Jinja processing for raw_string type parameters
is_jinja_expr = False
if not is_raw_string:
is_jinja_expr = jinja_utils.is_jinja_expression(
value
) or jinja_utils.is_jinja_expression(complex_value_str)

if is_jinja_expr:
try:
Expand Down Expand Up @@ -334,8 +345,12 @@ def render_live_params(
for name, value in six.iteritems(additional_contexts):
G.add_node(name, value=value)

[_process(G, name, value) for name, value in six.iteritems(params)]
_process_defaults(G, [action_parameters, runner_parameters])
parameter_schemas = [action_parameters, runner_parameters]
[
_process(G, name, value, parameter_schemas)
for name, value in six.iteritems(params)
]
_process_defaults(G, parameter_schemas)
_validate(G)

context = _resolve_dependencies(G)
Expand Down
2 changes: 1 addition & 1 deletion st2common/st2common/util/schema/action_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
},
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string", "raw_string" ]
},
"stringArray": {
"type": "array",
Expand Down
2 changes: 1 addition & 1 deletion st2common/st2common/util/schema/custom.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
},
"simpleTypes": {
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string", "raw_string" ]
},
"stringArray": {
"type": "array",
Expand Down
33 changes: 33 additions & 0 deletions st2common/tests/unit/test_param_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,39 @@ def test_get_finalized_params_with_casting_unicode_values(self):
self.assertEqual(r_runner_params, {})
self.assertEqual(r_action_params, expected_action_params)

def test_get_finalized_params_with_raw_string_parameter(self):
"""
Tests that parameters with type 'raw_string' are not processed for Jinja expressions.
"""
params = {
"a1": "value1",
"a2": "{{a1}}",
"a3": "{{a1}} and {{a4}}",
"a4": "{{a1}}",
"a5": "{{a1}}",
}
runner_param_info = {}
action_param_info = {
"a1": {"type": "string"},
"a2": {"type": "string"},
"a3": {"type": "raw_string"},
"a4": {"type": "raw_string"},
"a5": {"type": "string"},
}
action_context = {"api_user": "noob"}
r_runner_params, r_action_params = param_utils.get_finalized_params(
runner_param_info, action_param_info, params, action_context
)

# Regular string parameters should have their Jinja expressions evaluated
self.assertEqual(r_action_params["a1"], "value1")
self.assertEqual(r_action_params["a2"], "value1")
self.assertEqual(r_action_params["a5"], "value1")

# Parameters with type 'raw_string' should not be processed for Jinja expressions
self.assertEqual(r_action_params["a3"], "{{a1}} and {{a4}}")
self.assertEqual(r_action_params["a4"], "{{a1}}")

def test_get_finalized_params_with_dict(self):
# Note : In this test runner_params.r1 has a string value. However per runner_param_info the
# type is an integer. The expected type is considered and cast is performed accordingly.
Expand Down
Loading