Update SystemInfo to support username and shell

pull/137/head
Chip Senkbeil 2 years ago
parent 486e5399ff
commit 56a030e6dd
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

1
Cargo.lock generated

@ -779,6 +779,7 @@ dependencies = [
"tokio", "tokio",
"tokio-util", "tokio-util",
"walkdir", "walkdir",
"whoami",
"winsplit", "winsplit",
] ]

@ -35,6 +35,7 @@ strum = { version = "0.24.1", features = ["derive"] }
tokio = { version = "1.20.1", features = ["full"] } tokio = { version = "1.20.1", features = ["full"] }
tokio-util = { version = "0.7.3", features = ["codec"] } tokio-util = { version = "0.7.3", features = ["codec"] }
walkdir = "2.3.2" walkdir = "2.3.2"
whoami = "1.2.1"
winsplit = "0.1.0" winsplit = "0.1.0"
# Optional dependencies based on features # Optional dependencies based on features

@ -2125,6 +2125,12 @@ mod tests {
arch: std::env::consts::ARCH.to_string(), arch: std::env::consts::ARCH.to_string(),
current_dir: std::env::current_dir().unwrap_or_default(), current_dir: std::env::current_dir().unwrap_or_default(),
main_separator: std::path::MAIN_SEPARATOR, main_separator: std::path::MAIN_SEPARATOR,
username: whoami::username(),
shell: if cfg!(windows) {
std::env::var("ComSpec").unwrap_or_else(|_| String::from("cmd.exe"))
} else {
std::env::var("SHELL").unwrap_or_else(|_| String::from("/bin/sh"))
}
} }
); );
} }

@ -23,6 +23,12 @@ pub struct SystemInfo {
/// Primary separator for path components for the current platform /// Primary separator for path components for the current platform
/// as defined in https://doc.rust-lang.org/std/path/constant.MAIN_SEPARATOR.html /// as defined in https://doc.rust-lang.org/std/path/constant.MAIN_SEPARATOR.html
pub main_separator: char, pub main_separator: char,
/// Name of the user running the server process
pub username: String,
/// Default shell tied to user running the server process
pub shell: String,
} }
#[cfg(feature = "schemars")] #[cfg(feature = "schemars")]
@ -40,6 +46,12 @@ impl Default for SystemInfo {
arch: env::consts::ARCH.to_string(), arch: env::consts::ARCH.to_string(),
current_dir: env::current_dir().unwrap_or_default(), current_dir: env::current_dir().unwrap_or_default(),
main_separator: std::path::MAIN_SEPARATOR, main_separator: std::path::MAIN_SEPARATOR,
username: whoami::username(),
shell: if cfg!(windows) {
env::var("ComSpec").unwrap_or_else(|_| String::from("cmd.exe"))
} else {
env::var("SHELL").unwrap_or_else(|_| String::from("/bin/sh"))
},
} }
} }
} }

@ -837,6 +837,11 @@ impl DistantApi for SshDistantApi {
arch: "".to_string(), arch: "".to_string(),
current_dir, current_dir,
main_separator: if is_windows { '\\' } else { '/' }, main_separator: if is_windows { '\\' } else { '/' },
// TODO: We should be able to calculate these once the problem described with SIGPIPE
// is resolved, but for now we will just return empty strings
username: "".to_string(),
shell: "".to_string(),
}) })
} }
} }

@ -301,16 +301,20 @@ fn format_shell(data: DistantResponseData) -> Output {
arch, arch,
current_dir, current_dir,
main_separator, main_separator,
username,
shell,
}) => Output::StdoutLine( }) => Output::StdoutLine(
format!( format!(
concat!( concat!(
"Family: {:?}\n", "Family: {:?}",
"Operating System: {:?}\n", "Operating System: {:?}",
"Arch: {:?}\n", "Arch: {:?}",
"Cwd: {:?}\n", "Cwd: {:?}",
"Path Sep: {:?}", "Path Sep: {:?}",
"Username: {:?}",
"Shell: {:?}"
), ),
family, os, arch, current_dir, main_separator, family, os, arch, current_dir, main_separator, username, shell
) )
.into_bytes(), .into_bytes(),
), ),

Loading…
Cancel
Save