Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
DNS Witch
Nomilo
Commits
b3dab424
Commit
b3dab424
authored
Apr 04, 2021
by
Gaël Berthaud-Müller
Browse files
apply linter suggestions
parent
791b86f3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
31 deletions
+22
-31
src/config.rs
src/config.rs
+0
-1
src/models/dns.rs
src/models/dns.rs
+0
-1
src/models/errors.rs
src/models/errors.rs
+7
-10
src/models/users.rs
src/models/users.rs
+11
-13
src/routes/users.rs
src/routes/users.rs
+1
-1
src/routes/zones.rs
src/routes/zones.rs
+3
-5
No files found.
src/config.rs
View file @
b3dab424
...
...
@@ -4,7 +4,6 @@ use std::fs;
use
serde
::{
Deserialize
,
Deserializer
};
use
chrono
::
Duration
;
use
toml
;
#[derive(Debug,
Deserialize)]
...
...
src/models/dns.rs
View file @
b3dab424
...
...
@@ -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
;
...
...
src/models/errors.rs
View file @
b3dab424
...
...
@@ -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
()
}
src/models/users.rs
View file @
b3dab424
...
...
@@ -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
>
{
...
...
src/routes/users.rs
View file @
b3dab424
...
...
@@ -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
}))
}
...
...
src/routes/zones.rs
View file @
b3dab424
...
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment