1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-20 19:07:38 +03:00

Added CL arg to forget all frontier tokens

This is obviously quite annoying but should provide a magic fix to any
user with weird auth trouble (such as those seen by
EDCD/EDMarketConnector#1166 )

Closes EDCD/EDMarketConnector#890
This commit is contained in:
A_D 2021-06-12 16:35:33 +02:00
parent 44e4772d60
commit 284064d6ed
No known key found for this signature in database
GPG Key ID: 4BE9EB7DF45076C4
2 changed files with 31 additions and 8 deletions

View File

@ -82,6 +82,12 @@ if __name__ == '__main__': # noqa: C901
action='store_true'
)
parser.add_argument(
'--forget-frontier-auth',
help='resets all authentication tokens',
action='store_true'
)
parser.add_argument('--suppress-dupe-process-popup',
help='Suppress the popup from when the application detects another instance already running',
action='store_true'
@ -1675,6 +1681,11 @@ sys.path: {sys.path}'''
else:
log_locale('After switching to UTF-8 encoding (same language)')
# Do this after locale silliness, just in case
if args.forget_frontier_auth:
logger.info("Dropping all fdev tokens as --forget-frontier-auth was passed")
companion.Auth.invalidate(None)
# TODO: unittests in place of these
# logger.debug('Test from __main__')
# test_logging()

View File

@ -410,15 +410,27 @@ class Auth(object):
raise CredentialsError(f'{_("Error")}: {error!r}')
@staticmethod
def invalidate(cmdr: str) -> None:
def invalidate(cmdr: Optional[str]) -> None:
"""Invalidate Refresh Token for specified Commander."""
logger.info(f'Frontier CAPI Auth: Invalidated token for "{cmdr}"')
cmdrs = config.get_list('cmdrs', default=[])
idx = cmdrs.index(cmdr)
tokens = config.get_list('fdev_apikeys', default=[])
tokens = tokens + [''] * (len(cmdrs) - len(tokens))
tokens[idx] = ''
config.set('fdev_apikeys', tokens)
to_set = None
if cmdr is None:
logger.info('Frontier CAPI Auth: Invalidating ALL tokens!')
cmdrs = config.get_list('cmdrs', default=[])
to_set = [''] * len(cmdrs)
else:
logger.info(f'Frontier CAPI Auth: Invalidated token for "{cmdr}"')
cmdrs = config.get_list('cmdrs', default=[])
idx = cmdrs.index(cmdr)
to_set = config.get_list('fdev_apikeys', default=[])
to_set = to_set + [''] * (len(cmdrs) - len(to_set))
to_set[idx] = ''
if to_set is None:
logger.error('REFUSING TO SET NONE AS TOKENS!')
raise ValueError('Unexpected None for tokens while resetting')
config.set('fdev_apikeys', to_set)
config.save() # Save settings now for use by command-line app
# noinspection PyMethodMayBeStatic