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
4 changes: 2 additions & 2 deletions vortex-cloud/src/opendal/cos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use vortex_utils::aliases::hash_map::HashMap;

use crate::opendal::OpenDALStoreError;
use crate::opendal::build_operator;
use crate::opendal::property_as_bool;
use crate::opendal::property_or_env;
use crate::opendal::warn_on_unknown_properties;

Expand Down Expand Up @@ -129,8 +130,7 @@ where
&env_lookup,
),
root: properties.get("root").cloned(),
disable_config_load: properties.get("disable_config_load").map(String::as_str)
== Some("true"),
disable_config_load: property_as_bool(properties, "disable_config_load"),
})
}

Expand Down
54 changes: 54 additions & 0 deletions vortex-cloud/src/opendal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@ where
properties.get(key).cloned().or_else(|| env_lookup(env_var))
}

/// Take `key` from `properties` as a boolean, accepting the spellings `object_store` accepts in
/// its own configuration: `1`/`true`/`on`/`yes`/`y` and their negatives, case-insensitively.
///
/// An absent key is `false`. A value that is not a boolean is warned about and read as `false`,
/// which is how [`warn_on_unknown_properties`] already treats a key the service cannot use.
#[cfg(any(feature = "cos", feature = "oss"))]
pub(crate) fn property_as_bool(properties: &HashMap<String, String>, key: &str) -> bool {
let Some(value) = properties.get(key) else {
return false;
};
match value.trim().to_ascii_lowercase().as_str() {
"1" | "true" | "on" | "yes" | "y" => true,
"0" | "false" | "off" | "no" | "n" => false,
_ => {
warn!("ignoring OpenDAL store property {key}: `{value}` is not a boolean");
false
}
}
}

/// Log a warning for every property key the service does not recognize.
#[cfg(any(feature = "cos", feature = "goosefs", feature = "oss"))]
pub(crate) fn warn_on_unknown_properties(properties: &HashMap<String, String>, known: &[&str]) {
Expand Down Expand Up @@ -265,4 +285,38 @@ mod tests {
);
}
}

/// The spellings `object_store` accepts for its own boolean configuration, so that the same
/// property means the same thing whether a URL resolves to a native store or an OpenDAL one.
/// Values reach us verbatim from the caller's property map, hence the case and whitespace
/// cases; anything that is not a boolean stays `false` rather than becoming an error.
#[cfg(any(feature = "cos", feature = "oss"))]
#[rstest::rstest]
#[case("true", true)]
#[case("True", true)]
#[case("TRUE", true)]
#[case(" true ", true)]
#[case("1", true)]
#[case("on", true)]
#[case("yes", true)]
#[case("y", true)]
#[case("false", false)]
#[case("False", false)]
#[case("0", false)]
#[case("off", false)]
#[case("no", false)]
#[case("n", false)]
#[case("maybe", false)]
#[case("", false)]
fn property_as_bool_matches_object_store(#[case] value: &str, #[case] expected: bool) {
let mut props = HashMap::new();
props.insert("skip_signature".to_string(), value.to_string());
assert_eq!(property_as_bool(&props, "skip_signature"), expected);
}

#[cfg(any(feature = "cos", feature = "oss"))]
#[test]
fn property_as_bool_is_false_when_absent() {
assert!(!property_as_bool(&HashMap::new(), "skip_signature"));
}
}
3 changes: 2 additions & 1 deletion vortex-cloud/src/opendal/oss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use vortex_utils::aliases::hash_map::HashMap;

use crate::opendal::OpenDALStoreError;
use crate::opendal::build_operator;
use crate::opendal::property_as_bool;
use crate::opendal::property_or_env;
use crate::opendal::warn_on_unknown_properties;

Expand Down Expand Up @@ -140,7 +141,7 @@ where
&env_lookup,
),
root: properties.get("root").cloned(),
skip_signature: properties.get("skip_signature").map(String::as_str) == Some("true"),
skip_signature: property_as_bool(properties, "skip_signature"),
})
}

Expand Down