Skip to content

Commit b5a3714

Browse files
Xynnn007mythi
authored andcommitted
CDH: remove reading CDH_CONFIG_PATH env to get config path
Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
1 parent 662f79f commit b5a3714

1 file changed

Lines changed: 4 additions & 50 deletions

File tree

  • confidential-data-hub/hub/src/bin/config

confidential-data-hub/hub/src/bin/config/mod.rs

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,10 @@ pub fn read_config(config_path: Option<String>) -> Result<(CdhConfig, String)> {
2121
(config, log)
2222
}
2323
None => {
24-
if let std::result::Result::Ok(env_path) = env::var("CDH_CONFIG_PATH") {
25-
let log = format!("Read CDH's config path from env: {env_path}");
26-
let config = CdhConfig::from_file(&env_path[..])
27-
.with_context(|| format!("failed to read config file {env_path}"))?;
28-
(config, log)
29-
} else {
30-
let log = "No CDH config path specified. Using default configuration.".to_string();
31-
let config = CdhConfig::default_with_kernel_cmdline()
32-
.with_context(|| "failed to read default configuration".to_string())?;
33-
(config, log)
34-
}
24+
let log = "No CDH config path specified. Using default configuration.".to_string();
25+
let config = CdhConfig::default_with_kernel_cmdline()
26+
.with_context(|| "failed to read default configuration".to_string())?;
27+
(config, log)
3528
}
3629
};
3730

@@ -51,9 +44,6 @@ pub fn read_config(config_path: Option<String>) -> Result<(CdhConfig, String)> {
5144
mod tests {
5245
use std::{env, io::Write};
5346

54-
use anyhow::anyhow;
55-
use confidential_data_hub::{CdhConfig, KbsConfig, LogConfig, DEFAULT_CDH_SOCKET_ADDR};
56-
use image_rs::config::ImageConfig;
5747
use serial_test::serial;
5848

5949
use crate::config::read_config;
@@ -102,40 +92,4 @@ authenticated_registry_credentials_uri = "kbs:///default/auth/1"
10292
Some("kbs:///default/auth/1".into())
10393
);
10494
}
105-
106-
#[test]
107-
#[serial]
108-
fn test_config_path() {
109-
// --config takes precedence,
110-
// then env.CDH_CONFIG_PATH
111-
112-
let config = CdhConfig::default_with_kernel_cmdline().expect("Must be successful");
113-
let expected = CdhConfig {
114-
log: LogConfig::default(),
115-
kbc: KbsConfig {
116-
name: "offline_fs_kbc".into(),
117-
url: "".into(),
118-
kbs_cert: None,
119-
},
120-
credentials: Vec::new(),
121-
socket: DEFAULT_CDH_SOCKET_ADDR.into(),
122-
image: ImageConfig::from_kernel_cmdline(),
123-
skip_sealed_secret_verification: false,
124-
};
125-
assert_eq!(config, expected);
126-
127-
let config = CdhConfig::from_file("/thing").unwrap_err();
128-
let expected = anyhow!("configuration file \"/thing\" not found");
129-
assert_eq!(format!("{config}"), format!("{expected}"));
130-
131-
env::set_var("CDH_CONFIG_PATH", "/byenv");
132-
let result = read_config(None).unwrap_err();
133-
let expected = anyhow!("failed to read config file /byenv");
134-
assert_eq!(format!("{result}"), format!("{expected}"));
135-
env::remove_var("CDH_CONFIG_PATH");
136-
137-
let config = CdhConfig::from_file("/thing").unwrap_err();
138-
let expected = anyhow!("configuration file \"/thing\" not found");
139-
assert_eq!(format!("{config}"), format!("{expected}"));
140-
}
14195
}

0 commit comments

Comments
 (0)