config.py 2.99 KB
Newer Older
Markus Scheidgen's avatar
Markus Scheidgen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Copyright 2018 Markus Scheidgen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

15
16
17
18
19
"""
This module is used to store all configuration values. It makes use of
*namedtuples* to create key sensitive configuration objects.
"""

20
import os
Markus Scheidgen's avatar
Markus Scheidgen committed
21
import logging
22
23
from collections import namedtuple

24
25
FilesConfig = namedtuple(
    'FilesConfig', ['uploads_bucket', 'repository_bucket', 'archive_bucket', 'compress_archive'])
26
27
""" API independent configuration for the object storage. """

Markus Scheidgen's avatar
Markus Scheidgen committed
28
CeleryConfig = namedtuple('Celery', ['broker_url'])
Markus Scheidgen's avatar
Markus Scheidgen committed
29
""" Used to configure the RabbitMQ for celery. """
30

Markus Scheidgen's avatar
Markus Scheidgen committed
31
FSConfig = namedtuple('FSConfig', ['tmp', 'objects'])
32
33
""" Used to configure file stystem access. """

34
35
36
ElasticConfig = namedtuple('ElasticConfig', ['host', 'calc_index'])
""" Used to configure elastic search. """

Markus Scheidgen's avatar
Markus Scheidgen committed
37
MongoConfig = namedtuple('MongoConfig', ['host', 'port', 'users_db'])
38
39
""" Used to configure mongo db. """

Markus Scheidgen's avatar
Markus Scheidgen committed
40
LogstashConfig = namedtuple('LogstashConfig', ['enabled', 'host', 'tcp_port', 'level'])
41
""" Used to configure and enable/disable the ELK based centralized logging. """
42

43
NomadServicesConfig = namedtuple('NomadServicesConfig', ['api_host', 'api_port', 'api_base_path', 'api_secret'])
Markus Scheidgen's avatar
Markus Scheidgen committed
44
45
""" Used to configure nomad services: worker, handler, api """

46
files = FilesConfig(
47
48
    uploads_bucket='uploads',
    repository_bucket='repository',
49
    archive_bucket='archive',
50
    compress_archive=True
51
)
52
53
54
55
56
57
58

rabbit_host = os.environ.get('NOMAD_RABBITMQ_HOST', 'localhost')
rabbit_port = os.environ.get('NOMAD_RABBITMQ_PORT', None)
rabbit_user = 'rabbitmq'
rabbit_password = 'rabbitmq'
rabbit_url = 'pyamqp://%s:%s@%s//' % (rabbit_user, rabbit_password, rabbit_host)

59
celery = CeleryConfig(
Markus Scheidgen's avatar
Markus Scheidgen committed
60
    broker_url=rabbit_url
61
)
62

63
fs = FSConfig(
Markus Scheidgen's avatar
Markus Scheidgen committed
64
65
    tmp='.volumes/fs/tmp',
    objects='.volumes/fs/objects'
66
)
67
elastic = ElasticConfig(
68
    host=os.environ.get('NOMAD_ELASTIC_HOST', 'localhost'),
69
70
71
    calc_index='calcs'
)
mongo = MongoConfig(
72
    host=os.environ.get('NOMAD_MONGO_HOST', 'localhost'),
Markus Scheidgen's avatar
Markus Scheidgen committed
73
    port=int(os.environ.get('NOMAD_MONGO_PORT', 27017)),
74
75
    users_db='users'
)
76
logstash = LogstashConfig(
77
    enabled=True,
78
    host=os.environ.get('NOMAD_LOGSTASH_HOST', 'localhost'),
Markus Scheidgen's avatar
Markus Scheidgen committed
79
80
    tcp_port=int(os.environ.get('NOMAD_LOGSTASH_TCPPORT', '5000')),
    level=int(os.environ.get('NOMAD_LOGSTASH_LEVEL', logging.DEBUG))
81
)
Markus Scheidgen's avatar
Markus Scheidgen committed
82
services = NomadServicesConfig(
83
84
    api_host=os.environ.get('NOMAD_API_HOST', 'localhost'),
    api_port=int(os.environ.get('NOMAD_API_PORT', 8000)),
85
    api_base_path=os.environ.get('NOMAD_API_BASE_PATH', '/nomad/api'),
86
    api_secret='the quick fox jumps over something'
Markus Scheidgen's avatar
Markus Scheidgen committed
87
)