summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNavaL <ayoyo@thoughtworks.com>2016-06-23 12:01:17 +0200
committerNavaL <ayoyo@thoughtworks.com>2016-06-23 12:01:17 +0200
commit3b678f8d23a116a231be04e6f4da2219bd636362 (patch)
tree074d7e14dacd56538cb3b14ac0ed2601e439791e
parentde888b1d14df2981038b419e824b3df8908cd78d (diff)
refactoring: moved Service factories to the service config file
-rw-r--r--service/pixelated/application.py55
-rw-r--r--service/pixelated/config/services.py52
-rw-r--r--service/test/support/integration/app_test_client.py2
-rw-r--r--service/test/support/integration/multi_user_client.py3
-rw-r--r--service/test/unit/resources/test_keys_resources.py3
5 files changed, 59 insertions, 56 deletions
diff --git a/service/pixelated/application.py b/service/pixelated/application.py
index 580d1142..7d8cd76c 100644
--- a/service/pixelated/application.py
+++ b/service/pixelated/application.py
@@ -14,8 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-import os
import logging
+import os
from OpenSSL import SSL
from OpenSSL import crypto
@@ -31,8 +31,9 @@ from twisted.internet import ssl
from pixelated.adapter.welcome_mail import add_welcome_mail
from pixelated.config import arguments
from pixelated.config import logger
-from pixelated.config.leap import initialize_leap_single_user, init_monkeypatches, initialize_leap_provider
from pixelated.config import services
+from pixelated.config.leap import initialize_leap_single_user, init_monkeypatches, initialize_leap_provider
+from pixelated.config.services import ServicesFactory, SingleUserServicesFactory
from pixelated.config.site import PixelatedSite
from pixelated.resources.auth import LeapPasswordChecker, PixelatedRealm, PixelatedAuthSessionWrapper, SessionChecker
from pixelated.resources.login_resource import LoginResource
@@ -41,56 +42,6 @@ from pixelated.resources.root_resource import RootResource
log = logging.getLogger(__name__)
-class ServicesFactory(object):
-
- def __init__(self, mode):
- self._services_by_user = {}
- self.mode = mode
- self._map_email = {}
-
- def map_email(self, username, user_id):
- self._map_email[username] = user_id
-
- def is_logged_in(self, user_id):
- return user_id in self._services_by_user
-
- def services(self, user_id):
- return self._services_by_user[user_id]
-
- def log_out_user(self, user_id, using_email=False):
- if using_email:
- user_id = self._map_email[user_id.split('@')[0]]
-
- if self.is_logged_in(user_id):
- _services = self._services_by_user[user_id]
- _services.close()
- del self._services_by_user[user_id]
-
- def add_session(self, user_id, services):
- self._services_by_user[user_id] = services
-
- @defer.inlineCallbacks
- def create_services_from(self, leap_session):
- _services = services.Services(leap_session)
- yield _services.setup()
- self._services_by_user[leap_session.user_auth.uuid] = _services
-
-
-class SingleUserServicesFactory(object):
- def __init__(self, mode):
- self._services = None
- self.mode = mode
-
- def add_session(self, user_id, services):
- self._services = services
-
- def services(self, user_id):
- return self._services
-
- def log_out_user(self, user_id, using_email=False):
- reactor.stop()
-
-
class UserAgentMode(object):
def __init__(self, is_single_user):
self.is_single_user = is_single_user
diff --git a/service/pixelated/config/services.py b/service/pixelated/config/services.py
index de0e2537..cec4803e 100644
--- a/service/pixelated/config/services.py
+++ b/service/pixelated/config/services.py
@@ -9,7 +9,7 @@ from pixelated.adapter.services.mail_sender import MailSender
from pixelated.adapter.search import SearchEngine
from pixelated.adapter.services.draft_service import DraftService
from pixelated.adapter.listeners.mailbox_indexer_listener import listen_all_mailboxes
-from twisted.internet import defer
+from twisted.internet import defer, reactor
from pixelated.adapter.search.index_storage_key import SearchIndexStorageKey
from pixelated.adapter.services.feedback_service import FeedbackService
@@ -78,3 +78,53 @@ class Services(object):
def _setup_feedback_service(self):
return FeedbackService(self._leap_session)
+
+
+class ServicesFactory(object):
+
+ def __init__(self, mode):
+ self._services_by_user = {}
+ self.mode = mode
+ self._map_email = {}
+
+ def map_email(self, username, user_id):
+ self._map_email[username] = user_id
+
+ def is_logged_in(self, user_id):
+ return user_id in self._services_by_user
+
+ def services(self, user_id):
+ return self._services_by_user[user_id]
+
+ def log_out_user(self, user_id, using_email=False):
+ if using_email:
+ user_id = self._map_email[user_id.split('@')[0]]
+
+ if self.is_logged_in(user_id):
+ _services = self._services_by_user[user_id]
+ _services.close()
+ del self._services_by_user[user_id]
+
+ def add_session(self, user_id, services):
+ self._services_by_user[user_id] = services
+
+ @defer.inlineCallbacks
+ def create_services_from(self, leap_session):
+ _services = Services(leap_session)
+ yield _services.setup()
+ self._services_by_user[leap_session.user_auth.uuid] = _services
+
+
+class SingleUserServicesFactory(object):
+ def __init__(self, mode):
+ self._services = None
+ self.mode = mode
+
+ def add_session(self, user_id, services):
+ self._services = services
+
+ def services(self, user_id):
+ return self._services
+
+ def log_out_user(self, user_id, using_email=False):
+ reactor.stop()
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index 49f0552a..a66fc62b 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -39,7 +39,7 @@ from pixelated.adapter.services.feedback_service import FeedbackService
from pixelated.application import ServicesFactory, UserAgentMode, SingleUserServicesFactory, set_up_protected_resources
from pixelated.bitmask_libraries.config import LeapConfig
from pixelated.bitmask_libraries.session import LeapSession
-from pixelated.config.services import Services
+from pixelated.config.services import Services, ServicesFactory, SingleUserServicesFactory
from pixelated.config.site import PixelatedSite
from pixelated.adapter.mailstore import LeapMailStore
diff --git a/service/test/support/integration/multi_user_client.py b/service/test/support/integration/multi_user_client.py
index 5f24456b..656e0901 100644
--- a/service/test/support/integration/multi_user_client.py
+++ b/service/test/support/integration/multi_user_client.py
@@ -19,7 +19,8 @@ from twisted.internet import defer
from leap.auth import SRPAuth
-from pixelated.application import UserAgentMode, ServicesFactory, set_up_protected_resources
+from pixelated.application import UserAgentMode, set_up_protected_resources
+from pixelated.config.services import ServicesFactory
from pixelated.bitmask_libraries.session import LeapSession, LeapSessionFactory
import pixelated.config.services
diff --git a/service/test/unit/resources/test_keys_resources.py b/service/test/unit/resources/test_keys_resources.py
index 4aae8713..91c286c9 100644
--- a/service/test/unit/resources/test_keys_resources.py
+++ b/service/test/unit/resources/test_keys_resources.py
@@ -4,7 +4,8 @@ from mockito import mock, when, any as ANY
from leap.keymanager import KeyNotFound
from leap.keymanager.keys import OpenPGPKey
-from pixelated.application import ServicesFactory, UserAgentMode
+from pixelated.application import UserAgentMode
+from pixelated.config.services import ServicesFactory
from pixelated.resources.keys_resource import KeysResource
import twisted.trial.unittest as unittest
from twisted.web.test.requesthelper import DummyRequest