From b801e4a061f1804a7d02e2f1eac6489e8d2ae12a Mon Sep 17 00:00:00 2001 From: RishabhSaini Date: Fri, 21 Oct 2022 16:06:04 -0400 Subject: [PATCH] Add get_layer_info This API exposes the "GetLayerInfosForCopy" API in containers/image, which can be used to create a mapping between blob and diff IDs, allowing pulling via diffID. Signed-off-by: RishabhSaini --- src/imageproxy.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/imageproxy.rs b/src/imageproxy.rs index 5e94ead..56cc9bf 100644 --- a/src/imageproxy.rs +++ b/src/imageproxy.rs @@ -32,6 +32,8 @@ const MAX_MSG_SIZE: usize = 32 * 1024; // Introduced in https://github.com/containers/skopeo/pull/1523 static BASE_PROTO_VERSION: Lazy = Lazy::new(|| semver::VersionReq::parse("0.2.3").unwrap()); +static LAYER_INFO_PROTO_VERSION: Lazy = + Lazy::new(|| semver::VersionReq::parse("0.2.5").unwrap()); #[derive(Serialize)] struct Request { @@ -192,6 +194,20 @@ impl TryFrom for Command { } } +/// BlobInfo collects known information about a blob +#[derive(Debug, serde::Deserialize)] +pub struct ConvertedLayerInfo { + /// Uncompressed digest of a layer; for more information, see + /// https://github.com/opencontainers/image-spec/blob/main/config.md#layer-diffid + pub digest: String, + + /// Size of blob + pub size: i64, + + /// Mediatype of blob + pub media_type: oci_spec::image::MediaType, +} + impl ImageProxy { /// Create an image proxy that fetches the target image, using default configuration. pub async fn new() -> Result { @@ -430,6 +446,18 @@ impl ImageProxy { Ok((fd, finish)) } + ///Returns data that can be used to find the "diffid" corresponding to a particular layer. + #[instrument] + pub async fn get_layer_info(&self, img: &OpenedImage) -> Result>> { + tracing::debug!("Getting layer info"); + if !LAYER_INFO_PROTO_VERSION.matches(&self.protover) { + return Ok(None); + } + let reply = self.impl_request("GetLayerInfo", [img.0]).await?; + let layers: Vec = reply.0; + Ok(Some(layers)) + } + /// Close the connection and wait for the child process to exit successfully. #[instrument] pub async fn finalize(self) -> Result<()> {