Skip to content

Commit

Permalink
#patch: fix missing webhook fields when sanitifizing webhook data
Browse files Browse the repository at this point in the history
  • Loading branch information
circa10a committed Feb 6, 2024
1 parent df4e5e9 commit 1d3dfa8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/webhooks/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def sanitize_webhook(webhook: Dict, template_strs: Dict) -> Dict:
sanitized_webhook['url'] = Template(webhook['url']).substitute(template_strs)
sanitized_webhook['method'] = Template(webhook['method']).substitute(template_strs)
sanitized_webhook['headers'] = sanitized_headers
sanitized_webhook['data'] = Template(webhook['body']).substitute(template_strs)
sanitized_webhook['body'] = Template(webhook['body']).substitute(template_strs)
sanitized_webhook['timeout'] = webhook['timeout']
sanitized_webhook['notifyInterval'] = webhook['notifyInterval']
sanitized_webhook['objects'] = webhook['objects']

return sanitized_webhook

Expand All @@ -55,6 +57,14 @@ def process(webhooks: List[Dict], object_name: str, object_confidence: str) -> N
# Subsitute url, headers, body with object data, environment variables for secrets
webhook = sanitize_webhook(webhook, template_strs)
# Create opts to send request and hash to render an immutable ID to track last notification
# Opts for requests library
request_opts = {
'url': webhook['url'],
'method': webhook['method'],
'headers': webhook['headers'],
'data': webhook['body'],
'timeout': webhook['timeout']
}
# Get the webhook's ID and check when webhook was last notified
webhook_hash = dict_hash(webhook)
if webhook_hash in WEBHOOKS_LAST_NOTIFIED:
Expand All @@ -68,7 +78,7 @@ def process(webhooks: List[Dict], object_name: str, object_confidence: str) -> N
# Otherwise continue and notify
try:
log.info(f"Object {object_name} detected with confidence of {object_confidence}. Notifying {webhook['url']}")
response = requests.request(**webhook)
response = requests.request(**request_opts)
# Raise an error in the event of a non 2XX response code
response.raise_for_status()
# Request was successful, so we store last notified time
Expand Down

0 comments on commit 1d3dfa8

Please # to comment.