pub const INSECURE_REGISTRY_ENV: &str = "GTDX_ALLOW_INSECURE_REGISTRY";
pub fn insecure_registry_opt_in() -> bool {
parse_truthy(std::env::var(INSECURE_REGISTRY_ENV).ok().as_deref())
}
fn parse_truthy(value: Option<&str>) -> bool {
match value {
Some(raw) => {
let normalized = raw.trim().to_ascii_lowercase();
!matches!(normalized.as_str(), "" | "0" | "false" | "no")
}
None => false,
}
}
#[cfg(test)]
mod tests {
use super::parse_truthy;
#[test]
fn unset_is_default_secure() {
assert!(!parse_truthy(None));
}
#[test]
fn truthy_values_opt_in() {
for v in ["1", "true", "TRUE", "yes", "on", " 1 "] {
assert!(parse_truthy(Some(v)), "value {v:?} should opt in");
}
}
#[test]
fn falsy_values_stay_secure() {
for v in ["", "0", "false", "FALSE", "no", " 0 "] {
assert!(!parse_truthy(Some(v)), "value {v:?} should stay secure");
}
}
}