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

Function apply_registration

atomic-cli/src/commands/identity/register.rs:356–408  ·  view source on GitHub ↗

Record a completed registration in the global config. Two shapes, matching the pre-existing behavior: - `profile_name = Some(_)` (an `--identity` registration): insert a named `[servers.{name}]` profile carrying the URL, org, and identity binding. It becomes the active profile (`default_server`) only when nothing is active yet AND the legacy `[server]` block is unconfigured. - `profile_name = No

(
    config: &mut GlobalConfig,
    server_url: &str,
    slug: &str,
    single_tenant: bool,
    identity_name: &str,
    profile_name: Option<&str>,
)

Source from the content-addressed store, hash-verified

354///
355/// Returns the created profile name, if any.
356fn apply_registration(
357 config: &mut GlobalConfig,
358 server_url: &str,
359 slug: &str,
360 single_tenant: bool,
361 identity_name: &str,
362 profile_name: Option<&str>,
363) -> Option<String> {
364 if let Some(name) = profile_name {
365 let profile = atomic_config::ServerConfig {
366 url: Some(server_url.to_string()),
367 default_org: Some(slug.to_string()),
368 default_workspaces: std::collections::BTreeMap::new(),
369 identity: Some(identity_name.to_string()),
370 single_tenant,
371 };
372 config.servers.insert(name.to_string(), profile);
373
374 // Make it the active profile only when nothing else is active and
375 // the legacy [server] block wouldn't be silently overridden.
376 if config.default_server.is_none() && !config.server.is_configured() {
377 config.default_server = Some(name.to_string());
378 }
379 Some(name.to_string())
380 } else {
381 // If the active named profile already represents this server, update
382 // it directly. Writing only the legacy block would be ineffective:
383 // authentication intentionally lets the active profile win equal-host
384 // matches.
385 let matching_active = config.default_server.as_deref().and_then(|name| {
386 config
387 .servers
388 .get(name)
389 .filter(|server| server_urls_match(server.url.as_deref(), server_url))
390 .map(|_| name.to_string())
391 });
392
393 if let Some(name) = matching_active {
394 if let Some(server) = config.servers.get_mut(&name) {
395 server.url = Some(server_url.to_string());
396 server.default_org = Some(slug.to_string());
397 server.single_tenant = single_tenant;
398 server.identity = Some(identity_name.to_string());
399 }
400 } else {
401 config.server.url = Some(server_url.to_string());
402 config.server.default_org = Some(slug.to_string());
403 config.server.single_tenant = single_tenant;
404 config.server.identity = Some(identity_name.to_string());
405 }
406 None
407 }
408}
409
410fn server_urls_match(configured: Option<&str>, registered: &str) -> bool {
411 configured

Calls 6

server_urls_matchFunction · 0.85
is_noneMethod · 0.80
is_configuredMethod · 0.80
get_mutMethod · 0.80
getMethod · 0.65
insertMethod · 0.45