diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 0797f814..094a6015 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -151,6 +151,11 @@ if __name__ == '__main__': # noqa: C901 help='Force to raise ServerError on any CAPI query', action='store_true' ) + + parser.add_argument( + '--eddn-url', + help='Specify an alternate EDDN upload URL', + ) ########################################################################### args = parser.parse_args() @@ -176,6 +181,9 @@ if __name__ == '__main__': # noqa: C901 if args.force_localserver_for_auth: config.set_auth_force_localserver() + if args.eddn_url: + config.set_eddn_url(args.eddn_url) + if args.force_edmc_protocol: if sys.platform == 'win32': config.set_auth_force_edmc_protocol() diff --git a/config.py b/config.py index b1437047..7a51547a 100644 --- a/config.py +++ b/config.py @@ -207,6 +207,7 @@ class AbstractConfig(abc.ABC): __in_shutdown = False # Is the application currently shutting down ? __auth_force_localserver = False # Should we use localhost for auth callback ? __auth_force_edmc_protocol = False # Should we force edmc:// protocol ? + __eddn_url = None # Non-default EDDN URL def __init__(self) -> None: self.home_path = pathlib.Path.home() @@ -250,6 +251,19 @@ class AbstractConfig(abc.ABC): """ return self.__auth_force_edmc_protocol + def set_eddn_url(self, eddn_url: str): + """Set the specified eddn URL.""" + self.__eddn_url = eddn_url + + @property + def eddn_url(self) -> Optional[str]: + """ + Provide the custom EDDN URL. + + :return: str - Custom EDDN URL to use. + """ + return self.__eddn_url + @property def app_dir(self) -> str: """Return a string version of app_dir.""" diff --git a/plugins/eddn.py b/plugins/eddn.py index 36a4cb94..339baec0 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -88,14 +88,9 @@ HORIZ_SKU = 'ELITE_HORIZONS_V_PLANETARY_LANDINGS' class EDDN: """EDDN Data export.""" - DEBUG = 'eddn' in debug_senders - SERVER = 'https://eddn.edcd.io:4430' - if DEBUG: - SERVER = f'http://{edmc_data.DEBUG_WEBSERVER_HOST}:{edmc_data.DEBUG_WEBSERVER_PORT}' - - UPLOAD = f'{SERVER}/upload/' - if DEBUG: - UPLOAD = f'{SERVER}/eddn' + DEFAULT_URL = 'https://eddn.edcd.io:4430/upload' + if 'eddn' in debug_senders: + DEFAULT_URL = f'http://{edmc_data.DEBUG_WEBSERVER_HOST}:{edmc_data.DEBUG_WEBSERVER_PORT}/eddn' REPLAYPERIOD = 400 # Roughly two messages per second, accounting for send delays [ms] REPLAYFLUSH = 20 # Update log on disk roughly every 10 seconds @@ -109,6 +104,12 @@ class EDDN: self.replayfile: Optional[TextIO] = None # For delayed messages self.replaylog: List[str] = [] + if config.eddn_url is not None: + self.eddn_url = config.eddn_url + + else: + self.eddn_url = self.DEFAULT_URL + def load_journal_replay(self) -> bool: """ Load cached journal entries from disk. @@ -187,7 +188,7 @@ class EDDN: ('message', msg['message']), ]) - r = self.session.post(self.UPLOAD, data=json.dumps(to_send), timeout=self.TIMEOUT) + r = self.session.post(self.eddn_url, data=json.dumps(to_send), timeout=self.TIMEOUT) if r.status_code != requests.codes.ok: # Check if EDDN is still objecting to an empty commodities list