use sha2::{Digest, Sha256};
pub mod fs;
pub mod source_context;
pub use fs::{find_config_file, resolve_path, resolve_paths};
pub use source_context::SourceContext;
pub fn compute_hash(input: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(input.as_bytes());
hex::encode(hasher.finalize())
}
pub fn execute_command(_cmd: &str, _args: &[&str]) -> crate::Result<String> {
Ok(String::new())
}
pub fn sanitize_url(url: &str) -> String {
if let Some(proto_end) = url.find("://") {
let proto_end = proto_end + 3; let after_proto = &url[proto_end..];
if let Some(at_pos) = after_proto.find('@') {
let proto = &url[..proto_end];
let host_and_path = &after_proto[at_pos..];
return format!("{}***{}", proto, host_and_path);
}
}
url.to_string()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sanitize_url_with_credentials() {
assert_eq!(
sanitize_url("https://user:token@github.com/repo"),
"https://***@github.com/repo"
);
assert_eq!(
sanitize_url("oci://username:password@registry.io/chart"),
"oci://***@registry.io/chart"
);
}
#[test]
fn test_sanitize_url_without_credentials() {
assert_eq!(sanitize_url("https://github.com/repo"), "https://github.com/repo");
assert_eq!(sanitize_url("oci://registry.io/chart"), "oci://registry.io/chart");
}
#[test]
fn test_sanitize_url_with_port() {
assert_eq!(
sanitize_url("https://user:pass@example.com:8080/path"),
"https://***@example.com:8080/path"
);
}
#[test]
fn test_sanitize_url_no_protocol() {
assert_eq!(sanitize_url("user@host:/path"), "user@host:/path");
}
}