feat: v1.11.8, add keypair-keychain-import/export
This commit is contained in:
46
src/cmd_keypair_keychain_import.rs
Normal file
46
src/cmd_keypair_keychain_import.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use crate::keychain::KeychainKey;
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use rust_util::util_clap::{Command, CommandError};
|
||||
|
||||
pub struct CommandImpl;
|
||||
|
||||
impl Command for CommandImpl {
|
||||
fn name(&self) -> &str {
|
||||
"keypair-keychain-import"
|
||||
}
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||
SubCommand::with_name(self.name())
|
||||
.about("Import software keypair to keychain")
|
||||
.arg(
|
||||
Arg::with_name("keychain-name")
|
||||
.long("keychain-name")
|
||||
.takes_value(true)
|
||||
.help("Key chain name"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("import-key-value")
|
||||
.long("import-key-value")
|
||||
.takes_value(true)
|
||||
.help("Import key value"),
|
||||
)
|
||||
}
|
||||
|
||||
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
|
||||
let keychain_name = sub_arg_matches.value_of("keychain-name");
|
||||
let import_key_value = sub_arg_matches.value_of("import-key-value");
|
||||
|
||||
if let Some(keychain_name) = keychain_name {
|
||||
let keychain_key = KeychainKey::from_key_name_default(keychain_name);
|
||||
if let Some(_) = keychain_key.get_password()? {
|
||||
return simple_error!("Keychain key URI: {} exists", keychain_key.to_key_uri());
|
||||
}
|
||||
|
||||
if let Some(import_key_value) = import_key_value {
|
||||
keychain_key.set_password(import_key_value.as_bytes())?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user