Skip to content
Snippets Groups Projects
Commit 84a5fff7 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Change how config is handled

parent c9bd2b19
No related branches found
No related tags found
No related merge requests found
...@@ -25,12 +25,21 @@ def main(): ...@@ -25,12 +25,21 @@ def main():
print("All config:", restful_config) print("All config:", restful_config)
calcat_cfg = restful_config.get('calcat', {}) calcat_cfg = restful_config.get('calcat', {})
print("Loaded config:", calcat_cfg) print("Loaded config:", calcat_cfg)
calcat_cfg.setdefault('base-api-url', 'http://exflcalproxy:8080/api/') api_url = calcat_cfg.get('base-api-url', 'http://exflcalproxy:8080/api').rstrip('/')
calcat_cfg.setdefault('use-oauth2', False) assert api_url.endswith('/api')
base_url = api_url[:-4]
if calcat_cfg.get('use-oauth2', False):
oauth_info = {
'id': calcat_cfg['user-id'],
'secret': calcat_cfg['user-secret'],
'email': calcat_cfg['user-email']
}
else:
oauth_info = None
log.info("Upstream is %s (with%s Oauth)", calcat_cfg['base-api-url'], log.info("Upstream is %s (with%s Oauth)", calcat_cfg['base-api-url'],
'' if calcat_cfg['use-oauth2'] else 'out') '' if oauth_info else 'out')
app = ProxyApp(calcat_cfg, args.db) app = ProxyApp(base_url, oauth_info, args.db)
log.info("CalParrot will serve constant queries on http://127.0.0.1:%d", app.port) log.info("CalParrot will serve constant queries on http://127.0.0.1:%d", app.port)
if args.port_file: if args.port_file:
with open(args.port_file, 'w') as f: with open(args.port_file, 'w') as f:
......
...@@ -187,15 +187,15 @@ class ShutdownHandler(RequestHandler): ...@@ -187,15 +187,15 @@ class ShutdownHandler(RequestHandler):
class ProxyApp: class ProxyApp:
quit_event: asyncio.Event quit_event: asyncio.Event
def __init__(self, creds, db_path='calparrot.sqlite'): def __init__(self, base_url, oauth_info=None, db_path='calparrot.sqlite'):
self.response_store = ResponsesDB(db_path) self.response_store = ResponsesDB(db_path)
base_url = creds['base-api-url'].rstrip('/') # e.g. https://in.xfel.eu/calibration base_url = base_url.rstrip('/') # e.g. https://in.xfel.eu/calibration
if creds['use-oauth2']: if oauth_info:
self.client = XFELOauthClient( self.client = XFELOauthClient(
creds['client_id'], oauth_info['id'],
creds['client_secret'], oauth_info['secret'],
creds['user_email'], oauth_info['email'],
scope=None, scope=None,
token_url=base_url + '/oauth/token' token_url=base_url + '/oauth/token'
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment