Skip to content

Commit a18238b

Browse files
committed
examples/client: Add --insecure
To ease testing from local registries. Signed-off-by: Colin Walters <[email protected]>
1 parent a907e13 commit a18238b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

examples/client.rs

Lines changed: 19 additions & 2 deletions
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)]
@@ -38,8 +43,19 @@ struct Metadata {
3843
manifest: ImageManifest,
3944
}
4045

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+
4156
async fn get_metadata(o: GetMetadataOpts) -> Result<()> {
42-
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?;
4359
let img = proxy.open_image(&o.reference).await?;
4460
let (digest, manifest) = proxy.fetch_manifest(&img).await?;
4561
let metadata = Metadata { digest, manifest };
@@ -71,7 +87,8 @@ async fn get_blob(o: GetBlobOpts) -> Result<()> {
7187
}
7288

7389
async fn fetch_container_to_devnull(o: GetMetadataOpts) -> Result<()> {
74-
let proxy = containers_image_proxy::ImageProxy::new().await?;
90+
let config = o.proxy_opts();
91+
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
7592
let img = &proxy.open_image(&o.reference).await?;
7693
let manifest = proxy.fetch_manifest(img).await?.1;
7794
for layer in manifest.layers() {

0 commit comments

Comments
 (0)