Skip to content
Open
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
18 changes: 16 additions & 2 deletions iris_webhooks_module/IrisWebHooksInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,21 @@ def map_request_content(self, request_content, data):
# Handle templated strings
result[key] = self.replace_template_placeholders(value, data)

# handle nested values
# handle nested dicts
elif isinstance(value, dict):
result[key] = self.map_request_content(value, data)

else:
# handle nested lists
elif isinstance(value, list):
result[key] = [
self.map_request_content(item, data) if isinstance(item, dict)
else self.replace_template_placeholders(item, data) if isinstance(item, str) and '${{' in item
else item
for item in value
]

# handle string paths like "field.subfield"
elif isinstance(value, str):
keys = value.split('.')

if isinstance(data.get(keys[0]), list):
Expand All @@ -498,6 +508,10 @@ def map_request_content(self, request_content, data):
nested_value = self.get_nested(data, keys)
result[key] = nested_value if nested_value is not None else ""

Comment on lines 492 to 510

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is directed at any maintainer looking to merge this.

This section of original code still causes a bug where simple string values in dicts in a list such as Slack Blocks formatting get dropped.

For example:

"request_body": {
               "text": "[${{alerts.severity.severity_name}}] ${{alerts.alert_title}}",
                "blocks": [
                    {
                        "type": "header",
                        "text": {
                            "type": "plain_text",
                            "text": "[${{alerts.severity.severity_name}}] ${{alerts.alert_title}}"
                        }
                    },
...

Leads to parsed value of

{"text" : "[Low] Test Alert", "blocks": [{"type": "", "text": {"type": "", "text": "[Low] Test Alert"}}] ...}

Removing this entire section fixes the issue and I'm not even clear why this section is here as it seems unnecessary given that the expectation is the config should be valid JSON and should not be trying to interpret "some.key" as a path rather than a simple JSON key name.

Otherwise, this patch seems to work correctly and solved my problem with this module.

# pass through other types as-is
else:
result[key] = value

return result

def _render_url(self, url, link, rendering_format):
Expand Down