diff --git a/src/config.rs b/src/config.rs index e664e51..3da05aa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,6 @@ use std::fs; use serde::{Deserialize, Deserializer}; use chrono::Duration; -use toml; #[derive(Debug, Deserialize)] diff --git a/src/models/dns.rs b/src/models/dns.rs index b4e8663..334ba96 100644 --- a/src/models/dns.rs +++ b/src/models/dns.rs @@ -3,7 +3,6 @@ use std::fmt; use serde::{Serialize, Deserialize}; use trust_dns_client::serialize::binary::BinEncoder; -use base64; use super::trust_dns_types; diff --git a/src/models/errors.rs b/src/models/errors.rs index 7ae5b4f..c20cf43 100644 --- a/src/models/errors.rs +++ b/src/models/errors.rs @@ -69,15 +69,16 @@ impl From for ErrorResponse { } -impl Into> for ErrorResponse { - fn into(self) -> Outcome { - Outcome::Failure(self.into()) +impl From for Outcome { + fn from(e: ErrorResponse) -> Self { + Outcome::Failure(e.into()) } } -impl Into<(Status, ErrorResponse)> for ErrorResponse { - fn into(self) -> (Status, ErrorResponse) { - (self.status.clone(), self) + +impl From for (Status, ErrorResponse) { + fn from(e: ErrorResponse) -> Self { + (e.status, e) } } @@ -85,7 +86,3 @@ pub fn make_500(e: E) -> ErrorResponse { println!("Making 500 for Error: {:?}", e); ErrorResponse::new(Status::InternalServerError, "An unexpected error occured.".into()) } - -pub fn make_500_tuple(e: E) -> (Status, ErrorResponse) { - make_500(e).into() -} diff --git a/src/models/users.rs b/src/models/users.rs index 85195ef..21e4c7f 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -20,11 +20,11 @@ use jsonwebtoken::{ use crate::schema::*; use crate::DbConn; use crate::config::Config; -use crate::models::errors::{ErrorResponse, make_500_tuple}; +use crate::models::errors::{ErrorResponse, make_500}; -const BEARER: &'static str = "Bearer "; -const AUTH_HEADER: &'static str = "Authentication"; +const BEARER: &str = "Bearer "; +const AUTH_HEADER: &str = "Authentication"; #[derive(Debug, DbEnum, Deserialize, Clone)] @@ -111,8 +111,8 @@ impl<'r> FromRequest<'r> for UserInfo { return ErrorResponse::from(UserError::MalformedHeader).into() }; - let config = try_outcome!(request.guard::>().await.map_failure(make_500_tuple)); - let conn = try_outcome!(request.guard::().await.map_failure(make_500_tuple)); + let config = try_outcome!(request.guard::>().await.map_failure(make_500)); + let conn = try_outcome!(request.guard::().await.map_failure(make_500)); let token_data = AuthClaims::decode( token, &config.web_app.secret @@ -162,9 +162,7 @@ impl From for UserError { impl From for UserError { fn from(e: HasherError) -> Self { - match e { - other => UserError::PasswordError(other) - } + UserError::PasswordError(e) } } @@ -182,7 +180,7 @@ impl LocalUser { }; let new_localuser = LocalUser { - user_id: new_user_id.clone(), + user_id: new_user_id, username: user_request.username.clone(), password: make_password_with_algorithm(&user_request.password, Algorithm::Argon2), }; @@ -256,10 +254,10 @@ impl AuthClaims { let exp = iat + token_duration; AuthClaims { - jti: jti, + jti, sub: user_info.id.clone(), - exp: exp, - iat: iat, + exp, + iat, } } @@ -268,7 +266,7 @@ impl AuthClaims { token, &DecodingKey::from_secret(secret.as_ref()), &Validation::new(JwtAlgorithm::HS256) - ).and_then(|data| Ok(data.claims)) + ).map(|data| data.claims) } pub fn encode(self, secret: &str) -> JwtResult { diff --git a/src/routes/users.rs b/src/routes/users.rs index 0937901..d4c65a3 100644 --- a/src/routes/users.rs +++ b/src/routes/users.rs @@ -21,7 +21,7 @@ pub async fn create_auth_token( let token = AuthClaims::new(&user_info, config.web_app.token_duration) .encode(&config.web_app.secret) - .map_err(|e| make_500(e))?; + .map_err(make_500)?; Ok(Json(AuthTokenResponse { token })) } diff --git a/src/routes/zones.rs b/src/routes/zones.rs index 0d1ec2d..c5e3c01 100644 --- a/src/routes/zones.rs +++ b/src/routes/zones.rs @@ -38,11 +38,9 @@ pub async fn get_zone_records( let answers = response.answers(); let mut records: Vec<_> = answers.to_vec().into_iter() - .map(|record| dns::Record::from(record)) - .filter(|record| match record.rdata { - dns::RData::NULL { .. } | dns::RData::DNSSEC(_) => false, - _ => true, - }).collect(); + .map(dns::Record::from) + .filter(|record| !matches!(record.rdata, dns::RData::NULL { .. } | dns::RData::DNSSEC(_))) + .collect(); // AXFR response ends with SOA, we remove it so it is not doubled in the response. records.pop();