Skip to main content

pacsea/sources/
advisories.rs

1//! security.archlinux.org advisories fetched through arch-toolkit.
2
3use crate::integrations::arch_toolkit::ToolkitContext;
4use crate::state::types::NewsFeedItem;
5
6/// Result type alias for advisory fetching operations.
7type Result<T> = super::Result<T>;
8
9/// What: Fetch security advisories through arch-toolkit.
10///
11/// Inputs:
12/// - `limit`: Maximum advisories to return.
13/// - `cutoff_date`: Optional oldest accepted `YYYY-MM-DD` date.
14///
15/// Output:
16/// - Pacsea feed rows or an actionable network/parse error.
17///
18/// # Errors
19///
20/// Returns an error when client construction, transport, response bounds, or feed parsing fails.
21///
22/// Details:
23/// - Standalone callers construct a configured context; runtime aggregation can share one through
24///   [`fetch_security_advisories_with_context`]. The feed response is bounded to 512 KiB.
25pub async fn fetch_security_advisories(
26    limit: usize,
27    cutoff_date: Option<&str>,
28) -> Result<Vec<NewsFeedItem>> {
29    let context = ToolkitContext::new()?;
30    fetch_security_advisories_with_context(&context, limit, cutoff_date).await
31}
32
33/// What: Fetch advisories with a caller-owned shared toolkit context.
34///
35/// Inputs:
36/// - `context`: Runtime integration context.
37/// - `limit`: Maximum advisories to return.
38/// - `cutoff_date`: Optional oldest accepted date.
39///
40/// Output:
41/// - Pacsea feed rows or an actionable error.
42///
43/// # Errors
44///
45/// Returns an error when bounded toolkit feed retrieval or parsing fails.
46///
47/// Details:
48/// - Toolkit values are converted before reaching cache, filter, CLI, or UI surfaces.
49pub async fn fetch_security_advisories_with_context(
50    context: &ToolkitContext,
51    limit: usize,
52    cutoff_date: Option<&str>,
53) -> Result<Vec<NewsFeedItem>> {
54    crate::integrations::arch_toolkit::news::fetch_advisories(context, limit, cutoff_date)
55        .await
56        .map_err(Into::into)
57}