summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/config/args.py1
-rw-r--r--service/pixelated/runserver.py9
-rw-r--r--service/test/unit/runserver_test.py16
3 files changed, 26 insertions, 0 deletions
diff --git a/service/pixelated/config/args.py b/service/pixelated/config/args.py
index 6b77f341..4ac8a2ea 100644
--- a/service/pixelated/config/args.py
+++ b/service/pixelated/config/args.py
@@ -21,6 +21,7 @@ def parse():
parser = argparse.ArgumentParser(description='Pixelated user agent.')
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('--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 518ea5fb..5f30913b 100644
--- a/service/pixelated/runserver.py
+++ b/service/pixelated/runserver.py
@@ -52,6 +52,11 @@ def setup():
app.config['LEAP_SERVER_NAME'] = config['leap_provider_hostname']
app.config['LEAP_USERNAME'] = config['user']
app.config['LEAP_PASSWORD'] = config['password']
+ elif args.dispatcher_stdin:
+ config = fetch_credentials_from_dispatcher_stdin()
+ 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(args.host, args.port)
@@ -72,6 +77,10 @@ def fetch_credentials_from_dispatcher(filename):
return json.loads(fifo.read())
+def fetch_credentials_from_dispatcher_stdin():
+ return json.loads(sys.stdin.read())
+
+
def setup_debugger(enabled):
debug_enabled = enabled or os.environ.get('DEBUG', False)
log.startLogging(sys.stdout)
diff --git a/service/test/unit/runserver_test.py b/service/test/unit/runserver_test.py
index 51ee899c..801a60bf 100644
--- a/service/test/unit/runserver_test.py
+++ b/service/test/unit/runserver_test.py
@@ -59,6 +59,22 @@ class RunserverTest(unittest.TestCase):
sys.argv = ['tmp/does_not_exist', '--dispatcher', fifo_path]
pixelated.runserver.setup()
+ def test_that_organization_switch_reads_the_credentials_from_stdin(self):
+ data = json.dumps({'leap_provider_hostname': 'test_provider', 'user': 'test_user', 'password': 'test_password'})
+ orig_stdin = sys.stdin
+ try:
+ sys.stdin = Mock()
+ when(sys.stdin).read().thenReturn(data)
+
+ sys.argv = ['tmp/does_not_exist', '--dispatcher-stdin']
+ pixelated.runserver.setup()
+
+ self.assertEquals('test_provider', pixelated.runserver.app.config['LEAP_SERVER_NAME'])
+ self.assertEquals('test_user', pixelated.runserver.app.config['LEAP_USERNAME'])
+ self.assertEquals('test_password', pixelated.runserver.app.config['LEAP_PASSWORD'])
+ finally:
+ sys.stdin = orig_stdin
+
def test_start_services_provides_port(self):
bind_address = '127.0.0.1'
bind_port = 12345