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

Function resolve_identity_for_server

atomic-cli/src/commands/client.rs:175–204  ·  view source on GitHub ↗

Resolve the identity to authenticate as for a given server profile. Resolution order: 1. `server.identity` — a per-server identity override (set when `atomic identity register --identity ` is used). 2. Global default identity from the identity store. Shared by [`build_client_with_org`] and [`build_apex_client`] so the org-scoped and apex-scoped code paths pick the same identity. # Errors

(
    server: &atomic_config::ServerConfig,
)

Source from the content-addressed store, hash-verified

173/// - Per-server identity name not found in the store.
174/// - No default identity set.
175pub fn resolve_identity_for_server(
176 server: &atomic_config::ServerConfig,
177) -> CliResult<atomic_identity::Identity> {
178 let store = IdentityStore::open_default()
179 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to open identity store: {}", e)))?;
180
181 if let Some(ref identity_name) = server.identity {
182 // Server profile specifies an identity — use it.
183 store.load_by_name(identity_name).map_err(|e| {
184 CliError::Internal(anyhow::anyhow!(
185 "Identity '{}' specified by server profile not found: {}",
186 identity_name,
187 e
188 ))
189 })
190 } else {
191 // Fall back to global default identity.
192 store
193 .get_default()
194 .map_err(|e| {
195 CliError::Internal(anyhow::anyhow!("Failed to load default identity: {}", e))
196 })?
197 .ok_or_else(|| {
198 CliError::Internal(anyhow::anyhow!(
199 "No default identity set. Create one first:\n \
200 atomic identity new <name> --email <email> --set-default"
201 ))
202 })
203 }
204}
205
206/// Convenience: map a [`atomic_remote::RemoteError`] to a [`CliError`].
207pub fn remote_err(e: atomic_remote::RemoteError) -> CliError {

Callers 2

build_apex_clientFunction · 0.85
build_client_with_orgFunction · 0.85

Calls 2

load_by_nameMethod · 0.80
get_defaultMethod · 0.45

Tested by

no test coverage detected