Skip to content

Commit fbe78a9

Browse files
authored
Merge pull request #75 from cgwalters/fetch-devnull
examples: Add a thingy to fetch container to devnull
2 parents 918bfab + a18238b commit fbe78a9

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

examples/client.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ use std::io::Write;
22

33
use anyhow::Result;
44
use clap::Parser;
5+
use containers_image_proxy::ImageProxyConfig;
56
use oci_spec::image::{Digest, ImageManifest};
67
use tokio::io::AsyncReadExt;
78

89
#[derive(clap::Parser, Debug)]
910
struct GetMetadataOpts {
1011
/// The skopeo-style transport:image reference
1112
reference: String,
13+
14+
/// Disable TLS verification
15+
#[clap(long)]
16+
insecure: bool,
1217
}
1318

1419
#[derive(clap::Parser, Debug)]
@@ -29,6 +34,7 @@ struct GetBlobOpts {
2934
enum Opt {
3035
GetMetadata(GetMetadataOpts),
3136
GetBlob(GetBlobOpts),
37+
FetchContainerToDevNull(GetMetadataOpts),
3238
}
3339

3440
#[derive(serde::Serialize, Debug)]
@@ -37,8 +43,19 @@ struct Metadata {
3743
manifest: ImageManifest,
3844
}
3945

46+
impl GetMetadataOpts {
47+
fn proxy_opts(&self) -> containers_image_proxy::ImageProxyConfig {
48+
let mut r = ImageProxyConfig::default();
49+
if self.insecure {
50+
r.insecure_skip_tls_verification = Some(true)
51+
}
52+
r
53+
}
54+
}
55+
4056
async fn get_metadata(o: GetMetadataOpts) -> Result<()> {
41-
let proxy = containers_image_proxy::ImageProxy::new().await?;
57+
let config = o.proxy_opts();
58+
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
4259
let img = proxy.open_image(&o.reference).await?;
4360
let (digest, manifest) = proxy.fetch_manifest(&img).await?;
4461
let metadata = Metadata { digest, manifest };
@@ -69,10 +86,29 @@ async fn get_blob(o: GetBlobOpts) -> Result<()> {
6986
Ok(())
7087
}
7188

89+
async fn fetch_container_to_devnull(o: GetMetadataOpts) -> Result<()> {
90+
let config = o.proxy_opts();
91+
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
92+
let img = &proxy.open_image(&o.reference).await?;
93+
let manifest = proxy.fetch_manifest(img).await?.1;
94+
for layer in manifest.layers() {
95+
let (mut blob, driver) = proxy.get_descriptor(img, layer).await?;
96+
let mut devnull = tokio::io::sink();
97+
let copier = tokio::io::copy(&mut blob, &mut devnull);
98+
let (copier, driver) = tokio::join!(copier, driver);
99+
dbg!(&copier);
100+
dbg!(&driver);
101+
copier?;
102+
driver?;
103+
}
104+
Ok(())
105+
}
106+
72107
async fn run() -> Result<()> {
73108
match Opt::parse() {
74109
Opt::GetMetadata(o) => get_metadata(o).await,
75110
Opt::GetBlob(o) => get_blob(o).await,
111+
Opt::FetchContainerToDevNull(o) => fetch_container_to_devnull(o).await,
76112
}
77113
}
78114

0 commit comments

Comments
 (0)