Skip to content

Commit

Permalink
Port to oci-spec 0.7
Browse files Browse the repository at this point in the history
Now we can use a proper Digest type.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Sep 18, 2024
1 parent e741c37 commit 1ea8c3c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ jobs:
- name: Checkout ostree-rs-ext
uses: actions/checkout@v3
with:
repository: ostreedev/ostree-rs-ext
# repository: ostreedev/ostree-rs-ext
# Temporary fork until https://github.com/ostreedev/ostree-rs-ext/pull/663
# is published in a release
repository: jeckerbs/ostree-rs-ext
branch: ocidir-0.3
path: ostree-rs-ext
fetch-depth: 20
- name: Test ostree-rs-ext
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn-error-context = "0.2.0"
futures-util = "0.3.13"
# NOTE when bumping this in a semver-incompatible way, because we re-export it you
# must also bump the semver of this project.
oci-spec = "0.6.5"
oci-spec = "0.7.0"
rustix = { version = "0.38", features = ["process", "net"] }
serde = { features = ["derive"], version = "1.0.125" }
serde_json = "1.0.64"
Expand Down
4 changes: 2 additions & 2 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::Write;

use anyhow::Result;
use clap::Parser;
use oci_spec::image::ImageManifest;
use oci_spec::image::{Digest, ImageManifest};
use tokio::io::AsyncReadExt;

#[derive(clap::Parser, Debug)]
Expand All @@ -17,7 +17,7 @@ struct GetBlobOpts {
reference: String,

/// The digest of the target blob to fetch
digest: String,
digest: Digest,

/// The size of the blob to fetch
size: u64,
Expand Down
21 changes: 18 additions & 3 deletions src/imageproxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use anyhow::{anyhow, Context, Result};
use cap_std_ext::prelude::CapStdExtCommandExt;
use cap_std_ext::{cap_std, cap_tempfile};
use futures_util::Future;
use oci_spec::image::{Descriptor, Digest};
use serde::{Deserialize, Serialize};
use std::fs::File;
use std::ops::Range;
Expand Down Expand Up @@ -234,10 +235,10 @@ impl TryFrom<ImageProxyConfig> for Command {
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,
pub digest: Digest,

/// Size of blob
pub size: i64,
pub size: u64,

/// Mediatype of blob
pub media_type: oci_spec::image::MediaType,
Expand Down Expand Up @@ -474,7 +475,7 @@ impl ImageProxy {
pub async fn get_blob(
&self,
img: &OpenedImage,
digest: &str,
digest: &Digest,
size: u64,
) -> Result<(
impl AsyncBufRead + Send + Unpin,
Expand All @@ -493,6 +494,20 @@ impl ImageProxy {
Ok((fd, finish))
}

/// Fetch a descriptor. The requested size and digest are verified (by the proxy process).
#[instrument]
pub async fn get_descriptor(
&self,
img: &OpenedImage,
descriptor: &Descriptor,
) -> Result<(
impl AsyncBufRead + Send + Unpin,
impl Future<Output = Result<()>> + Unpin + '_,
)> {
self.get_blob(img, descriptor.digest(), descriptor.size())
.await
}

///Returns data that can be used to find the "diffid" corresponding to a particular layer.
#[instrument]
pub async fn get_layer_info(
Expand Down

0 comments on commit 1ea8c3c

Please sign in to comment.