Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chaos Parcel Service
backend
Commits
224fe34a
Verified
Commit
224fe34a
authored
Aug 13, 2023
by
hanfi
Browse files
Options
Downloads
Patches
Plain Diff
query live items in storage
parent
f9e99b80
Branches
Branches containing commit
No related tags found
1 merge request
!7
query live items in storage
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/main.py
+12
-2
12 additions, 2 deletions
backend/main.py
backend/utils.py
+10
-4
10 additions, 4 deletions
backend/utils.py
with
22 additions
and
6 deletions
backend/main.py
+
12
−
2
View file @
224fe34a
...
...
@@ -50,11 +50,11 @@ def get_db():
def
check_token
(
token
:
str
,
item_uuid
:
str
):
try
:
auth_data
=
oauth2_tokener
.
loads
(
token
,
max_age
=
settings
.
token_lifetime
*
60
)
print
(
auth_data
)
if
auth_data
==
"
all
"
or
auth_data
==
item_uuid
:
return
# success
except
BadSignature
:
pass
print
(
"
failed to load access token
"
)
print
(
item_uuid
)
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
...
...
@@ -127,6 +127,16 @@ def get_item_by_tag(
return
item
@app.get
(
"
/storage/{storage_name}
"
,
response_model
=
list
[
schemas
.
Item
])
def
get_storage
(
storage_name
:
str
,
token
:
str
=
Depends
(
oauth2_scheme
),
db
:
Session
=
Depends
(
get_db
),
):
check_token
(
token
,
None
)
return
utils
.
get_items_for_storage
(
db
,
storage_name
)
@app.get
(
"
/storages
"
,
response_model
=
list
[
schemas
.
Storage
])
def
list_storages
(
token
:
str
=
Depends
(
oauth2_scheme
),
db
:
Session
=
Depends
(
get_db
)):
check_token
(
token
,
None
)
...
...
This diff is collapsed.
Click to expand it.
backend/utils.py
+
10
−
4
View file @
224fe34a
...
...
@@ -20,10 +20,6 @@ def get_item_by_tag(db: Session, item_tag: str):
return
db
.
query
(
models
.
Item
).
filter
(
models
.
Item
.
tag
==
item_tag
).
first
()
def
get_items_for_storage
(
db
:
Session
,
storage_name
:
str
):
return
db
.
query
(
models
.
Storage
).
get
(
models
.
Storage
.
name
==
storage_name
).
items
def
get_storage
(
db
:
Session
,
storage_name
:
str
):
return
db
.
get
(
models
.
Storage
,
storage_name
)
...
...
@@ -38,6 +34,16 @@ def get_stored_items(db: Session):
)
def
get_items_for_storage
(
db
:
Session
,
storage_name
:
str
):
return
(
db
.
query
(
models
.
Item
)
.
filter
(
models
.
Item
.
storage
==
storage_name
)
.
filter
(
models
.
Item
.
received_at
!=
None
)
# noqa: E711
.
filter
(
models
.
Item
.
deployed_at
==
None
)
# noqa: E711
.
all
()
)
def
get_storages
(
db
:
Session
):
return
db
.
query
(
models
.
Storage
).
all
()
...
...
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