Skip to content
Snippets Groups Projects
Commit acbcc31c authored by hanfi's avatar hanfi
Browse files

Merge branch 'staging' into 'main'

query live items in storage

See merge request hanfi/bgp_backend!7
parents 2d8c8c69 224fe34a
Branches
No related tags found
1 merge request!7query live items in storage
...@@ -50,11 +50,11 @@ def get_db(): ...@@ -50,11 +50,11 @@ def get_db():
def check_token(token: str, item_uuid: str): def check_token(token: str, item_uuid: str):
try: try:
auth_data = oauth2_tokener.loads(token, max_age=settings.token_lifetime * 60) auth_data = oauth2_tokener.loads(token, max_age=settings.token_lifetime * 60)
print(auth_data)
if auth_data == "all" or auth_data == item_uuid: if auth_data == "all" or auth_data == item_uuid:
return # success return # success
except BadSignature: except BadSignature:
pass print("failed to load access token")
print(item_uuid)
raise HTTPException( raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_401_UNAUTHORIZED,
...@@ -127,6 +127,16 @@ def get_item_by_tag( ...@@ -127,6 +127,16 @@ def get_item_by_tag(
return item 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]) @app.get("/storages", response_model=list[schemas.Storage])
def list_storages(token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)): def list_storages(token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)):
check_token(token, None) check_token(token, None)
......
...@@ -20,10 +20,6 @@ def get_item_by_tag(db: Session, item_tag: str): ...@@ -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() 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): def get_storage(db: Session, storage_name: str):
return db.get(models.Storage, storage_name) return db.get(models.Storage, storage_name)
...@@ -38,6 +34,16 @@ def get_stored_items(db: Session): ...@@ -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): def get_storages(db: Session):
return db.query(models.Storage).all() return db.query(models.Storage).all()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment