rename CommandoSocket to CommandSocket
This commit is contained in:
parent
d7eedbd24b
commit
49e25688f1
@ -14,7 +14,7 @@ use serde::Serialize;
|
||||
use proxmox::api::{ApiMethod, Router, RpcEnvironmentType};
|
||||
use proxmox::tools::fs::{create_path, CreateOptions};
|
||||
|
||||
use crate::{ApiAuth, FileLogger, FileLogOptions, CommandoSocket};
|
||||
use crate::{ApiAuth, FileLogger, FileLogOptions, CommandSocket};
|
||||
|
||||
pub type GetIndexFn = fn(Option<String>, Option<String>, &ApiConfig, Parts) -> Response<Body>;
|
||||
|
||||
@ -182,13 +182,13 @@ impl ApiConfig {
|
||||
///
|
||||
/// When enabled, all requests are logged to the specified file.
|
||||
/// This function also registers a `api-access-log-reopen`
|
||||
/// command one the [CommandoSocket].
|
||||
/// command one the [CommandSocket].
|
||||
pub fn enable_access_log<P>(
|
||||
&mut self,
|
||||
path: P,
|
||||
dir_opts: Option<CreateOptions>,
|
||||
file_opts: Option<CreateOptions>,
|
||||
commando_sock: &mut CommandoSocket,
|
||||
commando_sock: &mut CommandSocket,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
P: Into<PathBuf>
|
||||
@ -221,13 +221,13 @@ impl ApiConfig {
|
||||
///
|
||||
/// When enabled, all authentification requests are logged to the
|
||||
/// specified file. This function also registers a
|
||||
/// `api-auth-log-reopen` command one the [CommandoSocket].
|
||||
/// `api-auth-log-reopen` command one the [CommandSocket].
|
||||
pub fn enable_auth_log<P>(
|
||||
&mut self,
|
||||
path: P,
|
||||
dir_opts: Option<CreateOptions>,
|
||||
file_opts: Option<CreateOptions>,
|
||||
commando_sock: &mut CommandoSocket,
|
||||
commando_sock: &mut CommandSocket,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
P: Into<PathBuf>
|
||||
|
@ -148,23 +148,25 @@ where
|
||||
}
|
||||
|
||||
// A callback for a specific commando socket.
|
||||
type CommandoSocketFn = Box<(dyn Fn(Option<&Value>) -> Result<Value, Error> + Send + Sync + 'static)>;
|
||||
type CommandSocketFn = Box<(dyn Fn(Option<&Value>) -> Result<Value, Error> + Send + Sync + 'static)>;
|
||||
|
||||
/// Tooling to get a single control command socket where one can
|
||||
/// register multiple commands dynamically.
|
||||
///
|
||||
/// You need to call `spawn()` to make the socket active.
|
||||
pub struct CommandoSocket {
|
||||
/// The socket is activated by calling [spawn](CommandSocket::spawn),
|
||||
/// which spawns an async tokio task to process the commands.
|
||||
pub struct CommandSocket {
|
||||
socket: PathBuf,
|
||||
gid: Gid,
|
||||
commands: HashMap<String, CommandoSocketFn>,
|
||||
commands: HashMap<String, CommandSocketFn>,
|
||||
}
|
||||
|
||||
impl CommandoSocket {
|
||||
impl CommandSocket {
|
||||
/// Creates a new instance.
|
||||
pub fn new<P>(path: P, gid: Gid) -> Self
|
||||
where P: Into<PathBuf>,
|
||||
{
|
||||
CommandoSocket {
|
||||
CommandSocket {
|
||||
socket: path.into(),
|
||||
gid,
|
||||
commands: HashMap::new(),
|
||||
|
@ -23,7 +23,7 @@ use proxmox::api::upid::UPID;
|
||||
use pbs_tools::task::WorkerTaskContext;
|
||||
use pbs_tools::logrotate::{LogRotate, LogRotateFiles};
|
||||
|
||||
use crate::{CommandoSocket, FileLogger, FileLogOptions};
|
||||
use crate::{CommandSocket, FileLogger, FileLogOptions};
|
||||
|
||||
struct TaskListLockGuard(File);
|
||||
|
||||
@ -324,7 +324,7 @@ pub fn worker_is_active_local(upid: &UPID) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// Register task control command on a [CommandoSocket].
|
||||
/// Register task control command on a [CommandSocket].
|
||||
///
|
||||
/// This create two commands:
|
||||
///
|
||||
@ -333,7 +333,7 @@ pub fn worker_is_active_local(upid: &UPID) -> bool {
|
||||
/// * ``worker-task-status <UPID>``: return true of false, depending on
|
||||
/// whether the worker is running or stopped.
|
||||
pub fn register_task_control_commands(
|
||||
commando_sock: &mut CommandoSocket,
|
||||
commando_sock: &mut CommandSocket,
|
||||
) -> Result<(), Error> {
|
||||
fn get_upid(args: Option<&Value>) -> Result<UPID, Error> {
|
||||
let args = if let Some(args) = args { args } else { bail!("missing args") };
|
||||
|
@ -80,7 +80,7 @@ async fn run() -> Result<(), Error> {
|
||||
)?;
|
||||
|
||||
let backup_user = pbs_config::backup_user()?;
|
||||
let mut commando_sock = proxmox_rest_server::CommandoSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
|
||||
let mut commando_sock = proxmox_rest_server::CommandSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
|
||||
|
||||
let dir_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
|
||||
let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
|
||||
|
@ -409,7 +409,7 @@ async fn run() -> Result<(), Error> {
|
||||
let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
|
||||
proxmox_rest_server::init_worker_tasks(pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR_M!().into(), file_opts.clone())?;
|
||||
|
||||
let mut commando_sock = proxmox_rest_server::CommandoSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
|
||||
let mut commando_sock = proxmox_rest_server::CommandSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
|
||||
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
|
||||
commando_sock.spawn()?;
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ async fn run() -> Result<(), Error> {
|
||||
config.register_template("console", "/usr/share/pve-xtermjs/index.html.hbs")?;
|
||||
|
||||
let backup_user = pbs_config::backup_user()?;
|
||||
let mut commando_sock = proxmox_rest_server::CommandoSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
|
||||
let mut commando_sock = proxmox_rest_server::CommandSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
|
||||
|
||||
let dir_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
|
||||
let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
|
||||
|
@ -91,7 +91,7 @@ async fn run(rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
|
||||
let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);
|
||||
proxmox_rest_server::init_worker_tasks(pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR_M!().into(), file_opts.clone())?;
|
||||
|
||||
let mut commando_sock = proxmox_rest_server::CommandoSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
|
||||
let mut commando_sock = proxmox_rest_server::CommandSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid);
|
||||
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
|
||||
commando_sock.spawn()?;
|
||||
|
||||
|
@ -11,7 +11,7 @@ use proxmox::tools::fs::CreateOptions;
|
||||
use pbs_api_types::{Authid, UPID};
|
||||
use pbs_tools::{task_log, task::WorkerTaskContext};
|
||||
|
||||
use proxmox_rest_server::{CommandoSocket, WorkerTask};
|
||||
use proxmox_rest_server::{CommandSocket, WorkerTask};
|
||||
|
||||
fn garbage_collection(worker: &WorkerTask) -> Result<(), Error> {
|
||||
|
||||
@ -48,7 +48,7 @@ fn worker_task_abort() -> Result<(), Error> {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async move {
|
||||
|
||||
let mut commando_sock = CommandoSocket::new(
|
||||
let mut commando_sock = CommandSocket::new(
|
||||
proxmox_rest_server::our_ctrl_sock(), nix::unistd::Gid::current());
|
||||
|
||||
let init_result: Result<(), Error> = try_block!({
|
||||
|
Loading…
Reference in New Issue
Block a user