From 9c39068d292d17fb3c29ec3c53de5250ddfb40d7 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 2 Sep 2015 14:04:01 -0300 Subject: [feat] load credentials from environment variable Look for file defined in the `BITMASK_CREDENTIALS` env variable and load `provider`, `username` and `password` data. Trigger login if they were loaded correctly. The credentials file should look like this: [Credentials] username = my-account@my-provider.com password = secret - Resolves: #7419 --- src/leap/bitmask/gui/mainwindow.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/leap/bitmask') diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 312048ba..b0f14aef 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -17,8 +17,11 @@ """ Main window for Bitmask. """ +import os import time +import ConfigParser + from datetime import datetime import psutil @@ -781,6 +784,10 @@ class MainWindow(QtGui.QMainWindow, SignalTracker): if self._wizard: self._load_from_wizard() else: + if self._load_credentials_from_env(): + self._login() + return + domain = self._settings.get_provider() if domain is not None: self._providers.select_provider_by_name(domain) @@ -796,6 +803,35 @@ class MainWindow(QtGui.QMainWindow, SignalTracker): if self._login_widget.load_user_from_keyring(saved_user): self._login() + def _load_credentials_from_env(self): + """ + Load username and password into the login widget from a file specified + in an environment variable. This is useful for test purposes. + + :return: True if credentials were loaded, False otherwise + :rtype: bool + """ + credentials = os.environ.get("BITMASK_CREDENTIALS") + + if credentials is None: + return False + + try: + config = ConfigParser.ConfigParser() + config.read(credentials) + username, domain = config.get('Credentials', 'username').split('@') + password = config.get('Credentials', 'password') + except Exception, e: + print "Error reading credentials file: {0}".format(e) + return False + + self._providers.select_provider_by_name(domain) + self._login_widget.set_provider(domain) + self._login_widget.set_user(username) + self._login_widget.set_password(password) + + return True + def _show_hide_unsupported_services(self): """ Given a set of configured providers, it creates a set of -- cgit v1.2.3