node: single function to get api secrets
This commit is contained in:
parent
92e5d38755
commit
e40d5b6474
3 changed files with 24 additions and 36 deletions
|
@ -356,8 +356,8 @@ impl NodeSetup {
|
|||
ui.add_space(6.0);
|
||||
|
||||
let secret_value = match modal_id {
|
||||
API_SECRET_MODAL => NodeConfig::get_api_secret(),
|
||||
_ => NodeConfig::get_foreign_api_secret()
|
||||
API_SECRET_MODAL => NodeConfig::get_api_secret(false),
|
||||
_ => NodeConfig::get_api_secret(true)
|
||||
};
|
||||
|
||||
let secret_text = if secret_value.is_some() {
|
||||
|
|
|
@ -505,22 +505,29 @@ impl NodeConfig {
|
|||
}
|
||||
|
||||
/// Get API secret text.
|
||||
pub fn get_api_secret() -> Option<String> {
|
||||
pub fn get_api_secret(foreign: bool) -> Option<String> {
|
||||
let r_config = Settings::node_config_to_read();
|
||||
let api_secret_path = r_config
|
||||
let api_secret_path = if foreign {
|
||||
&r_config
|
||||
.node
|
||||
.server
|
||||
.foreign_api_secret_path
|
||||
} else {
|
||||
&r_config
|
||||
.node
|
||||
.server
|
||||
.api_secret_path
|
||||
.clone();
|
||||
return if let Some(secret_path) = api_secret_path {
|
||||
let api_secret_file = File::open(secret_path).unwrap();
|
||||
let buf_reader = BufReader::new(api_secret_file);
|
||||
}.clone();
|
||||
if let Some(secret_path) = api_secret_path {
|
||||
if let Ok(file) = File::open(secret_path) {
|
||||
let buf_reader = BufReader::new(file);
|
||||
let mut lines_iter = buf_reader.lines();
|
||||
let first_line = lines_iter.next().unwrap();
|
||||
Some(first_line.unwrap())
|
||||
} else {
|
||||
if let Some(Ok(line)) = lines_iter.next() {
|
||||
return Some(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
};
|
||||
}
|
||||
|
||||
/// Save API secret text.
|
||||
|
@ -528,25 +535,6 @@ impl NodeConfig {
|
|||
Self::save_secret(api_secret, API_SECRET_FILE_NAME);
|
||||
}
|
||||
|
||||
/// Get Foreign API secret text.
|
||||
pub fn get_foreign_api_secret() -> Option<String> {
|
||||
let r_config = Settings::node_config_to_read();
|
||||
let foreign_secret_path = r_config
|
||||
.node
|
||||
.server
|
||||
.foreign_api_secret_path
|
||||
.clone();
|
||||
return if let Some(secret_path) = foreign_secret_path {
|
||||
let foreign_secret_file = File::open(secret_path).unwrap();
|
||||
let buf_reader = BufReader::new(foreign_secret_file);
|
||||
let mut lines_iter = buf_reader.lines();
|
||||
let first_line = lines_iter.next().unwrap();
|
||||
Some(first_line.unwrap())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
}
|
||||
|
||||
/// Update Foreign API secret.
|
||||
pub fn save_foreign_api_secret(api_secret: &String) {
|
||||
Self::save_secret(api_secret, FOREIGN_API_SECRET_FILE_NAME);
|
||||
|
|
|
@ -171,7 +171,7 @@ impl Wallet {
|
|||
// Setup node client.
|
||||
let integrated = || {
|
||||
let api_url = format!("http://{}", NodeConfig::get_api_address());
|
||||
let api_secret = NodeConfig::get_foreign_api_secret();
|
||||
let api_secret = NodeConfig::get_api_secret(true);
|
||||
(api_url, api_secret)
|
||||
};
|
||||
let (node_api_url, node_secret) = if let Some(id) = config.ext_conn_id {
|
||||
|
|
Loading…
Reference in a new issue