summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/core/configurable.py
blob: 51a100d613e4d804bb3ec8b878cd0bc2175270f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
# configurable.py
# Copyright (C) 2015, 2016 LEAP
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
Configurable Backend for Bitmask Service.
"""
from twisted.application import service

from leap.bitmask.config import (
    Configuration,
    DEFAULT_BASEDIR,
    MissingConfigEntry
)


class ConfigurableService(service.MultiService):

    config_file = u"bitmaskd.cfg"
    service_names = ('mail', 'eip', 'zmq', 'web', 'websockets')

    def __init__(self, basedir=DEFAULT_BASEDIR):
        service.MultiService.__init__(self)
        self.cfg = Configuration(self.config_file, basedir, DEFAULT_CONFIG)
        self.basedir = basedir

    def get_config(self, section, option, default=None, boolean=False):
        return self.cfg.get(section, option, default=default, boolean=boolean)

    def set_config(self, section, option, value):
        return self.cfg.set(section, option, value)


DEFAULT_CONFIG = """
[services]
mail = True
eip = True
zmq = True
web = True
onion = False
websockets = False
"""

__all__ = ["ConfigurableService", DEFAULT_BASEDIR, MissingConfigEntry]