Skip to content

Commit

Permalink
missed one.. thankfully can re-use the constant
Browse files Browse the repository at this point in the history
it is for the same purpose so documenting it

Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Mar 22, 2024
1 parent 56a5bf5 commit 0a3c5d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 4 additions & 1 deletion kube-client/src/client/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions kube-client/src/client/auth/oidc.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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<bool, errors::IdTokenError> {
Expand All @@ -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)
}
Expand Down

0 comments on commit 0a3c5d4

Please sign in to comment.