Record an agent identity on a server profile so hooks use it by default. Writes `agent_identity` on the named profile, or on the active one when no name is given. The human binding (`identity`) is left alone: enrollment and revocation still authenticate as the human.
(
server_override: Option<&str>,
agent_name: &str,
)
| 498 | /// name is given. The human binding (`identity`) is left alone: enrollment and |
| 499 | /// revocation still authenticate as the human. |
| 500 | pub fn bind_agent_identity( |
| 501 | server_override: Option<&str>, |
| 502 | agent_name: &str, |
| 503 | ) -> crate::error::CliResult<()> { |
| 504 | use crate::error::CliError; |
| 505 | |
| 506 | let mut config = GlobalConfig::load() |
| 507 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load config: {e}")))?; |
| 508 | |
| 509 | let profile = server_override |
| 510 | .map(str::to_string) |
| 511 | .or_else(|| config.default_server.clone()); |
| 512 | |
| 513 | match profile { |
| 514 | Some(name) => match config.servers.get_mut(&name) { |
| 515 | Some(server) => server.agent_identity = Some(agent_name.to_string()), |
| 516 | None => { |
| 517 | return Err(CliError::InvalidArgument { |
| 518 | message: format!("No server profile named '{name}'"), |
| 519 | }) |
| 520 | } |
| 521 | }, |
| 522 | // No named profiles yet — the legacy [server] block is the active one. |
| 523 | None => config.server.agent_identity = Some(agent_name.to_string()), |
| 524 | } |
| 525 | |
| 526 | config |
| 527 | .save() |
| 528 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to save config: {e}"))) |
| 529 | } |
| 530 | |
| 531 | /// Format an identity type for display. |
| 532 | pub fn format_identity_type(identity_type: &atomic_identity::IdentityType) -> &'static str { |
no test coverage detected