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,
)
| 173 | /// - Per-server identity name not found in the store. |
| 174 | /// - No default identity set. |
| 175 | pub 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`]. |
| 207 | pub fn remote_err(e: atomic_remote::RemoteError) -> CliError { |
no test coverage detected