From e634d3f139dd314afa96d9f0365d981a6bb01a8d Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Wed, 25 Jul 2018 22:44:32 +0200 Subject: [PATCH] deps: update chrono to 0.4 Signed-off-by: Igor Gnatenko --- Cargo.toml | 2 +- src/authenticator_delegate.rs | 8 ++++---- src/device.rs | 6 +++--- src/refresh.rs | 4 ++-- src/service_account.rs | 4 ++-- src/types.rs | 10 +++++----- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0b1ee87..ffccfed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0" [dependencies] base64 = "0.9" -chrono = "0.2" +chrono = "0.4" hyper = "0.10.2" hyper-rustls = "0.6.1" itertools = "0.7" diff --git a/src/authenticator_delegate.rs b/src/authenticator_delegate.rs index 381ec15..e46c5c0 100644 --- a/src/authenticator_delegate.rs +++ b/src/authenticator_delegate.rs @@ -7,7 +7,7 @@ use std::error::Error; use authenticator::Retry; use types::RequestError; -use chrono::{DateTime, Local, UTC}; +use chrono::{DateTime, Local, Utc}; use std::time::Duration; /// Contains state of pending authentication requests @@ -20,7 +20,7 @@ pub struct PollInformation { /// The `user_code` expires at the given time /// It's the time the user has left to authenticate your application - pub expires_at: DateTime, + pub expires_at: DateTime, /// The interval in which we may poll for a status change /// The server responds with errors of we poll too fast. pub interval: Duration, @@ -38,7 +38,7 @@ pub enum PollError { /// Connection failure - retry if you think it's worth it HttpError(hyper::Error), /// indicates we are expired, including the expiration date - Expired(DateTime), + Expired(DateTime), /// Indicates that the user declined access. String is server response AccessDenied, } @@ -83,7 +83,7 @@ pub trait AuthenticatorDelegate { /// Called if the request code is expired. You will have to start over in this case. /// This will be the last call the delegate receives. /// Given `DateTime` is the expiration date - fn expired(&mut self, &DateTime) {} + fn expired(&mut self, &DateTime) {} /// Called if the user denied access. You would have to start over. /// This will be the last call the delegate receives. diff --git a/src/device.rs b/src/device.rs index c89cd47..f61ca50 100644 --- a/src/device.rs +++ b/src/device.rs @@ -7,7 +7,7 @@ use hyper::header::ContentType; use url::form_urlencoded; use itertools::Itertools; use serde_json as json; -use chrono::{self, UTC}; +use chrono::{self, Utc}; use std::borrow::BorrowMut; use std::io::Read; use std::i64; @@ -133,7 +133,7 @@ impl DeviceFlow let pi = PollInformation { user_code: decoded.user_code, verification_url: decoded.verification_url, - expires_at: UTC::now() + chrono::Duration::seconds(decoded.expires_in), + expires_at: Utc::now() + chrono::Duration::seconds(decoded.expires_in), interval: Duration::from_secs(i64::abs(decoded.interval) as u64), }; self.state = Some(DeviceFlowState::Pending(pi.clone())); @@ -175,7 +175,7 @@ impl DeviceFlow _ => panic!("You have to call request_code() beforehand"), }; - if pi.expires_at <= UTC::now() { + if pi.expires_at <= Utc::now() { self.error = Some(PollError::Expired(pi.expires_at)); self.state = Some(DeviceFlowState::Error); return Err(&self.error.as_ref().unwrap()); diff --git a/src/refresh.rs b/src/refresh.rs index b980021..f68dd54 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -1,6 +1,6 @@ use types::{ApplicationSecret, FlowType, JsonError}; -use chrono::UTC; +use chrono::Utc; use hyper; use hyper::header::ContentType; use serde_json as json; @@ -107,7 +107,7 @@ impl RefreshFlow token_type: t.token_type, refresh_token: refresh_token.to_string(), expires_in: None, - expires_in_timestamp: Some(UTC::now().timestamp() + t.expires_in), + expires_in_timestamp: Some(Utc::now().timestamp() + t.expires_in), }); &self.result diff --git a/src/service_account.rs b/src/service_account.rs index 082b58d..80a5bf3 100644 --- a/src/service_account.rs +++ b/src/service_account.rs @@ -133,7 +133,7 @@ fn init_claims_from_key<'a, I, T>(key: &ServiceAccountKey, scopes: I) -> Claims where T: AsRef + 'a, I: IntoIterator { - let iat = chrono::UTC::now().timestamp(); + let iat = chrono::Utc::now().timestamp(); let expiry = iat + 3600 - 5; // Max validity is 1h. let mut scopes_string = scopes.into_iter().fold(String::new(), |mut acc, sc| { @@ -179,7 +179,7 @@ struct TokenResponse { impl TokenResponse { fn to_oauth_token(self) -> Token { - let expires_ts = chrono::UTC::now().timestamp() + self.expires_in.unwrap_or(0); + let expires_ts = chrono::Utc::now().timestamp() + self.expires_in.unwrap_or(0); Token { access_token: self.access_token.unwrap(), diff --git a/src/types.rs b/src/types.rs index e924d69..0f905f4 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, UTC, TimeZone}; +use chrono::{DateTime, Utc, TimeZone}; use std::error::Error; use std::fmt; use std::str::FromStr; @@ -203,12 +203,12 @@ impl Token { if self.access_token.len() == 0 { panic!("called expired() on unset token"); } - self.expiry_date() <= UTC::now() + self.expiry_date() <= Utc::now() } /// Returns a DateTime object representing our expiry date. - pub fn expiry_date(&self) -> DateTime { - UTC.timestamp(self.expires_in_timestamp + pub fn expiry_date(&self) -> DateTime { + Utc.timestamp(self.expires_in_timestamp .expect("Tokens without an absolute expiry are invalid"), 0) } @@ -220,7 +220,7 @@ impl Token { return self; } - self.expires_in_timestamp = Some(UTC::now().timestamp() + self.expires_in.unwrap()); + self.expires_in_timestamp = Some(Utc::now().timestamp() + self.expires_in.unwrap()); self.expires_in = None; self }