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>,
)
| 371 | /// |
| 372 | /// Returns the created profile name, if any. |
| 373 | fn apply_registration( |
| 374 | config: &mut GlobalConfig, |
| 375 | server_url: &str, |
| 376 | slug: &str, |
| 377 | single_tenant: bool, |
| 378 | identity_name: &str, |
| 379 | profile_name: Option<&str>, |
| 380 | ) -> Option<String> { |
| 381 | if let Some(name) = profile_name { |
| 382 | let profile = atomic_config::ServerConfig { |
| 383 | url: Some(server_url.to_string()), |
| 384 | default_org: Some(slug.to_string()), |
| 385 | default_workspaces: std::collections::BTreeMap::new(), |
| 386 | identity: Some(identity_name.to_string()), |
| 387 | // Registration binds the human; `atomic identity agent create` |
| 388 | // binds an agent later, if one is ever created for this server. |
| 389 | agent_identity: None, |
| 390 | single_tenant, |
| 391 | }; |
| 392 | config.servers.insert(name.to_string(), profile); |
| 393 | |
| 394 | // Make it the active profile only when nothing else is active and |
| 395 | // the legacy [server] block wouldn't be silently overridden. |
| 396 | if config.default_server.is_none() && !config.server.is_configured() { |
| 397 | config.default_server = Some(name.to_string()); |
| 398 | } |
| 399 | Some(name.to_string()) |
| 400 | } else { |
| 401 | // If the active named profile already represents this server, update |
| 402 | // it directly. Writing only the legacy block would be ineffective: |
| 403 | // authentication intentionally lets the active profile win equal-host |
| 404 | // matches. |
| 405 | let matching_active = config.default_server.as_deref().and_then(|name| { |
| 406 | config |
| 407 | .servers |
| 408 | .get(name) |
| 409 | .filter(|server| server_urls_match(server.url.as_deref(), server_url)) |
| 410 | .map(|_| name.to_string()) |
| 411 | }); |
| 412 | |
| 413 | if let Some(name) = matching_active { |
| 414 | if let Some(server) = config.servers.get_mut(&name) { |
| 415 | server.url = Some(server_url.to_string()); |
| 416 | server.default_org = Some(slug.to_string()); |
| 417 | server.single_tenant = single_tenant; |
| 418 | server.identity = Some(identity_name.to_string()); |
| 419 | } |
| 420 | } else { |
| 421 | config.server.url = Some(server_url.to_string()); |
| 422 | config.server.default_org = Some(slug.to_string()); |
| 423 | config.server.single_tenant = single_tenant; |
| 424 | config.server.identity = Some(identity_name.to_string()); |
| 425 | } |
| 426 | None |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | fn server_urls_match(configured: Option<&str>, registered: &str) -> bool { |