diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-08-06 11:46:02 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-08-06 18:56:34 +0300 |
commit | 6299228754893813341085d99c3924f7fefe1c18 (patch) | |
tree | 432e9f076b3b226487b8a77359545adba50e1714 /ick_controller.py | |
parent | 888db73b93aefe70d838d499f7f9cc43eee7372b (diff) | |
download | ick2-6299228754893813341085d99c3924f7fefe1c18.tar.gz |
Add: ControllerAPI, ControllerState
Diffstat (limited to 'ick_controller.py')
-rw-r--r-- | ick_controller.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ick_controller.py b/ick_controller.py new file mode 100644 index 0000000..e201a40 --- /dev/null +++ b/ick_controller.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 +# Copyright (C) 2017 Lars Wirzenius + + +import os + + +import apifw +import Crypto.PublicKey.RSA +import slog +import yaml + + +import ick2 + + +transactions = slog.Counter() +def counter(): + return 'HTTP transaction {}'.format(transactions.increment()) + + +def dict_logger(log, stack_info=None): + ick2.log.log(exc_info=stack_info, **log) + + +default_config = { + 'token-public-key': None, + 'token-audience': None, + 'token-issuer': None, + 'log': [], + 'statedir': None, +} + + +def load_config(filename, default_config): + config = yaml.safe_load(open(filename, 'r')) + actual_config = dict(default_config) + actual_config.update(config) + return actual_config + + +config_filename = os.environ.get('ICK_CONTROLLER_CONFIG') +if not config_filename: + raise Exception('No ICK_CONTROLLER_CONFIG defined in environment') +config = load_config(config_filename, default_config) +ick2.setup_logging(config) +ick2.log.log('info', msg_text='Ick2 controller starts', config=config) +api = ick2.ControllerAPI() +api.set_state_directory(config['statedir']) +api.load_projects() +app = apifw.create_bottle_application(api, counter, dict_logger, config) + +# If we are running this program directly with Python, and not via +# gunicorn, we can use the Bottle built-in debug server, which can +# make some things easier to debug. + +if __name__ == '__main__': + print('running in debug mode') + app.run(host='127.0.0.1', port=12765) |