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

Function configured_server_identity_bindings

atomic-cli/src/commands/auth.rs:80–134  ·  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

78/// Returns an empty list when no config exists or it can't be read, so
79/// resolution degrades cleanly to URL-based inference.
80fn configured_server_identity_bindings() -> Vec<ServerBinding> {
81 let config = match atomic_config::GlobalConfig::load() {
82 Ok(c) => c,
83 Err(e) => {
84 log::debug!("Could not load global config for server identities: {e}");
85 return Vec::new();
86 }
87 };
88
89 let host_of = |server: &atomic_config::ServerConfig| {
90 server
91 .url
92 .as_deref()
93 .and_then(|u| Url::parse(u).ok())
94 .and_then(|u| u.host_str().map(String::from))
95 };
96
97 let mut bindings = Vec::new();
98 let mut consider = |server: &atomic_config::ServerConfig, active: bool| {
99 if let (Some(host), Some(identity)) = (host_of(server), server.identity.as_ref()) {
100 bindings.push(ServerBinding {
101 host,
102 identity: identity.clone(),
103 active,
104 });
105 }
106 };
107
108 // The active profile is resolved exactly as management commands resolve
109 // it (`GlobalConfig::resolve_server`): `default_server` → named profile,
110 // else the legacy block. A dangling `default_server` name degrades to
111 // no active marker rather than failing auth resolution.
112 let active_named = config
113 .default_server
114 .as_deref()
115 .and_then(|name| config.servers.get(name));
116 match active_named {
117 Some(profile) => {
118 consider(profile, true);
119 for (name, server) in &config.servers {
120 if Some(name.as_str()) != config.default_server.as_deref() {
121 consider(server, false);
122 }
123 }
124 consider(&config.server, false);
125 }
126 None => {
127 for server in config.servers.values() {
128 consider(server, false);
129 }
130 consider(&config.server, true);
131 }
132 }
133 bindings
134}
135
136/// Pure identity resolution from a URL plus the configured server bindings.
137///

Callers 1

Calls 6

parseFunction · 0.85
as_refMethod · 0.80
getMethod · 0.65
pushMethod · 0.45
cloneMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected