improv: replace eprintln with logger (#18) + fix mod documentation
This commit is contained in:
parent
45c9112af2
commit
17a098ef89
@ -34,7 +34,10 @@ impl TryFrom<Ini> for Config {
|
||||
match u64::from_str(&exp_time) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
eprintln!("unable to convert JWT expiration time into u64 err={}", e);
|
||||
log::error!(
|
||||
"unable to convert JWT expiration time into u64 details={}",
|
||||
e
|
||||
);
|
||||
0
|
||||
}
|
||||
}
|
||||
@ -59,27 +62,27 @@ impl Config {
|
||||
/// validates config ini file
|
||||
fn validate(&self) -> bool {
|
||||
if self.jwt_exp_time <= 0 {
|
||||
eprintln!("invalid config parameter: JWT expiration time is negative or equals to 0");
|
||||
log::error!("invalid config parameter: JWT expiration time is negative or equals to 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
if self.jwt_issuer == "" {
|
||||
eprintln!("invalid config parameter: JWT issuer is empty");
|
||||
log::error!("invalid config parameter: JWT issuer is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
if self.jwt_pub_key == "" {
|
||||
eprintln!("invalid config parameter: JWT public key file path is empty");
|
||||
log::error!("invalid config parameter: JWT public key file path is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
if self.jwt_priv_key == "" {
|
||||
eprintln!("invalid config parameter: JWT private key file path is empty");
|
||||
log::error!("invalid config parameter: JWT private key file path is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
if self.filestore_path == "" {
|
||||
eprintln!("invalid config parameter: filestore path is empty");
|
||||
log::error!("invalid config parameter: filestore path is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
//! provides `Config` struct to load and validate `.ini` file
|
||||
mod config;
|
||||
|
||||
pub use config::Config;
|
||||
|
||||
@ -115,7 +115,7 @@ async fn test_route() {
|
||||
let config: Config = Config::default();
|
||||
let request_str = "POST /get/ HTTP/1.1\r\n\r\n";
|
||||
|
||||
let response: HTTPResponse = router.route(request_str, config).await;
|
||||
let response: HTTPResponse = router.route(request_str, "".to_string(), config).await;
|
||||
assert_eq!(
|
||||
HTTPStatusCode::Http400,
|
||||
response.status_line.get_status_code()
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
//! simple module to read `.pem` files and sign the token
|
||||
|
||||
use crate::config::Config;
|
||||
use jwt_simple::common::VerificationOptions;
|
||||
use jwt_simple::prelude::*;
|
||||
@ -28,7 +26,7 @@ impl JWTSigner {
|
||||
jwt_signer.private_key = c;
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(format!("unable to read the private key err={}", e));
|
||||
return Err(format!("unable to read the private key details={}", e));
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +35,7 @@ impl JWTSigner {
|
||||
jwt_signer.public_key = c;
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(format!("unable to read the public key err={}", e));
|
||||
return Err(format!("unable to read the public key details={}", e));
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +58,7 @@ impl JWTSigner {
|
||||
match RS384KeyPair::from_pem(&self.private_key) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(format!("unable to load the private key err={}", e));
|
||||
return Err(format!("unable to load the private key details={}", e));
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -70,7 +68,7 @@ impl JWTSigner {
|
||||
match jwt_key.sign(claims) {
|
||||
Ok(token) => Ok(token),
|
||||
Err(e) => {
|
||||
return Err(format!("unable to sign the token err={}", e));
|
||||
return Err(format!("unable to sign the token details={}", e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -82,12 +80,12 @@ impl JWTSigner {
|
||||
if let Err(e) =
|
||||
key.verify_token::<NoCustomClaims>(token, Some(verification_options))
|
||||
{
|
||||
return Err(format!("token validation failed err={}", e));
|
||||
return Err(format!("token validation failed details={}", e));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => Err(format!(
|
||||
"token validation failed can't read the public key err={}",
|
||||
"token validation failed, can't read the public key details={}",
|
||||
e
|
||||
)),
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
//! simple module to read `.pem` files and sign the token
|
||||
mod jwt;
|
||||
|
||||
pub use jwt::JWTSigner;
|
||||
|
||||
@ -41,10 +41,7 @@ impl FileStore {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"error occurred while reading store file: {}, err={:?}",
|
||||
self.path, e
|
||||
);
|
||||
log::error!("while reading store file: {}, details={:?}", self.path, e);
|
||||
}
|
||||
}
|
||||
self.credentials = credentials;
|
||||
@ -69,13 +66,13 @@ impl Store for FileStore {
|
||||
async fn is_auth(&mut self, data: &json::JsonValue) -> bool {
|
||||
// ensure that the store file already exists even after its instanciation
|
||||
if !Path::new(&self.path).is_file() {
|
||||
eprintln!("{} path referencing file store does not exist", self.path);
|
||||
log::error!("{} path referencing file store does not exist", self.path);
|
||||
return false;
|
||||
}
|
||||
|
||||
let credentials = Credentials::from(data);
|
||||
if credentials.is_empty() {
|
||||
eprintln!("unable to parse the credentials correctly from the incoming request");
|
||||
log::error!("unable to parse the credentials correctly from the incoming request");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
//! includes utility function, that's all !
|
||||
mod utils;
|
||||
|
||||
pub use utils::extract_json_value;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user