Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
StorageLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ProjectLeaf
StorageLeaf
Commits
350f1e5c
Commit
350f1e5c
authored
3 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
#9 - prevent unauthorized access to database cleanup route
parent
72ae144b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/logic/routers/GeneralRouter.py
+6
-4
6 additions, 4 deletions
src/logic/routers/GeneralRouter.py
with
6 additions
and
4 deletions
src/logic/routers/GeneralRouter.py
+
6
−
4
View file @
350f1e5c
...
...
@@ -4,7 +4,7 @@ from fastapi import APIRouter, Depends
from
sqlalchemy.orm
import
Session
from
Settings
import
VERSION
,
SETTINGS
from
logic.Dependencies
import
get_database
from
logic.Dependencies
import
get_database
,
check_api_key
from
logic.database
import
Schemas
,
DatabaseInfoProvider
from
logic.database.DatabaseCleaner
import
DatabaseCleaner
,
RetentionPolicy
...
...
@@ -30,16 +30,18 @@ async def databaseInfo(db: Session = Depends(get_database)):
@router.get
(
'
/databaseCleanup
'
,
summary
=
'
Cleans up the database by enforcing the configured retention policies
'
,
response_model
=
Schemas
.
DatabaseCleanupInfo
)
response_model
=
Schemas
.
DatabaseCleanupInfo
,
dependencies
=
[
Depends
(
check_api_key
)])
async
def
databaseCleanup
(
db
:
Session
=
Depends
(
get_database
)):
infoBefore
=
DatabaseInfoProvider
.
get_database_info
(
db
)
retentionPolicies
=
SETTINGS
[
'
database
'
][
'
retentionPolicies
'
]
policies
=
[]
for
item
in
retentionPolicies
:
policies
.
append
(
RetentionPolicy
(
resolutionInMinutes
=
item
[
'
resolutionInMinutes
'
],
ageInDays
=
item
[
'
ageInDays
'
]))
policies
.
append
(
RetentionPolicy
(
numberOfMeasurementsPerDay
=
item
[
'
numberOfMeasurementsPerDay
'
],
ageInDays
=
item
[
'
ageInDays
'
]))
DatabaseCleaner
(
policies
).
clean
(
db
,
datetime
.
now
())
DatabaseCleaner
(
policies
).
clean
(
db
,
datetime
.
now
()
.
date
()
)
infoAfter
=
DatabaseInfoProvider
.
get_database_info
(
db
)
...
...
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