Add response type and associated data; add operation to send stdin to remote process

pull/38/head
Chip Senkbeil 3 years ago
parent 9d7be8b4d7
commit a52fb82fbf
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -110,6 +110,195 @@ pub enum Operation {
detach: bool,
},
/// Sends additional data to stdin of running process
ProcStdin {
/// Id of the actively-running process to send stdin data
id: usize,
/// Data to send to stdin of process
data: Vec<u8>,
},
/// Retrieve a list of all processes being managed by the remote server
ProcList {},
}
/// Represents an response to an operation performed on the remote machine
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(
rename_all = "snake_case",
deny_unknown_fields,
tag = "status",
content = "payload"
)]
pub enum Response {
/// Represents a successfully-handled operation
Ok(ResponsePayload),
/// Represents an operation that failed
Error {
/// The message associated with the failure
msg: String,
},
}
/// Represents the payload of a successful response
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(
rename_all = "snake_case",
deny_unknown_fields,
tag = "type",
content = "data"
)]
pub enum ResponsePayload {
/// Response to reading a file
FileRead {
/// The path to the file on the remote machine
path: PathBuf,
/// Contents of the file
data: Vec<u8>,
},
/// Response to writing a file
FileWrite {
/// The path to the file on the remote machine
path: PathBuf,
/// Total bytes written
bytes_written: usize,
},
/// Response to appending to a file
FileAppend {
/// The path to the file on the remote machine
path: PathBuf,
/// Total bytes written
bytes_written: usize,
},
/// Response to reading a directory
DirRead {
/// The path to the directory on the remote machine
path: PathBuf,
/// Entries contained within directory
entries: Vec<DirEntry>,
},
/// Response to creating a directory
DirCreate {
/// The path to the directory on the remote machine
path: PathBuf,
},
/// Response to removing a directory
DirRemove {
/// The path to the directory on the remote machine
path: PathBuf,
/// Total files & directories removed within the directory (0 if directory was empty)
total_removed: usize,
},
/// Response to copying a file/directory
Copy {
/// The path to the file/directory on the remote machine
src: PathBuf,
/// New location on the remote machine for copy of file/directory
dst: PathBuf,
},
/// Response to moving/renaming a file/directory
Rename {
/// The path to the file/directory on the remote machine
src: PathBuf,
/// New location on the remote machine for the file/directory
dst: PathBuf,
},
/// Response to starting a new process
ProcStart {
/// Arbitrary id associated with running process
id: usize,
},
/// Actively-transmitted stdout as part of running process
ProcStdout {
/// Arbitrary id associated with running process
id: usize,
/// Data sent to stdout by process
data: Vec<u8>,
},
/// Actively-transmitted stderr as part of running process
ProcStderr {
/// Arbitrary id associated with running process
id: usize,
/// Data sent to stderr by process
data: Vec<u8>,
},
/// Response to a process finishing
ProcDone {
/// Arbitrary id associated with running process
id: usize,
/// Whether or not termination was successful
success: bool,
/// Exit code associated with termination, will be missing if terminated by signal
code: Option<i32>,
},
/// Response to retrieving a list of managed processes
ProcList {
/// List of managed processes
entries: Vec<RunningProcess>,
},
}
/// Represents information about a single entry within a directory
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct DirEntry {
/// Represents the full path to the entry
pub path: PathBuf,
/// Represents the type of the entry as a file/dir/symlink
pub file_type: FileType,
/// Depth at which this entry was created relative to the root (0 being immediately within
/// root)
pub depth: usize,
}
/// Represents the type associated with a dir entry
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", deny_unknown_fields, untagged)]
pub enum FileType {
Dir,
File,
SymLink,
}
/// Represents information about a running process
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct RunningProcess {
/// Name of the command being run
pub cmd: String,
/// Arguments for the command
pub args: Vec<String>,
/// Arbitrary id associated with running process
///
/// Not the same as the process' pid!
pub id: usize,
}

Loading…
Cancel
Save