diff --git a/docker-compose-dev.yaml b/docker-compose-dev.yaml index 3e67c369..d4d8b887 100644 --- a/docker-compose-dev.yaml +++ b/docker-compose-dev.yaml @@ -1,5 +1,9 @@ version: '3' +networks: + kibble: + driver: bridge + services: # Helper service to setup the Apache Kibble es node setup: @@ -12,6 +16,8 @@ services: - .:/kibble/ depends_on: - elasticsearch + networks: + - kibble # Apache Kibble API server kibble: @@ -25,6 +31,8 @@ services: - .:/kibble/ depends_on: - elasticsearch + networks: + - kibble # Apache Kibble web ui server ui: @@ -36,6 +44,8 @@ services: - 8000:8000 depends_on: - kibble + networks: + - kibble # Elasticsearch node required as a database for Apache Kibble elasticsearch: @@ -51,6 +61,8 @@ services: ES_JAVA_OPTS: -Xms256m -Xmx256m volumes: - "kibble-es-data:/usr/share/elasticsearch/data" + networks: + - kibble # Kibana to view and manage Elasticsearch kibana: @@ -59,6 +71,11 @@ services: - 5601:5601 depends_on: - elasticsearch + environment: + ELASTICSEARCH_URL: http://elasticsearch:9200 + ELASTICSEARCH_HOSTS: http://elasticsearch:9200 + networks: + - kibble volumes: # named volumes can be managed easier using docker-compose diff --git a/kibble/api/handler.py b/kibble/api/handler.py index d409b54d..8384d183 100644 --- a/kibble/api/handler.py +++ b/kibble/api/handler.py @@ -27,12 +27,11 @@ import sys import traceback -import yaml - from kibble.api.plugins import openapi from kibble.api.plugins.database import KibbleDatabase from kibble.api.plugins.session import KibbleSession -from kibble.settings import KIBBLE_YAML, YAML_DIRECTORY +from kibble.configuration import conf +from kibble.settings import YAML_DIRECTORY # Compile valid API URLs from the pages library # Allow backwards compatibility by also accepting .lua URLs @@ -45,10 +44,6 @@ urls.append((r"^(/api/%s)(/.+)?$" % page, handler.run)) -# Load Kibble master configuration -with open(KIBBLE_YAML, "r") as f: - config = yaml.safe_load(f) - # Instantiate database connections DB = None @@ -156,13 +151,13 @@ def application(environ, start_response): Checks against the pages library, and if submod found, runs it and returns the output. """ - db = KibbleDatabase(config) + db = KibbleDatabase(conf) path = environ.get("PATH_INFO", "") for regex, function in urls: m = re.match(regex, path) if m: callback = KibbleAPIWrapper(path, function) - session = KibbleSession(db, environ, config) + session = KibbleSession(db, environ, conf) a = 0 for bucket in callback(environ, start_response, session): if a == 0: diff --git a/kibble/api/plugins/database.py b/kibble/api/plugins/database.py index fb1a9fab..57467213 100644 --- a/kibble/api/plugins/database.py +++ b/kibble/api/plugins/database.py @@ -22,6 +22,8 @@ import elasticsearch +from kibble.configuration import KibbleConfigParser + class KibbleESWrapper(object): """ @@ -119,24 +121,13 @@ def count(self, index, doc_type="*", body=None): class KibbleDatabase(object): - def __init__(self, config): + def __init__(self, config: KibbleConfigParser): self.config = config - self.dbname = config["elasticsearch"]["dbname"] + self.dbname = config.get("elasticsearch", "dbname") self.ES = elasticsearch.Elasticsearch( - [ - { - "host": config["elasticsearch"]["host"], - "port": int(config["elasticsearch"]["port"]), - "use_ssl": config["elasticsearch"]["ssl"], - "verify_certs": False, - "url_prefix": config["elasticsearch"]["uri"] - if "uri" in config["elasticsearch"] - else "", - "http_auth": config["elasticsearch"]["auth"] - if "auth" in config["elasticsearch"] - else None, - } - ], + [config.get("elasticsearch", "conn_uri")], + use_ssl=config.getboolean("elasticsearch", "ssl"), + verify_certs=False, max_retries=5, retry_on_timeout=True, )