Compare commits

...

3 commits

Author SHA1 Message Date
54e4d28d0c combine_as_imports = true 2021-05-12 01:44:45 +02:00
41752ac344 Rajoute un paramètre pour désactiver le LDAP 2021-05-12 01:36:24 +02:00
423dfcd2ec fix isort 2021-05-12 01:26:24 +02:00
3 changed files with 10 additions and 6 deletions

View file

@ -1,4 +1,5 @@
LDAP_SERVER_URL = "ldaps://ldap.spi.ens.fr:636" LDAP_SERVER_URL = "ldaps://ldap.spi.ens.fr:636"
AUTHENS_USE_OLDCAS = True AUTHENS_USE_OLDCAS = True
AUTHENS_USE_PASSWORD = True AUTHENS_USE_PASSWORD = True
USE_LDAP = True
# TODO: CAS_SERVER_URL # TODO: CAS_SERVER_URL

View file

@ -1,7 +1,10 @@
"""Helper functions to get CAS metadata and create CAS accounts.""" """Helper functions to get CAS metadata and create CAS accounts."""
import warnings
# TODO: make the python-ldap dependency optional # TODO: make the python-ldap dependency optional
import ldap import ldap
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
@ -24,6 +27,10 @@ def fetch_cas_account(cas_login):
if not cas_login.isalnum(): if not cas_login.isalnum():
raise ValueError("Illegal CAS login: {}".format(cas_login)) raise ValueError("Illegal CAS login: {}".format(cas_login))
if not getattr(settings, "USE_LDAP", default_conf.USE_LDAP):
warnings.warn("Use of LDAP is disabled", RuntimeWarning)
return None
ldap_url = getattr(settings, "LDAP_SERVER_URL", default_conf.LDAP_SERVER_URL) ldap_url = getattr(settings, "LDAP_SERVER_URL", default_conf.LDAP_SERVER_URL)
ldap_obj = ldap.initialize(ldap_url) ldap_obj = ldap.initialize(ldap_url)
res = ldap_obj.search_s( res = ldap_obj.search_s(

View file

@ -10,13 +10,9 @@ ignore =
W503 W503
[isort] [isort]
# For black compat: https://github.com/ambv/black#how-black-wraps-lines profile = black
combine_as_imports = true combine_as_imports = true
default_section = THIRDPARTY
force_grid_wrap = 0
include_trailing_comma = true
known_django = django known_django = django
known_first_party = authens,tests known_first_party = authens,tests
line_length = 88 line_length = 88
multi_line_output = 3 sections = FUTURE,STDLIB,THIRDPARTY,DJANGO,FIRSTPARTY,LOCALFOLDER
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER