Fix base-path handling in key insert (#7775)

This fixes the handling of base-path when using `key insert`. Before
the base-path wasn't setup correctly, as done when starting a node. This
resulted in putting the keys into the wrong directory. This pr fixes
this by creating the correct base-path/config dir for the keystore.
Besides that it also removes the insert command from `subkey` as it
doesn't make that much sense. If requested, we could bring it back later.
This commit is contained in:
Bastian Köcher
2020-12-28 15:08:30 +01:00
committed by GitHub
parent 6cd8a45292
commit 05ae24d90a
14 changed files with 206 additions and 136 deletions
@@ -18,8 +18,7 @@
use crate::error::Result;
use sc_service::config::KeystoreConfig;
use std::fs;
use std::path::PathBuf;
use std::{fs, path::{PathBuf, Path}};
use structopt::StructOpt;
use crate::error;
use sp_core::crypto::SecretString;
@@ -33,6 +32,7 @@ pub struct KeystoreParams {
/// Specify custom URIs to connect to for keystore-services
#[structopt(long = "keystore-uri")]
pub keystore_uri: Option<String>,
/// Specify custom keystore path.
#[structopt(long = "keystore-path", value_name = "PATH", parse(from_os_str))]
pub keystore_path: Option<PathBuf>,
@@ -64,15 +64,14 @@ pub struct KeystoreParams {
/// Parse a sercret string, returning a displayable error.
pub fn secret_string_from_str(s: &str) -> std::result::Result<SecretString, String> {
Ok(std::str::FromStr::from_str(s)
.map_err(|_e| "Could not get SecretString".to_string())?)
std::str::FromStr::from_str(s).map_err(|_| "Could not get SecretString".to_string())
}
impl KeystoreParams {
/// Get the keystore configuration for the parameters
/// returns a vector of remote-urls and the local Keystore configuration
pub fn keystore_config(&self, base_path: &PathBuf) -> Result<(Option<String>, KeystoreConfig)> {
///
/// Returns a vector of remote-urls and the local Keystore configuration
pub fn keystore_config(&self, config_dir: &Path) -> Result<(Option<String>, KeystoreConfig)> {
let password = if self.password_interactive {
#[cfg(not(target_os = "unknown"))]
{
@@ -92,7 +91,7 @@ impl KeystoreParams {
let path = self
.keystore_path
.clone()
.unwrap_or_else(|| base_path.join(DEFAULT_KEYSTORE_CONFIG_PATH));
.unwrap_or_else(|| config_dir.join(DEFAULT_KEYSTORE_CONFIG_PATH));
Ok((self.keystore_uri.clone(), KeystoreConfig::Path { path, password }))
}