Skip to content

Commit

Permalink
Merge pull request #55 from flowintel/fastapi-0.115.7
Browse files Browse the repository at this point in the history
chg: upgrade to fastapi 0.115.7
  • Loading branch information
righel authored Jan 23, 2025
2 parents 1cac51a + d4abee0 commit 0143604
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 514 deletions.
11 changes: 6 additions & 5 deletions api/app/repositories/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
from fastapi_pagination.ext.sqlalchemy import paginate
from pymisp import MISPAttribute, MISPTag
from sqlalchemy.orm import Session
from sqlalchemy.sql import select


def get_attributes(
db: Session, event_id: int = None, deleted: bool = None, object_id: int = None
):
query = db.query(attribute_models.Attribute)
query = select(attribute_models.Attribute)

if event_id is not None:
query = query.filter(attribute_models.Attribute.event_id == event_id)
query = query.where(attribute_models.Attribute.event_id == event_id)

if deleted is not None:
query = query.filter(attribute_models.Attribute.deleted == deleted)
query = query.where(attribute_models.Attribute.deleted == deleted)

if object_id is not None:
query = query.filter(attribute_models.Attribute.object_id == object_id)
query = query.where(attribute_models.Attribute.object_id == object_id)

return paginate(query)
return paginate(db, query)


def get_attribute_by_id(
Expand Down
11 changes: 6 additions & 5 deletions api/app/repositories/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@
from fastapi_pagination.ext.sqlalchemy import paginate
from pymisp import MISPEvent, MISPOrganisation
from sqlalchemy.orm import Session
from sqlalchemy.sql import select

logger = logging.getLogger(__name__)


def get_events(db: Session, info: str = None, deleted: bool = None, uuid: str = None):
query = db.query(event_models.Event)
query = select(event_models.Event)

if info is not None:
search = f"%{info}%"
query = query.filter(event_models.Event.info.like(search))
query = query.where(event_models.Event.info.like(search))

if deleted is not None:
query = query.filter(event_models.Event.deleted == deleted)
query = query.where(event_models.Event.deleted == deleted)

if uuid is not None:
query = query.filter(event_models.Event.uuid == uuid)
query = query.where(event_models.Event.uuid == uuid)

return paginate(query)
return paginate(db, query)


def get_event_by_id(db: Session, event_id: int):
Expand Down
8 changes: 5 additions & 3 deletions api/app/repositories/galaxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,26 @@
from fastapi import HTTPException, Query, status
from fastapi_pagination.ext.sqlalchemy import paginate
from sqlalchemy.orm import Session
from sqlalchemy.sql import select

logger = logging.getLogger(__name__)


def get_galaxies(
db: Session, enabled: bool = Query(None), filter: str = Query(None)
) -> galaxies_models.Galaxy:
query = db.query(galaxies_models.Galaxy)
query = select(galaxies_models.Galaxy)

if filter:
query = query.filter(galaxies_models.Galaxy.name.ilike(f"%{filter}%"))
query = query.where(galaxies_models.Galaxy.name.ilike(f"%{filter}%"))

if enabled is not None:
query = query.filter(galaxies_models.Galaxy.enabled == enabled)
query = query.where(galaxies_models.Galaxy.enabled == enabled)

query = query.order_by(galaxies_models.Galaxy.name)

return paginate(
db,
query,
additional_data={"query": {"filter": filter}},
)
Expand Down
9 changes: 5 additions & 4 deletions api/app/repositories/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
from pymisp import MISPTag
from sqlalchemy import func
from sqlalchemy.orm import Session
from sqlalchemy.sql import select


def get_tags(db: Session, hidden: bool = Query(None), filter: str = Query(None)):
query = db.query(tag_models.Tag)
query = select(tag_models.Tag)

if hidden is not None:
query = query.filter(tag_models.Tag.hide_tag == hidden)
query = query.where(tag_models.Tag.hide_tag == hidden)

if filter:
query = query.filter(tag_models.Tag.name.ilike(f"%{filter}%"))
query = query.where(tag_models.Tag.name.ilike(f"%{filter}%"))

query = query.order_by(tag_models.Tag.name)

return paginate(query)
return paginate(db, query)


def get_tag_by_id(db: Session, tag_id: int):
Expand Down
8 changes: 5 additions & 3 deletions api/app/repositories/taxonomies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
from fastapi import HTTPException, Query, status
from fastapi_pagination.ext.sqlalchemy import paginate
from sqlalchemy.orm import Session
from sqlalchemy.sql import select


def get_taxonomies(
db: Session, enabled: bool = Query(None), filter: str = Query(None)
) -> taxonomies_models.Taxonomy:
query = db.query(taxonomies_models.Taxonomy)
query = select(taxonomies_models.Taxonomy)

if filter:
query = query.filter(taxonomies_models.Taxonomy.namespace.ilike(f"%{filter}%"))
query = query.where(taxonomies_models.Taxonomy.namespace.ilike(f"%{filter}%"))

if enabled is not None:
query = query.filter(taxonomies_models.Taxonomy.enabled == enabled)
query = query.where(taxonomies_models.Taxonomy.enabled == enabled)

query = query.order_by(taxonomies_models.Taxonomy.namespace)

return paginate(
db,
query,
additional_data={"query": {"enabled": enabled, "filter": filter}},
)
Expand Down
Loading

0 comments on commit 0143604

Please sign in to comment.