diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 93869299..002fb19a 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -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() diff --git a/companion.py b/companion.py index f8cf6c26..09c0047b 100644 --- a/companion.py +++ b/companion.py @@ -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