summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2016-11-10 23:50:35 -0200
committerdrebs <drebs@leap.se>2016-11-10 23:50:35 -0200
commit564f55802455d08c9a38e892bb4b25ad6fbcb87d (patch)
treeb214482c46ecd09d531a3bc7bf254bf47d367fb5 /server
parentc1950b41e0995b0213227bd0ce2c633f312037dc (diff)
parent0fd7e9f018b02161a844c11332ffced56b256010 (diff)
Merge tag '0.9.0'
Tag version 0.9.0
Diffstat (limited to 'server')
-rwxr-xr-xserver/pkg/create-user-db2
-rw-r--r--server/pkg/requirements-latest.pip2
-rw-r--r--server/pkg/requirements-leap.pip2
-rw-r--r--server/pkg/requirements.pip5
-rw-r--r--server/pkg/soledad-server4
-rw-r--r--server/setup.py14
-rw-r--r--server/src/leap/soledad/server/__init__.py93
-rw-r--r--server/src/leap/soledad/server/auth.py7
-rw-r--r--server/src/leap/soledad/server/config.py67
9 files changed, 109 insertions, 87 deletions
diff --git a/server/pkg/create-user-db b/server/pkg/create-user-db
index 5e48d4de..b955b4c3 100755
--- a/server/pkg/create-user-db
+++ b/server/pkg/create-user-db
@@ -80,7 +80,7 @@ def ensure_database(dbname):
url = url_for_db(dbname)
db_security = CONF['database-security']
db = CouchDatabase.open_database(url=url, create=True,
- replica_uid=None, ensure_ddocs=True,
+ replica_uid=None,
database_security=db_security)
print ('success! Ensured that database %s exists, with replica_uid: %s' %
(db._dbname, db.replica_uid))
diff --git a/server/pkg/requirements-latest.pip b/server/pkg/requirements-latest.pip
index 46a7ccba..d32e1ffa 100644
--- a/server/pkg/requirements-latest.pip
+++ b/server/pkg/requirements-latest.pip
@@ -1,5 +1,5 @@
--index-url https://pypi.python.org/simple/
--e 'git+https://github.com/pixelated-project/leap_pycommon.git@develop#egg=leap.common'
+-e 'git+https://github.com/leapcode/leap_pycommon.git@develop#egg=leap.common'
-e '../common'
-e .
diff --git a/server/pkg/requirements-leap.pip b/server/pkg/requirements-leap.pip
index aaad340c..93b447e5 100644
--- a/server/pkg/requirements-leap.pip
+++ b/server/pkg/requirements-leap.pip
@@ -1 +1 @@
-leap.soledad.common>=0.6.5
+leap.soledad.common>=0.9.0
diff --git a/server/pkg/requirements.pip b/server/pkg/requirements.pip
index 2d845f24..e92dfde6 100644
--- a/server/pkg/requirements.pip
+++ b/server/pkg/requirements.pip
@@ -1,6 +1,5 @@
configparser
PyOpenSSL
twisted>=12.3.0
-#pinned for wheezy compatibility
-Beaker==1.6.3 #wheezy
-couchdb==0.8 #wheezy
+Beaker
+couchdb
diff --git a/server/pkg/soledad-server b/server/pkg/soledad-server
index 74ed122e..9dada6a0 100644
--- a/server/pkg/soledad-server
+++ b/server/pkg/soledad-server
@@ -12,7 +12,6 @@
PATH=/sbin:/bin:/usr/sbin:/usr/bin
PIDFILE=/var/run/soledad.pid
OBJ=leap.soledad.server.application
-LOGFILE=/var/log/soledad.log
HTTPS_PORT=2424
CONFDIR=/etc/soledad
CERT_PATH="${CONFDIR}/soledad-server.pem"
@@ -37,7 +36,8 @@ case "${1}" in
--exec ${TWISTD_PATH} -- \
--uid=${USER} --gid=${GROUP} \
--pidfile=${PIDFILE} \
- --logfile=${LOGFILE} \
+ --syslog \
+ --prefix=soledad-server \
web \
--wsgi=${OBJ} \
--port=ssl:${HTTPS_PORT}:privateKey=${PRIVKEY_PATH}:certKey=${CERT_PATH}:sslmethod=${SSL_METHOD}
diff --git a/server/setup.py b/server/setup.py
index b3b26010..a18d0b2d 100644
--- a/server/setup.py
+++ b/server/setup.py
@@ -122,13 +122,13 @@ requirements = utils.parse_requirements()
if utils.is_develop_mode():
print
- print ("[WARNING] Skipping leap-specific dependencies "
- "because development mode is detected.")
- print ("[WARNING] You can install "
- "the latest published versions with "
- "'pip install -r pkg/requirements-leap.pip'")
- print ("[WARNING] Or you can instead do 'python setup.py develop' "
- "from the parent folder of each one of them.")
+ print("[WARNING] Skipping leap-specific dependencies "
+ "because development mode is detected.")
+ print("[WARNING] You can install "
+ "the latest published versions with "
+ "'pip install -r pkg/requirements-leap.pip'")
+ print("[WARNING] Or you can instead do 'python setup.py develop' "
+ "from the parent folder of each one of them.")
print
else:
requirements += utils.parse_requirements(
diff --git a/server/src/leap/soledad/server/__init__.py b/server/src/leap/soledad/server/__init__.py
index 34570b52..d154e3fe 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 leap.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
# ----------------------------------------------------------------------------
@@ -312,25 +267,23 @@ def _load_config():
def _get_couch_state():
conf = _load_config()
- state = CouchServerState(conf['couch_url'], create_cmd=conf['create_cmd'])
+ state = CouchServerState(conf['couch_url'], create_cmd=conf['create_cmd'],
+ check_schema_versions=True)
SoledadBackend.BATCH_SUPPORT = conf.get('batching', False)
return state
-
-def application(environ, start_response):
- """return WSGI application that may be used by `twistd -web`"""
- state = _get_couch_state()
+try:
+ _couch_state = _get_couch_state()
+ # a WSGI application that may be used by `twistd -web`
application = GzipMiddleware(
- SoledadTokenAuthMiddleware(SoledadApp(state)))
- return application(environ, start_response)
+ SoledadTokenAuthMiddleware(SoledadApp(_couch_state)))
+except:
+ pass
-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']
diff --git a/server/src/leap/soledad/server/auth.py b/server/src/leap/soledad/server/auth.py
index ecee2d5d..b7186b3b 100644
--- a/server/src/leap/soledad/server/auth.py
+++ b/server/src/leap/soledad/server/auth.py
@@ -22,13 +22,16 @@ import json
from abc import ABCMeta, abstractmethod
from routes.mapper import Mapper
-from twisted.python import log
+from leap.soledad.common.log import getLogger
from leap.soledad.common.l2db import DBNAME_CONSTRAINTS, errors as u1db_errors
from leap.soledad.common import SHARED_DB_NAME
from leap.soledad.common import USER_DB_PREFIX
+logger = getLogger(__name__)
+
+
class URLToAuthorization(object):
"""
Verify if actions can be performed by a user.
@@ -378,7 +381,7 @@ class SoledadTokenAuthMiddleware(SoledadAuthMiddleware):
try:
return self._state.verify_token(uuid, token)
except Exception as e:
- log.err(e)
+ logger.error(e)
return False
def _get_auth_error_string(self):
diff --git a/server/src/leap/soledad/server/config.py b/server/src/leap/soledad/server/config.py
new file mode 100644
index 00000000..4a791cbe
--- /dev/null
+++ b/server/src/leap/soledad/server/config.py
@@ -0,0 +1,67 @@
+# -*- coding: utf-8 -*-
+# config.py
+# Copyright (C) 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/>.
+
+
+import configparser
+
+
+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