mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #5327: Be more strict when capturing anticipated ImportError exceptions
This commit is contained in:
@ -137,19 +137,24 @@ class LDAPBackend:
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
try:
|
||||
import ldap
|
||||
from django_auth_ldap.backend import LDAPBackend as LDAPBackend_, LDAPSettings
|
||||
except ImportError:
|
||||
raise ImproperlyConfigured(
|
||||
"LDAP authentication has been configured, but django-auth-ldap is not installed."
|
||||
)
|
||||
import ldap
|
||||
except ModuleNotFoundError as e:
|
||||
if getattr(e, 'name') == 'django_auth_ldap':
|
||||
raise ImproperlyConfigured(
|
||||
"LDAP authentication has been configured, but django-auth-ldap is not installed."
|
||||
)
|
||||
raise e
|
||||
|
||||
try:
|
||||
from netbox import ldap_config
|
||||
except ImportError:
|
||||
raise ImproperlyConfigured(
|
||||
"ldap_config.py does not exist"
|
||||
)
|
||||
except ModuleNotFoundError as e:
|
||||
if getattr(e, 'name') == 'ldap_config':
|
||||
raise ImproperlyConfigured(
|
||||
"LDAP configuration file not found: Check that ldap_config.py has been created alongside "
|
||||
"configuration.py."
|
||||
)
|
||||
raise e
|
||||
|
||||
try:
|
||||
getattr(ldap_config, 'AUTH_LDAP_SERVER_URI')
|
||||
|
Reference in New Issue
Block a user