mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-19 02:17:38 +03:00
CAPI: Implement a one-shot override of the Access Token
This allows you to force use of an expired token so as to test the code paths for that without waiting up to 4 hours for the current one to expire. NB: The Access Token is *only* stored in the headers of the `requests` object.
This commit is contained in:
parent
919136874d
commit
6bec46be4e
@ -151,6 +151,12 @@ if __name__ == '__main__': # noqa: C901
|
||||
action='store_true'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--capi-use-debug-access-token',
|
||||
help='Load a debug Access Token from disk (from config.app_dir_pathapp_dir_path / access_token.txt)',
|
||||
action='store_true'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--eddn-url',
|
||||
help='Specify an alternate EDDN upload URL',
|
||||
@ -170,6 +176,11 @@ if __name__ == '__main__': # noqa: C901
|
||||
logger.info('Pretending CAPI is down')
|
||||
conf_module.capi_pretend_down = True
|
||||
|
||||
if args.capi_use_debug_access_token:
|
||||
import config as conf_module
|
||||
with open(conf_module.config.app_dir_path / 'access_token.txt', 'r') as at:
|
||||
conf_module.capi_debug_access_token = at.readline().strip()
|
||||
|
||||
level_to_set: Optional[int] = None
|
||||
if args.trace or args.trace_on:
|
||||
level_to_set = logging.TRACE # type: ignore # it exists
|
||||
|
@ -759,7 +759,13 @@ class Session(object):
|
||||
if conf_module.capi_pretend_down:
|
||||
raise ServerConnectionError(f'Pretending CAPI down: {capi_endpoint}')
|
||||
|
||||
if conf_module.capi_debug_access_token is not None:
|
||||
self.requests_session.headers['Authorization'] = f'Bearer {conf_module.capi_debug_access_token}' # type: ignore # noqa: E501
|
||||
# This is one-shot
|
||||
conf_module.capi_debug_access_token = None
|
||||
|
||||
r = self.requests_session.get(self.server + capi_endpoint, timeout=timeout) # type: ignore
|
||||
|
||||
logger.trace_if('capi.worker', '... got result...')
|
||||
r.raise_for_status() # Typically 403 "Forbidden" on token expiry
|
||||
# May also fail here if token expired since response is empty
|
||||
|
@ -46,6 +46,7 @@ debug_senders: List[str] = []
|
||||
trace_on: List[str] = []
|
||||
|
||||
capi_pretend_down: bool = False
|
||||
capi_debug_access_token: Optional[str]
|
||||
# This must be done here in order to avoid an import cycle with EDMCLogging.
|
||||
# Other code should use EDMCLogging.get_main_logger
|
||||
if os.getenv("EDMC_NO_UI"):
|
||||
|
Loading…
x
Reference in New Issue
Block a user