Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jul 22, 2024
1 parent 4598d43 commit a96fca6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ fn local_config_file() -> String {
}

fn load_key() -> Result<Secret> {
Ok(Secret::from(fs::read(
global_config_folder().join(key_file()),
)?))
let key_path = global_config_folder().join(key_file());
if !key_path.exists() {
return Err(Error::KeyNotFound);
}
Ok(Secret::from(fs::read(key_path)?))
}

pub fn locate_local_config() -> Option<PathBuf> {
Expand Down Expand Up @@ -194,6 +196,8 @@ pub fn load_default_config() -> Result<Vec<Arc<NodeConfig>>> {
pub async fn update_global_config() -> Result<Option<Vec<Arc<NodeConfig>>>> {
static HASH: Mutex<Option<Vec<u8>>> = Mutex::new(None);

log_info!("Config", "Updating resolver config");

let url = format!("{}{}", Updates::url(), global_config_file());
let data = reqwest::get(&url).await?.bytes().await?.to_vec();

Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub enum Error {
#[error("Could not locate local config")]
LocalConfigNotFound,

#[error("Could not locate key file")]
KeyNotFound,

#[error("Passwords do not match")]
PasswordsDoNotMatch,
}
Expand Down
13 changes: 13 additions & 0 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ pub mod impls {
use console::style;
use std::fmt;

pub fn log_info(source: &str, args: &fmt::Arguments<'_>) {
println!("{:>12} {}", style(source).cyan().bold(), args);
}

pub fn log_success(source: &str, args: &fmt::Arguments<'_>) {
println!("{:>12} {}", style(source).green().bold(), args);
}
Expand All @@ -15,6 +19,15 @@ pub mod impls {
}
}

#[macro_export]
macro_rules! log_info {
($target:expr, $($t:tt)*) => (
$crate::log::impls::log_info($target, &format_args!($($t)*))
)
}

pub use log_info;

#[macro_export]
macro_rules! log_success {
($target:expr, $($t:tt)*) => (
Expand Down
4 changes: 2 additions & 2 deletions src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ impl Resolver {
match event {
Events::Start => {
if let Err(err) = self.update(true).await {
log_error!("Config", "{err}");
log_error!("Config", "[startup] {err}");
}
},
Events::Update => {
if let Err(err) = self.update(false).await {
log_error!("Config", "{err}");
log_error!("Config", "[update] {err}");
}
},
}
Expand Down

0 comments on commit a96fca6

Please sign in to comment.