Working on refactor to use hashmaps
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
parent
29804b0dce
commit
5b86f754f4
|
@ -3,14 +3,19 @@
|
|||
//! Different PeachCloud microservices import peach-lib, so that they can share
|
||||
//! this interface.
|
||||
//!
|
||||
//! Config values are looked up from three locations in this order by key name:
|
||||
//! 1. from environmental variables
|
||||
//! 2. from a configuration file
|
||||
//! 3. from default values
|
||||
//!
|
||||
//! The configuration file is located at: "/var/lib/peachcloud/config.yml"
|
||||
//! unless its path is configured by setting PEACH_CONFIG_PATH env variable.
|
||||
|
||||
use std::{env, fs};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use fslock::LockFile;
|
||||
use log::debug;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use crate::error::PeachError;
|
||||
|
||||
|
@ -27,161 +32,168 @@ lazy_static! {
|
|||
DEFAULT_YAML_PATH.to_string()
|
||||
}
|
||||
};
|
||||
// lock file (used to avoid race conditions during config reading & writing)
|
||||
// the lock file path is the config file path + ".lock"
|
||||
static ref LOCK_FILE_PATH: String = format!("{}.lock", *CONFIG_PATH);
|
||||
}
|
||||
|
||||
// lock file (used to avoid race conditions during config reading & writing)
|
||||
|
||||
|
||||
// default values
|
||||
pub const DEFAULT_DYN_SERVER_ADDRESS: &str = "http://dynserver.dyn.peachcloud.org";
|
||||
pub const DEFAULT_DYN_NAMESERVER: &str = "ns.peachcloud.org";
|
||||
|
||||
// we make use of Serde default values in order to make PeachCloud
|
||||
// robust and keep running even with a not fully complete config.yml
|
||||
// main type which represents all peachcloud configurations
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PeachConfig {
|
||||
#[serde(default)]
|
||||
pub external_domain: String,
|
||||
#[serde(default)]
|
||||
pub dyn_domain: String,
|
||||
#[serde(default)]
|
||||
pub dyn_dns_server_address: String,
|
||||
#[serde(default)]
|
||||
pub dyn_use_custom_server: bool,
|
||||
#[serde(default)]
|
||||
pub dyn_nameserver: String,
|
||||
#[serde(default)]
|
||||
pub dyn_tsig_key_path: String,
|
||||
#[serde(default)] // default is false
|
||||
pub dyn_enabled: bool,
|
||||
#[serde(default)] // default is empty vector
|
||||
pub ssb_admin_ids: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub admin_password_hash: String,
|
||||
#[serde(default)]
|
||||
pub temporary_password_hash: String,
|
||||
// primary interface for getting config values
|
||||
pub fn get_config_value(key: &str) -> Result<String, PeachError> {
|
||||
// first check if it is an environmental variable
|
||||
if let Ok(val) = env::var(key) {
|
||||
Ok(val)
|
||||
} else {
|
||||
// then check disc
|
||||
let peach_config_on_disc = load_peach_config_from_disc()?;
|
||||
let val = peach_config_on_disc.get(key);
|
||||
// then check defaults
|
||||
match val {
|
||||
Some(v) => Ok(v.to_string()),
|
||||
None => {
|
||||
match get_peach_config_defaults().get(key) {
|
||||
Some(v) => Ok(v.to_string()),
|
||||
None => {
|
||||
Err(PeachError::InvalidKey { msg: format!("No default config value set for key: {}", key) })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// helper functions for serializing and deserializing PeachConfig from disc
|
||||
pub fn save_peach_config(peach_config: PeachConfig) -> Result<PeachConfig, PeachError> {
|
||||
|
||||
// Default values for PeachCloud configs which are used for any key which is not set
|
||||
// via an environment variable or in a saved configuration file.
|
||||
pub fn get_peach_config_defaults() -> HashMap<String, String> {
|
||||
let peach_config_defaults: HashMap<String, String> = HashMap::from([
|
||||
("STANDALONE_MODE".to_string(), "true".to_string()),
|
||||
("DISABLE_AUTH".to_string(), "false".to_string()),
|
||||
("ADDR".to_string(), "127.0.0.1".to_string()),
|
||||
("PORT".to_string(), "8000".to_string()),
|
||||
("EXTERNAL_DOMAIN".to_string(), "".to_string()),
|
||||
("DYN_DOMAIN".to_string(), "".to_string()),
|
||||
("DYN_DNS_SERVER_ADDRESS".to_string(), "http://dynserver.dyn.peachcloud.org".to_string()),
|
||||
("DYN_USE_CUSTOM_SERVER".to_string(), "true".to_string()),
|
||||
("DYN_TSIG_KEY_PATH".to_string(), "".to_string()),
|
||||
("DYN_NAMESERVER".to_string(), "ns.peachcloud.org".to_string()),
|
||||
("DYN_ENABLED".to_string(), "false".to_string()),
|
||||
("SSB_ADMIN_IDS".to_string(), "[]".to_string()),
|
||||
("ADMIN_PASSWORD_HASH".to_string(), "146".to_string()),
|
||||
("TEMPORARY_PASSWORD_HASH".to_string(), "".to_string()),
|
||||
("GO_SBOT_DATADIR".to_string(), "".to_string()),
|
||||
("PEACH_CONFIGDIR".to_string(), "/var/lib/peachcloud".to_string()),
|
||||
]);
|
||||
peach_config_defaults
|
||||
}
|
||||
|
||||
|
||||
// helper function to load PeachCloud configuration files saved to disc
|
||||
pub fn load_peach_config_from_disc() -> Result<HashMap<String, String>, PeachError> {
|
||||
let peach_config : HashMap<String, String> = HashMap::new();
|
||||
// TODO: implement
|
||||
Ok(peach_config)
|
||||
}
|
||||
|
||||
pub fn save_peach_config_to_disc(peach_config: HashMap<String, String>) -> Result<HashMap<String, String>, PeachError> {
|
||||
|
||||
// use a file lock to avoid race conditions while saving config
|
||||
let mut lock = LockFile::open(&*LOCK_FILE_PATH)?;
|
||||
lock.lock()?;
|
||||
|
||||
// convert HashMap to yaml
|
||||
let yaml_str = serde_yaml::to_string(&peach_config)?;
|
||||
|
||||
fs::write((*CONFIG_PATH).to_string(), yaml_str).map_err(|source| PeachError::Write {
|
||||
// write yaml to file
|
||||
fs::write(CONFIG_PATH.as_str(), yaml_str).map_err(|source| PeachError::Write {
|
||||
source,
|
||||
path: (*CONFIG_PATH).to_string(),
|
||||
path: CONFIG_PATH.to_string(),
|
||||
})?;
|
||||
|
||||
// unlock file lock
|
||||
lock.unlock()?;
|
||||
|
||||
// return peach_config
|
||||
// return modified HashMap
|
||||
Ok(peach_config)
|
||||
}
|
||||
|
||||
pub fn load_peach_config() -> Result<PeachConfig, PeachError> {
|
||||
let peach_config_exists = std::path::Path::new(&*CONFIG_PATH).exists();
|
||||
// helper functions for serializing and deserializing PeachConfig from disc
|
||||
pub fn save_peach_config_value(key: &str, value: String) -> Result<HashMap<String, String>, PeachError> {
|
||||
|
||||
let peach_config: PeachConfig = if !peach_config_exists {
|
||||
debug!("Loading peach config: {} does not exist", *CONFIG_PATH);
|
||||
PeachConfig {
|
||||
external_domain: "".to_string(),
|
||||
dyn_domain: "".to_string(),
|
||||
dyn_dns_server_address: DEFAULT_DYN_SERVER_ADDRESS.to_string(),
|
||||
dyn_use_custom_server: false,
|
||||
dyn_nameserver: DEFAULT_DYN_NAMESERVER.to_string(),
|
||||
dyn_tsig_key_path: "".to_string(),
|
||||
dyn_enabled: false,
|
||||
ssb_admin_ids: Vec::new(),
|
||||
// default password is `peach`
|
||||
admin_password_hash: "146".to_string(),
|
||||
temporary_password_hash: "".to_string(),
|
||||
}
|
||||
}
|
||||
// otherwise we load peach config from disk
|
||||
else {
|
||||
debug!("Loading peach config: {} exists", *CONFIG_PATH);
|
||||
let contents = fs::read_to_string((*CONFIG_PATH).to_string()).map_err(|source| PeachError::Read {
|
||||
source,
|
||||
path: (*CONFIG_PATH).to_string(),
|
||||
})?;
|
||||
serde_yaml::from_str(&contents)?
|
||||
};
|
||||
// get current config from disc
|
||||
let mut peach_config = load_peach_config_from_disc()?;
|
||||
|
||||
Ok(peach_config)
|
||||
// insert new key/value
|
||||
peach_config.insert(key.to_string(), value);
|
||||
|
||||
// save hte modified hashmap to disc
|
||||
save_peach_config_to_disc(peach_config)
|
||||
}
|
||||
|
||||
// interfaces for setting specific config values
|
||||
|
||||
// set all dyn configuration values at once
|
||||
pub fn set_peach_dyndns_config(
|
||||
dyn_domain: &str,
|
||||
dyn_dns_server_address: &str,
|
||||
dyn_tsig_key_path: &str,
|
||||
dyn_enabled: bool,
|
||||
) -> Result<PeachConfig, PeachError> {
|
||||
let mut peach_config = load_peach_config()?;
|
||||
peach_config.dyn_domain = dyn_domain.to_string();
|
||||
peach_config.dyn_dns_server_address = dyn_dns_server_address.to_string();
|
||||
peach_config.dyn_tsig_key_path = dyn_tsig_key_path.to_string();
|
||||
peach_config.dyn_enabled = dyn_enabled;
|
||||
save_peach_config(peach_config)
|
||||
) -> Result<HashMap<String, String>, PeachError> {
|
||||
let mut peach_config = load_peach_config_from_disc()?;
|
||||
let dyn_enabled_str = match dyn_enabled {
|
||||
true => "true",
|
||||
false => "false"
|
||||
};
|
||||
peach_config.insert("DYN_DOMAIN".to_string(), dyn_domain.to_string());
|
||||
peach_config.insert("DYN_DNS_SERVER_ADDRESS".to_string(), dyn_dns_server_address.to_string());
|
||||
peach_config.insert("DYN_TSIG_KEY_PATH".to_string(), dyn_tsig_key_path.to_string());
|
||||
peach_config.insert("DYN_ENABLED".to_string(), dyn_enabled_str.to_string());
|
||||
save_peach_config_to_disc(peach_config)
|
||||
}
|
||||
|
||||
pub fn set_external_domain(new_external_domain: &str) -> Result<PeachConfig, PeachError> {
|
||||
let mut peach_config = load_peach_config()?;
|
||||
peach_config.external_domain = new_external_domain.to_string();
|
||||
save_peach_config(peach_config)
|
||||
pub fn set_external_domain(new_external_domain: &str) -> Result<HashMap<String, String>, PeachError> {
|
||||
save_peach_config_value("EXTERNAL_DOMAIN", new_external_domain.to_string())
|
||||
}
|
||||
|
||||
pub fn get_peachcloud_domain() -> Result<Option<String>, PeachError> {
|
||||
let peach_config = load_peach_config()?;
|
||||
if !peach_config.external_domain.is_empty() {
|
||||
Ok(Some(peach_config.external_domain))
|
||||
} else if !peach_config.dyn_domain.is_empty() {
|
||||
Ok(Some(peach_config.dyn_domain))
|
||||
let external_domain = get_config_value("EXTERNAL_DOMAIN")?;
|
||||
let dyn_domain = get_config_value("DYN_DOMAIN")?;
|
||||
if !external_domain.is_empty() {
|
||||
Ok(Some(external_domain.to_string()))
|
||||
} else if !dyn_domain.is_empty() {
|
||||
Ok(Some(dyn_domain.to_string()))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_dyndns_server_address() -> Result<String, PeachError> {
|
||||
let peach_config = load_peach_config()?;
|
||||
// if the user is using a custom dyn server then load the address from the config
|
||||
if peach_config.dyn_use_custom_server {
|
||||
Ok(peach_config.dyn_dns_server_address)
|
||||
}
|
||||
// otherwise hardcode the address
|
||||
else {
|
||||
Ok(DEFAULT_DYN_SERVER_ADDRESS.to_string())
|
||||
get_config_value("DYN_DNS_SERVER_ADDRESS")
|
||||
}
|
||||
|
||||
pub fn set_dyndns_enabled_value(enabled_value: bool) -> Result<HashMap<String, String>, PeachError> {
|
||||
match enabled_value {
|
||||
true => save_peach_config_value("DYN_ENABLED", "true".to_string()),
|
||||
false => save_peach_config_value("DYN_ENABLED", "false".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_dyndns_enabled_value(enabled_value: bool) -> Result<PeachConfig, PeachError> {
|
||||
let mut peach_config = load_peach_config()?;
|
||||
peach_config.dyn_enabled = enabled_value;
|
||||
save_peach_config(peach_config)
|
||||
pub fn get_dyndns_enabled_value() -> Result<bool, PeachError> {
|
||||
let val = get_config_value("DYN_ENABLED")?;
|
||||
return Ok(val == "true")
|
||||
}
|
||||
|
||||
pub fn add_ssb_admin_id(ssb_id: &str) -> Result<PeachConfig, PeachError> {
|
||||
let mut peach_config = load_peach_config()?;
|
||||
peach_config.ssb_admin_ids.push(ssb_id.to_string());
|
||||
save_peach_config(peach_config)
|
||||
pub fn add_ssb_admin_id(ssb_id: &str) -> Result<Vec<String>, PeachError> {
|
||||
let mut ssb_admin_ids = get_ssb_admin_ids()?;
|
||||
ssb_admin_ids.push(ssb_id.to_string());
|
||||
save_ssb_admin_ids(ssb_admin_ids)
|
||||
}
|
||||
|
||||
pub fn delete_ssb_admin_id(ssb_id: &str) -> Result<PeachConfig, PeachError> {
|
||||
let mut peach_config = load_peach_config()?;
|
||||
let mut ssb_admin_ids = peach_config.ssb_admin_ids;
|
||||
pub fn delete_ssb_admin_id(ssb_id: &str) -> Result<Vec<String>, PeachError> {
|
||||
let mut ssb_admin_ids = get_ssb_admin_ids()?;
|
||||
let index_result = ssb_admin_ids.iter().position(|x| *x == ssb_id);
|
||||
match index_result {
|
||||
Some(index) => {
|
||||
ssb_admin_ids.remove(index);
|
||||
peach_config.ssb_admin_ids = ssb_admin_ids;
|
||||
save_peach_config(peach_config)
|
||||
save_ssb_admin_ids(ssb_admin_ids)
|
||||
}
|
||||
None => Err(PeachError::SsbAdminIdNotFound {
|
||||
id: ssb_id.to_string(),
|
||||
|
@ -189,32 +201,39 @@ pub fn delete_ssb_admin_id(ssb_id: &str) -> Result<PeachConfig, PeachError> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_admin_password_hash(password_hash: &str) -> Result<PeachConfig, PeachError> {
|
||||
let mut peach_config = load_peach_config()?;
|
||||
peach_config.admin_password_hash = password_hash.to_string();
|
||||
save_peach_config(peach_config)
|
||||
pub fn save_ssb_admin_ids(ssb_admin_ids: Vec<String>) -> Result<Vec<String>, PeachError> {
|
||||
// save_peach_config_value("SSB_ADMIN_IDS", ssb_admin_ids.to_string())
|
||||
// TODO: implement
|
||||
Ok(ssb_admin_ids)
|
||||
}
|
||||
|
||||
pub fn set_admin_password_hash(password_hash: String) -> Result<HashMap<String, String>, PeachError> {
|
||||
save_peach_config_value("ADMIN_PASSWORD_HASH", password_hash)
|
||||
}
|
||||
|
||||
pub fn get_admin_password_hash() -> Result<String, PeachError> {
|
||||
let peach_config = load_peach_config()?;
|
||||
if !peach_config.admin_password_hash.is_empty() {
|
||||
Ok(peach_config.admin_password_hash)
|
||||
let admin_password_hash = get_config_value("ADMIN_PASSWORD_HASH")?;
|
||||
if !admin_password_hash.is_empty() {
|
||||
Ok(admin_password_hash.to_string())
|
||||
} else {
|
||||
Err(PeachError::PasswordNotSet)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_temporary_password_hash(password_hash: &str) -> Result<PeachConfig, PeachError> {
|
||||
let mut peach_config = load_peach_config()?;
|
||||
peach_config.temporary_password_hash = password_hash.to_string();
|
||||
save_peach_config(peach_config)
|
||||
pub fn set_temporary_password_hash(password_hash: String) -> Result<HashMap<String, String>, PeachError> {
|
||||
save_peach_config_value("TEMPORARY_PASSWORD_HASH", password_hash)
|
||||
}
|
||||
|
||||
pub fn get_temporary_password_hash() -> Result<String, PeachError> {
|
||||
let peach_config = load_peach_config()?;
|
||||
if !peach_config.temporary_password_hash.is_empty() {
|
||||
Ok(peach_config.temporary_password_hash)
|
||||
let admin_password_hash = get_config_value("TEMPORARY_PASSWORD_HASH")?;
|
||||
if !admin_password_hash.is_empty() {
|
||||
Ok(admin_password_hash.to_string())
|
||||
} else {
|
||||
Err(PeachError::PasswordNotSet)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_ssb_admin_ids() -> Result<Vec<String>, PeachError> {
|
||||
let mut ssb_admin_ids = vec!["x".to_string(), "y".to_string(), "z".to_string()];
|
||||
Ok(ssb_admin_ids)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ use jsonrpc_client_http::HttpTransport;
|
|||
use log::{debug, info};
|
||||
use regex::Regex;
|
||||
|
||||
use crate::config_manager::get_dyndns_server_address;
|
||||
use crate::config_manager::{get_dyndns_server_address, get_config_value, get_dyndns_enabled_value};
|
||||
use crate::{config_manager, error::PeachError};
|
||||
|
||||
/// constants for dyndns configuration
|
||||
|
@ -107,7 +107,11 @@ fn get_public_ip_address() -> Result<String, PeachError> {
|
|||
/// Reads dyndns configurations from config.yml
|
||||
/// and then uses nsupdate to update the IP address for the configured domain
|
||||
pub fn dyndns_update_ip() -> Result<bool, PeachError> {
|
||||
let peach_config = config_manager::load_peach_config()?;
|
||||
let dyn_tsig_key_path = get_config_value("DYN_TSIG_KEY_PATH")?;
|
||||
let dyn_enabled = get_dyndns_enabled_value()?;
|
||||
let dyn_domain = get_config_value("DYN_DOMAIN")?;
|
||||
let dyn_dns_server_address = get_config_value("DYN_DNS_SERVER_ADDRESS")?;
|
||||
let dyn_nameserver = get_config_value("DYN_NAMESERVER")?;
|
||||
info!(
|
||||
"Using config:
|
||||
dyn_tsig_key_path: {:?}
|
||||
|
@ -116,13 +120,13 @@ pub fn dyndns_update_ip() -> Result<bool, PeachError> {
|
|||
dyn_enabled: {:?}
|
||||
dyn_nameserver: {:?}
|
||||
",
|
||||
peach_config.dyn_tsig_key_path,
|
||||
peach_config.dyn_domain,
|
||||
peach_config.dyn_dns_server_address,
|
||||
peach_config.dyn_enabled,
|
||||
peach_config.dyn_nameserver,
|
||||
dyn_tsig_key_path,
|
||||
dyn_domain,
|
||||
dyn_dns_server_address,
|
||||
dyn_enabled,
|
||||
dyn_nameserver,
|
||||
);
|
||||
if !peach_config.dyn_enabled {
|
||||
if !dyn_enabled {
|
||||
info!("dyndns is not enabled, not updating");
|
||||
Ok(false)
|
||||
} else {
|
||||
|
@ -130,7 +134,7 @@ pub fn dyndns_update_ip() -> Result<bool, PeachError> {
|
|||
let mut nsupdate_command = Command::new("nsupdate");
|
||||
nsupdate_command
|
||||
.arg("-k")
|
||||
.arg(&peach_config.dyn_tsig_key_path)
|
||||
.arg(&dyn_tsig_key_path)
|
||||
.arg("-v");
|
||||
// pass nsupdate commands via stdin
|
||||
let public_ip_address = get_public_ip_address()?;
|
||||
|
@ -142,9 +146,9 @@ pub fn dyndns_update_ip() -> Result<bool, PeachError> {
|
|||
update delete {DOMAIN} A
|
||||
update add {DOMAIN} 30 A {PUBLIC_IP_ADDRESS}
|
||||
send",
|
||||
NAMESERVER = peach_config.dyn_nameserver,
|
||||
ZONE = peach_config.dyn_domain,
|
||||
DOMAIN = peach_config.dyn_domain,
|
||||
NAMESERVER = dyn_nameserver,
|
||||
ZONE = dyn_domain,
|
||||
DOMAIN = dyn_domain,
|
||||
PUBLIC_IP_ADDRESS = public_ip_address,
|
||||
);
|
||||
info!("ns_commands: {:?}", ns_commands);
|
||||
|
@ -217,8 +221,7 @@ pub fn get_num_seconds_since_successful_dns_update() -> Result<Option<i64>, Peac
|
|||
/// and has successfully run recently (in the last six minutes)
|
||||
pub fn is_dns_updater_online() -> Result<bool, PeachError> {
|
||||
// first check if it is enabled in peach-config
|
||||
let peach_config = config_manager::load_peach_config()?;
|
||||
let is_enabled = peach_config.dyn_enabled;
|
||||
let is_enabled = get_dyndns_enabled_value()?;
|
||||
// then check if it has successfully run within the last 6 minutes (60*6 seconds)
|
||||
let num_seconds_since_successful_update = get_num_seconds_since_successful_dns_update()?;
|
||||
let ran_recently: bool = match num_seconds_since_successful_update {
|
||||
|
@ -248,8 +251,7 @@ pub fn get_dyndns_subdomain(dyndns_full_domain: &str) -> Option<String> {
|
|||
|
||||
// helper function which checks if a dyndns domain is new
|
||||
pub fn check_is_new_dyndns_domain(dyndns_full_domain: &str) -> Result<bool, PeachError> {
|
||||
let peach_config = config_manager::load_peach_config()?;
|
||||
let previous_dyndns_domain = peach_config.dyn_domain;
|
||||
let previous_dyndns_domain = get_config_value("DYN_DOMAIN")?;
|
||||
Ok(dyndns_full_domain != previous_dyndns_domain)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,11 @@ use std::{io, str, string};
|
|||
/// This type represents all possible errors that can occur when interacting with the PeachCloud library.
|
||||
#[derive(Debug)]
|
||||
pub enum PeachError {
|
||||
/// Represents looking up a Config value with a non-existent key
|
||||
InvalidKey {
|
||||
msg: String,
|
||||
},
|
||||
|
||||
/// Represents a failure to determine the path of the user's home directory.
|
||||
HomeDir,
|
||||
|
||||
|
@ -102,6 +107,7 @@ impl std::error::Error for PeachError {
|
|||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match *self {
|
||||
PeachError::HomeDir => None,
|
||||
PeachError::InvalidKey{ .. } => None,
|
||||
PeachError::Io(_) => None,
|
||||
PeachError::JsonRpcClientCore(_) => None,
|
||||
PeachError::JsonRpcCore(_) => None,
|
||||
|
@ -130,6 +136,9 @@ impl std::error::Error for PeachError {
|
|||
impl std::fmt::Display for PeachError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match *self {
|
||||
PeachError::InvalidKey { ref msg} => {
|
||||
write!(f, "Invalid key in config lookup: {}", msg)
|
||||
}
|
||||
PeachError::HomeDir => {
|
||||
write!(
|
||||
f,
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn validate_new_passwords(new_password1: &str, new_password2: &str) -> Resul
|
|||
/// Sets a new password for the admin user
|
||||
pub fn set_new_password(new_password: &str) -> Result<(), PeachError> {
|
||||
let new_password_hash = hash_password(new_password);
|
||||
config_manager::set_admin_password_hash(&new_password_hash)?;
|
||||
config_manager::set_admin_password_hash(new_password_hash)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ pub fn hash_password(password: &str) -> String {
|
|||
/// which can be used to reset the permanent password
|
||||
pub fn set_new_temporary_password(new_password: &str) -> Result<(), PeachError> {
|
||||
let new_password_hash = hash_password(new_password);
|
||||
config_manager::set_temporary_password_hash(&new_password_hash)?;
|
||||
config_manager::set_temporary_password_hash(new_password_hash)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -103,8 +103,8 @@ using this link: http://peach.local/auth/reset",
|
|||
};
|
||||
msg += &remote_link;
|
||||
// finally send the message to the admins
|
||||
let peach_config = config_manager::load_peach_config()?;
|
||||
for ssb_admin_id in peach_config.ssb_admin_ids {
|
||||
let ssb_admin_ids = config_manager::get_ssb_admin_ids()?;
|
||||
for ssb_admin_id in ssb_admin_ids {
|
||||
// use golgi to send a private message on scuttlebutt
|
||||
match task::block_on(publish_private_msg(&msg, &ssb_admin_id)) {
|
||||
Ok(_) => (),
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str};
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::error::PeachError;
|
||||
use crate::config_manager::get_config_value;
|
||||
|
||||
/* HELPER FUNCTIONS */
|
||||
|
||||
|
|
Loading…
Reference in New Issue