use vta_cli_common::commands::acl;
use vta_sdk::client::VtaClient;
use crate::cli::AclCommands;
pub(crate) async fn run(
client: &VtaClient,
command: AclCommands,
) -> Result<(), Box<dyn std::error::Error>> {
match command {
AclCommands::List { context } => acl::cmd_acl_list(client, context.as_deref()).await,
AclCommands::Get { did } => acl::cmd_acl_get(client, &did).await,
AclCommands::Create {
did,
role,
label,
contexts,
expires,
} => match resolve_expires_at(expires.as_deref()) {
Ok(expires_at) => {
acl::cmd_acl_create(client, did, role, label, contexts, expires_at).await
}
Err(e) => Err(e),
},
AclCommands::Update {
did,
role,
label,
contexts,
} => acl::cmd_acl_update(client, &did, role, label, contexts).await,
AclCommands::Delete { did } => acl::cmd_acl_delete(client, &did).await,
}
}
fn resolve_expires_at(expires: Option<&str>) -> Result<Option<u64>, Box<dyn std::error::Error>> {
match expires {
Some(s) => Ok(Some(
vta_cli_common::duration::duration_to_expires_at(s)
.map_err(|e| format!("--expires: {e}"))?,
)),
None => Ok(None),
}
}