Skip to main content

docker_registry/v2/
referrers.rs

1use log::trace;
2use reqwest::{self, Method, StatusCode};
3
4use crate::{
5  errors::Result,
6  v2::{manifest::OciImageIndex, *},
7};
8
9impl Client {
10  /// Retrieve the list of referrers for a given manifest digest.
11  ///
12  /// Returns an OCI Image Index containing descriptors of manifests
13  /// that reference the given digest via their `subject` field.
14  ///
15  /// Optionally filter by `artifact_type` (e.g. `application/vnd.example.sbom.v1`).
16  ///
17  /// See: <https://github.com/opencontainers/distribution-spec/blob/main/spec.md#listing-referrers>
18  pub async fn get_referrers(
19    &self,
20    name: &str,
21    digest: &str,
22    artifact_type: Option<&str>,
23  ) -> Result<OciImageIndex> {
24    let mut ep = format!("{}/v2/{}/referrers/{}", self.base_url, name, digest);
25    if let Some(at) = artifact_type {
26      ep = format!("{ep}?artifactType={at}");
27    }
28    let url = reqwest::Url::parse(&ep)?;
29
30    let resp = self.build_reqwest(Method::GET, url.clone()).send().await?;
31
32    let status = resp.status();
33    trace!("GET '{}' status: {:?}", resp.url(), status);
34
35    match status {
36      StatusCode::OK => Ok(resp.json::<OciImageIndex>().await?),
37      _ => Err(ApiErrors::from(resp).await),
38    }
39  }
40}