Commit b3dab424 authored by Gaël Berthaud-Müller's avatar Gaël Berthaud-Müller
Browse files

apply linter suggestions

parent 791b86f3
...@@ -4,7 +4,6 @@ use std::fs; ...@@ -4,7 +4,6 @@ use std::fs;
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
use chrono::Duration; use chrono::Duration;
use toml;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
......
...@@ -3,7 +3,6 @@ use std::fmt; ...@@ -3,7 +3,6 @@ use std::fmt;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use trust_dns_client::serialize::binary::BinEncoder; use trust_dns_client::serialize::binary::BinEncoder;
use base64;
use super::trust_dns_types; use super::trust_dns_types;
......
...@@ -69,15 +69,16 @@ impl From<UserError> for ErrorResponse { ...@@ -69,15 +69,16 @@ impl From<UserError> for ErrorResponse {
} }
impl<S> Into<Outcome<S, ErrorResponse>> for ErrorResponse { impl<S> From<ErrorResponse> for Outcome<S, ErrorResponse> {
fn into(self) -> Outcome<S, ErrorResponse> { fn from(e: ErrorResponse) -> Self {
Outcome::Failure(self.into()) Outcome::Failure(e.into())
} }
} }
impl Into<(Status, ErrorResponse)> for ErrorResponse {
fn into(self) -> (Status, ErrorResponse) { impl From<ErrorResponse> for (Status, ErrorResponse) {
(self.status.clone(), self) fn from(e: ErrorResponse) -> Self {
(e.status, e)
} }
} }
...@@ -85,7 +86,3 @@ pub fn make_500<E: std::fmt::Debug>(e: E) -> ErrorResponse { ...@@ -85,7 +86,3 @@ pub fn make_500<E: std::fmt::Debug>(e: E) -> ErrorResponse {
println!("Making 500 for Error: {:?}", e); println!("Making 500 for Error: {:?}", e);
ErrorResponse::new(Status::InternalServerError, "An unexpected error occured.".into()) ErrorResponse::new(Status::InternalServerError, "An unexpected error occured.".into())
} }
pub fn make_500_tuple<E: std::fmt::Debug>(e: E) -> (Status, ErrorResponse) {
make_500(e).into()
}
...@@ -20,11 +20,11 @@ use jsonwebtoken::{ ...@@ -20,11 +20,11 @@ use jsonwebtoken::{
use crate::schema::*; use crate::schema::*;
use crate::DbConn; use crate::DbConn;
use crate::config::Config; 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 BEARER: &str = "Bearer ";
const AUTH_HEADER: &'static str = "Authentication"; const AUTH_HEADER: &str = "Authentication";
#[derive(Debug, DbEnum, Deserialize, Clone)] #[derive(Debug, DbEnum, Deserialize, Clone)]
...@@ -111,8 +111,8 @@ impl<'r> FromRequest<'r> for UserInfo { ...@@ -111,8 +111,8 @@ impl<'r> FromRequest<'r> for UserInfo {
return ErrorResponse::from(UserError::MalformedHeader).into() return ErrorResponse::from(UserError::MalformedHeader).into()
}; };
let config = try_outcome!(request.guard::<State<Config>>().await.map_failure(make_500_tuple)); let config = try_outcome!(request.guard::<State<Config>>().await.map_failure(make_500));
let conn = try_outcome!(request.guard::<DbConn>().await.map_failure(make_500_tuple)); let conn = try_outcome!(request.guard::<DbConn>().await.map_failure(make_500));
let token_data = AuthClaims::decode( let token_data = AuthClaims::decode(
token, &config.web_app.secret token, &config.web_app.secret
...@@ -162,9 +162,7 @@ impl From<DieselError> for UserError { ...@@ -162,9 +162,7 @@ impl From<DieselError> for UserError {
impl From<HasherError> for UserError { impl From<HasherError> for UserError {
fn from(e: HasherError) -> Self { fn from(e: HasherError) -> Self {
match e { UserError::PasswordError(e)
other => UserError::PasswordError(other)
}
} }
} }
...@@ -182,7 +180,7 @@ impl LocalUser { ...@@ -182,7 +180,7 @@ impl LocalUser {
}; };
let new_localuser = LocalUser { let new_localuser = LocalUser {
user_id: new_user_id.clone(), user_id: new_user_id,
username: user_request.username.clone(), username: user_request.username.clone(),
password: make_password_with_algorithm(&user_request.password, Algorithm::Argon2), password: make_password_with_algorithm(&user_request.password, Algorithm::Argon2),
}; };
...@@ -256,10 +254,10 @@ impl AuthClaims { ...@@ -256,10 +254,10 @@ impl AuthClaims {
let exp = iat + token_duration; let exp = iat + token_duration;
AuthClaims { AuthClaims {
jti: jti, jti,
sub: user_info.id.clone(), sub: user_info.id.clone(),
exp: exp, exp,
iat: iat, iat,
} }
} }
...@@ -268,7 +266,7 @@ impl AuthClaims { ...@@ -268,7 +266,7 @@ impl AuthClaims {
token, token,
&DecodingKey::from_secret(secret.as_ref()), &DecodingKey::from_secret(secret.as_ref()),
&Validation::new(JwtAlgorithm::HS256) &Validation::new(JwtAlgorithm::HS256)
).and_then(|data| Ok(data.claims)) ).map(|data| data.claims)
} }
pub fn encode(self, secret: &str) -> JwtResult<String> { pub fn encode(self, secret: &str) -> JwtResult<String> {
......
...@@ -21,7 +21,7 @@ pub async fn create_auth_token( ...@@ -21,7 +21,7 @@ pub async fn create_auth_token(
let token = AuthClaims::new(&user_info, config.web_app.token_duration) let token = AuthClaims::new(&user_info, config.web_app.token_duration)
.encode(&config.web_app.secret) .encode(&config.web_app.secret)
.map_err(|e| make_500(e))?; .map_err(make_500)?;
Ok(Json(AuthTokenResponse { token })) Ok(Json(AuthTokenResponse { token }))
} }
......
...@@ -38,11 +38,9 @@ pub async fn get_zone_records( ...@@ -38,11 +38,9 @@ pub async fn get_zone_records(
let answers = response.answers(); let answers = response.answers();
let mut records: Vec<_> = answers.to_vec().into_iter() let mut records: Vec<_> = answers.to_vec().into_iter()
.map(|record| dns::Record::from(record)) .map(dns::Record::from)
.filter(|record| match record.rdata { .filter(|record| !matches!(record.rdata, dns::RData::NULL { .. } | dns::RData::DNSSEC(_)))
dns::RData::NULL { .. } | dns::RData::DNSSEC(_) => false, .collect();
_ => true,
}).collect();
// AXFR response ends with SOA, we remove it so it is not doubled in the response. // AXFR response ends with SOA, we remove it so it is not doubled in the response.
records.pop(); records.pop();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment