1use forms::{FormValues, SSH_KEY_ADD};
4use rpc::Session;
5
6use crate::CommandError;
7use crate::flat::{Reply, submit};
8
9pub async fn add(
16 session: &mut Session,
17 key: &str,
18 label: Option<&str>,
19) -> Result<String, CommandError> {
20 let mut values = FormValues::default();
21 values.set("key", key);
22 label
23 .into_iter()
24 .for_each(|label| values.set("label", label));
25 match submit(session, &SSH_KEY_ADD, &values).await?.reply {
26 Reply::Entity(id) => Ok(id),
27 other => Err(CommandError::Command(format!(
28 "unexpected ssh-key reply: {other:?}"
29 ))),
30 }
31}