diff --git a/python/humbug/report.py b/python/humbug/report.py index 7e0ad6a..c631795 100644 --- a/python/humbug/report.py +++ b/python/humbug/report.py @@ -17,7 +17,7 @@ from typing import List, Optional import uuid -from bugout.app import Bugout +import requests from .consent import HumbugConsent from .system_information import ( @@ -26,6 +26,15 @@ ) +DEFAULT_URL = "https://spire.bugout.dev" + + +class BugoutUnexpectedStatusResponse(Exception): + """ + Raised when Bugout server response return incorrect status. + """ + + @dataclass class Report: title: str @@ -38,19 +47,22 @@ class Modes(Enum): SYNCHRONOUS = 1 -class Reporter: +class HumbugReporter: def __init__( self, name: str, consent: HumbugConsent, + url: Optional[str] = None, client_id: Optional[str] = None, session_id: Optional[str] = None, system_information: Optional[SystemInformation] = None, bugout_token: Optional[str] = None, - bugout_journal_id: Optional[str] = None, timeout_seconds: int = 10, mode: Modes = Modes.DEFAULT, ): + if url is None: + url = DEFAULT_URL + self.url = url self.name = name self.consent = consent self.client_id = client_id @@ -61,9 +73,7 @@ def __init__( if system_information is None: system_information = generate_system_information() self.system_information = system_information - self.bugout = Bugout() self.bugout_token = bugout_token - self.bugout_journal_id = bugout_journal_id self.timeout_seconds = timeout_seconds self.report_futures: List[concurrent.futures.Future] = [] @@ -107,28 +117,27 @@ def system_tags(self) -> List[str]: def publish(self, report: Report, wait: bool = False) -> None: if not self.consent.check(): return - if self.bugout_token is None or self.bugout_journal_id is None: + if self.bugout_token is None: return + json = {"title": report.title, "content": report.content, "tags": report.tags} + headers = { + "Authorization": "Bearer {}".format(self.bugout_token), + } + url = "{}/humbug/reports".format(self.url.rstrip("/")) + try: report.tags = list(set(report.tags)) if wait or self.executor is None: - self.bugout.create_entry( - token=self.bugout_token, - journal_id=self.bugout_journal_id, - title=report.title, - content=report.content, - tags=report.tags, - timeout=self.timeout_seconds, + requests.post( + url=url, headers=headers, json=json, timeout=self.timeout_seconds ) else: report_future = self.executor.submit( - self.bugout.create_entry, - token=self.bugout_token, - journal_id=self.bugout_journal_id, - title=report.title, - content=report.content, - tags=report.tags, + requests.post, + url=url, + headers=headers, + json=json, timeout=self.timeout_seconds, ) self.report_futures.append(report_future) @@ -405,3 +414,15 @@ def showtraceback(*args, **kwargs): ipython_shell.showtraceback = showtraceback self.setup_excepthook(publish=True, tags=tags) + + +class Reporter(HumbugReporter): + + """ + Deprecated. + Old class name. + """ + + def __init__(self, bugout_journal_id: Optional[str] = None, *args, **kw): + super().__init__(*args, **kw) + self.bugout_journal_id = bugout_journal_id diff --git a/python/humbug/test_report.py b/python/humbug/test_report.py index b739e1b..524a434 100644 --- a/python/humbug/test_report.py +++ b/python/humbug/test_report.py @@ -6,7 +6,7 @@ class TestReporter(unittest.TestCase): def setUp(self): self.consent = consent.HumbugConsent(True) - self.reporter = report.Reporter("TestReporter", self.consent) + self.reporter = report.Reporter(name="TestReporter", consent=self.consent) def test_system_report_successful(self): self.reporter.system_report(publish=False) diff --git a/python/recipes/error_reporting.py b/python/recipes/error_reporting.py index b3dceff..b3dc309 100644 --- a/python/recipes/error_reporting.py +++ b/python/recipes/error_reporting.py @@ -9,11 +9,10 @@ from humbug.report import Reporter DEMO_BUGOUT_ACCESS_TOKEN = "a390de7a-c64f-482c-b3f4-b9322ffaadef" -DEMO_BUGOUT_JOURNAL_ID = "1bf50549-a8ef-430f-b788-fb2ac864d42a" """ LEND ME YOUR EYES, FRIEND: -Please replace the bugout_access_token and bugout_journal_id with the values you generate in the +Please replace the bugout_access_token with the value you generate in the process of setting up a "Usage Reports" integration at https://bugout.dev. Full instructions can be found here: https://github.com/bugout-dev/humbug/blob/main/README.md @@ -24,12 +23,8 @@ If you would like access to the demo knowledge base, email me at neeraj@bugout.dev. """ bugout_access_token: str = DEMO_BUGOUT_ACCESS_TOKEN -bugout_journal_id: str = DEMO_BUGOUT_JOURNAL_ID -if ( - bugout_access_token == DEMO_BUGOUT_ACCESS_TOKEN - or bugout_journal_id == DEMO_BUGOUT_JOURNAL_ID -): +if bugout_access_token == DEMO_BUGOUT_ACCESS_TOKEN: print( "It seems you are running this script with the demo Bugout access token and journal id." ) @@ -66,7 +61,6 @@ consent, session_id=session_id, bugout_token=bugout_access_token, - bugout_journal_id=bugout_journal_id, ) """ diff --git a/python/recipes/system_reporting.py b/python/recipes/system_reporting.py index f269bcc..d101fa4 100644 --- a/python/recipes/system_reporting.py +++ b/python/recipes/system_reporting.py @@ -9,11 +9,10 @@ from humbug.report import Reporter DEMO_BUGOUT_ACCESS_TOKEN = "a390de7a-c64f-482c-b3f4-b9322ffaadef" -DEMO_BUGOUT_JOURNAL_ID = "1bf50549-a8ef-430f-b788-fb2ac864d42a" """ LEND ME YOUR EYES, FRIEND: -Please replace the bugout_access_token and bugout_journal_id with the values you generate in the +Please replace the bugout_access_token with the value you generate in the process of setting up a "Usage Reports" integration at https://bugout.dev. Full instructions can be found here: https://github.com/bugout-dev/humbug/blob/main/README.md @@ -24,15 +23,9 @@ If you would like access to the demo knowledge base, email me at neeraj@bugout.dev. """ bugout_access_token: str = DEMO_BUGOUT_ACCESS_TOKEN -bugout_journal_id: str = DEMO_BUGOUT_JOURNAL_ID -if ( - bugout_access_token == DEMO_BUGOUT_ACCESS_TOKEN - or bugout_journal_id == DEMO_BUGOUT_JOURNAL_ID -): - print( - "It seems you are running this script with the demo Bugout access token and journal id." - ) +if bugout_access_token == DEMO_BUGOUT_ACCESS_TOKEN: + print("It seems you are running this script with the demo Bugout access token.") print( "If you continue, this script will publish reports to a Bugout.dev knowledge base that you do not have access to." ) @@ -66,7 +59,6 @@ consent, session_id=session_id, bugout_token=bugout_access_token, - bugout_journal_id=bugout_journal_id, ) """ diff --git a/python/setup.py b/python/setup.py index 775d46e..687a380 100644 --- a/python/setup.py +++ b/python/setup.py @@ -6,9 +6,9 @@ setup( name="humbug", - version="0.1.16", + version="0.2.0", packages=find_packages(), - install_requires=["bugout"], + install_requires=["requests"], extras_require={ "dev": ["black", "mypy", "wheel"], "distribute": ["setuptools", "twine", "wheel"],