Skip to content

Commit

Permalink
chg: fixed an issue when converting the event string to a dict.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Dec 11, 2024
1 parent 3f9d065 commit c5f242a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions fedivuln/publish.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import argparse
import json
from typing import Any
from urllib.parse import urljoin

import requests
Expand Down Expand Up @@ -35,19 +34,20 @@
}


def create_status_content(event_data: dict[str, Any], topic: str) -> str:
def create_status_content(event_data: str, topic: str) -> str:
"""Generates a status update for posting based on the monitored topic."""
event_dict = json.loads(event_data)
status = TEMPLATES.get(topic, "")
match topic:
case "vulnerability":
status = status.replace("<VULNID>", event_data["payload"]["vulnerability"])
status = status.replace("<VULNID>", event_dict["payload"]["vulnerability"])
case "comment":
status = status.replace("<VULNID>", event_data["payload"]["vulnerability"])
status = status.replace("<VULNID>", event_dict["payload"]["vulnerability"])
case "bundle":
status = status.replace("<BUNDLETITLE>", event_data["payload"]["name"])
status = status.replace("<BUNDLETITLE>", event_dict["payload"]["name"])
case _:
pass
status = status.replace("<LINK>", event_data["uri"])
status = status.replace("<LINK>", event_dict["uri"])
return status


Expand Down Expand Up @@ -85,10 +85,10 @@ def listen_to_http_event_stream(url, headers=None, params=None, topic="comment")
data_line = line[5:].strip()
try:
# Attempt to parse the data as JSON
message = json.loads(data_line)
event_data = json.loads(data_line)
# print("Received JSON message:")
# print(message)
publish(create_status_content(message, topic))
publish(create_status_content(event_data, topic))
except json.JSONDecodeError:
# Handle plain text messages
print(f"Received plain message: {data_line}")
Expand Down

0 comments on commit c5f242a

Please sign in to comment.