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);
|
ui.add_space(6.0);
|
||||||
|
|
||||||
let secret_value = match modal_id {
|
let secret_value = match modal_id {
|
||||||
API_SECRET_MODAL => NodeConfig::get_api_secret(),
|
API_SECRET_MODAL => NodeConfig::get_api_secret(false),
|
||||||
_ => NodeConfig::get_foreign_api_secret()
|
_ => NodeConfig::get_api_secret(true)
|
||||||
};
|
};
|
||||||
|
|
||||||
let secret_text = if secret_value.is_some() {
|
let secret_text = if secret_value.is_some() {
|
||||||
|
|
|
@ -505,22 +505,29 @@ impl NodeConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get API secret text.
|
/// 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 r_config = Settings::node_config_to_read();
|
||||||
let api_secret_path = r_config
|
let api_secret_path = if foreign {
|
||||||
.node
|
&r_config
|
||||||
.server
|
.node
|
||||||
.api_secret_path
|
.server
|
||||||
.clone();
|
.foreign_api_secret_path
|
||||||
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);
|
|
||||||
let mut lines_iter = buf_reader.lines();
|
|
||||||
let first_line = lines_iter.next().unwrap();
|
|
||||||
Some(first_line.unwrap())
|
|
||||||
} else {
|
} else {
|
||||||
None
|
&r_config
|
||||||
};
|
.node
|
||||||
|
.server
|
||||||
|
.api_secret_path
|
||||||
|
}.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();
|
||||||
|
if let Some(Ok(line)) = lines_iter.next() {
|
||||||
|
return Some(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Save API secret text.
|
/// Save API secret text.
|
||||||
|
@ -528,25 +535,6 @@ impl NodeConfig {
|
||||||
Self::save_secret(api_secret, API_SECRET_FILE_NAME);
|
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.
|
/// Update Foreign API secret.
|
||||||
pub fn save_foreign_api_secret(api_secret: &String) {
|
pub fn save_foreign_api_secret(api_secret: &String) {
|
||||||
Self::save_secret(api_secret, FOREIGN_API_SECRET_FILE_NAME);
|
Self::save_secret(api_secret, FOREIGN_API_SECRET_FILE_NAME);
|
||||||
|
|
|
@ -171,7 +171,7 @@ impl Wallet {
|
||||||
// Setup node client.
|
// Setup node client.
|
||||||
let integrated = || {
|
let integrated = || {
|
||||||
let api_url = format!("http://{}", NodeConfig::get_api_address());
|
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)
|
(api_url, api_secret)
|
||||||
};
|
};
|
||||||
let (node_api_url, node_secret) = if let Some(id) = config.ext_conn_id {
|
let (node_api_url, node_secret) = if let Some(id) = config.ext_conn_id {
|
||||||
|
|
Loading…
Reference in a new issue