summaryrefslogtreecommitdiff
path: root/src/auth.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-10-15 13:02:28 +0200
committerfx <[email protected]>2023-10-15 13:03:11 +0200
commit981e5c548e7098f4a391384d316ec7a52c1fa979 (patch)
tree4757ccdecb6d266aa49b1351ef093b729ced4a74 /src/auth.rs
parent0948f75248a5daf8229ce1f40d1b3ec8d9aecbac (diff)
downloadwebol-981e5c548e7098f4a391384d316ec7a52c1fa979.tar
webol-981e5c548e7098f4a391384d316ec7a52c1fa979.tar.gz
webol-981e5c548e7098f4a391384d316ec7a52c1fa979.zip
auth logging changes
Diffstat (limited to 'src/auth.rs')
-rw-r--r--src/auth.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/auth.rs b/src/auth.rs
index b7693a0..81e798f 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -1,21 +1,26 @@
1use std::error::Error; 1use std::error::Error;
2use axum::headers::HeaderValue; 2use axum::headers::HeaderValue;
3use axum::http::StatusCode; 3use axum::http::StatusCode;
4use tracing::error; 4use tracing::{debug, error, trace};
5use crate::auth::AuthError::{MissingSecret, ServerError, WrongSecret}; 5use crate::auth::AuthError::{MissingSecret, ServerError, WrongSecret};
6use crate::config::SETTINGS; 6use crate::config::SETTINGS;
7 7
8pub fn auth(secret: Option<&HeaderValue>) -> Result<bool, AuthError> { 8pub fn auth(secret: Option<&HeaderValue>) -> Result<bool, AuthError> {
9 debug!("auth request with secret {:?}", secret);
9 if let Some(value) = secret { 10 if let Some(value) = secret {
11 trace!("value exists");
10 let key = SETTINGS 12 let key = SETTINGS
11 .get_string("apikey") 13 .get_string("apikey")
12 .map_err(|err| ServerError(Box::new(err)))?; 14 .map_err(|err| ServerError(Box::new(err)))?;
13 if value.to_str().map_err(|err| ServerError(Box::new(err)))? == key.as_str() { 15 if value.to_str().map_err(|err| ServerError(Box::new(err)))? == key.as_str() {
16 debug!("successful auth");
14 Ok(true) 17 Ok(true)
15 } else { 18 } else {
19 debug!("unsuccessful auth (wrong secret)");
16 Err(WrongSecret) 20 Err(WrongSecret)
17 } 21 }
18 } else { 22 } else {
23 debug!("unsuccessful auth (no secret)");
19 Err(MissingSecret) 24 Err(MissingSecret)
20 } 25 }
21} 26}