mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-16 09:10:35 +03:00
Merge pull request #857 from EDCD/enhancement/856-CL-arg-force-local-webserver
Add `--force-localserver-for-auth` CL arg to EDMarketConnector
This commit is contained in:
commit
9b1b34f273
@ -55,6 +55,11 @@ if __name__ == '__main__': # noqa: C901
|
||||
action='store_true'
|
||||
)
|
||||
|
||||
parser.add_argument('--force-localserver-for-auth',
|
||||
help='Force EDMC to use a localhost webserver for Frontier Auth callback',
|
||||
action='store_true'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.trace:
|
||||
@ -63,6 +68,9 @@ if __name__ == '__main__': # noqa: C901
|
||||
else:
|
||||
edmclogger.set_channels_loglevel(logging.DEBUG)
|
||||
|
||||
if args.force_localserver_for_auth:
|
||||
config.set_auth_force_localserver()
|
||||
|
||||
def no_other_instance_running() -> bool: # noqa: CCR001
|
||||
"""
|
||||
Ensure only one copy of the app is running for the configured journal directory.
|
||||
|
24
config.py
24
config.py
@ -118,6 +118,7 @@ class Config(object):
|
||||
|
||||
def __init__(self):
|
||||
self.__in_shutdown = False # Is the application currently shutting down ?
|
||||
self.__auth_force_localserver = False # Should we use localhost for auth callback ?
|
||||
|
||||
self.app_dir = join(NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], appname)
|
||||
if not isdir(self.app_dir):
|
||||
@ -186,10 +187,18 @@ class Config(object):
|
||||
def shutting_down(self) -> bool:
|
||||
return self.__in_shutdown
|
||||
|
||||
def set_auth_force_localserver(self):
|
||||
self.__auth_force_localserver = True
|
||||
|
||||
@property
|
||||
def auth_force_localserver(self) -> bool:
|
||||
return self.__auth_force_localserver
|
||||
|
||||
elif platform=='win32':
|
||||
|
||||
def __init__(self):
|
||||
self.__in_shutdown = False # Is the application currently shutting down ?
|
||||
self.__auth_force_localserver = False # Should we use localhost for auth callback ?
|
||||
|
||||
self.app_dir = join(KnownFolderPath(FOLDERID_LocalAppData), appname)
|
||||
if not isdir(self.app_dir):
|
||||
@ -285,12 +294,20 @@ class Config(object):
|
||||
def shutting_down(self) -> bool:
|
||||
return self.__in_shutdown
|
||||
|
||||
def set_auth_force_localserver(self):
|
||||
self.__auth_force_localserver = True
|
||||
|
||||
@property
|
||||
def auth_force_localserver(self) -> bool:
|
||||
return self.__auth_force_localserver
|
||||
|
||||
elif platform=='linux':
|
||||
|
||||
SECTION = 'config'
|
||||
|
||||
def __init__(self):
|
||||
self.__in_shutdown = False # Is the application currently shutting down ?
|
||||
self.__auth_force_localserver = False # Should we use localhost for auth callback ?
|
||||
|
||||
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
|
||||
self.app_dir = join(getenv('XDG_DATA_HOME', expanduser('~/.local/share')), appname)
|
||||
@ -371,6 +388,13 @@ class Config(object):
|
||||
def shutting_down(self) -> bool:
|
||||
return self.__in_shutdown
|
||||
|
||||
def set_auth_force_localserver(self):
|
||||
self.__auth_force_localserver = True
|
||||
|
||||
@property
|
||||
def auth_force_localserver(self) -> bool:
|
||||
return self.__auth_force_localserver
|
||||
|
||||
def _escape(self, val):
|
||||
return str(val).replace(u'\\', u'\\\\').replace(u'\n', u'\\n').replace(u';', u'\\;')
|
||||
|
||||
|
@ -7,7 +7,9 @@ import sys
|
||||
|
||||
from config import appname, config
|
||||
from constants import protocolhandler_redirect
|
||||
from EDMCLogging import get_main_logger
|
||||
|
||||
logger = get_main_logger()
|
||||
|
||||
if sys.platform == 'win32':
|
||||
from ctypes import *
|
||||
@ -74,7 +76,7 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False):
|
||||
protocolhandler.master.after(ProtocolHandler.POLL, protocolhandler.poll)
|
||||
|
||||
|
||||
elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine:
|
||||
elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver:
|
||||
|
||||
class WNDCLASS(Structure):
|
||||
_fields_ = [('style', UINT),
|
||||
@ -217,6 +219,7 @@ else: # Linux / Run from source
|
||||
GenericProtocolHandler.__init__(self)
|
||||
self.httpd = HTTPServer(('localhost', 0), HTTPRequestHandler)
|
||||
self.redirect = 'http://localhost:%d/auth' % self.httpd.server_port
|
||||
logger.trace(f'Web server listening on {self.redirect}')
|
||||
self.thread = None
|
||||
|
||||
def start(self, master):
|
||||
|
Loading…
x
Reference in New Issue
Block a user