Skip to content

Commit

Permalink
fix: [API] Fixed an issue when storing the UUID of a scan.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Dec 19, 2023
1 parent f41cff6 commit 5f39075
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
4 changes: 2 additions & 2 deletions api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def create_item(db: Session, item: schemas.ItemCreate):
return db_item


def create_tst(db: Session, data: schemas.ItemCreate):
def create_tst(db: Session, data: schemas.TimeStampTokenCreate):
"""Create a TimeStampToken."""
db_tst = models.TimeStampToken(tst=data)
db_tst = models.TimeStampToken(**data)
db.add(db_tst)
db.commit()
db.refresh(db_tst)
Expand Down
25 changes: 15 additions & 10 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from fastapi import Depends
from fastapi import FastAPI
from fastapi import HTTPException
from fastapi import Request
from fastapi.openapi.utils import get_openapi
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -96,19 +95,25 @@ async def create_item(item: schemas.ScanDataCreate, db: Session = db_session):
#


@app.post("/tst/")
async def create_tst(request: Request, db: Session = db_session):
@app.post("/tst/", response_model=schemas.TimeStampTokenCreate)
async def create_tst(
data: schemas.TimeStampTokenCreate, db: Session = db_session
) -> schemas.TimeStampToken:
"""Insert a TimeStampToken."""
data: bytes = await request.body()
new_tst = crud.create_tst(db=db, data=data)
return {"message": new_tst.id}
dict_data = {
"scan_uuid": data.scan_uuid,
"tst": data.tst
}
new_tst = crud.create_tst(db=db, data=dict_data)
return new_tst


@app.get("/tsts/", response_model=str)
async def read_tst(skip: int = 0, limit: int = 100, db: Session = db_session) -> str:
@app.get("/tsts/", response_model=list[schemas.TimeStampToken])
async def read_tst(
skip: int = 0, limit: int = 100, db: Session = db_session
) -> list[schemas.TimeStampToken]:
tsts = crud.get_tst(db, skip=skip, limit=limit)
tst_list = [elem.tst for elem in tsts]
return str(tst_list)
return tsts


#
Expand Down
1 change: 1 addition & 0 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid

from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import LargeBinary
Expand Down
12 changes: 12 additions & 0 deletions api/schemas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import uuid

from pydantic import BaseModel


Expand Down Expand Up @@ -36,5 +38,15 @@ class ScanDataCreate(ScanData):
pass


#
# Timestamp
#


class TimeStampToken(BaseModel):
scan_uuid: uuid.UUID
tst: bytes


class TimeStampTokenCreate(TimeStampToken):
pass
4 changes: 3 additions & 1 deletion scandale/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import subprocess
import time
import uuid

import spade
from spade.agent import Agent
Expand Down Expand Up @@ -51,12 +52,13 @@ async def run(self):
) # Set the language of the message content

# Set the message content
scan_uuid = str(uuid.uuid4())
msg.body = json.dumps(
{
"version": self.config["version"],
"format": self.config["format"],
"meta": {
"uuid": self.config["uuid"],
"uuid": scan_uuid,
"ts": int(time.time()),
"type": self.config["type"],
},
Expand Down

0 comments on commit 5f39075

Please sign in to comment.