1
0
Fork 0
mirror of https://github.com/imjasonh/krust synced 2026-07-07 22:35:25 +00:00

feat: Add RegistryAuth::from_default() convenience methods

- Add from_default() and from_default_str() methods to RegistryAuth
- These methods automatically resolve auth from Docker config and credential helpers
- Update example to demonstrate both explicit and auto auth approaches
- Simplify krust's auth wrapper to use the new convenience method
- Fix test environment variable pollution

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jason Hall 2025-06-08 10:49:28 -04:00
parent a6ae83c3b2
commit 672ada3dd2
Failed to extract signature
9 changed files with 148 additions and 239 deletions

View file

@ -91,21 +91,30 @@ fn test_resolve_auth_bearer_token() -> Result<()> {
fs::write(&config_path, config)?;
// Save current env var
let old_val = env::var("DOCKER_CONFIG").ok();
// Save current env vars
let old_docker_config = env::var("DOCKER_CONFIG").ok();
let old_registry_auth = env::var("REGISTRY_AUTH_FILE").ok();
// Set our test config and clear other env vars
env::set_var("DOCKER_CONFIG", tmp_dir.path());
env::remove_var("REGISTRY_AUTH_FILE");
// Should resolve to bearer auth
let auth = resolve_auth("ghcr.io/user/image")?;
assert!(matches!(auth, RegistryAuth::Bearer(token)
if token == "test-bearer-token"));
// Restore env var
if let Some(val) = old_val {
// Restore env vars
if let Some(val) = old_docker_config {
env::set_var("DOCKER_CONFIG", val);
} else {
env::remove_var("DOCKER_CONFIG");
}
if let Some(val) = old_registry_auth {
env::set_var("REGISTRY_AUTH_FILE", val);
} else {
env::remove_var("REGISTRY_AUTH_FILE");
}
Ok(())
}