summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYongqin Liu <yongqin.liu@android.linaro.org>2018-05-21 02:19:46 +0000
committerYongqin Liu <yongqin.liu@linaro.org>2018-05-21 10:23:49 +0800
commit8d23ae2b3aba6feabb4b9ab686bee1059d6d73f2 (patch)
tree636d594c80df238c9c6cf149876685e386e6066d
parent8c7442db31d57870c4821c74de0631374b33d6f8 (diff)
update to set linaro login for user account authentication
Signed-off-by: Yongqin Liu <yongqin.liu@android.linaro.org>
-rwxr-xr-xdeploy.sh19
-rw-r--r--lcr/settings.py35
2 files changed, 49 insertions, 5 deletions
diff --git a/deploy.sh b/deploy.sh
index 2d8eef1..2c4149d 100755
--- a/deploy.sh
+++ b/deploy.sh
@@ -1,5 +1,13 @@
#!/bin/bash
+if [ "/*" = "$0" ]; then
+ echo "Please run this script with absolute path"
+ exit 1
+fi
+
+if [ -n "$1" ]; then
+ work_root=$1
+fi
if [ -d "${work_root}" ]; then
work_root=${work_root}
elif [ -d /sata250/django_instances ]; then
@@ -24,6 +32,10 @@ cd ${virenv_dir}
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
+sudo apt-get update
+#sudo apt-get install python-django-auth-ldap
+## dependency for python-ldap
+sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
# https://virtualenv.pypa.io/en/stable/
sudo pip install virtualenv
virtualenv ${virenv_dir}
@@ -38,14 +50,17 @@ pip install pyaml
pip install lava-tool
pip install django-crispy-forms
pip install django psycopg2
+pip install python-ldap # will install the 3.0 version
+# https://django-auth-ldap.readthedocs.io/en/latest/install.html
+pip install django-auth-ldap # needs python-ldap >= 3.0
# https://docs.djangoproject.com/en/1.11/intro/tutorial01/
python -m django --version
#python manage.py startapp ${instance_report_app}
# django-admin startproject ${instance_name}
cd ${work_root} && git clone https://git.linaro.org/people/yongqin.liu/public/lcr-report.git
-cd ${instance_dir} && python manage.py runserver 0.0.0.0:9000
-echo "Please update the LAVA_USER_TOKEN and LAVA_USER in report/views.py"
+#cd ${instance_dir} && python manage.py runserver 0.0.0.0:9000
+#echo "Please update the LAVA_USER_TOKEN and LAVA_USER in report/views.py"
# python manage.py createsuperuser
# By running makemigrations, you’re telling Django that you’ve made some changes to your models (in this case,
diff --git a/lcr/settings.py b/lcr/settings.py
index 2dcf4ac..cb38e35 100644
--- a/lcr/settings.py
+++ b/lcr/settings.py
@@ -12,6 +12,12 @@ https://docs.djangoproject.com/en/1.11/ref/settings/
import os
+db_name = ""
+db_username = ""
+db_passwd = ""
+bind_user=""
+bind_passwd=""
+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -85,9 +91,9 @@ DATABASES = {
#}
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
- 'NAME': 'lcrreport',
- 'USER': 'lcrreport',
- 'PASSWORD': '',
+ 'NAME': '%s' % db_name,
+ 'USER': '%s' % db_username,
+ 'PASSWORD': '%s' % db_passwd,
'HOST': 'localhost',
'PORT': '',
}
@@ -201,3 +207,26 @@ LOGGING = {
#DATA_UPLOAD_MAX_NUMBER_FIELDS = 100000
CRISPY_TEMPLATE_PACK = 'bootstrap3'
+
+#######################################################################
+#######################################################################
+## Setting to use linaro login
+INSTALLED_APPS.append('ldap')
+INSTALLED_APPS.append('django_auth_ldap')
+import ldap
+from django_auth_ldap.config import (LDAPSearch, LDAPSearchUnion)
+
+AUTHENTICATION_BACKENDS = ['django_auth_ldap.backend.LDAPBackend',
+ 'django.contrib.auth.backends.ModelBackend']
+
+AUTH_LDAP_SERVER_URI = "ldap://login.linaro.org"
+AUTH_LDAP_BIND_DN = "uid=%s,ou=staff,ou=accounts,dc=linaro,dc=org" % (bind_user)
+AUTH_LDAP_BIND_PASSWORD = "%s" % ( bind_passwd )
+# AUTH_LDAP_USER_SEARCH and AUTH_LDAP_USER_DN_TEMPLATE are mutually
+#AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=staff,ou=accounts,dc=linaro,dc=org"
+AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=staff,ou=accounts,dc=linaro,dc=org",
+ ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
+AUTH_LDAP_USER_ATTR_MAP = {
+ "first_name": "givenName",
+ "email": "mail"
+}