forked from janek/mostr
feat(main): auto-migrate existing key
This commit is contained in:
parent
a0e411d2e9
commit
9a9c30dbb7
30
src/main.rs
30
src/main.rs
|
@ -97,6 +97,18 @@ async fn main() -> Result<()> {
|
||||||
builder
|
builder
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut rl = DefaultEditor::new()?;
|
||||||
|
rl.set_auto_add_history(true);
|
||||||
|
or_warn!(
|
||||||
|
rl.create_external_writer().map(
|
||||||
|
|wr| builder
|
||||||
|
// Without this filter at least at Info, the program hangs
|
||||||
|
.filter(Some("rustyline"), LevelFilter::Warn)
|
||||||
|
.write_style(WriteStyle::Always)
|
||||||
|
.target(Target::Pipe(wr)))
|
||||||
|
);
|
||||||
|
builder.init();
|
||||||
|
|
||||||
let config_dir =
|
let config_dir =
|
||||||
ProjectDirs::from("", "", "mostr")
|
ProjectDirs::from("", "", "mostr")
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
|
@ -110,17 +122,13 @@ async fn main() -> Result<()> {
|
||||||
PathBuf::new()
|
PathBuf::new()
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut rl = DefaultEditor::new()?;
|
let key_file = config_dir.join("key");
|
||||||
rl.set_auto_add_history(true);
|
if let Ok(Some(keys)) = fs::read_to_string(key_file.as_path()).map(|s| or_warn!(Keys::from_str(&s.trim()))) {
|
||||||
or_warn!(
|
info!("Migrating private key from plaintext file {}", key_file.to_string_lossy());
|
||||||
rl.create_external_writer().map(
|
or_warn!(Entry::new("mostr", "keys")
|
||||||
|wr| builder
|
.and_then(|e| e.set_secret(keys.secret_key().unwrap().as_secret_bytes()))
|
||||||
// Without this filter at least at Info, the program hangs
|
.inspect(|_| { or_warn!(fs::remove_file(key_file)); }));
|
||||||
.filter(Some("rustyline"), LevelFilter::Warn)
|
}
|
||||||
.write_style(WriteStyle::Always)
|
|
||||||
.target(Target::Pipe(wr)))
|
|
||||||
);
|
|
||||||
builder.init();
|
|
||||||
|
|
||||||
let keys = read_keys(&mut rl)?;
|
let keys = read_keys(&mut rl)?;
|
||||||
let relayfile = config_dir.join("relays");
|
let relayfile = config_dir.join("relays");
|
||||||
|
|
Loading…
Reference in New Issue