diff options
author | FxQnLr <[email protected]> | 2024-02-25 15:15:19 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2024-02-25 15:15:19 +0100 |
commit | 9058f191b69ecafc8fdeace227ac113412d03888 (patch) | |
tree | 88ae071fa31c9a5831722ec82878ccf8fd2b224a /src/auth.rs | |
parent | 2f9f18b80a9e2134f674f345e48a5f21de5efadd (diff) | |
download | webol-9058f191b69ecafc8fdeace227ac113412d03888.tar webol-9058f191b69ecafc8fdeace227ac113412d03888.tar.gz webol-9058f191b69ecafc8fdeace227ac113412d03888.zip |
Closes #16. Impl auth as extractor
Diffstat (limited to 'src/auth.rs')
-rw-r--r-- | src/auth.rs | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/src/auth.rs b/src/auth.rs deleted file mode 100644 index 22f87e7..0000000 --- a/src/auth.rs +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | use axum::http::HeaderValue; | ||
2 | use tracing::{debug, trace}; | ||
3 | use crate::config::Config; | ||
4 | use crate::error::Error; | ||
5 | |||
6 | pub fn auth(config: &Config, secret: Option<&HeaderValue>) -> Result<Response, Error> { | ||
7 | debug!("auth request with secret {:?}", secret); | ||
8 | let res = if let Some(value) = secret { | ||
9 | trace!("auth value exists"); | ||
10 | let key = &config.apikey; | ||
11 | if value.to_str()? == key.as_str() { | ||
12 | debug!("successful auth"); | ||
13 | Response::Success | ||
14 | } else { | ||
15 | debug!("unsuccessful auth (wrong secret)"); | ||
16 | Response::WrongSecret | ||
17 | } | ||
18 | } else { | ||
19 | debug!("unsuccessful auth (no secret)"); | ||
20 | Response::MissingSecret | ||
21 | }; | ||
22 | Ok(res) | ||
23 | } | ||
24 | |||
25 | #[derive(Debug)] | ||
26 | pub enum Response { | ||
27 | Success, | ||
28 | WrongSecret, | ||
29 | MissingSecret | ||
30 | } | ||