From 7a8e9cc142ad368434031e4e008b40281d68150b Mon Sep 17 00:00:00 2001 From: Bruno Wagner Date: Thu, 4 Jun 2015 19:11:46 -0300 Subject: Config dispatcher and config_ua are now in credentials --- service/pixelated/config/args.py | 5 ++- service/pixelated/config/config_ua.py | 44 ----------------------- service/pixelated/config/credentials.py | 54 +++++++++++++++++++++++++++++ service/pixelated/config/dispatcher.py | 38 -------------------- service/pixelated/config/initialize_leap.py | 26 +++----------- 5 files changed, 60 insertions(+), 107 deletions(-) delete mode 100644 service/pixelated/config/config_ua.py create mode 100644 service/pixelated/config/credentials.py delete mode 100644 service/pixelated/config/dispatcher.py (limited to 'service/pixelated/config') diff --git a/service/pixelated/config/args.py b/service/pixelated/config/args.py index dd3b715d..2c7470e2 100644 --- a/service/pixelated/config/args.py +++ b/service/pixelated/config/args.py @@ -49,9 +49,8 @@ def parse_maintenance_args(): def parser_add_default_arguments(parser): parser.add_argument('--debug', action='store_true', help='DEBUG mode.') - parser.add_argument('--dispatcher', help='run in organization mode, the credentials will be read from specified file', metavar='file') - parser.add_argument('--dispatcher-stdin', help='run in organization mode, the credentials will be read from stdin', default=False, action='store_true', dest='dispatcher_stdin') - parser.add_argument('-c', '--config', dest='config_file', metavar='', default=None, help='use specified file for credentials (for test purposes only)') + 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='', 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('-lc', '--leap-provider-cert', metavar='', default=None, help='use specified file for LEAP provider cert authority certificate (url https:///ca.crt)') parser.add_argument('-lf', '--leap-provider-cert-fingerprint', metavar='', default=None, help='use specified fingerprint to validate connection with LEAP provider', dest='leap_provider_cert_fingerprint') diff --git a/service/pixelated/config/config_ua.py b/service/pixelated/config/config_ua.py deleted file mode 100644 index 5afb501b..00000000 --- a/service/pixelated/config/config_ua.py +++ /dev/null @@ -1,44 +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 . - -import ConfigParser -import os -import getpass - - -def parse_config_from_file(config_file): - config_parser = ConfigParser.ConfigParser() - config_file_path = os.path.abspath(os.path.expanduser(config_file)) - config_parser.read(config_file_path) - provider, user, password = \ - config_parser.get('pixelated', 'leap_server_name'), \ - config_parser.get('pixelated', 'leap_username'), \ - config_parser.get('pixelated', 'leap_password') - - return provider, user, password - - -def prompt_for_credentials(): - provider = raw_input('Which provider do you want to connect to:\n') - username = raw_input('What\'s your username registered on the provider:\n') - password = getpass.getpass('Type your password:\n') - return provider, username, password - - -def config_user_agent(config_file): - provider, user, password = parse_config_from_file(config_file) if config_file else prompt_for_credentials() - - return (provider, user, password) diff --git a/service/pixelated/config/credentials.py b/service/pixelated/config/credentials.py new file mode 100644 index 00000000..ae1bc4f3 --- /dev/null +++ b/service/pixelated/config/credentials.py @@ -0,0 +1,54 @@ +# +# Copyright (c) 2015 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 . + +import os +import getpass +import json +import sys +import ConfigParser + + +def read(organization_mode, credentials_file): + if organization_mode: + return read_from_dispatcher() + else: + if credentials_file: + return read_from_file(credentials_file) + return prompt_for_credentials() + + +def prompt_for_credentials(): + provider = raw_input('Which provider do you want to connect to:\n') + username = raw_input('What\'s your username registered on the provider:\n') + password = getpass.getpass('Type your password:\n') + return provider, username, password + + +def read_from_file(credentials_file): + config_parser = ConfigParser.ConfigParser() + credentials_file_path = os.path.abspath(os.path.expanduser(credentials_file)) + config_parser.read(credentials_file_path) + provider, user, password = \ + config_parser.get('pixelated', 'leap_server_name'), \ + config_parser.get('pixelated', 'leap_username'), \ + config_parser.get('pixelated', 'leap_password') + return provider, user, password + + +def read_from_dispatcher(): + config = json.loads(sys.stdin.read()) + + return config['leap_provider_hostname'], config['user'], config['password'] diff --git a/service/pixelated/config/dispatcher.py b/service/pixelated/config/dispatcher.py deleted file mode 100644 index eb5634ab..00000000 --- a/service/pixelated/config/dispatcher.py +++ /dev/null @@ -1,38 +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 . - -import json -import sys -import os - - -def config_dispatcher(dispatcher): - - def fetch_credentials_from_dispatcher(filename): - if not os.path.exists(filename): - print('The credentials pipe doesn\'t exist') - sys.exit(1) - with open(filename, 'r') as fifo: - return json.loads(fifo.read()) - - def fetch_credentials_from_dispatcher_stdin(): - return json.loads(sys.stdin.read()) - - config = fetch_credentials_from_dispatcher(dispatcher) if dispatcher else fetch_credentials_from_dispatcher_stdin() - - return (config['leap_provider_hostname'], - config['user'], - config['password']) diff --git a/service/pixelated/config/initialize_leap.py b/service/pixelated/config/initialize_leap.py index b693fde6..3ddc3a57 100644 --- a/service/pixelated/config/initialize_leap.py +++ b/service/pixelated/config/initialize_leap.py @@ -1,6 +1,5 @@ from pixelated.config.config import Config -from pixelated.config.config_ua import config_user_agent -from pixelated.config.dispatcher import config_dispatcher +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 @@ -8,39 +7,22 @@ from pixelated.bitmask_libraries.session import open_leap_session def initialize_leap(leap_provider_cert, leap_provider_cert_fingerprint, - config_file, - dispatcher, - dispatcher_stdin, + credentials_file, + organization_mode, leap_home): - init_monkeypatches() - - provider, user, password = gather_credentials(dispatcher, - dispatcher_stdin, - config_file) - + provider, user, password = credentials.read(organization_mode, credentials_file) init_leap_cert(leap_provider_cert, leap_provider_cert_fingerprint) - events_server.ensure_server(port=8090) - leap_session = create_leap_session(provider, user, password, leap_home) - return leap_session -def gather_credentials(dispatcher, dispatcher_stdin, config_file): - if dispatcher or dispatcher_stdin: - return config_dispatcher(dispatcher) - else: - return config_user_agent(config_file) - - 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 -- cgit v1.2.3