summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2015-09-02 14:04:01 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2015-09-02 16:46:22 -0300
commit9c39068d292d17fb3c29ec3c53de5250ddfb40d7 (patch)
tree33e46082c05837d2229cf4b9564b833531a3cd57 /src
parent2fa5d0f38b79d0536652034c3007dfae290ef6fc (diff)
[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
Diffstat (limited to 'src')
-rw-r--r--src/leap/bitmask/gui/mainwindow.py36
1 files changed, 36 insertions, 0 deletions
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