Yaleman/issue989 (#2111)

* adding version command to ssh_authorizedkys
* adding version and help to kanidm_unixd_tasks
This commit is contained in:
James Hodgkinson 2023-09-16 14:22:03 +10:00 committed by GitHub
parent d5ed335b52
commit a239fbdd94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 3 deletions

View file

@ -1,4 +1,5 @@
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
#[command(version)]
struct SshAuthorizedOpt { struct SshAuthorizedOpt {
#[clap(short, long = "debug")] #[clap(short, long = "debug")]
debug: bool, debug: bool,

View file

@ -1,10 +1,10 @@
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
#[command(name="kanidm_ssh_authorizedkeys")] #[command(name = "kanidm_ssh_authorizedkeys")]
struct SshAuthorizedOpt { struct SshAuthorizedOpt {
#[clap(short, long)] #[clap(short, long)]
debug: bool, debug: bool,
#[clap()] #[clap()]
account_id: String, account_id: Option<String>,
#[clap(short, long, action = clap::ArgAction::SetTrue)] #[clap(short, long, action = clap::ArgAction::SetTrue)]
version: bool, version: bool,
} }

View file

@ -34,8 +34,14 @@ async fn main() -> ExitCode {
println!("ssh_authorizedkeys {}", env!("KANIDM_PKG_VERSION")); println!("ssh_authorizedkeys {}", env!("KANIDM_PKG_VERSION"));
return ExitCode::SUCCESS; return ExitCode::SUCCESS;
} }
sketching::tracing_subscriber::fmt::init(); sketching::tracing_subscriber::fmt::init();
if opt.account_id.is_none() {
error!("No account specified, quitting!");
return ExitCode::FAILURE;
}
debug!("Starting authorized keys tool ..."); debug!("Starting authorized keys tool ...");
let cfg = match KanidmUnixdConfig::new().read_options_from_optional_config(DEFAULT_CONFIG_PATH) let cfg = match KanidmUnixdConfig::new().read_options_from_optional_config(DEFAULT_CONFIG_PATH)
@ -60,7 +66,8 @@ async fn main() -> ExitCode {
); );
return ExitCode::FAILURE; return ExitCode::FAILURE;
} }
let req = ClientRequest::SshKey(opt.account_id); // safe because we've already thrown an error if it's not there
let req = ClientRequest::SshKey(opt.account_id.unwrap_or("".to_string()));
match call_daemon(cfg.sock_path.as_str(), req, cfg.unix_sock_timeout).await { match call_daemon(cfg.sock_path.as_str(), req, cfg.unix_sock_timeout).await {
Ok(r) => match r { Ok(r) => match r {

View file

@ -267,6 +267,19 @@ async fn main() -> ExitCode {
let ceuid = get_effective_uid(); let ceuid = get_effective_uid();
let cegid = get_effective_gid(); let cegid = get_effective_gid();
for arg in std::env::args() {
if arg.contains("--version") {
println!("kanidm_unixd_tasks {}", env!("CARGO_PKG_VERSION"));
return ExitCode::SUCCESS;
} else if arg.contains("--help") {
println!("kanidm_unixd_tasks {}", env!("CARGO_PKG_VERSION"));
println!("Usage: kanidm_unixd_tasks");
println!(" --version");
println!(" --help");
return ExitCode::SUCCESS;
}
}
#[allow(clippy::expect_used)] #[allow(clippy::expect_used)]
tracing_forest::worker_task() tracing_forest::worker_task()
.set_global(true) .set_global(true)