Bind (or clear) an identity for a server profile.
(&self, cmd: &ServerSetIdentity)
| 445 | |
| 446 | /// Bind (or clear) an identity for a server profile. |
| 447 | fn set_identity_for_server(&self, cmd: &ServerSetIdentity) -> CliResult<()> { |
| 448 | let mut config = GlobalConfig::load() |
| 449 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load config: {}", e)))?; |
| 450 | |
| 451 | let profile = |
| 452 | config |
| 453 | .servers |
| 454 | .get_mut(&cmd.name) |
| 455 | .ok_or_else(|| CliError::InvalidArgument { |
| 456 | message: format!( |
| 457 | "Server profile '{}' not found. \ |
| 458 | Use 'atomic server add {} <url>' to create it.", |
| 459 | cmd.name, cmd.name |
| 460 | ), |
| 461 | })?; |
| 462 | |
| 463 | if cmd.clear { |
| 464 | profile.identity = None; |
| 465 | config |
| 466 | .save() |
| 467 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to save config: {}", e)))?; |
| 468 | print_success(&format!( |
| 469 | "Identity cleared for server profile '{}'", |
| 470 | cmd.name |
| 471 | )); |
| 472 | print_hint("Management commands will now use the global default identity."); |
| 473 | } else { |
| 474 | let identity_name = cmd.identity.as_deref().unwrap(); |
| 475 | profile.identity = Some(identity_name.to_string()); |
| 476 | config |
| 477 | .save() |
| 478 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to save config: {}", e)))?; |
| 479 | print_success(&format!( |
| 480 | "Identity '{}' bound to server profile '{}'", |
| 481 | identity_name, cmd.name |
| 482 | )); |
| 483 | } |
| 484 | |
| 485 | Ok(()) |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | impl Command for ServerCmd { |
no test coverage detected