diff options
author | FxQnLr <[email protected]> | 2023-10-15 17:51:08 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2023-10-15 17:51:08 +0200 |
commit | e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b (patch) | |
tree | 4d7a2e553c0ea67f7aa3c63d788d76d714479fd1 /src/auth.rs | |
parent | b0e8aabfb9ea0f4c40a2aa330dd59f07b6c91216 (diff) | |
parent | abd4fbbf0ebd0385f68507eb20f9385db1b96793 (diff) | |
download | webol-e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b.tar webol-e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b.tar.gz webol-e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b.zip |
Merge pull request #2 from FxQnLr/test
Get working actions and build into main
Diffstat (limited to 'src/auth.rs')
-rw-r--r-- | src/auth.rs | 7 |
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 @@ | |||
1 | use std::error::Error; | 1 | use std::error::Error; |
2 | use axum::headers::HeaderValue; | 2 | use axum::headers::HeaderValue; |
3 | use axum::http::StatusCode; | 3 | use axum::http::StatusCode; |
4 | use tracing::error; | 4 | use tracing::{debug, error, trace}; |
5 | use crate::auth::AuthError::{MissingSecret, ServerError, WrongSecret}; | 5 | use crate::auth::AuthError::{MissingSecret, ServerError, WrongSecret}; |
6 | use crate::config::SETTINGS; | 6 | use crate::config::SETTINGS; |
7 | 7 | ||
8 | pub fn auth(secret: Option<&HeaderValue>) -> Result<bool, AuthError> { | 8 | pub 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 | } |