2020-02-13 00:43:01 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
use log::debug;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
use futures::executor::block_on;
|
|
|
|
|
2020-02-15 01:27:25 +01:00
|
|
|
use kanidm_unix_common::client::call_daemon;
|
2020-02-29 05:02:14 +01:00
|
|
|
use kanidm_unix_common::unix_config::KanidmUnixdConfig;
|
2020-02-13 00:43:01 +01:00
|
|
|
use kanidm_unix_common::unix_proto::{ClientRequest, ClientResponse};
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct ClientOpt {
|
|
|
|
#[structopt(short = "d", long = "debug")]
|
|
|
|
debug: bool,
|
|
|
|
#[structopt()]
|
|
|
|
account_id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
let opt = ClientOpt::from_args();
|
|
|
|
if opt.debug {
|
|
|
|
::std::env::set_var("RUST_LOG", "kanidm=debug,kanidm_client=debug");
|
|
|
|
} else {
|
|
|
|
::std::env::set_var("RUST_LOG", "kanidm=info,kanidm_client=info");
|
|
|
|
}
|
|
|
|
env_logger::init();
|
|
|
|
|
|
|
|
debug!("Starting authorized keys tool ...");
|
2020-02-29 05:02:14 +01:00
|
|
|
|
|
|
|
let cfg = KanidmUnixdConfig::new()
|
|
|
|
.read_options_from_optional_config("/etc/kanidm/unixd")
|
|
|
|
.expect("Failed to parse /etc/kanidm/unixd");
|
|
|
|
|
2020-02-13 00:43:01 +01:00
|
|
|
let req = ClientRequest::SshKey(opt.account_id.clone());
|
|
|
|
|
2020-02-29 05:02:14 +01:00
|
|
|
match block_on(call_daemon(cfg.sock_path.as_str(), req)) {
|
2020-02-13 00:43:01 +01:00
|
|
|
Ok(r) => match r {
|
|
|
|
ClientResponse::SshKeys(sk) => sk.iter().for_each(|k| {
|
|
|
|
println!("{}", k);
|
|
|
|
}),
|
|
|
|
_ => {
|
|
|
|
error!("Error: unexpected response -> {:?}", r);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
error!("Error -> {:?}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|