Skip to content

Commit

Permalink
chg: [style] Format witj black.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Dec 11, 2023
1 parent 82ea5a5 commit d4b63a4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
8 changes: 6 additions & 2 deletions api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ def get_items(db: Session, skip: int = 0, limit: int = 100):
return db.query(models.Item).offset(skip).limit(limit).all()


def get_item(db: Session, item_id: int, query: str=""):
def get_item(db: Session, item_id: int, query: str = ""):
if query:
return db.query(models.Item).filter(models.Item.scan_data['payload']['row'].astext == query).first()
return (
db.query(models.Item)
.filter(models.Item.scan_data["payload"]["row"].astext == query)
.first()
)
return db.query(models.Item).filter(models.Item.id == item_id).first()


Expand Down
8 changes: 6 additions & 2 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ def get_db():


@app.get("/items/", response_model=list[schemas.ItemBase])
async def read_items(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)) -> List[schemas.ItemBase]:
async def read_items(
skip: int = 0, limit: int = 100, db: Session = Depends(get_db)
) -> List[schemas.ItemBase]:
items = crud.get_items(db, skip=skip, limit=limit)
return items


@app.get("/items/{item_id}", response_model=schemas.ItemBase)
def read_item(item_id: int=0, q: str="", db: Session = Depends(get_db)) -> schemas.ItemBase:
def read_item(
item_id: int = 0, q: str = "", db: Session = Depends(get_db)
) -> schemas.ItemBase:
db_item = crud.get_item(db, item_id=item_id, query=q)
if db_item is None:
raise HTTPException(status_code=404, detail="Item not found")
Expand Down
7 changes: 4 additions & 3 deletions api/schemas.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
from pydantic import BaseModel



class Payload(BaseModel):
row: str


class Meta(BaseModel):
uuid: str
ts: str
type: str


class ScanData(BaseModel):
version: str
format: str
meta: Meta
payload: Payload


class ItemBase(BaseModel):
id: int
scan_data: ScanData

class Config:
orm_mode = True


class ItemCreate(ItemBase):
pass


4 changes: 2 additions & 2 deletions pumpkin/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def setup(self):

async def main():
jid = "correlation-engine@localhost"
passwd = "securePasswordforCE" # getpass.getpass(f"Password for {jid}:\n")
passwd = "securePasswordforCE" # getpass.getpass(f"Password for {jid}:\n")
agent = CorrelationEngine(jid, passwd)
await agent.start()

Expand All @@ -67,7 +67,7 @@ async def main():
print("Wait until user interrupts with ctrl+C")

# wait until user interrupts with ctrl+C
while True: # not agent.CollectingBehav.is_killed():
while True: # not agent.CollectingBehav.is_killed():
try:
await asyncio.sleep(1)
except KeyboardInterrupt:
Expand Down
7 changes: 2 additions & 5 deletions pumpkin/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from spade.message import Message


def exec_cmd(cmd: str="fortune", working_dir: str = "") -> str:
def exec_cmd(cmd: str = "fortune", working_dir: str = "") -> str:
"""Execute a command in a sub process and wait for the result."""
bash_string = r"""#!/bin/bash
set -e
Expand Down Expand Up @@ -79,13 +79,12 @@ async def setup(self):
self.add_behaviour(self.InformBehav)



async def main(probe_jid, passwd):
agent = CorrelationEngine(probe_jid, passwd)
await agent.start()

# wait until user interrupts with ctrl+C
while True: # not agent.CollectingBehav.is_killed():
while True: # not agent.CollectingBehav.is_killed():
try:
await asyncio.sleep(1)
except KeyboardInterrupt:
Expand All @@ -96,7 +95,6 @@ async def main(probe_jid, passwd):
await agent.stop()



if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="probe-agent")
parser.add_argument(
Expand All @@ -119,4 +117,3 @@ async def main(probe_jid, passwd):
passwd = config["passwd"]

spade.run(main(probe_jid, passwd))

0 comments on commit d4b63a4

Please sign in to comment.