Skip to content

Commit

Permalink
Update chrono to use const expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
themisir committed Feb 18, 2024
1 parent ec32de7 commit 60c8a62
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 21 deletions.
85 changes: 71 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "identity"
version = "0.1.7"
version = "0.1.8"
edition = "2021"

[dependencies]
Expand Down Expand Up @@ -38,7 +38,7 @@ argon2 = "0.5"

sqlx = { version = "0.7", features = ["runtime-tokio", "sqlite", "chrono"] }
refinery = { version = "0.8", features = ["rusqlite"] }
chrono = { version = "0.4", features = ["serde"] }
chrono = { version = "0.4.34", features = ["serde"] }

url = { version = "2.4", features = ["serde"] }

Expand Down
9 changes: 4 additions & 5 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use cookie::Cookie;
use hyper::{client::HttpConnector, Body};
use hyper_tls::HttpsConnector;
use log::{error, info, warn};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};

pub async fn middleware(
Expand Down Expand Up @@ -56,8 +55,8 @@ pub async fn middleware(

pub const PROXY_COOKIE_NAME: &str = "_identity.im";
pub const PROXY_AUTHORIZE_ENDPOINT: &str = "/.identity/authorize";
pub static PROXY_TOKEN_TTL: Lazy<Duration> = Lazy::new(|| Duration::hours(1));
pub static PROXY_TOKEN_REFRESH_THRESHOLD: Lazy<Duration> = Lazy::new(|| Duration::minutes(15));
pub const PROXY_TOKEN_TTL: Duration = Duration::hours(1);
pub const PROXY_TOKEN_REFRESH_THRESHOLD: Duration = Duration::minutes(15);

pub struct ProxyClient {
config: UpstreamConfig,
Expand Down Expand Up @@ -130,7 +129,7 @@ impl ProxyClient {
}
};

let token_ttl = cfg.cookie_ttl.map_or(*PROXY_TOKEN_TTL, |v| v.into());
let token_ttl = cfg.cookie_ttl.map_or(PROXY_TOKEN_TTL, |v| v.into());

Ok(Self {
config: cfg.clone(),
Expand Down Expand Up @@ -186,7 +185,7 @@ impl ProxyClient {
state: &AppState,
claims: &Claims,
) -> anyhow::Result<Option<String>> {
let refresh_needed = claims.valid_for() < *PROXY_TOKEN_REFRESH_THRESHOLD;
let refresh_needed = claims.valid_for() < PROXY_TOKEN_REFRESH_THRESHOLD;
if refresh_needed {
let user_id = i32::from_str(claims.sub.as_str())?;
let user = state
Expand Down

0 comments on commit 60c8a62

Please sign in to comment.