mirror of
https://git.proxmox.com/git/proxmox
synced 2025-07-31 19:36:43 +00:00
rename CommandoSocket to CommandSocket
This commit is contained in:
parent
249aae1f05
commit
ad449a5780
@ -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>
|
||||||
|
@ -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(),
|
||||||
|
@ -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") };
|
||||||
|
Loading…
Reference in New Issue
Block a user