Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
Frank Villaro-Dixon 2024-05-28 11:24:38 +02:00
parent 7ab7caa50e
commit 104de8e87e
2 changed files with 6 additions and 9 deletions

View file

@ -44,7 +44,7 @@ impl Auth {
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
hasher.update(token); hasher.update(token);
let result = hasher.finalize(); let result = hasher.finalize();
return format!("{:x}", result) == self.hash; format!("{:x}", result) == self.hash
} }
_ => false, _ => false,
} }
@ -81,7 +81,7 @@ fn default_opentsdb_url() -> String {
pub fn load_config_file(filename: &str) -> Config { pub fn load_config_file(filename: &str) -> Config {
let yaml_content = fs::read_to_string(filename) let yaml_content = fs::read_to_string(filename)
.expect(format!("Unable to read config file {}", filename).as_str()); .unwrap_or_else(|_| panic!("Unable to read config file {}", filename));
let config: Config = serde_yaml::from_str(&yaml_content).expect("Unable to parse YAML"); let config: Config = serde_yaml::from_str(&yaml_content).expect("Unable to parse YAML");
config config
} }

View file

@ -1,7 +1,7 @@
use actix_web::http::StatusCode; use actix_web::http::StatusCode;
use actix_web::middleware::Logger; use actix_web::middleware::Logger;
use actix_web::{error, web, App, HttpResponse, HttpServer, Responder}; use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use log::{debug, error, info, log_enabled, Level}; use log::{debug, error, info};
use reqwest::Client; use reqwest::Client;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
@ -64,7 +64,7 @@ async fn put_post(
client.metrics.join(", ") client.metrics.join(", ")
); );
error!("{}", emsg); error!("{}", emsg);
return HttpResponse::Forbidden().body(format!("{}", emsg)); return HttpResponse::Forbidden().body(emsg.to_string());
} }
let post_url = format!("{}put", shared.cfg.config.opentsdb.url); let post_url = format!("{}put", shared.cfg.config.opentsdb.url);
@ -113,10 +113,7 @@ async fn main() -> std::io::Result<()> {
let web_client = Client::new(); let web_client = Client::new();
let shared = ClientData { let shared = ClientData { web_client, cfg };
web_client: web_client,
cfg: cfg,
};
let client_data = web::Data::new(shared); let client_data = web::Data::new(shared);
HttpServer::new(move || { HttpServer::new(move || {