Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Luca (strifel)
uffd
Commits
8904ab96
Commit
8904ab96
authored
4 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Added lazyconfig_* functions to configure LDAP models with app config
parent
e967d2b5
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.pylintrc
+1
-0
1 addition, 0 deletions
.pylintrc
uffd/lazyconfig.py
+54
-0
54 additions, 0 deletions
uffd/lazyconfig.py
uffd/mail/models.py
+4
-3
4 additions, 3 deletions
uffd/mail/models.py
uffd/user/models.py
+5
-4
5 additions, 4 deletions
uffd/user/models.py
with
64 additions
and
7 deletions
.pylintrc
+
1
−
0
View file @
8904ab96
...
...
@@ -146,6 +146,7 @@ disable=missing-module-docstring,
too-few-public-methods,
method-hidden,
bad-continuation,
too-many-ancestors,
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
...
...
This diff is collapsed.
Click to expand it.
uffd/lazyconfig.py
0 → 100644
+
54
−
0
View file @
8904ab96
from
collections
import
UserString
,
UserList
from
flask
import
current_app
class
LazyConfigString
(
UserString
):
def
__init__
(
self
,
seq
=
None
,
key
=
None
,
default
=
None
,
error
=
True
):
# pylint: disable=super-init-not-called
self
.
__seq
=
seq
self
.
__key
=
key
self
.
__default
=
default
self
.
__error
=
error
@property
def
data
(
self
):
if
self
.
__seq
is
not
None
:
obj
=
self
.
__seq
elif
self
.
__error
:
obj
=
current_app
.
config
[
self
.
__key
]
else
:
obj
=
current_app
.
config
.
get
(
self
.
__key
,
self
.
__default
)
return
str
(
obj
)
def
__bytes__
(
self
):
return
self
.
data
.
encode
()
def
__get__
(
self
,
obj
,
owner
=
None
):
return
self
.
data
def
lazyconfig_str
(
key
,
**
kwargs
):
return
LazyConfigString
(
None
,
key
,
**
kwargs
)
class
LazyConfigList
(
UserList
):
def
__init__
(
self
,
seq
=
None
,
key
=
None
,
default
=
None
,
error
=
True
):
# pylint: disable=super-init-not-called
self
.
__seq
=
seq
self
.
__key
=
key
self
.
__default
=
default
self
.
__error
=
error
@property
def
data
(
self
):
if
self
.
__seq
is
not
None
:
obj
=
self
.
__seq
elif
self
.
__error
:
obj
=
current_app
.
config
[
self
.
__key
]
else
:
obj
=
current_app
.
config
.
get
(
self
.
__key
,
self
.
__default
)
return
obj
def
__get__
(
self
,
obj
,
owner
=
None
):
return
self
.
data
def
lazyconfig_list
(
key
,
**
kwargs
):
return
LazyConfigList
(
None
,
key
,
**
kwargs
)
This diff is collapsed.
Click to expand it.
uffd/mail/models.py
+
4
−
3
View file @
8904ab96
from
uffd.ldap
import
LDAPModel
,
LDAPAttribute
from
uffd.lazyconfig
import
lazyconfig_str
,
lazyconfig_list
class
Mail
(
LDAPModel
):
ldap_base
=
'
ou=postfix,dc=example,dc=com
'
ldap_base
=
lazyconfig_str
(
'
LDAP_BASE_MAIL
'
)
ldap_dn_attribute
=
'
uid
'
ldap_dn_base
=
'
ou=postfix,dc=example,dc=com
'
ldap_dn_base
=
lazyconfig_str
(
'
LDAP_BASE_MAIL
'
)
ldap_filter
=
'
(objectClass=postfixVirtual)
'
ldap_object_classes
=
[
'
top
'
,
'
postfixVirtual
'
]
ldap_object_classes
=
lazyconfig_list
(
'
MAIL_LDAP_OBJECTCLASSES
'
)
uid
=
LDAPAttribute
(
'
uid
'
)
receivers
=
LDAPAttribute
(
'
mailacceptinggeneralid
'
,
multi
=
True
)
...
...
This diff is collapsed.
Click to expand it.
uffd/user/models.py
+
5
−
4
View file @
8904ab96
...
...
@@ -5,6 +5,7 @@ from flask import current_app
from
ldap3.utils.hashed
import
hashed
,
HASHED_SALTED_SHA512
from
uffd.ldap
import
LDAPModel
,
LDAPAttribute
,
LDAPRelation
from
uffd.lazyconfig
import
lazyconfig_str
,
lazyconfig_list
def
get_next_uid
():
max_uid
=
current_app
.
config
[
'
LDAP_USER_MIN_UID
'
]
...
...
@@ -17,11 +18,11 @@ def get_next_uid():
return
next_uid
class
User
(
LDAPModel
):
ldap_base
=
'
ou=users,dc=example,dc=com
'
ldap_base
=
lazyconfig_str
(
'
LDAP_BASE_USER
'
)
ldap_dn_attribute
=
'
uid
'
ldap_dn_base
=
'
ou=users,dc=example,dc=com
'
ldap_dn_base
=
lazyconfig_str
(
'
LDAP_BASE_USER
'
)
ldap_filter
=
'
(objectClass=person)
'
ldap_object_classes
=
[
'
top
'
,
'
inetOrgPerson
'
,
'
organizationalPerson
'
,
'
person
'
,
'
posixAccount
'
]
ldap_object_classes
=
lazyconfig_list
(
'
LDAP_USER_OBJECTCLASSES
'
)
uid
=
LDAPAttribute
(
'
uidNumber
'
,
default
=
get_next_uid
)
loginname
=
LDAPAttribute
(
'
uid
'
)
...
...
@@ -101,7 +102,7 @@ class User(LDAPModel):
return
True
class
Group
(
LDAPModel
):
ldap_base
=
'
ou=groups,dc=example,dc=com
'
ldap_base
=
lazyconfig_str
(
'
LDAP_BASE_GROUPS
'
)
ldap_filter
=
'
(objectClass=groupOfUniqueNames)
'
gid
=
LDAPAttribute
(
'
gidNumber
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment