Add utility code to get max UID
Other changes: - Introduce logging - Introduce .env config parameters - LDAP_SEARCH_BASE: The base used in the LDAP search to find uid - IPV6_WORK_USER_GROUP: The LDAP group to which the newly added user should belong to
This commit is contained in:
parent
8e07151837
commit
f3d90a2b7d
1 changed files with 41 additions and 0 deletions
|
@ -12,9 +12,12 @@ https://docs.djangoproject.com/en/2.1/ref/settings/
|
|||
|
||||
import os
|
||||
import ldap
|
||||
import logging
|
||||
from decouple import config, Csv
|
||||
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -207,6 +210,44 @@ LOGGING = {
|
|||
},
|
||||
}
|
||||
|
||||
LDAP_SEARCH_BASE=config(
|
||||
'LDAP_SEARCH_BASE',
|
||||
default='ou=users,dc=ungleich,dc=ch'
|
||||
)
|
||||
|
||||
LDAP_MAX_UID_PATH = os.path.join(
|
||||
os.path.abspath(os.path.dirname(__file__)),
|
||||
'ldap_max_uid_file'
|
||||
)
|
||||
|
||||
IPV6_WORK_USER_GROUP = config('IPV6_WORK_USER_GROUP', cast=int)
|
||||
|
||||
|
||||
def set_max_uid(max_uid):
|
||||
"""
|
||||
a utility function to save max_uid value to a file
|
||||
|
||||
:param max_uid: an integer representing the max uid
|
||||
:return:
|
||||
"""
|
||||
with open(LDAP_MAX_UID_PATH, 'w+') as handler:
|
||||
handler.write(max_uid)
|
||||
|
||||
|
||||
def get_max_uid():
|
||||
"""
|
||||
A utility function to read the max uid value that was previously set
|
||||
|
||||
:return: An integer representing the max uid value that was previously set
|
||||
"""
|
||||
try:
|
||||
with open(LDAP_MAX_UID_PATH, 'r+') as handler:
|
||||
return int(handler.read())
|
||||
except FileNotFoundError as fnfe:
|
||||
logger.error("File not found : " + str(fnfe))
|
||||
ret = config('DEFAULT_START_UID', cast=int, default=10000)
|
||||
logger.error("So, returing UID={}".format(ret))
|
||||
|
||||
if config('ENABLE_DEBUG_LOG', cast=bool, default=False):
|
||||
loggers_dict = {}
|
||||
LOGGING['handlers']['file'] = {
|
||||
|
|
Loading…
Reference in a new issue