Bug#797223:
Implementation attached, tox tested only.
From d107eb7d1985b01dcf415ae9eb391dccc4d511c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi>
Date: Mon, 30 Oct 2017 23:01:30 +0200
Subject: [PATCH] Use nm.d.o REST API instead of LDAP
---
TODO | 1 -
debian/control | 2 --
distro_tracker/vendor/debian/sso_auth.py | 37 +++++++++++++-------------------
docs/setup/setup.rst | 3 +--
tox.ini | 1 -
5 files changed, 16 insertions(+), 28 deletions(-)
diff --git a/TODO b/TODO
index 60f9975..87d41fd 100644
--- a/TODO
+++ b/TODO
@@ -19,7 +19,6 @@ Misc possible enhancements:
* Codebase is Python 3 compatible but some optional dependencies need to
be ported:
- python-soappy => switch to pysimplesoap
- - python-ldap => replace LDAP access with nm.d.o REST api, cf #797223
* Re-enable a smarter clickjacking protection: only activate it when the
page is rendered for a logged in user and allow callers to pass a
"anonymous=1" parameter that will force render the web page as if
diff --git a/debian/control b/debian/control
index 62be97c..a5189e6 100644
--- a/debian/control
+++ b/debian/control
@@ -16,7 +16,6 @@ Build-Depends: debhelper (>= 9),
python-django-jsonfield,
python-django-captcha,
python-gpgme,
- python-ldap,
python-lzma,
python-requests (>= 2),
python-soappy,
@@ -69,7 +68,6 @@ Depends: ${python:Depends},
python-yaml,
python-pyinotify,
${misc:Depends}
-Recommends: python-ldap
Description: Python libraries of Distro Tracker
Distro Tracker offers a web interface to display an overview of each source
package provided as well as an email interface to be notified of changes
diff --git a/distro_tracker/vendor/debian/sso_auth.py b/distro_tracker/vendor/debian/sso_auth.py
index f749353..a39a9bf 100644
--- a/distro_tracker/vendor/debian/sso_auth.py
+++ b/distro_tracker/vendor/debian/sso_auth.py
@@ -9,18 +9,16 @@
# except according to the terms contained in the LICENSE file.
from __future__ import unicode_literals
+import json
from django.contrib.auth.middleware import RemoteUserMiddleware
from django.contrib.auth.backends import RemoteUserBackend
from django.contrib import auth
from django.core.exceptions import ImproperlyConfigured
+from django.utils.http import urlencode
from distro_tracker.accounts.models import UserEmail
from distro_tracker.accounts.models import User
-
-try:
- import ldap
-except ImportError:
- ldap = None
+from distro_tracker.core.utils.http import get_resource_content
class DebianSsoUserMiddleware(RemoteUserMiddleware):
@@ -101,7 +99,7 @@ class DebianSsoUserBackend(RemoteUserBackend):
user (identified by their @debian.org email) in Distro Tracker. If
a matching User model instance does not exist, one is
automatically created. In that case the DDs first and last name
- are pulled from Debian's LDAP.
+ are pulled from Debian's NM REST API.
"""
def authenticate(self, remote_user):
if not remote_user:
@@ -130,27 +128,22 @@ class DebianSsoUserBackend(RemoteUserBackend):
def get_user_details(self, remote_user):
"""
- Gets the details of the given user from the Debian LDAP.
+ Gets the details of the given user from the Debian NM REST API.
:return: Dict with the keys ``first_name``, ``last_name``
- ``None`` if the LDAP lookup did not return anything.
+ ``None`` if the API lookup did not return anything.
"""
- if ldap is None:
- return None
if not remote_user.endswith('@debian.org'):
- # We only know how to extract data for DD via LDAP
+ # We only know how to extract data for DD via NM API
return None
- l = ldap.initialize('ldap://db.debian.org')
- result_set = l.search_s(
- 'dc=debian,dc=org',
- ldap.SCOPE_SUBTREE,
- 'uid={}'.format(self.get_uid(remote_user)),
- None)
- if not result_set:
- return None
+ content = get_resource_content(
+ 'https://nm.debian.org/api/people?' +
+ urlencode({'uid': self.get_uid(remote_user)}))
+ result = json.loads(content)['r']
- result = result_set[0]
+ if not result:
+ return None
return {
- 'first_name': result[1]['cn'][0].decode('utf-8'),
- 'last_name': result[1]['sn'][0].decode('utf-8'),
+ 'first_name': result[0]['cn'],
+ 'last_name': result[0]['sn'],
}
diff --git a/docs/setup/setup.rst b/docs/setup/setup.rst
index dad9ac0..cd95ba6 100644
--- a/docs/setup/setup.rst
+++ b/docs/setup/setup.rst
@@ -22,7 +22,6 @@ Distro Tracker currently depends on the following Debian packages:
- python-bs4
- python-pyinotify
- python-soappy (optional)
-- python-ldap (optional)
- python-tox (for development only)
- python-selenium (for development only)
- chromedriver (for development only)
@@ -35,7 +34,7 @@ For Python2.7, the following additional packages are required:
Here is the list of required packages for development on Debian Jessie::
- $ sudo apt install python-django python-requests python-django-jsonfield python-django-debug-toolbar python-debian python-apt python-gpgme python-yaml python-bs4 python-soappy python-ldap python-pyinotify python-tox python-mock python-lzma python-selenium python3-django python3-requests python3-django-jsonfield python3-django-debug-toolbar python3-debian python3-apt python3-gpgme python3-yaml python3-bs4 python3-pyinotify python3-selenium chromium chromedriver
+ $ sudo apt install python-django python-requests python-django-jsonfield python-django-debug-toolbar python-debian python-apt python-gpgme python-yaml python-bs4 python-soappy python-pyinotify python-tox python-mock python-lzma python-selenium python3-django python3-requests python3-django-jsonfield python3-django-debug-toolbar python3-debian python3-apt python3-gpgme python3-yaml python3-bs4 python3-pyinotify python3-selenium chromium chromedriver
.. _database_setup:
diff --git a/tox.ini b/tox.ini
index 7687289..66e1671 100644
--- a/tox.ini
+++ b/tox.ini
@@ -38,7 +38,6 @@ deps =
py27-tests: mock
py27-tests: pyliblzma
py27-tests: SOAPpy
- py27-tests: python_ldap
tests: requests
tests: django_jsonfield
tests: django_debug_toolbar
--
2.14.1
Reply to: