summaryrefslogtreecommitdiff
path: root/server.py
blob: eb565e9f22279ba277cbe282059d52aba1f61759 (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
"""
A U1DB server that stores data using couchdb.

This should be run with:
    twistd -n web --wsgi=leap.soledad.server.application
"""

import configparser
from twisted.web.wsgi import WSGIResource
from twisted.internet import reactor
from u1db.remote import http_app
from leap.soledad.backends.couch import CouchServerState


def load_configuration(file_path):
    conf = {
        'couch_url': 'http://localhost:5984',
        'working_dir': '/tmp',
    }
    config = configparser.ConfigParser()
    config.read(file_path)
    if 'soledad-server' in config:
        for key in conf:
            if key in config['soledad-server']:
                conf[key] = config['soledad-server'][key]
    return conf


conf = load_configuration('/etc/leap/soledad-server.ini')

state = CouchServerState(conf['couch_url'])
# TODO: change working dir to something meaningful
state.set_workingdir(conf['working_dir'])
application = http_app.HTTPApp(state)

resource = WSGIResource(reactor, reactor.getThreadPool(), application)