mirror of
https://github.com/resf/distro-tools.git
synced 2024-11-27 23:46:26 +00:00
Add last_updated_at to list_advisories_osv
This commit is contained in:
parent
650a80989e
commit
0d51fdb161
@ -7,7 +7,7 @@ from fastapi_pagination.links import Page
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
|
|
||||||
from apollo.db import Advisory
|
from apollo.db import Advisory, RedHatIndexState
|
||||||
from apollo.db.advisory import fetch_advisories
|
from apollo.db.advisory import fetch_advisories
|
||||||
from apollo.rpmworker.repomd import EPOCH_RE, NEVRA_RE
|
from apollo.rpmworker.repomd import EPOCH_RE, NEVRA_RE
|
||||||
from apollo.server.settings import UI_URL, get_setting
|
from apollo.server.settings import UI_URL, get_setting
|
||||||
@ -20,6 +20,8 @@ T = TypeVar("T")
|
|||||||
|
|
||||||
|
|
||||||
class Pagination(Page[T], Generic[T]):
|
class Pagination(Page[T], Generic[T]):
|
||||||
|
last_updated_at: Optional[str]
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
allow_population_by_field_name = True
|
allow_population_by_field_name = True
|
||||||
fields = {"items": {"alias": "advisories"}}
|
fields = {"items": {"alias": "advisories"}}
|
||||||
@ -226,7 +228,11 @@ def to_osv_advisory(ui_url: str, advisory: Advisory) -> OSVAdvisory:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/", response_model=Pagination[OSVAdvisory], response_model_exclude_none=True)
|
@router.get(
|
||||||
|
"/",
|
||||||
|
response_model=Pagination[OSVAdvisory],
|
||||||
|
response_model_exclude_none=True
|
||||||
|
)
|
||||||
async def get_advisories_osv(
|
async def get_advisories_osv(
|
||||||
params: Params = Depends(),
|
params: Params = Depends(),
|
||||||
product: Optional[str] = None,
|
product: Optional[str] = None,
|
||||||
@ -255,12 +261,26 @@ async def get_advisories_osv(
|
|||||||
|
|
||||||
ui_url = await get_setting(UI_URL)
|
ui_url = await get_setting(UI_URL)
|
||||||
osv_advisories = [to_osv_advisory(ui_url, x) for x in advisories]
|
osv_advisories = [to_osv_advisory(ui_url, x) for x in advisories]
|
||||||
return create_page(osv_advisories, count, params)
|
page = create_page(osv_advisories, count, params)
|
||||||
|
|
||||||
|
state = await RedHatIndexState.first()
|
||||||
|
page.last_updated_at = state.last_indexed_at.isoformat("T").replace(
|
||||||
|
"+00:00",
|
||||||
|
"",
|
||||||
|
) + "Z"
|
||||||
|
|
||||||
|
return page
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{advisory_id}", response_model=OSVAdvisory, response_model_exclude_none=True)
|
@router.get(
|
||||||
|
"/{advisory_id}",
|
||||||
|
response_model=OSVAdvisory,
|
||||||
|
response_model_exclude_none=True
|
||||||
|
)
|
||||||
async def get_advisory_osv(advisory_id: str):
|
async def get_advisory_osv(advisory_id: str):
|
||||||
advisory = await Advisory.filter(name=advisory_id, kind="Security").prefetch_related(
|
advisory = await Advisory.filter(
|
||||||
|
name=advisory_id, kind="Security"
|
||||||
|
).prefetch_related(
|
||||||
"packages",
|
"packages",
|
||||||
"cves",
|
"cves",
|
||||||
"fixes",
|
"fixes",
|
||||||
|
Loading…
Reference in New Issue
Block a user