summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/config/app_factory.py4
-rw-r--r--service/pixelated/config/args.py2
-rw-r--r--service/pixelated/runserver.py22
-rw-r--r--service/test/unit/runserver_test.py8
4 files changed, 15 insertions, 21 deletions
diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py
index bbc29527..c479a913 100644
--- a/service/pixelated/config/app_factory.py
+++ b/service/pixelated/config/app_factory.py
@@ -86,8 +86,8 @@ def init_leap_session(app):
except ConnectionError, error:
print("Can't connect to the requested provider")
sys.exit(1)
- except LeapAuthException:
- print("Couldn't authenticate with the credentials provided")
+ except LeapAuthException, e:
+ print("Couldn't authenticate with the credentials provided %s" % e.message)
sys.exit(1)
return leap_session
diff --git a/service/pixelated/config/args.py b/service/pixelated/config/args.py
index 9b75a04b..6b77f341 100644
--- a/service/pixelated/config/args.py
+++ b/service/pixelated/config/args.py
@@ -20,7 +20,7 @@ import argparse
def parse():
parser = argparse.ArgumentParser(description='Pixelated user agent.')
parser.add_argument('--debug', action='store_true', help='DEBUG mode.')
- parser.add_argument('--dispatcher', action='store_true', help='run in organization mode, the credentials will be received from the dispatcher this way')
+ parser.add_argument('--dispatcher', help='run in organization mode, the credentials will be read from specified file', metavar='file')
parser.add_argument('--host', default='127.0.0.1', help='the host to run the user agent on')
parser.add_argument('--port', type=int, default=3333, help='the port to run the user agent on')
parser.add_argument('-c', '--config', metavar='configfile', default=None, help='use specified file for credentials (for test purposes only)')
diff --git a/service/pixelated/runserver.py b/service/pixelated/runserver.py
index 51c8d40a..832008ad 100644
--- a/service/pixelated/runserver.py
+++ b/service/pixelated/runserver.py
@@ -17,7 +17,7 @@
import os
import sys
import logging
-
+import json
from klein import Klein
klein_app = Klein()
@@ -35,7 +35,6 @@ import pixelated.support.ext_sqlcipher # monkey patch for sqlcipher in debian
app = Klein()
app.config = {}
-credentials_pipe = os.path.join('/', 'data', 'credentials-fifo')
def setup():
@@ -46,10 +45,10 @@ def setup():
register(*args.register[::-1])
else:
if args.dispatcher:
- provider, user, password = fetch_credentials_from_dispatcher()
- app.config['LEAP_SERVER_NAME'] = provider
- app.config['LEAP_USERNAME'] = user
- app.config['LEAP_PASSWORD'] = password
+ config = fetch_credentials_from_dispatcher(args.dispatcher)
+ app.config['LEAP_SERVER_NAME'] = config['leap_provider_hostname']
+ app.config['LEAP_USERNAME'] = config['user']
+ app.config['LEAP_PASSWORD'] = config['password']
else:
configuration_setup(args.config)
start_services()
@@ -62,15 +61,12 @@ def register(username, server_name):
print('User already exists')
-def fetch_credentials_from_dispatcher():
- if not os.path.exists(credentials_pipe):
+def fetch_credentials_from_dispatcher(filename):
+ if not os.path.exists(filename):
print('The credentials pipe doesn\'t exist')
sys.exit(1)
- with open(credentials_pipe, 'r') as cred_file:
- provider = cred_file.read()
- username = cred_file.read()
- password = cred_file.read()
- return provider, username, password
+ with open(filename, 'r') as fifo:
+ return json.loads(fifo.read())
def setup_debugger(enabled):
diff --git a/service/test/unit/runserver_test.py b/service/test/unit/runserver_test.py
index 4a9bca6f..e3cd8439 100644
--- a/service/test/unit/runserver_test.py
+++ b/service/test/unit/runserver_test.py
@@ -18,6 +18,7 @@ import unittest
import sys
import os
import thread
+import json
import pixelated.runserver
from mockito import *
@@ -51,12 +52,9 @@ class RunserverTest(unittest.TestCase):
os.remove(fifo_path)
test_fifo = os.mkfifo('/tmp/credentials-pipe')
thread.start_new_thread(self.spin_up_fifo, (fifo_path,))
- sys.argv = ['tmp/does_not_exist', '--dispatcher']
- pixelated.runserver.credentials_pipe = fifo_path
+ sys.argv = ['tmp/does_not_exist', '--dispatcher', fifo_path]
pixelated.runserver.setup()
def spin_up_fifo(self, test_fifo):
with open(test_fifo, 'w') as fifo:
- fifo.write('test_provider')
- fifo.write('test_user')
- fifo.write('test_password')
+ fifo.write(json.dumps({'leap_provider_hostname': 'test_provider', 'user': 'test_user', 'password': 'test_password'}))