Skip to content

Commit

Permalink
olap
Browse files Browse the repository at this point in the history
  • Loading branch information
racnan committed Jan 30, 2024
1 parent d43547a commit 651582a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/router/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ pub const ROUTING_CONFIG_ID_LENGTH: usize = 10;
pub const LOCKER_REDIS_PREFIX: &str = "LOCKER_PM_TOKEN";
pub const LOCKER_REDIS_EXPIRY_SECONDS: u32 = 60 * 15; // 15 minutes

#[cfg(any(feature = "olap", feature = "oltp"))]
// #[cfg(any(feature = "olap", feature = "oltp"))]
pub const JWT_TOKEN_TIME_IN_SECS: u64 = 60 * 60 * 24 * 2; // 2 days

#[cfg(any(feature = "olap", feature = "oltp"))]
// #[cfg(any(feature = "olap", feature = "oltp"))]
pub const USER_BLACKLIST_PREFIX: &str = "BU_";

#[cfg(feature = "email")]
Expand Down
14 changes: 10 additions & 4 deletions crates/router/src/services/authentication/blacklist.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use std::sync::Arc;

use common_utils::date_time;
use error_stack::{IntoReport, ResultExt};
use redis_interface::RedisConnectionPool;

#[cfg(feature = "olap")]
use crate::core::errors::{UserErrors, UserResult};
#[cfg(feature = "olap")]
use common_utils::date_time;
#[cfg(feature = "olap")]
use crate::routes::AppState;
use crate::{
consts::{JWT_TOKEN_TIME_IN_SECS, USER_BLACKLIST_PREFIX},
core::errors::{ApiErrorResponse, RouterResult, UserErrors, UserResult},
routes::{app::AppStateInfo, AppState},
core::errors::{ApiErrorResponse, RouterResult},
routes::app::AppStateInfo,
};

#[cfg(feature = "olap")]
pub async fn insert_user_in_blacklist(state: &AppState, user_id: &str) -> UserResult<()> {
let token = format!("{}{}", USER_BLACKLIST_PREFIX, user_id);
let expiry =
Expand All @@ -33,7 +39,7 @@ pub async fn check_user_in_blacklist<A: AppStateInfo>(
.get_key::<Option<i64>>(token.as_str())
.await
.change_context(ApiErrorResponse::InternalServerError)
.map(|timestamp| timestamp.is_some_and(|timestamp| timestamp > token_issued_at))
.map(|timestamp| timestamp.map_or(false, |timestamp| timestamp > token_issued_at))
}

fn get_redis_connection<A: AppStateInfo>(state: &A) -> RouterResult<Arc<RedisConnectionPool>> {
Expand Down

0 comments on commit 651582a

Please sign in to comment.