Collect the server profiles from the global config — both the default `[server]` block and every named `[servers.*]` profile — that declare an identity, marking which one is **active** (the profile `default_server` names, or the legacy block when unset). Servers without an identity binding are skipped. Returns an empty list when no config exists or it can't be read, so resolution degrades cleanly
()
| 103 | /// Returns an empty list when no config exists or it can't be read, so |
| 104 | /// resolution degrades cleanly to URL-based inference. |
| 105 | fn configured_server_identity_bindings() -> Vec<ServerBinding> { |
| 106 | let config = match atomic_config::GlobalConfig::load() { |
| 107 | Ok(c) => c, |
| 108 | Err(e) => { |
| 109 | log::debug!("Could not load global config for server identities: {e}"); |
| 110 | return Vec::new(); |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | let host_of = |server: &atomic_config::ServerConfig| { |
| 115 | server |
| 116 | .url |
| 117 | .as_deref() |
| 118 | .and_then(|u| Url::parse(u).ok()) |
| 119 | .and_then(|u| u.host_str().map(String::from)) |
| 120 | }; |
| 121 | |
| 122 | let mut bindings = Vec::new(); |
| 123 | let mut consider = |server: &atomic_config::ServerConfig, active: bool| { |
| 124 | if let (Some(host), Some(identity)) = (host_of(server), server.identity.as_ref()) { |
| 125 | bindings.push(ServerBinding { |
| 126 | host, |
| 127 | identity: identity.clone(), |
| 128 | agent_identity: server.agent_identity.clone(), |
| 129 | active, |
| 130 | }); |
| 131 | } |
| 132 | }; |
| 133 | |
| 134 | // The active profile is resolved exactly as management commands resolve |
| 135 | // it (`GlobalConfig::resolve_server`): `default_server` → named profile, |
| 136 | // else the legacy block. A dangling `default_server` name degrades to |
| 137 | // no active marker rather than failing auth resolution. |
| 138 | let active_named = config |
| 139 | .default_server |
| 140 | .as_deref() |
| 141 | .and_then(|name| config.servers.get(name)); |
| 142 | match active_named { |
| 143 | Some(profile) => { |
| 144 | consider(profile, true); |
| 145 | for (name, server) in &config.servers { |
| 146 | if Some(name.as_str()) != config.default_server.as_deref() { |
| 147 | consider(server, false); |
| 148 | } |
| 149 | } |
| 150 | consider(&config.server, false); |
| 151 | } |
| 152 | None => { |
| 153 | for server in config.servers.values() { |
| 154 | consider(server, false); |
| 155 | } |
| 156 | consider(&config.server, true); |
| 157 | } |
| 158 | } |
| 159 | bindings |
| 160 | } |
| 161 | |
| 162 | /// Pure identity resolution from a URL plus the configured server bindings. |