rename CommandoSocket to CommandSocket

This commit is contained in:
Dietmar Maurer 2021-09-30 12:31:38 +02:00
parent 249aae1f05
commit ad449a5780
3 changed files with 16 additions and 14 deletions

View File

@ -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>

View File

@ -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(),

View File

@ -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") };