Skip to content

Commit 356fb92

Browse files
authored
Merge pull request #37 from RishabhSaini/issue/153
Add get_layer_info_json
2 parents 8b7b64b + b801e4a commit 356fb92

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/imageproxy.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const MAX_MSG_SIZE: usize = 32 * 1024;
3232
// Introduced in https://github.com/containers/skopeo/pull/1523
3333
static BASE_PROTO_VERSION: Lazy<semver::VersionReq> =
3434
Lazy::new(|| semver::VersionReq::parse("0.2.3").unwrap());
35+
static LAYER_INFO_PROTO_VERSION: Lazy<semver::VersionReq> =
36+
Lazy::new(|| semver::VersionReq::parse("0.2.5").unwrap());
3537

3638
#[derive(Serialize)]
3739
struct Request {
@@ -192,6 +194,20 @@ impl TryFrom<ImageProxyConfig> for Command {
192194
}
193195
}
194196

197+
/// BlobInfo collects known information about a blob
198+
#[derive(Debug, serde::Deserialize)]
199+
pub struct ConvertedLayerInfo {
200+
/// Uncompressed digest of a layer; for more information, see
201+
/// https://github.com/opencontainers/image-spec/blob/main/config.md#layer-diffid
202+
pub digest: String,
203+
204+
/// Size of blob
205+
pub size: i64,
206+
207+
/// Mediatype of blob
208+
pub media_type: oci_spec::image::MediaType,
209+
}
210+
195211
impl ImageProxy {
196212
/// Create an image proxy that fetches the target image, using default configuration.
197213
pub async fn new() -> Result<Self> {
@@ -430,6 +446,18 @@ impl ImageProxy {
430446
Ok((fd, finish))
431447
}
432448

449+
///Returns data that can be used to find the "diffid" corresponding to a particular layer.
450+
#[instrument]
451+
pub async fn get_layer_info(&self, img: &OpenedImage) -> Result<Option<Vec<ConvertedLayerInfo>>> {
452+
tracing::debug!("Getting layer info");
453+
if !LAYER_INFO_PROTO_VERSION.matches(&self.protover) {
454+
return Ok(None);
455+
}
456+
let reply = self.impl_request("GetLayerInfo", [img.0]).await?;
457+
let layers: Vec<ConvertedLayerInfo> = reply.0;
458+
Ok(Some(layers))
459+
}
460+
433461
/// Close the connection and wait for the child process to exit successfully.
434462
#[instrument]
435463
pub async fn finalize(self) -> Result<()> {

0 commit comments

Comments
 (0)