Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
ViaResto-website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
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
Aymeric Chaumont
ViaResto-website
Commits
2d8ecb36
Commit
2d8ecb36
authored
2 years ago
by
Antoine Gaudron-Desjardins
Browse files
Options
Downloads
Patches
Plain Diff
protect OpenAPI interface
parent
d335d892
Branches
Branches containing commit
No related tags found
1 merge request
!53
Interface admin
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
backend/db/crud.py
+2
-0
2 additions, 0 deletions
backend/db/crud.py
backend/db/models.py
+2
-1
2 additions, 1 deletion
backend/db/models.py
backend/db/schemas.py
+1
-0
1 addition, 0 deletions
backend/db/schemas.py
backend/main.py
+23
-3
23 additions, 3 deletions
backend/main.py
with
28 additions
and
4 deletions
backend/db/crud.py
+
2
−
0
View file @
2d8ecb36
...
@@ -382,6 +382,7 @@ def update_user(user: schemas.User, user_info: dict, db: Session):
...
@@ -382,6 +382,7 @@ def update_user(user: schemas.User, user_info: dict, db: Session):
if
existing_user
:
if
existing_user
:
existing_user
.
cookie
=
user
.
cookie
existing_user
.
cookie
=
user
.
cookie
existing_user
.
expiration_date
=
expiration_date
existing_user
.
expiration_date
=
expiration_date
existing_user
.
admin
=
"
admin eatfast
"
in
user_info
[
"
roles
"
]
db
.
delete
(
user
)
db
.
delete
(
user
)
db
.
add
(
existing_user
)
db
.
add
(
existing_user
)
db
.
commit
()
db
.
commit
()
...
@@ -390,6 +391,7 @@ def update_user(user: schemas.User, user_info: dict, db: Session):
...
@@ -390,6 +391,7 @@ def update_user(user: schemas.User, user_info: dict, db: Session):
else
:
else
:
user
.
username
=
full_name
user
.
username
=
full_name
user
.
expiration_date
=
expiration_date
user
.
expiration_date
=
expiration_date
user
.
admin
=
"
admin eatfast
"
in
user_info
[
"
roles
"
]
db
.
add
(
user
)
db
.
add
(
user
)
db
.
commit
()
db
.
commit
()
db
.
refresh
(
user
)
db
.
refresh
(
user
)
...
...
This diff is collapsed.
Click to expand it.
backend/db/models.py
+
2
−
1
View file @
2d8ecb36
"""
"""
Models of the database for magasin app
Models of the database for magasin app
"""
"""
from
sqlalchemy
import
Column
,
ForeignKey
,
Integer
,
DateTime
,
Float
,
Interval
,
String
,
Text
,
Time
from
sqlalchemy
import
Boolean
,
Column
,
ForeignKey
,
Integer
,
DateTime
,
Float
,
Interval
,
String
,
Text
,
Time
from
sqlalchemy.orm
import
relationship
from
sqlalchemy.orm
import
relationship
from
db.database
import
Base
from
db.database
import
Base
...
@@ -82,5 +82,6 @@ class Users(Base):
...
@@ -82,5 +82,6 @@ class Users(Base):
username
=
Column
(
String
(
50
))
username
=
Column
(
String
(
50
))
cookie
=
Column
(
String
(
50
))
cookie
=
Column
(
String
(
50
))
expiration_date
=
Column
(
DateTime
)
expiration_date
=
Column
(
DateTime
)
admin
=
Column
(
Boolean
)
comments
=
relationship
(
"
Comments
"
)
comments
=
relationship
(
"
Comments
"
)
comments
=
relationship
(
"
CollaborativeRecords
"
)
comments
=
relationship
(
"
CollaborativeRecords
"
)
This diff is collapsed.
Click to expand it.
backend/db/schemas.py
+
1
−
0
View file @
2d8ecb36
...
@@ -138,3 +138,4 @@ class User(BaseModel):
...
@@ -138,3 +138,4 @@ class User(BaseModel):
username
:
str
username
:
str
cookie
:
str
cookie
:
str
expiration_date
:
datetime
expiration_date
:
datetime
admin
:
Optional
[
bool
]
=
Field
(
default
=
False
,
title
=
"
Set to true to allow access to the admin interface
"
)
This diff is collapsed.
Click to expand it.
backend/main.py
+
23
−
3
View file @
2d8ecb36
from
fastapi
import
FastAPI
from
fastapi
import
Cookie
,
Depends
,
FastAPI
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.responses
import
JSONResponse
from
fastapi.openapi.docs
import
get_swagger_ui_html
from
fastapi.openapi.utils
import
get_openapi
from
sqlalchemy.orm
import
Session
from
dotenv
import
load_dotenv
from
dotenv
import
load_dotenv
from
threading
import
Thread
from
threading
import
Thread
import
os
import
os
from
db
import
database
,
models
from
db
import
database
,
models
,
crud
from
db.database
import
get_db
from
routers
import
*
from
routers
import
*
from
video_capture
import
handle_cameras
from
video_capture
import
handle_cameras
app
=
FastAPI
(
docs_url
=
"
/api/docs
"
,
openapi_url
=
"
/api/openapi.js
on
"
)
app
=
FastAPI
(
docs_url
=
None
,
redoc_url
=
None
,
openapi_url
=
N
on
e
)
# load environment variables
# load environment variables
load_dotenv
()
load_dotenv
()
...
@@ -34,6 +39,21 @@ async def on_startup():
...
@@ -34,6 +39,21 @@ async def on_startup():
t
.
start
()
t
.
start
()
# Docs OpenAPI
@app.get
(
"
/api/openapi.json
"
)
async
def
get_open_api_endpoint
(
connect_id
:
str
=
Cookie
(...),
db
:
Session
=
Depends
(
get_db
)):
user
=
crud
.
get_user
(
connect_id
,
db
)
if
user
.
admin
:
return
JSONResponse
(
get_openapi
(
title
=
"
FastAPI
"
,
version
=
1
,
routes
=
app
.
routes
))
@app.get
(
"
/api/docs
"
)
async
def
get_documentation
(
connect_id
:
str
=
Cookie
(...),
db
:
Session
=
Depends
(
get_db
)):
user
=
crud
.
get_user
(
connect_id
,
db
)
if
user
.
admin
:
return
get_swagger_ui_html
(
openapi_url
=
"
/openapi.json
"
,
title
=
"
docs
"
)
# Integration of routers
# Integration of routers
app
.
include_router
(
infos
.
router
)
app
.
include_router
(
infos
.
router
)
app
.
include_router
(
records
.
router
)
app
.
include_router
(
records
.
router
)
...
...
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