summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changes/feature-7419_load-credentials-from-env1
-rw-r--r--src/leap/bitmask/gui/mainwindow.py36
2 files changed, 37 insertions, 0 deletions
diff --git a/changes/feature-7419_load-credentials-from-env b/changes/feature-7419_load-credentials-from-env
new file mode 100644
index 00000000..7704df01
--- /dev/null
+++ b/changes/feature-7419_load-credentials-from-env
@@ -0,0 +1 @@
+- Load credentials from environment variables and trigger login. Closes feature #7419.
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