MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / parse_credential_pairs

Function parse_credential_pairs

crates/openshell-cli/src/run.rs:4021–4055  ·  view source on GitHub ↗
(items: &[String])

Source from the content-addressed store, hash-verified

4019}
4020
4021fn parse_credential_pairs(items: &[String]) -> Result<HashMap<String, String>> {
4022 let mut map = HashMap::new();
4023
4024 for item in items {
4025 if let Some((key, value)) = item.split_once('=') {
4026 let key = key.trim();
4027 if key.is_empty() {
4028 return Err(miette::miette!("--credential key cannot be empty"));
4029 }
4030 map.insert(key.to_string(), value.to_string());
4031 continue;
4032 }
4033
4034 let key = item.trim();
4035 if key.is_empty() {
4036 return Err(miette::miette!("--credential key cannot be empty"));
4037 }
4038
4039 let value = std::env::var(key).map_err(|_| {
4040 miette::miette!(
4041 "--credential {key} requires local env var '{key}' to be set to a non-empty value"
4042 )
4043 })?;
4044
4045 if value.trim().is_empty() {
4046 return Err(miette::miette!(
4047 "--credential {key} requires local env var '{key}' to be set to a non-empty value"
4048 ));
4049 }
4050
4051 map.insert(key.to_string(), value);
4052 }
4053
4054 Ok(map)
4055}
4056
4057pub fn parse_credential_expiry_cli_value(value: &str) -> std::result::Result<i64, String> {
4058 parse_credential_expiry_value(value, None).map_err(|err| err.to_string())

Calls 1

is_emptyMethod · 0.45