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-util",
"walkdir",
"whoami",
"winsplit",
]

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

@ -2125,6 +2125,12 @@ mod tests {
arch: std::env::consts::ARCH.to_string(),
current_dir: std::env::current_dir().unwrap_or_default(),
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
/// as defined in https://doc.rust-lang.org/std/path/constant.MAIN_SEPARATOR.html
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")]
@ -40,6 +46,12 @@ impl Default for SystemInfo {
arch: env::consts::ARCH.to_string(),
current_dir: env::current_dir().unwrap_or_default(),
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(),
current_dir,
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,
current_dir,
main_separator,
username,
shell,
}) => Output::StdoutLine(
format!(
concat!(
"Family: {:?}\n",
"Operating System: {:?}\n",
"Arch: {:?}\n",
"Cwd: {:?}\n",
"Family: {:?}",
"Operating System: {:?}",
"Arch: {:?}",
"Cwd: {:?}",
"Path Sep: {:?}",
"Username: {:?}",
"Shell: {:?}"
),
family, os, arch, current_dir, main_separator,
family, os, arch, current_dir, main_separator, username, shell
)
.into_bytes(),
),

Loading…
Cancel
Save