Skip to content

Commit

Permalink
chg: [models] Added scan_uuid in the TimeStampToken model.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Dec 19, 2023
1 parent c5a3393 commit f41cff6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def create_item(db: Session, item: schemas.ItemCreate):

def create_tst(db: Session, data: schemas.ItemCreate):
"""Create a TimeStampToken."""
print(data)
db_tst = models.TimeStampToken(tst=data)
db.add(db_tst)
db.commit()
Expand All @@ -47,4 +46,7 @@ def get_tst(db: Session, skip: int = 0, limit: int = 100):


def db_stats(db: Session):
return db.query(models.Item).count()
return {
"scans": db.query(models.Item).count(),
"tst": db.query(models.TimeStampToken).count(),
}
8 changes: 8 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import uuid
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import LargeBinary
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.dialects.postgresql import UUID

from .database import Base

Expand All @@ -17,4 +19,10 @@ class TimeStampToken(Base):
__tablename__ = "time_stamp_tokens"

id = Column(Integer, primary_key=True, index=True)
scan_uuid = Column(
UUID(as_uuid=True),
default=uuid.uuid4,
unique=True,
nullable=False,
)
tst = Column(LargeBinary)
8 changes: 6 additions & 2 deletions scandale/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ async def run(self):
return
# TimeStampToken (TST, see RFC 3161)
tst = RT.timestamp(data=msg.body)
dict_tst = {
"tst": str(tst),
"scan_uuid": dict_msg["meta"]["uuid"],
}

requests.post(
urllib.parse.urljoin(config.API_URL, "items/"),
Expand All @@ -61,8 +65,8 @@ async def run(self):
)
requests.post(
urllib.parse.urljoin(config.API_URL, "tst/"),
data=tst,
headers=self.headers_octet_stream,
json=dict_tst,
headers=self.headers_json,
)
else:
print("Did not received any message after 10 seconds")
Expand Down

0 comments on commit f41cff6

Please sign in to comment.