Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion crates/oci-core/src/core/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const MAX_BLOB_RETRIES: usize = 2;
#[derive(Clone, Default)]
pub struct ClientConfig {
pub user_agent: Option<String>,
pub insecure_skip_tls_verify: bool,
}

fn env_flag(name: &str) -> bool {
Expand Down Expand Up @@ -72,12 +73,19 @@ pub struct Client {

impl Client {
pub fn new(config: ClientConfig) -> Self {
let builder = reqwest::Client::builder().user_agent(
let mut builder = reqwest::Client::builder().user_agent(
config
.user_agent
.clone()
.unwrap_or_else(|| "docker-image-pusher/0.0".to_string()),
);

// 如果配置了跳过 TLS 验证,则禁用证书验证
if config.insecure_skip_tls_verify {
eprintln!("[TLS] ⚠️ Warning: TLS certificate verification is disabled.(insecure mode)");
builder = builder.danger_accept_invalid_certs(true);
}

let http = builder.build().expect("Failed to build client");
Self {
http,
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub const GZIP_MAGIC_BYTES: [u8; 2] = [0x1F, 0x8B];
about = "Stream large Docker/OCI images through a tiny local cache"
)]
struct Cli {
/// Skip TLS certificate verification (for self-signed certificates)
#[arg(long, global = true)]
insecure: bool,

#[command(subcommand)]
command: Commands,
}
Expand Down Expand Up @@ -140,7 +144,10 @@ impl PusherError {
#[tokio::main]
async fn main() -> Result<(), PusherError> {
let cli = Cli::parse();
let client = Client::new(ClientConfig::default());
let client = Client::new(ClientConfig {
user_agent: None,
insecure_skip_tls_verify: cli.insecure,
});

match cli.command {
Commands::Push {
Expand Down