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

Function load_identity_by_scanning

atomic-agent/src/identity.rs:493–514  ·  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

491
492/// Scan all identity directories and try to find one matching the ID.
493fn load_identity_by_scanning(identities_dir: &Path, id_base32: &str) -> Option<UserIdentityInfo> {
494 // Already tried by ID match; try loading the first User identity as fallback
495 let entries = std::fs::read_dir(identities_dir).ok()?;
496
497 for entry in entries.flatten() {
498 if !entry.path().is_dir() {
499 continue;
500 }
501
502 let identity_path = entry.path().join("identity.toml");
503 if let Ok(content) = std::fs::read_to_string(&identity_path) {
504 // Check if it contains the right ID, or if it's a User type identity
505 if content.contains(id_base32)
506 || (content.contains("type = \"user\"")
507 || content.contains("identity_type = \"user\""))
508 {
509 return parse_identity_toml(&content);
510 }
511 }
512 }
513 None
514}
515
516/// Parse minimal identity info from an identity.toml file.
517fn 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