Skip to content

Commit

Permalink
chg: [FediVuln-Publish] Allows to use dedicate oauth client cred and …
Browse files Browse the repository at this point in the history
…user cred.
  • Loading branch information
cedricbonhomme committed Dec 5, 2024
1 parent a6de9ba commit b250a5e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions fedivuln/conf_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
mastodon_clientcred = "mastodon_clientcred.secret"
mastodon_usercred = "mastodon_usercred.secret"

# Optional in case you need to publish status with a different account
mastodon_clientcred_push = "mastodon_clientcred_push.secret"
mastodon_usercred_push = "mastodon_usercred_push.secret"


vulnerability_lookup_base_url = "https://vulnerability.circl.lu/"
vulnerability_auth_token = ""
2 changes: 2 additions & 0 deletions fedivuln/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def load_config(path):
app_name = conf.app_name
mastodon_clientcred = conf.mastodon_clientcred
mastodon_usercred = conf.mastodon_usercred
mastodon_clientcred_push = conf.mastodon_clientcred_push
mastodon_usercred_push = conf.mastodon_usercred_push

vulnerability_lookup_base_url = conf.vulnerability_lookup_base_url
vulnerability_auth_token = conf.vulnerability_auth_token
15 changes: 11 additions & 4 deletions fedivuln/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
from fedivuln import config

# Set up your Mastodon instance with access credentials
if config.mastodon_clientcred_push and config.mastodon_usercred_push:
client_id = config.mastodon_clientcred_push
access_token = config.mastodon_usercred_push
else:
client_id = config.mastodon_clientcred
access_token = config.mastodon_usercred

mastodon = Mastodon(
client_id=config.mastodon_clientcred,
access_token=config.mastodon_usercred,
client_id=client_id,
access_token=access_token,
api_base_url=config.api_base_url,
)

Expand Down Expand Up @@ -61,7 +68,7 @@ def listen_to_http_event_stream(url, headers=None, params=None, topic="comment")
params (dict): Optional query parameters for the request.
"""
try:
print("Connecting to stream. Listening for events...\n")
print("Connecting to stream. Listening for events")
# Open a streaming connection
with requests.get(url, headers=headers, params=params, stream=True) as response:
# Force the headers to be fetched immediately
Expand Down Expand Up @@ -99,7 +106,7 @@ def listen_to_http_event_stream(url, headers=None, params=None, topic="comment")


def main():
# Point of entry in execution mode
"""Parsing of arguments."""
parser = argparse.ArgumentParser(prog="FediVuln-Publish")
parser.add_argument(
"-t",
Expand Down
8 changes: 4 additions & 4 deletions fedivuln/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def remove_case_insensitive_duplicates(input_list):

def push_sighting_to_vulnerability_lookup(status_uri, vulnerability_ids):
"""Create a sighting from an incoming status and push it to the Vulnerability Lookup instance."""
print("Pushing sighting to Vulnerability Lookup...")
print("Pushing sighting to Vulnerability Lookup")
vuln_lookup = PyVulnerabilityLookup(
config.vulnerability_lookup_base_url, token=config.vulnerability_auth_token
)
Expand All @@ -116,7 +116,7 @@ def push_sighting_to_vulnerability_lookup(status_uri, vulnerability_ids):

# def push_status_to_vulnerability_lookup(status, vulnerability_ids):
# """Push the status to the Vulnerability Lookup instance."""
# print("Pushing status to Vulnerability Lookup...")
# print("Pushing status to Vulnerability Lookup")
# headers_json = {
# "Content-Type": "application/json",
# "accept": "application/json",
Expand Down Expand Up @@ -172,10 +172,10 @@ def main():
listener = VulnStreamListener(push_sighting=arguments.push_sighting)

if arguments.user:
print("Starting Mastodon user stream...")
print("Starting Mastodon user stream")
mastodon.stream_user(listener)
elif arguments.public:
print("Starting Mastodon local public stream...")
print("Starting Mastodon local public stream")
mastodon.stream_public(listener)
else:
parser.print_help(sys.stderr)
Expand Down

0 comments on commit b250a5e

Please sign in to comment.