From b250a5e45751e4799e5fc66206b9932821ff3ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bonhomme?= Date: Thu, 5 Dec 2024 11:41:11 +0100 Subject: [PATCH] chg: [FediVuln-Publish] Allows to use dedicate oauth client cred and user cred. --- fedivuln/conf_sample.py | 5 +++++ fedivuln/config.py | 2 ++ fedivuln/publish.py | 15 +++++++++++---- fedivuln/stream.py | 8 ++++---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/fedivuln/conf_sample.py b/fedivuln/conf_sample.py index 851a837..a96ca33 100644 --- a/fedivuln/conf_sample.py +++ b/fedivuln/conf_sample.py @@ -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 = "" diff --git a/fedivuln/config.py b/fedivuln/config.py index 5b2b63b..e7659a8 100644 --- a/fedivuln/config.py +++ b/fedivuln/config.py @@ -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 diff --git a/fedivuln/publish.py b/fedivuln/publish.py index 6dc214f..5d876bd 100644 --- a/fedivuln/publish.py +++ b/fedivuln/publish.py @@ -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, ) @@ -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 @@ -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", diff --git a/fedivuln/stream.py b/fedivuln/stream.py index 472330c..85645fa 100644 --- a/fedivuln/stream.py +++ b/fedivuln/stream.py @@ -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 ) @@ -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", @@ -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)