Skip to content

Commit

Permalink
Better ergonomics
Browse files Browse the repository at this point in the history
  • Loading branch information
durch committed Jun 17, 2024
1 parent 816cd2f commit 34f48be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "goauth"
version = "0.15.0"
version = "0.16.0"
authors = ["Drazen Urch <[email protected]>"]
description = "Crate for authenticating Server to Server Apps for Google Cloud Engine."
repository = "https://github.com/durch/rust-goauth"
Expand Down
20 changes: 12 additions & 8 deletions src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ impl TokenFetcher {
pub fn new(
jwt: Jwt<JwtClaims>,
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(
Expand Down Expand Up @@ -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<JwtClaims>, Credentials) {
let token_url = mockito::server_url();
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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)) {}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 34f48be

Please sign in to comment.