From 145945d80c7d4006854c7e0ad7554b411562778c Mon Sep 17 00:00:00 2001 From: Joonas Bergius Date: Sun, 13 Oct 2024 17:33:56 -0500 Subject: [PATCH] feat: Add option for using monolithic push Signed-off-by: Joonas Bergius --- src/client.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/client.rs b/src/client.rs index 5c79d5fc..51f11f25 100644 --- a/src/client.rs +++ b/src/client.rs @@ -559,14 +559,18 @@ impl Client { data: &[u8], digest: &str, ) -> Result { - match self.push_blob_chunked(image_ref, data, digest).await { - Ok(url) => Ok(url), - Err(OciDistributionError::SpecViolationError(violation)) => { - warn!(?violation, "Registry is not respecting the OCI Distribution Specification when doing chunked push operations"); - warn!("Attempting monolithic push"); - self.push_blob_monolithically(image_ref, data, digest).await + if self.config.use_monolithic_push { + self.push_blob_monolithically(image_ref, data, digest).await + } else { + match self.push_blob_chunked(image_ref, data, digest).await { + Ok(url) => Ok(url), + Err(OciDistributionError::SpecViolationError(violation)) => { + warn!(?violation, "Registry is not respecting the OCI Distribution Specification when doing chunked push operations"); + warn!("Attempting monolithic push"); + self.push_blob_monolithically(image_ref, data, digest).await + } + Err(e) => Err(e), } - Err(e) => Err(e), } } @@ -1797,6 +1801,9 @@ pub struct ClientConfig { /// Accept invalid certificates. Defaults to false pub accept_invalid_certificates: bool, + /// Use monolithic push for pushing blobs. Defaults to false + pub use_monolithic_push: bool, + /// A list of extra root certificate to trust. This can be used to connect /// to servers using self-signed certificates pub extra_root_certificates: Vec, @@ -1861,6 +1868,7 @@ impl Default for ClientConfig { #[cfg(feature = "native-tls")] accept_invalid_hostnames: false, accept_invalid_certificates: false, + use_monolithic_push: false, extra_root_certificates: Vec::new(), platform_resolver: Some(Box::new(current_platform_resolver)), max_concurrent_upload: DEFAULT_MAX_CONCURRENT_UPLOAD,