Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,30 @@ use oci_spec::image::{Digest, ImageManifest};
use tokio::io::AsyncReadExt;

#[derive(clap::Parser, Debug)]
struct GetMetadataOpts {
/// The skopeo-style transport:image reference
reference: String,
struct CommonOpts {
/// Emit debugging to stderr
#[clap(long)]
debug: bool,

/// Disable TLS verification
#[clap(long)]
insecure: bool,
}

#[derive(clap::Parser, Debug)]
struct GetMetadataOpts {
#[clap(flatten)]
common: CommonOpts,

/// The skopeo-style transport:image reference
reference: String,
}

#[derive(clap::Parser, Debug)]
struct GetBlobOpts {
#[clap(flatten)]
common: CommonOpts,
Comment on lines +31 to +32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Great job refactoring the common options into CommonOpts and applying it to GetBlobOpts.

However, it seems the get-blob-raw subcommand, which also uses GetBlobOpts, was missed. The get_blob_raw function still calls ImageProxy::new().await? and doesn't use the new common options from GetBlobOpts.

To ensure the --debug and --insecure flags work consistently across all subcommands as the PR title suggests, you should update get_blob_raw to create the proxy with the configuration, similar to what you've done for get_blob:

async fn get_blob_raw(o: GetBlobOpts) -> Result<()> {
    let config = o.common.to_config();
    let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
    // ...
}


/// The skopeo-style transport:image reference
reference: String,

Expand Down Expand Up @@ -54,9 +67,12 @@ struct Metadata {
manifest: ImageManifest,
}

impl GetMetadataOpts {
fn proxy_opts(&self) -> containers_image_proxy::ImageProxyConfig {
impl CommonOpts {
fn to_config(self) -> ImageProxyConfig {
let mut r = ImageProxyConfig::default();
if self.debug {
r.debug = true;
}
if self.insecure {
r.insecure_skip_tls_verification = Some(true)
}
Expand All @@ -65,7 +81,7 @@ impl GetMetadataOpts {
}

async fn get_metadata(o: GetMetadataOpts) -> Result<()> {
let config = o.proxy_opts();
let config = o.common.to_config();
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
let img = proxy.open_image(&o.reference).await?;
let (digest, manifest) = proxy.fetch_manifest(&img).await?;
Expand All @@ -75,7 +91,8 @@ async fn get_metadata(o: GetMetadataOpts) -> Result<()> {
}

async fn get_blob(o: GetBlobOpts) -> Result<()> {
let proxy = containers_image_proxy::ImageProxy::new().await?;
let config = o.common.to_config();
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
let img = proxy.open_image(&o.reference).await?;
let (mut blob, driver) = proxy.get_blob(&img, &o.digest, o.size).await?;

Expand Down Expand Up @@ -121,7 +138,7 @@ async fn get_blob_raw(o: GetBlobOpts) -> Result<()> {
}

async fn fetch_container_to_devnull(o: FetchContainerToDevNullOpts) -> Result<()> {
let config = o.metaopts.proxy_opts();
let config = o.metaopts.common.to_config();
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
let img = &proxy.open_image(&o.metaopts.reference).await?;
let manifest = proxy.fetch_manifest(img).await?.1;
Expand Down