summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2014-11-06 16:46:38 +0100
committerFolker Bernitt <fbernitt@thoughtworks.com>2014-11-06 16:46:38 +0100
commit46692d1994ab83a0def7bd24f02efa0eaa130871 (patch)
tree3a871bce56bf400fbdd65a3b85f0175bfc557981 /service/pixelated
parent73f931813b54bafa9c70d88068c13dfcb804288b (diff)
Issue #100: Read credentials from pipe.
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/config/app_factory.py4
-rw-r--r--service/pixelated/config/args.py2
-rw-r--r--service/pixelated/runserver.py22
3 files changed, 12 insertions, 16 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):