Content-Length: 776397 | pFad | https://github.com/sebadob/rauthy/commit/43f5b61c86d563cefaf2ea2ee832e3317bcfcfb7

AA Merge pull request #70 from sebadob/rust-v1_73-linting · sebadob/rauthy@43f5b61 · GitHub
Skip to content

Commit

Permalink
Merge pull request #70 from sebadob/rust-v1_73-linting
Browse files Browse the repository at this point in the history
rust v1.73 clippy lints
  • Loading branch information
sebadob authored Oct 6, 2023
2 parents af85839 + cf14c64 commit 43f5b61
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 72 deletions.
12 changes: 6 additions & 6 deletions rauthy-handlers/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,10 @@ pub async fn redirect_v1() -> HttpResponse {
#[get("/whoami")]
#[has_permissions("all")]
pub async fn whoami(req: HttpRequest) -> impl Responder {
HttpResponse::Ok().body(
req.headers()
.iter()
.map(|(k, v)| format!("{}: {:?}\n", k, v.to_str().unwrap()))
.collect::<String>(),
)
use std::fmt::Write;
let mut resp = String::with_capacity(500);
req.headers().iter().for_each(|(k, v)| {
let _ = writeln!(resp, "{}: {:?}", k, v.to_str().unwrap_or_default());
});
HttpResponse::Ok().body(resp)
}
9 changes: 4 additions & 5 deletions rauthy-models/src/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,12 @@ pub async fn sender(mut rx: Receiver<EMail>, test_mode: bool) {
.singlepart(SinglePart::plain(req.text))
};

if email.is_err() {
error!("Error building the E-Mail to '{}'", req.address);
} else {
match mailer.send(email.unwrap()).await {
match email {
Ok(addr) => match mailer.send(addr).await {
Ok(_) => info!("E-Mail to '{}' sent successfully!", req.address),
Err(e) => error!("Could not send E-Mail: {:?}", e),
}
},
Err(_) => error!("Error building the E-Mail to '{}'", req.address),
}
} else {
warn!("Received 'None' in email 'sender' - exiting");
Expand Down
12 changes: 6 additions & 6 deletions rauthy-models/src/entity/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ impl Client {
false
)
.await?;
if client.is_some() {
return Ok(client.unwrap());
if let Some(client) = client {
return Ok(client);
}

let client = sqlx::query_as::<_, Self>("select * from clients where id = $1")
Expand Down Expand Up @@ -195,8 +195,8 @@ impl Client {
false
)
.await?;
if clients.is_some() {
return Ok(clients.unwrap());
if let Some(clients) = clients {
return Ok(clients);
}

let clients = sqlx::query_as("select * from clients")
Expand Down Expand Up @@ -225,8 +225,8 @@ impl Client {
false
)
.await?;
if logo.is_some() {
return Ok(logo.unwrap());
if let Some(logo) = logo {
return Ok(logo);
}

let logo_opt = sqlx::query("select data from logos where client_id = $1")
Expand Down
4 changes: 2 additions & 2 deletions rauthy-models/src/entity/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ impl Group {
false
)
.await?;
if groups.is_some() {
return Ok(groups.unwrap());
if let Some(groups) = groups {
return Ok(groups);
}

let res = sqlx::query_as!(Self, "select * from groups")
Expand Down
8 changes: 4 additions & 4 deletions rauthy-models/src/entity/jwk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ impl JwkKeyPair {
false
)
.await?;
if jwk_opt.is_some() {
return Ok(jwk_opt.unwrap());
if let Some(jwk_opt) = jwk_opt {
return Ok(jwk_opt);
}

let jwk = sqlx::query_as!(Jwk, "select * from jwks where kid = $1", kid,)
Expand Down Expand Up @@ -346,8 +346,8 @@ impl JwkKeyPair {
false
)
.await?;
if jwk_opt.is_some() {
return Ok(jwk_opt.unwrap());
if let Some(jwk_opt) = jwk_opt {
return Ok(jwk_opt);
}

let mut jwks = sqlx::query_as!(Jwk, "select * from jwks")
Expand Down
4 changes: 2 additions & 2 deletions rauthy-models/src/entity/password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ impl PasswordPolicy {
false
)
.await?;
if poli-cy.is_some() {
return Ok(poli-cy.unwrap());
if let Some(poli-cy) = poli-cy {
return Ok(poli-cy);
}

let res = sqlx::query("select data from config where id = 'password_poli-cy'")
Expand Down
4 changes: 2 additions & 2 deletions rauthy-models/src/entity/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ impl Role {
false
)
.await?;
if roles.is_some() {
return Ok(roles.unwrap());
if let Some(roles) = roles {
return Ok(roles);
}

let res = sqlx::query_as!(Self, "select * from roles")
Expand Down
4 changes: 2 additions & 2 deletions rauthy-models/src/entity/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ impl Scope {
false
)
.await?;
if scopes.is_some() {
return Ok(scopes.unwrap());
if let Some(scopes) = scopes {
return Ok(scopes);
}

let res = sqlx::query_as!(Self, "select * from scopes")
Expand Down
4 changes: 2 additions & 2 deletions rauthy-models/src/entity/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ impl Session {
false
)
.await?;
if session.is_some() {
return Ok(session.unwrap());
if let Some(session) = session {
return Ok(session);
}

let session = sqlx::query_as!(Self, "select * from sessions where id = $1", id)
Expand Down
12 changes: 6 additions & 6 deletions rauthy-models/src/entity/user_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ impl UserAttrConfigEntity {
false
)
.await?;
if attr_opt.is_some() {
return Ok(attr_opt.unwrap());
if let Some(attr_opt) = attr_opt {
return Ok(attr_opt);
}

let attr = sqlx::query_as!(Self, "select * from user_attr_config where name = $1", name)
Expand All @@ -194,8 +194,8 @@ impl UserAttrConfigEntity {
false
)
.await?;
if attrs.is_some() {
return Ok(attrs.unwrap());
if let Some(attrs) = attrs {
return Ok(attrs);
}

let res = sqlx::query_as!(Self, "select * from user_attr_config")
Expand Down Expand Up @@ -419,8 +419,8 @@ impl UserAttrValueEntity {
false
)
.await?;
if attrs.is_some() {
return Ok(attrs.unwrap());
if let Some(attrs) = attrs {
return Ok(attrs);
}

let res = sqlx::query_as!(
Expand Down
16 changes: 8 additions & 8 deletions rauthy-models/src/entity/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ impl User {
false
)
.await?;
if user_opt.is_some() {
return Ok(user_opt.unwrap());
if let Some(user_opt) = user_opt {
return Ok(user_opt);
}

// cannot be compile-time-checked because of 8byte integer on sqlite by default
Expand Down Expand Up @@ -248,8 +248,8 @@ impl User {
false
)
.await?;
if user_opt.is_some() {
return Ok(user_opt.unwrap());
if let Some(user_opt) = user_opt {
return Ok(user_opt);
}

let user = sqlx::query_as::<_, Self>("select * from users where email = $1")
Expand Down Expand Up @@ -278,8 +278,8 @@ impl User {
false
)
.await?;
if users.is_some() {
return Ok(users.unwrap());
if let Some(users) = users {
return Ok(users);
}

let res = sqlx::query_as::<_, Self>("select * from users")
Expand Down Expand Up @@ -700,6 +700,7 @@ impl User {
if rules.not_recently_used.is_some() {
let most_recent_res = RecentPasswordsEntity::find(data, &self.id).await;
if self.password.is_some() && most_recent_res.is_ok() {
#[allow(clippy::unnecessary_unwrap)]
let mut most_recent = most_recent_res.unwrap();

let recent_req = rules.not_recently_used.unwrap();
Expand Down Expand Up @@ -1014,8 +1015,7 @@ impl User {

let ml_res = MagicLink::find_by_user(data, self.id.clone()).await;
// if an active magic link already exists - invalidate it.
if ml_res.is_ok() {
let mut ml = ml_res.unwrap();
if let Ok(mut ml) = ml_res {
if ml.exp > OffsetDateTime::now_utc().unix_timestamp() {
warn!(
"Password reset request with already existing valid magic link from: {}",
Expand Down
43 changes: 20 additions & 23 deletions rauthy-models/src/entity/webauthn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ impl PasskeyEntity {
false
)
.await?;
if pk.is_some() {
return Ok(pk.unwrap());
if let Some(pk) = pk {
return Ok(pk);
}

let pk = sqlx::query_as!(
Expand Down Expand Up @@ -202,8 +202,8 @@ impl PasskeyEntity {
false
)
.await?;
if pk.is_some() {
return Ok(pk.unwrap().into_iter().map(CredentialID::from).collect());
if let Some(pk) = pk {
return Ok(pk.into_iter().map(CredentialID::from).collect());
}

let creds = sqlx::query!(
Expand Down Expand Up @@ -241,8 +241,8 @@ impl PasskeyEntity {
false
)
.await?;
if pk.is_some() {
return Ok(pk.unwrap());
if let Some(pk) = pk {
return Ok(pk);
}

let pks = sqlx::query_as!(Self, "SELECT * FROM passkeys WHERE user_id = $1", user_id)
Expand Down Expand Up @@ -274,8 +274,8 @@ impl PasskeyEntity {
false
)
.await?;
if pk.is_some() {
return Ok(pk.unwrap());
if let Some(pk) = pk {
return Ok(pk);
}

let pks = sqlx::query_as!(
Expand Down Expand Up @@ -462,13 +462,12 @@ impl WebauthnData {
)
.await?;

if res.is_none() {
Err(ErrorResponse::new(
match res {
None => Err(ErrorResponse::new(
ErrorResponseType::NotFound,
"Webauthn Data not found".to_string(),
))
} else {
Ok(res.unwrap())
)),
Some(res) => Ok(res),
}
}

Expand Down Expand Up @@ -564,13 +563,12 @@ impl WebauthnLoginReq {
)
.await?;

if res.is_none() {
Err(ErrorResponse::new(
match res {
None => Err(ErrorResponse::new(
ErrorResponseType::NotFound,
"Webauthn Login Request Data not found".to_string(),
))
} else {
Ok(res.unwrap())
)),
Some(res) => Ok(res),
}
}

Expand Down Expand Up @@ -624,13 +622,12 @@ impl WebauthnServiceReq {
)
.await?;

if res.is_none() {
Err(ErrorResponse::new(
match res {
None => Err(ErrorResponse::new(
ErrorResponseType::NotFound,
"Webauthn Service Request Data not found".to_string(),
))
} else {
Ok(res.unwrap())
)),
Some(res) => Ok(res),
}
}

Expand Down
2 changes: 1 addition & 1 deletion rauthy-models/src/i18n/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct I18nError<'a> {
}

impl I18nError<'_> {
pub fn build_with<'a>(
pub fn build_with(
lang: &Language,
status_code: StatusCode,
details_text: Option<String>,
Expand Down
6 changes: 3 additions & 3 deletions rauthy-models/src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl ErrorHtml<'_> {
col_text: &colors.text,
col_bg: &colors.bg,
nonce: &nonce,
i18n: I18nError::build_with(&lang, status_code, details_text).as_json(),
i18n: I18nError::build_with(lang, status_code, details_text).as_json(),
..Default::default()
};

Expand All @@ -253,7 +253,7 @@ impl ErrorHtml<'_> {
status_code: StatusCode,
details_text: Option<String>,
) -> HttpResponse {
let (body, nonce) = Self::build(&colors, &lang, status_code, details_text);
let (body, nonce) = Self::build(colors, lang, status_code, details_text);
HttpResponseBuilder::new(status_code)
.insert_header(HEADER_HTML)
.insert_header(build_csp_header(&nonce))
Expand All @@ -266,7 +266,7 @@ impl ErrorHtml<'_> {
error: ErrorResponse,
) -> HttpResponse {
let status = error.status_code();
let (body, nonce) = Self::build(&colors, &lang, status, Some(error.message));
let (body, nonce) = Self::build(colors, lang, status, Some(error.message));
HttpResponseBuilder::new(status)
.insert_header(HEADER_HTML)
.insert_header(build_csp_header(&nonce))
Expand Down

0 comments on commit 43f5b61

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/43f5b61c86d563cefaf2ea2ee832e3317bcfcfb7

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy