50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
//! `hivectl gateway` — htpasswd user management for the gateway's HTTP
|
|
//! Basic auth. The daemon owns the bcrypt hash + htpasswd write (see the
|
|
//! `Gateway*User` `HostRequest`s); hivectl resolves the password
|
|
//! client-side and relays the request over the host admin socket.
|
|
|
|
use std::path::Path;
|
|
|
|
use anyhow::Result;
|
|
|
|
use crate::util::{daemon_request, resolve_password};
|
|
|
|
pub(crate) async fn gateway_create_user(
|
|
socket: &Path,
|
|
username: &str,
|
|
password: Option<&str>,
|
|
password_stdin: bool,
|
|
) -> Result<()> {
|
|
let pw = resolve_password(password, password_stdin)?.ok_or_else(|| {
|
|
anyhow::anyhow!("a password is required — pass --password or --password-stdin")
|
|
})?;
|
|
daemon_request(
|
|
socket,
|
|
hive_host_sock::HostRequest::GatewayCreateUser {
|
|
username: username.to_owned(),
|
|
password: pw,
|
|
},
|
|
"gateway",
|
|
)
|
|
.await
|
|
}
|
|
|
|
pub(crate) async fn gateway_delete_user(socket: &Path, username: &str) -> Result<()> {
|
|
daemon_request(
|
|
socket,
|
|
hive_host_sock::HostRequest::GatewayDeleteUser {
|
|
username: username.to_owned(),
|
|
},
|
|
"gateway",
|
|
)
|
|
.await
|
|
}
|
|
|
|
pub(crate) async fn gateway_list_users(socket: &Path) -> Result<()> {
|
|
daemon_request(
|
|
socket,
|
|
hive_host_sock::HostRequest::GatewayListUsers,
|
|
"gateway",
|
|
)
|
|
.await
|
|
}
|