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

Function configured_server_identity_bindings

atomic-remote/src/auth/mod.rs:123–178  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

121/// Returns an empty list when no config exists or it can't be read, so
122/// resolution degrades cleanly to URL-based inference.
123fn configured_server_identity_bindings() -> Vec<ServerBinding> {
124 let config = match atomic_config::GlobalConfig::load() {
125 Ok(c) => c,
126 Err(e) => {
127 log::debug!("Could not load global config for server identities: {e}");
128 return Vec::new();
129 }
130 };
131
132 let host_of = |server: &atomic_config::ServerConfig| {
133 server
134 .url
135 .as_deref()
136 .and_then(|u| Url::parse(u).ok())
137 .and_then(|u| u.host_str().map(String::from))
138 };
139
140 let mut bindings = Vec::new();
141 let mut consider = |server: &atomic_config::ServerConfig, active: bool| {
142 if let (Some(host), Some(identity)) = (host_of(server), server.identity.as_ref()) {
143 bindings.push(ServerBinding {
144 host,
145 identity: identity.clone(),
146 agent_identity: server.agent_identity.clone(),
147 active,
148 });
149 }
150 };
151
152 // The active profile is resolved exactly as management commands resolve
153 // it (`GlobalConfig::resolve_server`): `default_server` → named profile,
154 // else the legacy block. A dangling `default_server` name degrades to
155 // no active marker rather than failing auth resolution.
156 let active_named = config
157 .default_server
158 .as_deref()
159 .and_then(|name| config.servers.get(name));
160 match active_named {
161 Some(profile) => {
162 consider(profile, true);
163 for (name, server) in &config.servers {
164 if Some(name.as_str()) != config.default_server.as_deref() {
165 consider(server, false);
166 }
167 }
168 consider(&config.server, false);
169 }
170 None => {
171 for server in config.servers.values() {
172 consider(server, false);
173 }
174 consider(&config.server, true);
175 }
176 }
177 bindings
178}
179
180/// Pure identity resolution from a URL plus the configured server bindings.

Callers 1

Calls 7

as_refMethod · 0.80
getMethod · 0.65
parseFunction · 0.50
okMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected