From 34f48be3caef4918a78a9b9915d02278bac34e34 Mon Sep 17 00:00:00 2001 From: durch Date: Mon, 17 Jun 2024 17:38:51 +0200 Subject: [PATCH] Better ergonomics --- Cargo.toml | 2 +- src/fetcher.rs | 20 ++++++++++++-------- src/lib.rs | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e984d2dae..da223fc63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "goauth" -version = "0.15.0" +version = "0.16.0" authors = ["Drazen Urch "] description = "Crate for authenticating Server to Server Apps for Google Cloud Engine." repository = "https://github.com/durch/rust-goauth" diff --git a/src/fetcher.rs b/src/fetcher.rs index 20fb23139..44cfb0660 100644 --- a/src/fetcher.rs +++ b/src/fetcher.rs @@ -38,9 +38,14 @@ impl TokenFetcher { pub fn new( jwt: Jwt, credentials: Credentials, - refresh_buffer: Duration, + refresh_buffer_seconds: i64, ) -> TokenFetcher { - TokenFetcher::with_client(Client::new(), jwt, credentials, refresh_buffer) + TokenFetcher::with_client( + Client::new(), + jwt, + credentials, + Duration::new(refresh_buffer_seconds, 0), + ) } pub fn with_client( @@ -129,7 +134,6 @@ mod tests { use smpl_jwt::Jwt; use std::thread; use std::time::Duration as StdDuration; - use time::Duration; fn get_mocks() -> (Jwt, Credentials) { let token_url = mockito::server_url(); @@ -168,7 +172,7 @@ mod tests { async fn basic_token_fetch() { let (jwt, credentials) = get_mocks(); - let refresh_buffer = Duration::new(0, 0); + let refresh_buffer = 0; let fetcher = TokenFetcher::new(jwt, credentials, refresh_buffer); let (expected_token, json) = token_json("token", "Bearer", 1); @@ -183,7 +187,7 @@ mod tests { async fn basic_token_refresh() { let (jwt, credentials) = get_mocks(); - let refresh_buffer = Duration::new(0, 0); + let refresh_buffer = 0; let fetcher = TokenFetcher::new(jwt, credentials, refresh_buffer); let expires_in = 1; @@ -212,7 +216,7 @@ mod tests { let (jwt, credentials) = get_mocks(); let refresh_buffer = 4; - let fetcher = TokenFetcher::new(jwt, credentials, Duration::new(refresh_buffer, 0)); + let fetcher = TokenFetcher::new(jwt, credentials, refresh_buffer); let expires_in = 5; let (_expected_token, json) = token_json("token", "Bearer", expires_in); @@ -240,7 +244,7 @@ mod tests { async fn doesnt_token_refresh_unnecessarily() { let (jwt, credentials) = get_mocks(); - let refresh_buffer = Duration::new(0, 0); + let refresh_buffer = 0; let fetcher = TokenFetcher::new(jwt, credentials, refresh_buffer); let expires_in = 1; @@ -265,7 +269,7 @@ mod tests { #[test] fn is_send_and_sync() { let (jwt, credentials) = get_mocks(); - let refresh_buffer = Duration::new(0, 0); + let refresh_buffer = 0; let fetcher = TokenFetcher::new(jwt, credentials, refresh_buffer); fn check(_: &(dyn Send + Sync)) {} diff --git a/src/lib.rs b/src/lib.rs index 28e97643a..b8474b105 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ use auth::{JwtClaims, Token}; use credentials::Credentials; use reqwest::Client; -use smpl_jwt::Jwt; +pub use smpl_jwt::Jwt; use std::str::FromStr; use tokio::runtime::Runtime;