use clap::Args;
use serde::{Deserialize, Serialize};
use crate::constants;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, clap::ValueEnum)]
#[clap(rename_all = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum AccessControl {
Owner,
Group,
Anyone,
}
impl AccessControl {
pub fn into_mode(self) -> u32 {
match self {
Self::Owner => 0o600,
Self::Group => 0o660,
Self::Anyone => 0o666,
}
}
}
impl Default for AccessControl {
fn default() -> Self {
Self::Owner
}
}
#[derive(Args, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct NetworkSettings {
#[clap(long)]
pub unix_socket: Option<std::path::PathBuf>,
#[clap(long)]
pub windows_pipe: Option<String>,
}
impl NetworkSettings {
pub fn merge(&mut self, other: Self) {
self.unix_socket = self.unix_socket.take().or(other.unix_socket);
self.windows_pipe = self.windows_pipe.take().or(other.windows_pipe);
}
pub fn as_unix_socket_opt(&self) -> Option<&std::path::Path> {
self.unix_socket.as_deref()
}
pub fn as_windows_pipe_opt(&self) -> Option<&str> {
self.windows_pipe.as_deref()
}
pub fn to_unix_socket_path_candidates(&self) -> Vec<&std::path::Path> {
match self.unix_socket.as_deref() {
Some(path) => vec![path],
None => vec![
constants::user::UNIX_SOCKET_PATH.as_path(),
constants::global::UNIX_SOCKET_PATH.as_path(),
],
}
}
pub fn to_windows_pipe_name_candidates(&self) -> Vec<&str> {
match self.windows_pipe.as_deref() {
Some(name) => vec![name],
None => vec![
constants::user::WINDOWS_PIPE_NAME.as_str(),
constants::global::WINDOWS_PIPE_NAME.as_str(),
],
}
}
}