1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 08:17:13 +03:00

EDDN: Make use of new CL arg to use custom upload URL

This also entailed slightly reworking the way the EDDN code uses this
URL.  It was very generalised, so as to allow for the debug "just send
and log locally" code, but as the only URL is the 'upload' one much of
that seemed un-necessary.

So that code has been simplified.
This commit is contained in:
Athanasius 2021-09-24 10:59:15 +01:00
parent e6e1cbd221
commit f9875b5b9a
No known key found for this signature in database
GPG Key ID: AE3E527847057C7D
3 changed files with 32 additions and 9 deletions

View File

@ -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()

View File

@ -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."""

View File

@ -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