rename CommandoSocket to CommandSocket

This commit is contained in:
Dietmar Maurer 2021-09-30 12:31:38 +02:00
parent d7eedbd24b
commit 49e25688f1
8 changed files with 22 additions and 20 deletions

View File

@ -14,7 +14,7 @@ use serde::Serialize;
use proxmox::api::{ApiMethod, Router, RpcEnvironmentType}; use proxmox::api::{ApiMethod, Router, RpcEnvironmentType};
use proxmox::tools::fs::{create_path, CreateOptions}; 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>; 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. /// When enabled, all requests are logged to the specified file.
/// This function also registers a `api-access-log-reopen` /// This function also registers a `api-access-log-reopen`
/// command one the [CommandoSocket]. /// command one the [CommandSocket].
pub fn enable_access_log<P>( pub fn enable_access_log<P>(
&mut self, &mut self,
path: P, path: P,
dir_opts: Option<CreateOptions>, dir_opts: Option<CreateOptions>,
file_opts: Option<CreateOptions>, file_opts: Option<CreateOptions>,
commando_sock: &mut CommandoSocket, commando_sock: &mut CommandSocket,
) -> Result<(), Error> ) -> Result<(), Error>
where where
P: Into<PathBuf> P: Into<PathBuf>
@ -221,13 +221,13 @@ impl ApiConfig {
/// ///
/// When enabled, all authentification requests are logged to the /// When enabled, all authentification requests are logged to the
/// specified file. This function also registers a /// 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>( pub fn enable_auth_log<P>(
&mut self, &mut self,
path: P, path: P,
dir_opts: Option<CreateOptions>, dir_opts: Option<CreateOptions>,
file_opts: Option<CreateOptions>, file_opts: Option<CreateOptions>,
commando_sock: &mut CommandoSocket, commando_sock: &mut CommandSocket,
) -> Result<(), Error> ) -> Result<(), Error>
where where
P: Into<PathBuf> P: Into<PathBuf>

View File

@ -148,23 +148,25 @@ where
} }
// A callback for a specific commando socket. // 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 /// Tooling to get a single control command socket where one can
/// register multiple commands dynamically. /// register multiple commands dynamically.
/// ///
/// You need to call `spawn()` to make the socket active. /// The socket is activated by calling [spawn](CommandSocket::spawn),
pub struct CommandoSocket { /// which spawns an async tokio task to process the commands.
pub struct CommandSocket {
socket: PathBuf, socket: PathBuf,
gid: Gid, 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 pub fn new<P>(path: P, gid: Gid) -> Self
where P: Into<PathBuf>, where P: Into<PathBuf>,
{ {
CommandoSocket { CommandSocket {
socket: path.into(), socket: path.into(),
gid, gid,
commands: HashMap::new(), commands: HashMap::new(),

View File

@ -23,7 +23,7 @@ use proxmox::api::upid::UPID;
use pbs_tools::task::WorkerTaskContext; use pbs_tools::task::WorkerTaskContext;
use pbs_tools::logrotate::{LogRotate, LogRotateFiles}; use pbs_tools::logrotate::{LogRotate, LogRotateFiles};
use crate::{CommandoSocket, FileLogger, FileLogOptions}; use crate::{CommandSocket, FileLogger, FileLogOptions};
struct TaskListLockGuard(File); 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: /// 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 /// * ``worker-task-status <UPID>``: return true of false, depending on
/// whether the worker is running or stopped. /// whether the worker is running or stopped.
pub fn register_task_control_commands( pub fn register_task_control_commands(
commando_sock: &mut CommandoSocket, commando_sock: &mut CommandSocket,
) -> Result<(), Error> { ) -> Result<(), Error> {
fn get_upid(args: Option<&Value>) -> Result<UPID, Error> { fn get_upid(args: Option<&Value>) -> Result<UPID, Error> {
let args = if let Some(args) = args { args } else { bail!("missing args") }; let args = if let Some(args) = args { args } else { bail!("missing args") };

View File

@ -80,7 +80,7 @@ async fn run() -> Result<(), Error> {
)?; )?;
let backup_user = pbs_config::backup_user()?; 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 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); let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);

View File

@ -409,7 +409,7 @@ async fn run() -> Result<(), Error> {
let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid); 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())?; 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)?; proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
commando_sock.spawn()?; commando_sock.spawn()?;
} }

View File

@ -187,7 +187,7 @@ async fn run() -> Result<(), Error> {
config.register_template("console", "/usr/share/pve-xtermjs/index.html.hbs")?; config.register_template("console", "/usr/share/pve-xtermjs/index.html.hbs")?;
let backup_user = pbs_config::backup_user()?; 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 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); let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid);

View File

@ -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); 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())?; 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)?; proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
commando_sock.spawn()?; commando_sock.spawn()?;

View File

@ -11,7 +11,7 @@ use proxmox::tools::fs::CreateOptions;
use pbs_api_types::{Authid, UPID}; use pbs_api_types::{Authid, UPID};
use pbs_tools::{task_log, task::WorkerTaskContext}; 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> { fn garbage_collection(worker: &WorkerTask) -> Result<(), Error> {
@ -48,7 +48,7 @@ fn worker_task_abort() -> Result<(), Error> {
let rt = tokio::runtime::Runtime::new().unwrap(); let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async move { 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()); proxmox_rest_server::our_ctrl_sock(), nix::unistd::Gid::current());
let init_result: Result<(), Error> = try_block!({ let init_result: Result<(), Error> = try_block!({