Skip to content

Commit

Permalink
feat: add get dependents for a package
Browse files Browse the repository at this point in the history
  • Loading branch information
dejanb committed Aug 16, 2023
1 parent ad2825e commit 5ba652c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spog/api/src/guac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) fn configure(auth: Option<Arc<Authenticator>>) -> impl FnOnce(&mut Se
config.service(web::resource("/api/v1/packages").wrap(new_auth!(auth)).to(get));
//TODO auth?
config.service(web::resource("/api/v1/packages/dependencies").to(get_dependencies));
config.service(web::resource("/api/v1/packages/dependents").to(get_dependents));
}
}

Expand Down Expand Up @@ -60,5 +61,30 @@ pub async fn get_dependencies(
) -> actix_web::Result<HttpResponse> {
let deps = guac.get_dependencies(&purl).await?;

Ok(HttpResponse::Ok().json(deps))
}

#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize)]
pub struct GetDependents {
pub purl: String,
}

#[utoipa::path(
get,
path = "/api/v1/packages/dependents",
responses(
(status = 200, description = "Package was found"),
(status = NOT_FOUND, description = "Package was not found")
),
params(
("purl" = String, Path, description = "Package URL of the package to fetch information for"),
)
)]
pub async fn get_dependents(
guac: web::Data<GuacService>,
web::Query(GetDependencies { purl }): web::Query<GetDependencies>,
) -> actix_web::Result<HttpResponse> {
let deps = guac.get_dependents(&purl).await?;

Ok(HttpResponse::Ok().json(deps))
}
6 changes: 6 additions & 0 deletions spog/api/src/services/guac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ impl GuacService {
let deps = self.client.is_dependency(purl).await.map_err(Error::Guac)?;
Ok(deps)
}

/// Lookup dependents for a provided Package URL
pub async fn get_dependents(&self, purl: &str) -> Result<Vec<String>, Error> {
let deps = self.client.is_dependent(purl).await.map_err(Error::Guac)?;
Ok(deps)
}
}

0 comments on commit 5ba652c

Please sign in to comment.