🏡 index : ~doyle/jogre.git

author Jordan Doyle <jordan@doyle.la> 2023-09-18 1:42:09.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-09-18 1:42:09.0 +01:00:00
commit
1fdfbe1fe57efab99023318fe4e5e9782869664b [patch]
tree
c881d7ccbc965f4244c63b8fbab738a72ccaa3af
parent
f656ad1f8bb9904c6b8f1612c515f4fbad726780
download
1fdfbe1fe57efab99023318fe4e5e9782869664b.tar.gz

Deny clippy::pedantic



Diff

 jogre-server/src/main.rs                    | 3 +++
 jogre-server/src/layers/auth_required.rs    | 3 ++-
 jogre-server/src/methods/session.rs         | 9 +++++++--
 jogre-server/src/store/rocksdb.rs           | 5 +++--
 jogre-server/src/methods/oauth/authorize.rs | 7 +++++++
 jogre-server/src/methods/oauth/refresh.rs   | 7 +++++++
 jogre-server/src/methods/oauth/token.rs     | 4 +++-
 7 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/jogre-server/src/main.rs b/jogre-server/src/main.rs
index d6968bf..2dd4f5b 100644
--- a/jogre-server/src/main.rs
+++ a/jogre-server/src/main.rs
@@ -1,3 +1,6 @@
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]

mod config;
mod context;
mod layers;
diff --git a/jogre-server/src/layers/auth_required.rs b/jogre-server/src/layers/auth_required.rs
index 5285ba4..7e4e1d3 100644
--- a/jogre-server/src/layers/auth_required.rs
+++ a/jogre-server/src/layers/auth_required.rs
@@ -7,6 +7,7 @@
    response::{IntoResponse, Response},
    RequestExt,
};
use oxide_auth::frontends::simple::endpoint;
use oxide_auth_axum::{OAuthResource, WebError};
use tracing::{debug, error};

@@ -29,7 +30,7 @@
        Ok(v) => v,
        Err(e) => {
            error!("Rejecting request due to it being unauthorized");
            return e.map_err(|e| e.pack::<WebError>()).into_response();
            return e.map_err(endpoint::Error::pack::<WebError>).into_response();
        }
    };

diff --git a/jogre-server/src/methods/session.rs b/jogre-server/src/methods/session.rs
index 53b7581..ede525f 100644
--- a/jogre-server/src/methods/session.rs
+++ a/jogre-server/src/methods/session.rs
@@ -1,4 +1,7 @@
use std::sync::{Arc, OnceLock};
use std::{
    collections::{BTreeSet, HashMap},
    sync::{Arc, OnceLock},
};

use axum::{extract::State, Extension, Json};
use jmap_proto::{
@@ -72,11 +75,11 @@
                max_calls_in_request: context.core_capabilities.max_calls_in_request.into(),
                max_objects_in_get: context.core_capabilities.max_objects_in_get.into(),
                max_objects_in_set: context.core_capabilities.max_objects_in_set.into(),
                collation_algorithms: Default::default(),
                collation_algorithms: BTreeSet::default(),
            },
        },
        accounts,
        primary_accounts: Default::default(),
        primary_accounts: HashMap::default(),
        username: username.into(),
        api_url: API_URL
            .get_or_init(|| {
diff --git a/jogre-server/src/store/rocksdb.rs b/jogre-server/src/store/rocksdb.rs
index e8813df..9259200 100644
--- a/jogre-server/src/store/rocksdb.rs
+++ a/jogre-server/src/store/rocksdb.rs
@@ -54,12 +54,13 @@
    }
}

#[allow(clippy::unnecessary_wraps)] // rocksdb api restriction
fn rocksdb_merger(
    _new_key: &[u8],
    existing_val: Option<&[u8]>,
    operands: &MergeOperands,
) -> Option<Vec<u8>> {
    let mut new_val = existing_val.map(|v| v.to_vec()).unwrap_or_default();
    let mut new_val = existing_val.map(<[u8]>::to_vec).unwrap_or_default();

    for operand in operands {
        let (operation, operand) = MergeOperation::parse(operand);
@@ -153,7 +154,7 @@
        Ok(self
            .db
            .prefix_iterator_cf(access_handle, user_id.as_bytes())
            .map(|v| v.unwrap())
            .map(Result::unwrap)
            .filter_map(|(key, _access_level)| {
                let Some(account) = key.strip_prefix(user_id.as_bytes()) else {
                    panic!("got invalid key from rocksdb");
diff --git a/jogre-server/src/methods/oauth/authorize.rs b/jogre-server/src/methods/oauth/authorize.rs
index 0cf85da..2b393d0 100644
--- a/jogre-server/src/methods/oauth/authorize.rs
+++ a/jogre-server/src/methods/oauth/authorize.rs
@@ -1,13 +1,18 @@
use std::sync::Arc;

use axum::extract::State;
use oxide_auth::frontends::simple::endpoint;
use oxide_auth_axum::{OAuthResponse, WebError};

use crate::context::{oauth2::OAuthRequestWrapper, Context};

#[allow(clippy::unused_async)]
pub async fn handle(
    State(context): State<Arc<Context>>,
    request: OAuthRequestWrapper,
) -> Result<OAuthResponse, WebError> {
    context.oauth2.authorize(request).map_err(|e| e.pack())
    context
        .oauth2
        .authorize(request)
        .map_err(endpoint::Error::pack)
}
diff --git a/jogre-server/src/methods/oauth/refresh.rs b/jogre-server/src/methods/oauth/refresh.rs
index 0c4fe6a..9ae918f 100644
--- a/jogre-server/src/methods/oauth/refresh.rs
+++ a/jogre-server/src/methods/oauth/refresh.rs
@@ -1,13 +1,18 @@
use std::sync::Arc;

use axum::extract::State;
use oxide_auth::frontends::simple::endpoint;
use oxide_auth_axum::{OAuthResponse, WebError};

use crate::context::{oauth2::OAuthRequestWrapper, Context};

#[allow(clippy::unused_async)]
pub async fn handle(
    State(context): State<Arc<Context>>,
    request: OAuthRequestWrapper,
) -> Result<OAuthResponse, WebError> {
    context.oauth2.refresh(request).map_err(|e| e.pack())
    context
        .oauth2
        .refresh(request)
        .map_err(endpoint::Error::pack)
}
diff --git a/jogre-server/src/methods/oauth/token.rs b/jogre-server/src/methods/oauth/token.rs
index 36720c5..7ce9c20 100644
--- a/jogre-server/src/methods/oauth/token.rs
+++ a/jogre-server/src/methods/oauth/token.rs
@@ -1,13 +1,15 @@
use std::sync::Arc;

use axum::extract::State;
use oxide_auth::frontends::simple::endpoint;
use oxide_auth_axum::{OAuthResponse, WebError};

use crate::context::{oauth2::OAuthRequestWrapper, Context};

#[allow(clippy::unused_async)]
pub async fn handle(
    State(context): State<Arc<Context>>,
    request: OAuthRequestWrapper,
) -> Result<OAuthResponse, WebError> {
    context.oauth2.token(request).map_err(|e| e.pack())
    context.oauth2.token(request).map_err(endpoint::Error::pack)
}