MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / load_identity_by_scanning

Function load_identity_by_scanning

atomic-agent/src/identity.rs:421–442  ·  view source on GitHub ↗

Scan all identity directories and try to find one matching the ID.

(identities_dir: &Path, id_base32: &str)

Source from the content-addressed store, hash-verified

419
420/// Scan all identity directories and try to find one matching the ID.
421fn load_identity_by_scanning(identities_dir: &Path, id_base32: &str) -> Option<UserIdentityInfo> {
422 // Already tried by ID match; try loading the first User identity as fallback
423 let entries = std::fs::read_dir(identities_dir).ok()?;
424
425 for entry in entries.flatten() {
426 if !entry.path().is_dir() {
427 continue;
428 }
429
430 let identity_path = entry.path().join("identity.toml");
431 if let Ok(content) = std::fs::read_to_string(&identity_path) {
432 // Check if it contains the right ID, or if it's a User type identity
433 if content.contains(id_base32)
434 || (content.contains("type = \"user\"")
435 || content.contains("identity_type = \"user\""))
436 {
437 return parse_identity_toml(&content);
438 }
439 }
440 }
441 None
442}
443
444/// Parse minimal identity info from an identity.toml file.
445fn parse_identity_toml(content: &str) -> Option<UserIdentityInfo> {

Callers 1

Calls 4

parse_identity_tomlFunction · 0.85
is_dirMethod · 0.80
pathMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected