Allow loading bind secret from file
This commit is contained in:
@@ -36,9 +36,18 @@ class LDAPConnection:
|
||||
self.__LDAP_FILTER = ldap_setting("FILTER", "")
|
||||
self.__LDAP_SEARCH_BASE = ldap_setting("SEARCH_BASE", "")
|
||||
|
||||
password = ldap_setting("BIND_PW", "")
|
||||
if not password:
|
||||
pwfile = ldap_setting("BIND_PW_FILE", "")
|
||||
if pw_file:
|
||||
with open(pwfile, "r") as f:
|
||||
password = f.read().replace("\n", "")
|
||||
else:
|
||||
logging.error("No bind password specified")
|
||||
|
||||
self.__ldap_connection = ldap.initialize(ldap_setting("SERVER", ""))
|
||||
try:
|
||||
self.__ldap_connection.simple_bind_s(ldap_setting("BIND_DN", ""), ldap_setting("BIND_PW", ""))
|
||||
self.__ldap_connection.simple_bind_s(ldap_setting("BIND_DN", ""), password)
|
||||
except ldap.LDAPError as err:
|
||||
logging.error(f"LDAP Error occuring during bind: {err.desc}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user