Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
constellation
Manage
Activity
Members
Labels
Plan
Issues
8
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nounous
constellation
Commits
2f2bcaec
Verified
Commit
2f2bcaec
authored
2 years ago
by
Benjamin Graillot
Committed by
ynerant
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[unix_ldap] Add command to force LDAP sync
parent
bae266ea
No related branches found
No related tags found
1 merge request
!44
Unix ldap
Pipeline
#11443
failed with stages
in 3 minutes and 21 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
unix_ldap/apps.py
+4
-4
4 additions, 4 deletions
unix_ldap/apps.py
unix_ldap/management/commands/ldap_sync.py
+12
-0
12 additions, 0 deletions
unix_ldap/management/commands/ldap_sync.py
unix_ldap/signals.py
+8
-3
8 additions, 3 deletions
unix_ldap/signals.py
with
24 additions
and
7 deletions
unix_ldap/apps.py
+
4
−
4
View file @
2f2bcaec
from
django.apps
import
AppConfig
from
django.db.models.signals
import
post_delete
,
post_save
from
django.db.models.signals
import
post_delete
,
post_save
,
pre_save
from
.signals
import
p
ost
_save_passwd
from
.signals
import
p
re
_save_passwd
class
UnixLdapConfig
(
AppConfig
):
...
...
@@ -9,7 +9,7 @@ class UnixLdapConfig(AppConfig):
name
=
'
unix_ldap
'
def
ready
(
self
):
p
ost
_save
.
connect
(
p
ost
_save_passwd
,
p
re
_save
.
connect
(
p
re
_save_passwd
,
sender
=
'
unix.Passwd
'
,
)
This diff is collapsed.
Click to expand it.
unix_ldap/management/commands/ldap_sync.py
0 → 100644
+
12
−
0
View file @
2f2bcaec
from
django.core.management.base
import
BaseCommand
,
CommandError
from
unix.models
import
Passwd
from
unix.signals
import
base
,
sync_passwd
class
Command
(
BaseCommand
):
help
=
"
Synchronize database with LDAP
"
def
handle
(
self
,
*
args
,
**
options
):
base
=
base
()
for
instance
in
Passwd
.
objects
.
all
():
sync_passwd
(
base
,
instance
)
This diff is collapsed.
Click to expand it.
unix_ldap/signals.py
+
8
−
3
View file @
2f2bcaec
...
...
@@ -11,9 +11,7 @@ def base():
base
.
set_option
(
ldap
.
OPT_X_TLS_NEWCTX
,
0
)
base
.
simple_bind_s
(
settings
.
LDAP_USER
,
settings
.
LDAP_PASSWORD
)
def
post_save_passwd
(
sender
,
instance
,
using
,
**
kwargs
):
base
=
base
()
def
sync_passwd
(
base
,
instance
):
ldap_user
=
{
'
objectClass
'
:
[
b
'
inetOrgPerson
'
,
b
'
organizationalPerson
'
,
b
'
person
'
,
b
'
posixAccount
'
],
'
uid
'
:
instance
.
uid
.
encode
(
'
ascii
'
),
...
...
@@ -30,3 +28,10 @@ def post_save_passwd(sender, instance, using, **kwargs):
base
.
add_s
(
f
'
{
settings
.
LDAP_USERS_KEY
}
=
{
instance
.
uid
}
,
{
settings
.
LDAP_USERS_DN
}
'
,
modlist
.
addModList
(
ldap_user
))
else
:
base
.
modify_s
(
f
'
{
settings
.
LDAP_USERS_KEY
}
=
{
instance
.
uid
}
,
{
settings
.
LDAP_USERS_DN
}
'
,
modlist
.
modifyModlist
(
old_ldap_user
,
ldap_user
))
def
pre_save_passwd
(
sender
,
instance
,
using
,
**
kwargs
):
try
:
base
=
base
()
except
ldap
.
SERVER_DOWN
:
raise
sync_passwd
(
base
,
instance
)
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