From b6c23d43e03671959fdd7a0fbe475a27bff22a50 Mon Sep 17 00:00:00 2001 From: Bin Tang Date: Thu, 20 Jul 2023 14:06:38 +0800 Subject: [PATCH] parse image pull auth from env Signed-off-by: Bin Tang --- api/src/config.rs | 11 +++++++++++ src/bin/nydusd/main.rs | 13 +++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/api/src/config.rs b/api/src/config.rs index 616da06cac6..c00eb649be6 100644 --- a/api/src/config.rs +++ b/api/src/config.rs @@ -202,6 +202,17 @@ impl ConfigV2 { false } } + + /// Fill authorization for registry backend. + pub fn update_registry_auth_info(&mut self, auth: &Option) { + if let Some(auth) = auth { + if let Some(backend) = self.backend.as_mut() { + if let Some(registry) = backend.registry.as_mut() { + registry.auth = Some(auth.to_string()); + } + } + } + } } impl FromStr for ConfigV2 { diff --git a/src/bin/nydusd/main.rs b/src/bin/nydusd/main.rs index 6a8eeab6988..63a4db0265e 100644 --- a/src/bin/nydusd/main.rs +++ b/src/bin/nydusd/main.rs @@ -21,7 +21,7 @@ use nix::sys::signal; use rlimit::Resource; use nydus::{get_build_time_info, SubCmdArgs}; -use nydus_api::BuildTimeInfo; +use nydus_api::{BuildTimeInfo, ConfigV2}; use nydus_app::{dump_program_info, setup_logging}; use nydus_service::daemon::DaemonController; use nydus_service::{ @@ -423,7 +423,16 @@ fn process_fs_service( ) } None => match args.value_of("config") { - Some(v) => std::fs::read_to_string(v)?, + Some(v) => { + let auth = std::env::var("IMAGE_PULL_AUTH").ok(); + if auth.is_some() { + let mut config = ConfigV2::from_file(v)?; + config.update_registry_auth_info(&auth); + serde_json::to_string(&config)? + } else { + std::fs::read_to_string(v)? + } + } None => { let e = NydusError::InvalidArguments( "both --config and --localfs-dir are missing".to_string(),