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;
use serde::{Deserialize, Deserializer};
use chrono::Duration;
use toml;
#[derive(Debug, Deserialize)]
......
......@@ -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;
......
......@@ -69,15 +69,16 @@ impl From<UserError> for ErrorResponse {
}
impl<S> Into<Outcome<S, ErrorResponse>> for ErrorResponse {
fn into(self) -> Outcome<S, ErrorResponse> {
Outcome::Failure(self.into())
impl<S> From<ErrorResponse> for Outcome<S, ErrorResponse> {
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<ErrorResponse> for (Status, ErrorResponse) {
fn from(e: ErrorResponse) -> Self {
(e.status, e)
}
}
......@@ -85,7 +86,3 @@ pub fn make_500<E: std::fmt::Debug>(e: E) -> ErrorResponse {
println!("Making 500 for Error: {:?}", e);
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::{
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::<State<Config>>().await.map_failure(make_500_tuple));
let conn = try_outcome!(request.guard::<DbConn>().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));
let token_data = AuthClaims::decode(
token, &config.web_app.secret
......@@ -162,9 +162,7 @@ impl From<DieselError> for UserError {
impl From<HasherError> 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<String> {
......
......@@ -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 }))
}
......
......@@ -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();
......
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