Bug 1086672 - Add files that were missed. r=fix
authorArmen Zambrano Gasparnian <armenzg@mozilla.com>
Thu, 29 Jan 2015 14:24:16 -0500 (2015-01-29)
changeset 3615 04ff04530e9a39370622921a9f88fb0c3f92582c
parent 3614 89039ca686216bdbf56ca59958029e0702bb45a1
child 3617 4d33f708fdddb7775e497075e5fba768312f7286
child 3618 069e6f8e814bd5dae355c8d3a31d392e39078346
push id2825
push userarmenzg@mozilla.com
push dateThu, 29 Jan 2015 19:24:29 +0000 (2015-01-29)
reviewersfix
bugs1086672
Bug 1086672 - Add files that were missed. r=fix
mozharness/lib/__init__.py
mozharness/lib/python/__init__.py
mozharness/lib/python/authentication.py
new file mode 100644
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/mozharness/lib/python/authentication.py
@@ -0,0 +1,44 @@
+# ***** BEGIN LICENSE BLOCK *****
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+# ***** END LICENSE BLOCK *****
+
+"""module for http authentication operations"""
+import getpass
+import os
+
+CREDENTIALS_PATH = os.path.expanduser("~/.mozilla/credentials.cfg")
+DIRNAME = os.path.dirname(CREDENTIALS_PATH)
+
+def get_credentials():
+    """ Returns credentials for http access either from
+    disk or directly from the user (which we store)
+    """
+    if not os.path.exists(DIRNAME):
+        os.makedirs(DIRNAME)
+
+    if os.path.isfile(CREDENTIALS_PATH):
+        with open(CREDENTIALS_PATH, 'r') as file_handler:
+            content = file_handler.read().splitlines()
+
+        https_username = content[0].strip()
+        https_password = content[1].strip()
+    else:
+        https_username = \
+                raw_input("Please enter your full LDAP email address: ")
+        https_password = getpass.getpass()
+
+        with open(CREDENTIALS_PATH, "w+") as file_handler:
+            file_handler.write("%s\n" % https_username)
+            file_handler.write("%s\n" % https_password)
+
+        os.chmod(CREDENTIALS_PATH, 0600)
+
+    return https_username, https_password
+
+def get_credentials_path():
+    if os.path.isfile(CREDENTIALS_PATH):
+        get_credentials()
+
+    return CREDENTIALS_PATH