config.py 3.53 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'])
29
""" Used to configure the RabbitMQ and Redis backends for celery. """
30

31
MinioConfig = namedtuple('Minio', ['host', 'port', 'accesskey', 'secret'])
32
33
""" Used to configure the minio object storage API. """

34
FSConfig = namedtuple('FSConfig', ['tmp'])
35
36
""" Used to configure file stystem access. """

37
38
39
ElasticConfig = namedtuple('ElasticConfig', ['host', 'calc_index'])
""" Used to configure elastic search. """

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

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

46
NomadServicesConfig = namedtuple('NomadServicesConfig', ['api_base_path', 'objects_host', 'objects_port', 'objects_base_path', 'api_secret'])
Markus Scheidgen's avatar
Markus Scheidgen committed
47
48
""" Used to configure nomad services: worker, handler, api """

49
files = FilesConfig(
50
51
    uploads_bucket='uploads',
    repository_bucket='repository',
52
53
    archive_bucket='archive',
    compress_archive=False
54
)
55
56
57
58
59
60
61
62
63
64

rabbit_host = os.environ.get('NOMAD_RABBITMQ_HOST', 'localhost')
rabbit_port = os.environ.get('NOMAD_RABBITMQ_PORT', None)
rabbit_user = 'rabbitmq'
rabbit_password = 'rabbitmq'
redis_host = os.environ.get('NOMAD_REDIS_HOST', 'localhost')

rabbit_url = 'pyamqp://%s:%s@%s//' % (rabbit_user, rabbit_password, rabbit_host)
redis_url = 'redis://%s/0' % redis_host

65
celery = CeleryConfig(
Markus Scheidgen's avatar
Markus Scheidgen committed
66
    broker_url=rabbit_url
67
)
68

69
minio = MinioConfig(
70
71
    host=os.environ.get('NOMAD_MINIO_HOST', 'localhost'),
    port=int(os.environ.get('NOMAD_MINIO_PORT', '9007')),
72
73
    accesskey='AKIAIOSFODNN7EXAMPLE',
    secret='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
74
75
)
fs = FSConfig(
76
    tmp='.volumes/fs'
77
)
78
elastic = ElasticConfig(
79
    host=os.environ.get('NOMAD_ELASTIC_HOST', 'localhost'),
80
81
82
    calc_index='calcs'
)
mongo = MongoConfig(
83
    host=os.environ.get('NOMAD_MONGO_HOST', 'localhost'),
Markus Scheidgen's avatar
Markus Scheidgen committed
84
    port=int(os.environ.get('NOMAD_MONGO_PORT', 27017)),
85
86
    users_db='users'
)
87
logstash = LogstashConfig(
88
    enabled=True,
89
    host=os.environ.get('NOMAD_LOGSTASH_HOST', 'localhost'),
Markus Scheidgen's avatar
Markus Scheidgen committed
90
91
    tcp_port=int(os.environ.get('NOMAD_LOGSTASH_TCPPORT', '5000')),
    level=int(os.environ.get('NOMAD_LOGSTASH_LEVEL', logging.DEBUG))
92
)
Markus Scheidgen's avatar
Markus Scheidgen committed
93
services = NomadServicesConfig(
94
    api_base_path=os.environ.get('NOMAD_API_BASE_PATH', '/nomad/api'),
Markus Scheidgen's avatar
Markus Scheidgen committed
95
    objects_host=os.environ.get('NOMAD_OBJECTS_HOST', 'localhost'),
Markus Scheidgen's avatar
Markus Scheidgen committed
96
    objects_port=int(os.environ.get('NOMAD_OBJECTS_PORT', minio.port)),
97
98
    objects_base_path=os.environ.get('NOMAD_OBJECTS_BASE_PATH', ''),
    api_secret='the quick fox jumps over something'
Markus Scheidgen's avatar
Markus Scheidgen committed
99
)