Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csentry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
Anders Harrisson
csentry
Commits
1d11f2f6
Commit
1d11f2f6
authored
7 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Add command to run all maintenance tasks
parent
642cee2e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/commands.py
+20
-8
20 additions, 8 deletions
app/commands.py
app/tokens.py
+1
-0
1 addition, 0 deletions
app/tokens.py
with
21 additions
and
8 deletions
app/commands.py
+
20
−
8
View file @
1d11f2f6
...
@@ -48,6 +48,19 @@ def sync_user(connection, user):
...
@@ -48,6 +48,19 @@ def sync_user(connection, user):
return
user
return
user
def
sync_users
():
"""
Synchronize all users from the database with information the LDAP server
"""
current_app
.
logger
.
info
(
'
Synchronize database with information from the LDAP server
'
)
try
:
connection
=
ldap_manager
.
connection
except
ldap3
.
core
.
exceptions
.
LDAPException
as
e
:
current_app
.
logger
.
warning
(
f
'
Failed to connect to the LDAP server:
{
e
}
'
)
return
for
user
in
User
.
query
.
all
():
sync_user
(
connection
,
user
)
db
.
session
.
commit
()
def
register_cli
(
app
):
def
register_cli
(
app
):
@app.cli.command
()
@app.cli.command
()
def
initdb
():
def
initdb
():
...
@@ -65,16 +78,15 @@ def register_cli(app):
...
@@ -65,16 +78,15 @@ def register_cli(app):
@app.cli.command
()
@app.cli.command
()
def
syncusers
():
def
syncusers
():
"""
Synchronize all users from the database with information the LDAP server
"""
"""
Synchronize all users from the database with information the LDAP server
"""
try
:
sync_users
()
connection
=
ldap_manager
.
connection
except
ldap3
.
core
.
exceptions
.
LDAPException
as
e
:
current_app
.
logger
.
warning
(
f
'
Failed to connect to the LDAP server:
{
e
}
'
)
return
for
user
in
User
.
query
.
all
():
sync_user
(
connection
,
user
)
db
.
session
.
commit
()
@app.cli.command
()
@app.cli.command
()
def
delete_expired_tokens
():
def
delete_expired_tokens
():
"""
Prune database from expired tokens
"""
"""
Prune database from expired tokens
"""
tokens
.
prune_database
()
tokens
.
prune_database
()
@app.cli.command
()
def
maintenance
():
"""
Run maintenance commands
"""
sync_users
()
tokens
.
prune_database
()
This diff is collapsed.
Click to expand it.
app/tokens.py
+
1
−
0
View file @
1d11f2f6
...
@@ -90,6 +90,7 @@ def revoke_token(token_id, user_id):
...
@@ -90,6 +90,7 @@ def revoke_token(token_id, user_id):
def
prune_database
():
def
prune_database
():
"""
Delete tokens that have expired from the database
"""
"""
Delete tokens that have expired from the database
"""
current_app
.
logger
.
info
(
'
Delete expired tokens
'
)
now
=
datetime
.
now
()
now
=
datetime
.
now
()
expired
=
models
.
Token
.
query
.
filter
(
models
.
Token
.
expires
<
now
).
all
()
expired
=
models
.
Token
.
query
.
filter
(
models
.
Token
.
expires
<
now
).
all
()
for
token
in
expired
:
for
token
in
expired
:
...
...
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