From 0a3c5d476b51af8004e66dcd4913bcfd601152b7 Mon Sep 17 00:00:00 2001 From: clux Date: Fri, 22 Mar 2024 18:36:41 +0000 Subject: [PATCH] missed one.. thankfully can re-use the constant it is for the same purpose so documenting it Signed-off-by: clux --- kube-client/src/client/auth/mod.rs | 5 ++++- kube-client/src/client/auth/oidc.rs | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/kube-client/src/client/auth/mod.rs b/kube-client/src/client/auth/mod.rs index 82ac3e964..aa4e692f0 100644 --- a/kube-client/src/client/auth/mod.rs +++ b/kube-client/src/client/auth/mod.rs @@ -168,7 +168,10 @@ macro_rules! const_unwrap { } }; } -const TEN_SEC: chrono::TimeDelta = const_unwrap!(Duration::try_seconds(10)); + +/// Common constant for checking if an auth token is close to expiring +pub const TEN_SEC: chrono::TimeDelta = const_unwrap!(Duration::try_seconds(10)); +/// Common duration for time between reloads const SIXTY_SEC: chrono::TimeDelta = const_unwrap!(Duration::try_seconds(60)); // See https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/client-go/plugin/pkg/client/auth diff --git a/kube-client/src/client/auth/oidc.rs b/kube-client/src/client/auth/oidc.rs index 0c3d5cbd0..e4aeff4e2 100644 --- a/kube-client/src/client/auth/oidc.rs +++ b/kube-client/src/client/auth/oidc.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; -use chrono::{Duration, TimeZone, Utc}; +use super::TEN_SEC; +use chrono::{TimeZone, Utc}; use form_urlencoded::Serializer; use http::{ header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE}, @@ -148,8 +149,6 @@ pub struct Oidc { impl Oidc { /// Config key for the ID token. const CONFIG_ID_TOKEN: &'static str = "id-token"; - /// How many seconds before ID token expiration we want to refresh it. - const EXPIRY_DELTA_SECONDS: i64 = 10; /// Check whether the stored ID token can still be used. fn token_valid(&self) -> Result { @@ -166,7 +165,7 @@ impl Oidc { .earliest() .ok_or(errors::IdTokenError::InvalidExpirationTimestamp)?; - let valid = Utc::now() + Duration::seconds(Self::EXPIRY_DELTA_SECONDS) < timestamp; + let valid = Utc::now() + TEN_SEC < timestamp; Ok(valid) }