summaryrefslogtreecommitdiff
path: root/server/src/leap/soledad/server/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/leap/soledad/server/__init__.py')
-rw-r--r--server/src/leap/soledad/server/__init__.py88
1 files changed, 19 insertions, 69 deletions
diff --git a/server/src/leap/soledad/server/__init__.py b/server/src/leap/soledad/server/__init__.py
index 34570b52..97bcf888 100644
--- a/server/src/leap/soledad/server/__init__.py
+++ b/server/src/leap/soledad/server/__init__.py
@@ -80,7 +80,6 @@ documents on the shared database is handled by `leap.soledad.server.auth`
module.
"""
-import configparser
import urlparse
import sys
@@ -88,11 +87,10 @@ from leap.soledad.common.l2db.remote import http_app, utils
from leap.soledad.server.auth import SoledadTokenAuthMiddleware
from leap.soledad.server.gzip_middleware import GzipMiddleware
-from leap.soledad.server.sync import (
- SyncResource,
- MAX_REQUEST_SIZE,
- MAX_ENTRY_SIZE,
-)
+from leap.soledad.server.sync import SyncResource
+from leap.soledad.server.sync import MAX_REQUEST_SIZE
+from leap.soledad.server.sync import MAX_ENTRY_SIZE
+from soledad.server.config import load_configuration
from leap.soledad.common import SHARED_DB_NAME
from leap.soledad.common.backend import SoledadBackend
@@ -100,6 +98,14 @@ from leap.soledad.common.couch.state import CouchServerState
from ._version import get_versions
+
+__all__ = [
+ 'SoledadApp',
+ 'application',
+ '__version__',
+]
+
+
# ----------------------------------------------------------------------------
# Soledad WSGI application
# ----------------------------------------------------------------------------
@@ -250,57 +256,6 @@ http_app.HTTPInvocationByMethodWithBody = HTTPInvocationByMethodWithBody
# ----------------------------------------------------------------------------
-# Auxiliary functions
-# ----------------------------------------------------------------------------
-CONFIG_DEFAULTS = {
- 'soledad-server': {
- 'couch_url': 'http://localhost:5984',
- 'create_cmd': None,
- 'admin_netrc': '/etc/couchdb/couchdb-admin.netrc',
- 'batching': False
- },
- 'database-security': {
- 'members': ['soledad'],
- 'members_roles': [],
- 'admins': [],
- 'admins_roles': []
- }
-}
-
-
-def load_configuration(file_path):
- """
- Load server configuration from file.
-
- @param file_path: The path to the configuration file.
- @type file_path: str
-
- @return: A dictionary with the configuration.
- @rtype: dict
- """
- defaults = dict(CONFIG_DEFAULTS)
- config = configparser.SafeConfigParser()
- config.read(file_path)
- for section in defaults:
- if not config.has_section(section):
- continue
- for key, value in defaults[section].items():
- if not config.has_option(section, key):
- continue
- elif type(value) == bool:
- defaults[section][key] = config.getboolean(section, key)
- elif type(value) == list:
- values = config.get(section, key).split(',')
- values = [v.strip() for v in values]
- defaults[section][key] = values
- else:
- defaults[section][key] = config.get(section, key)
- # TODO: implement basic parsing/sanitization of options comming from
- # config file.
- return defaults
-
-
-# ----------------------------------------------------------------------------
# Run as Twisted WSGI Resource
# ----------------------------------------------------------------------------
@@ -317,20 +272,15 @@ def _get_couch_state():
return state
-def application(environ, start_response):
- """return WSGI application that may be used by `twistd -web`"""
- state = _get_couch_state()
- application = GzipMiddleware(
- SoledadTokenAuthMiddleware(SoledadApp(state)))
- return application(environ, start_response)
+_couch_state = _get_couch_state()
+# a WSGI application that may be used by `twistd -web`
+application = GzipMiddleware(
+ SoledadTokenAuthMiddleware(SoledadApp(_couch_state)))
-def debug_local_application_do_not_use(environ, start_response):
- """in where we bypass token auth middleware for ease of mind while
- debugging in your local environment"""
- state = _get_couch_state()
- application = SoledadApp(state)
- return application(environ, start_response)
+# another WSGI application in which we bypass token auth middleware for ease of
+# mind while debugging in your local environment
+# debug_local_application_do_not_use = SoledadApp(_couch_state)
__version__ = get_versions()['version']