diff options
author | Leonardo Schäffer <leonardo.schaffer@gmail.com> | 2015-06-25 11:20:44 -0300 |
---|---|---|
committer | Leonardo Schäffer <leonardo.schaffer@gmail.com> | 2015-06-25 11:20:44 -0300 |
commit | 42f31aa607750eb7c00224e7c1c353b27cbd7519 (patch) | |
tree | 4bbfae731c8427c526f22bacb9136e5ed3e69d8c /service/pixelated/config | |
parent | 7f349abe67b8e1a71798478f6c26b08773f2d869 (diff) | |
parent | 0b179c61043a9854fa23b8fd40fd252864ecd021 (diff) |
Merge branch 'master' into floatlabel_for_compose
Diffstat (limited to 'service/pixelated/config')
-rw-r--r-- | service/pixelated/config/app_factory.py | 52 | ||||
-rw-r--r-- | service/pixelated/config/arguments.py | 9 | ||||
-rw-r--r-- | service/pixelated/config/leap.py | 33 | ||||
-rw-r--r-- | service/pixelated/config/services.py | 65 |
4 files changed, 81 insertions, 78 deletions
diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py deleted file mode 100644 index 1c7fb8a1..00000000 --- a/service/pixelated/config/app_factory.py +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright (c) 2014 ThoughtWorks, Inc. -# -# Pixelated is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pixelated 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Pixelated. If not, see <http://www.gnu.org/licenses/>. - -from pixelated.resources.root_resource import RootResource -from pixelated.adapter.services.mail_service import MailService -from pixelated.adapter.model.mail import InputMail -from pixelated.adapter.services.mail_sender import MailSender -from pixelated.adapter.services.mailboxes import Mailboxes -from pixelated.adapter.soledad.soledad_querier import SoledadQuerier -from pixelated.adapter.search import SearchEngine -from pixelated.adapter.services.draft_service import DraftService -from pixelated.adapter.listeners.mailbox_indexer_listener import MailboxIndexerListener - - -def init_app(leap_home, leap_session): - keymanager = leap_session.nicknym.keymanager - - soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad) - - search_engine = SearchEngine(soledad_querier, agent_home=leap_home) - pixelated_mail_sender = MailSender(leap_session.account_email(), leap_session.smtp) - - pixelated_mailboxes = Mailboxes(leap_session.account, soledad_querier, search_engine) - - pixelated_mailboxes.add_welcome_mail_for_fresh_user() - - draft_service = DraftService(pixelated_mailboxes) - mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender, soledad_querier, search_engine) - soledad_querier.remove_duplicates() - search_engine.index_mails(mails=mail_service.all_mails(), - callback=soledad_querier.mark_all_as_not_recent) - - MailboxIndexerListener.SEARCH_ENGINE = search_engine - InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email() - - resource = RootResource() - resource.initialize(soledad_querier, keymanager, search_engine, mail_service, draft_service) - - return resource diff --git a/service/pixelated/config/arguments.py b/service/pixelated/config/arguments.py index 8899f9a8..56f83421 100644 --- a/service/pixelated/config/arguments.py +++ b/service/pixelated/config/arguments.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 argparse -from pixelated.bitmask_libraries.config import DEFAULT_LEAP_HOME def parse_user_agent_args(): @@ -24,6 +24,7 @@ def parse_user_agent_args(): parser_add_default_arguments(parser) parser.add_argument('--host', default='127.0.0.1', help='the host to run the user agent on') + parser.add_argument('--organization-mode', help='Runs the user agent in organization mode, the credentials will be received from the stdin', default=False, action='store_true', dest='organization_mode') parser.add_argument('--port', type=int, default=3333, help='the port to run the user agent on') parser.add_argument('-sk', '--sslkey', metavar='<server.key>', default=None, help='use specified file as web server\'s SSL key (when using the user-agent together with the pixelated-dispatcher)') parser.add_argument('-sc', '--sslcert', metavar='<server.crt>', default=None, help='use specified file as web server\'s SSL certificate (when using the user-agent together with the pixelated-dispatcher)') @@ -50,13 +51,15 @@ def parse_register_args(): parser = argparse.ArgumentParser(description='Pixelated register') parser.add_argument('provider', metavar='provider', action='store') parser.add_argument('username', metavar='username', action='store') + parser.add_argument('-lc', '--leap-provider-cert', metavar='<leap-provider.crt>', default=None, help='use specified file for LEAP provider cert authority certificate (url https://<LEAP-provider-domain>/ca.crt)') + parser.add_argument('-lf', '--leap-provider-cert-fingerprint', metavar='<leap provider certificate fingerprint>', default=None, help='use specified fingerprint to validate connection with LEAP provider', dest='leap_provider_cert_fingerprint') + parser.add_argument('--leap-home', help='The folder where the user agent stores its data. Defaults to ~/.leap', dest='leap_home', default=os.path.join(os.path.expanduser("~"), '.leap')) return parser.parse_args() def parser_add_default_arguments(parser): parser.add_argument('--debug', action='store_true', help='DEBUG mode.') - parser.add_argument('--organization-mode', help='Runs the user agent in organization mode, the credentials will be received from the stdin', default=False, action='store_true', dest='organization_mode') parser.add_argument('-c', '--config', dest='credentials_file', metavar='<credentials_file>', default=None, help='use specified file for credentials (for test purposes only)') - parser.add_argument('--leap-home', help='The folder where the user agent stores its data. Defaults to ~/.leap', dest='leap_home', default=DEFAULT_LEAP_HOME) + parser.add_argument('--leap-home', help='The folder where the user agent stores its data. Defaults to ~/.leap', dest='leap_home', default=os.path.join(os.path.expanduser("~"), '.leap')) parser.add_argument('-lc', '--leap-provider-cert', metavar='<leap-provider.crt>', default=None, help='use specified file for LEAP provider cert authority certificate (url https://<LEAP-provider-domain>/ca.crt)') parser.add_argument('-lf', '--leap-provider-cert-fingerprint', metavar='<leap provider certificate fingerprint>', default=None, help='use specified fingerprint to validate connection with LEAP provider', dest='leap_provider_cert_fingerprint') diff --git a/service/pixelated/config/leap.py b/service/pixelated/config/leap.py index f13a3fc7..52cd4c8f 100644 --- a/service/pixelated/config/leap.py +++ b/service/pixelated/config/leap.py @@ -2,8 +2,10 @@ from __future__ import absolute_import import random from pixelated.config import credentials from leap.common.events import server as events_server -import pixelated.bitmask_libraries.certs as certs -from pixelated.bitmask_libraries.session import open_leap_session +from pixelated.bitmask_libraries.config import LeapConfig +from pixelated.bitmask_libraries.certs import LeapCertificate +from pixelated.bitmask_libraries.provider import LeapProvider +from pixelated.bitmask_libraries.session import LeapSessionFactory def initialize_leap(leap_provider_cert, @@ -12,33 +14,18 @@ def initialize_leap(leap_provider_cert, organization_mode, leap_home): init_monkeypatches() - provider, user, password = credentials.read(organization_mode, credentials_file) - init_leap_cert(leap_provider_cert, leap_provider_cert_fingerprint) events_server.ensure_server(random.randrange(8000, 11999)) - leap_session = create_leap_session(provider, user, password, leap_home) - leap_session.start_background_jobs() - return leap_session + provider, username, password = credentials.read(organization_mode, credentials_file) + LeapCertificate.set_cert_and_fingerprint(leap_provider_cert, leap_provider_cert_fingerprint) + config = LeapConfig(leap_home=leap_home, start_background_jobs=True) + provider = LeapProvider(provider, config) + LeapCertificate(provider).setup_ca_bundle() + leap_session = LeapSessionFactory(provider).create(username, password) -def create_leap_session(provider, username, password, leap_home): - leap_session = open_leap_session(username, - password, - provider, - leap_home) - leap_session.soledad_session.soledad.sync(defer_decryption=False) - leap_session.nicknym.generate_openpgp_key() return leap_session -def init_leap_cert(leap_provider_cert, leap_provider_cert_fingerprint): - if leap_provider_cert_fingerprint is None: - certs.LEAP_CERT = leap_provider_cert or True - certs.LEAP_FINGERPRINT = None - else: - certs.LEAP_FINGERPRINT = leap_provider_cert_fingerprint - certs.LEAP_CERT = False - - def init_monkeypatches(): import pixelated.extensions.protobuf_socket import pixelated.extensions.sqlcipher_wal diff --git a/service/pixelated/config/services.py b/service/pixelated/config/services.py new file mode 100644 index 00000000..f1c7a540 --- /dev/null +++ b/service/pixelated/config/services.py @@ -0,0 +1,65 @@ +from pixelated.adapter.services.mail_service import MailService +from pixelated.adapter.model.mail import InputMail +from pixelated.adapter.services.mail_sender import MailSender +from pixelated.adapter.services.mailboxes import Mailboxes +from pixelated.adapter.soledad.soledad_querier import SoledadQuerier +from pixelated.adapter.search import SearchEngine +from pixelated.adapter.services.draft_service import DraftService +from pixelated.adapter.listeners.mailbox_indexer_listener import MailboxIndexerListener + + +class Services(object): + + def __init__(self, leap_home, leap_session): + + soledad_querier = SoledadQuerier(soledad=leap_session.soledad_session.soledad) + + self.search_engine = self.setup_search_engine( + leap_home, + soledad_querier) + + pixelated_mailboxes = Mailboxes( + leap_session.account, + soledad_querier, + self.search_engine) + + self.mail_service = self.setup_mail_service( + leap_session, + soledad_querier, + self.search_engine, + pixelated_mailboxes) + + self.keymanager = self.setup_keymanager(leap_session) + self.draft_service = self.setup_draft_service(pixelated_mailboxes) + + self.post_setup(soledad_querier, leap_session) + + def post_setup(self, soledad_querier, leap_session): + self.search_engine.index_mails( + mails=self.mail_service.all_mails(), + callback=soledad_querier.mark_all_as_not_recent) + soledad_querier.remove_duplicates() + InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email() + + def setup_keymanager(self, leap_session): + return leap_session.nicknym.keymanager + + def setup_search_engine(self, leap_home, soledad_querier): + key = soledad_querier.get_index_masterkey() + search_engine = SearchEngine(key, agent_home=leap_home) + MailboxIndexerListener.SEARCH_ENGINE = search_engine + return search_engine + + def setup_mail_service(self, leap_session, soledad_querier, search_engine, pixelated_mailboxes): + pixelated_mailboxes.add_welcome_mail_for_fresh_user() + pixelated_mail_sender = MailSender( + leap_session.account_email(), + leap_session.smtp) + return MailService( + pixelated_mailboxes, + pixelated_mail_sender, + soledad_querier, + search_engine) + + def setup_draft_service(self, pixelated_mailboxes): + return DraftService(pixelated_mailboxes) |