Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
4b7cd796
Commit
4b7cd796
authored
Sep 27, 2019
by
BaiJiangJie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature] 添加同步 LDAP/AD 用户的定时任务1
parent
ed5b2f8b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
utils.py
apps/settings/utils.py
+1
-1
tasks.py
apps/users/tasks.py
+25
-0
No files found.
apps/settings/utils.py
View file @
4b7cd796
...
...
@@ -186,7 +186,7 @@ class LDAPUtil:
result
=
{
'total'
:
len
(
user_items
),
'succeed'
:
succeed
,
'failed'
:
failed
}
return
result
def
sync_users
(
self
,
username_list
):
def
sync_users
(
self
,
username_list
=
None
):
user_items
=
self
.
search_filter_user_items
(
username_list
)
result
=
self
.
create_or_update_users
(
user_items
)
return
result
apps/users/tasks.py
View file @
4b7cd796
...
...
@@ -10,6 +10,8 @@ from .models import User
from
.utils
import
(
send_password_expiration_reminder_mail
,
send_user_expiration_reminder_mail
)
from
settings.utils
import
LDAPUtil
from
django.conf
import
settings
logger
=
get_logger
(
__file__
)
...
...
@@ -66,3 +68,26 @@ def check_user_expired_periodic():
}
create_or_update_celery_periodic_tasks
(
tasks
)
@shared_task
def
sync_ldap_user
():
logger
.
info
(
"Start sync ldap user periodic task"
)
util
=
LDAPUtil
()
result
=
util
.
sync_users
()
logger
.
info
(
"Result: {}"
.
format
(
result
))
@shared_task
@after_app_ready_start
def
sync_ldap_user_periodic
():
if
not
settings
.
AUTH_LDAP
:
return
tasks
=
{
'sync_ldap_user_periodic'
:
{
'task'
:
sync_ldap_user
.
name
,
'interval'
:
None
,
'crontab'
:
'* * * * *'
,
'enabled'
:
True
,
}
}
create_or_update_celery_periodic_tasks
(
tasks
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment