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

Function load_identity_by_scanning

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

308
309/// Scan all identity directories and try to find one matching the ID.
310fn load_identity_by_scanning(identities_dir: &Path, id_base32: &str) -> Option<UserIdentityInfo> {
311 // Already tried by ID match; try loading the first User identity as fallback
312 let entries = std::fs::read_dir(identities_dir).ok()?;
313
314 for entry in entries.flatten() {
315 if !entry.path().is_dir() {
316 continue;
317 }
318
319 let identity_path = entry.path().join("identity.toml");
320 if let Ok(content) = std::fs::read_to_string(&identity_path) {
321 // Check if it contains the right ID, or if it's a User type identity
322 if content.contains(id_base32)
323 || (content.contains("type = \"user\"")
324 || content.contains("identity_type = \"user\""))
325 {
326 return parse_identity_toml(&content);
327 }
328 }
329 }
330 None
331}
332
333/// Parse minimal identity info from an identity.toml file.
334fn 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