From c2bb59b4c5ad3b8a272712b53044624be3a531e0 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 30 Jan 2016 13:44:36 +0100 Subject: [PATCH 1/2] fix(rustup): use std::time::Duration and Thread::sleep --- changelog.md | 2 +- examples/auth.rs | 12 ++++++------ src/device.rs | 12 +++++++----- src/helper.rs | 21 +++++++++++---------- src/lib.rs.in | 4 ++-- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/changelog.md b/changelog.md index 6f4d987..d1d7bae 100644 --- a/changelog.md +++ b/changelog.md @@ -110,7 +110,7 @@ This release essentially make yup-oauth2 work on rustc *stable*. #### Bug Fixes -* **rustup** replace sleep with sleep_ms ([727c1d80](https://github.com/Byron/yup-oauth2/commit/727c1d801b4ae8f7b7cb80050139926bbcb9bf48)) +* **rustup** replace sleep with sleep ([727c1d80](https://github.com/Byron/yup-oauth2/commit/727c1d801b4ae8f7b7cb80050139926bbcb9bf48)) diff --git a/examples/auth.rs b/examples/auth.rs index f76be92..e10c6b8 100644 --- a/examples/auth.rs +++ b/examples/auth.rs @@ -11,8 +11,8 @@ use chrono::{Local}; use getopts::{HasArg,Options,Occur,Fail}; use std::env; use std::default::Default; -use time::Duration; -use std::thread::sleep_ms; +use std::time::Duration; +use std::thread::sleep; fn usage(program: &str, opts: &Options, err: Option) -> ! { @@ -69,9 +69,9 @@ fn main() { You have time until {} to do that. Do not terminate the program until you deny or grant access !", pi.user_code, pi.verification_url, pi.expires_at.with_timezone(&Local)); - let delay = Duration::seconds(5); + let delay = Duration::from_secs(5); println!("Browser opens automatically in {} seconds", delay); - sleep_ms(delay.num_milliseconds() as u32); + sleep(delay); open::that(&pi.verification_url).ok(); println!("DONE - waiting for authorization ..."); } @@ -81,7 +81,7 @@ fn main() { connector: hyper::net::HttpConnector }); - match oauth2::Authenticator::new(&secret, StdoutHandler, client, + match oauth2::Authenticator::new(&secret, StdoutHandler, client, oauth2::NullStorage, None).token(&m.free) { Ok(t) => { println!("Authentication granted !"); @@ -94,4 +94,4 @@ fn main() { std::process::exit(10); } } -} \ No newline at end of file +} diff --git a/src/device.rs b/src/device.rs index a5ded6a..20cc939 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,7 +1,9 @@ use std::iter::IntoIterator; -use time::Duration; +use std::time::Duration; use std::default::Default; use std::fmt; +use std::i64; +use time; use hyper; use hyper::header::ContentType; @@ -230,8 +232,8 @@ impl DeviceFlow let pi = PollInformation { user_code: decoded.user_code, verification_url: decoded.verification_url, - expires_at: UTC::now() + Duration::seconds(decoded.expires_in), - interval: Duration::seconds(decoded.interval), + expires_at: UTC::now() + time::Duration::seconds(decoded.expires_in), + interval: Duration::from_secs(i64::abs(decoded.interval) as u64), }; self.state = Some(DeviceFlowState::Pending(pi.clone())); @@ -337,7 +339,7 @@ impl DeviceFlow pub mod tests { use super::*; use std::default::Default; - use time::Duration; + use std::time::Duration; use hyper; use yup_hyper_mock::{SequentialConnector, MockStream}; @@ -394,7 +396,7 @@ pub mod tests { match flow.request_code("bogus_client_id", "bogus_secret", &["https://www.googleapis.com/auth/youtube.upload"]) { - Ok(pi) => assert_eq!(pi.interval, Duration::seconds(0)), + Ok(pi) => assert_eq!(pi.interval, Duration::from_secs(0)), _ => unreachable!(), } diff --git a/src/helper.rs b/src/helper.rs index 0b29395..83f232e 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -2,7 +2,7 @@ use std::iter::IntoIterator; use std::borrow::BorrowMut; use std::collections::HashMap; use std::hash::{SipHasher, Hash, Hasher}; -use std::thread::sleep_ms; +use std::thread::sleep; use std::cmp::min; use std::error::Error; use std::fmt; @@ -11,7 +11,8 @@ use std::convert::From; use common::{Token, FlowType, ApplicationSecret}; use device::{PollInformation, RequestError, DeviceFlow, PollError}; use refresh::{RefreshResult, RefreshFlow}; -use chrono::{DateTime, UTC, Duration, Local}; +use chrono::{DateTime, UTC, Local}; +use std::time::Duration; use hyper; @@ -203,7 +204,7 @@ impl Authenticator RequestError::HttpError(err) => { match self.delegate.connection_error(&err) { Retry::Abort|Retry::Skip => return Err(Box::new(StringError::from(&err as &Error))), - Retry::After(d) => sleep_ms(d.num_milliseconds() as u32), + Retry::After(d) => sleep(d), } }, RequestError::InvalidClient @@ -234,7 +235,7 @@ impl Authenticator match self.delegate.connection_error(err) { Retry::Abort|Retry::Skip => return Err(Box::new(StringError::from(err as &Error))), - Retry::After(d) => sleep_ms(d.num_milliseconds() as u32), + Retry::After(d) => sleep(d), } }, &&PollError::Expired(ref t) => { @@ -251,7 +252,7 @@ impl Authenticator match self.delegate.pending(&pi) { Retry::Abort|Retry::Skip => return Err(Box::new(StringError::new("Pending authentication aborted".to_string(), None))), - Retry::After(d) => sleep_ms(min(d, pi.interval).num_milliseconds() as u32), + Retry::After(d) => sleep(min(d, pi.interval)), }, Ok(Some(token)) => return Ok(token) } @@ -301,7 +302,7 @@ impl GetToken for Authenticator return Err(Box::new(StringError::new( err.description().to_string(), None))), - Retry::After(d) => sleep_ms(d.num_milliseconds() as u32), + Retry::After(d) => sleep(d), } }, RefreshResult::RefreshError(ref err_str, ref err_description) => { @@ -322,7 +323,7 @@ impl GetToken for Authenticator Retry::Skip => break, Retry::Abort => return Err(Box::new(err)), Retry::After(d) => { - sleep_ms(d.num_milliseconds() as u32); + sleep(d); continue; } } @@ -351,7 +352,7 @@ impl GetToken for Authenticator Retry::Skip => break, Retry::Abort => return Err(Box::new(err)), Retry::After(d) => { - sleep_ms(d.num_milliseconds() as u32); + sleep(d); continue; } } @@ -367,7 +368,7 @@ impl GetToken for Authenticator match self.delegate.token_storage_failure(false, &err) { Retry::Abort|Retry::Skip => Err(Box::new(err)), Retry::After(d) => { - sleep_ms(d.num_milliseconds() as u32); + sleep(d); continue } } @@ -437,7 +438,7 @@ pub trait AuthenticatorDelegate { /// * Only used in `DeviceFlow`. Return value will only be used if it /// is larger than the interval desired by the server. fn pending(&mut self, &PollInformation) -> Retry { - Retry::After(Duration::seconds(5)) + Retry::After(Duration::from_secs(5)) } /// The server has returned a `user_code` which must be shown to the user, diff --git a/src/lib.rs.in b/src/lib.rs.in index da2294b..6bc0cb6 100644 --- a/src/lib.rs.in +++ b/src/lib.rs.in @@ -9,8 +9,8 @@ extern crate log; #[cfg(test)] extern crate yup_hyper_mock; extern crate mime; -extern crate url; extern crate time; +extern crate url; extern crate itertools; mod device; @@ -21,5 +21,5 @@ mod helper; pub use device::{DeviceFlow, PollInformation, PollError}; pub use refresh::{RefreshFlow, RefreshResult}; pub use common::{Token, FlowType, ApplicationSecret, ConsoleApplicationSecret, Scheme, TokenType}; -pub use helper::{TokenStorage, NullStorage, MemoryStorage, Authenticator, +pub use helper::{TokenStorage, NullStorage, MemoryStorage, Authenticator, AuthenticatorDelegate, Retry, DefaultAuthenticatorDelegate, GetToken}; From 5dbd93a68ceea9f577e609710f46f6fc4678aa6a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 30 Jan 2016 13:47:57 +0100 Subject: [PATCH 2/2] chore(version-up): 0.5.4 --- Cargo.toml | 2 +- changelog.md | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dbaad6c..ffb5e47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yup-oauth2" -version = "0.5.3" +version = "0.5.4" authors = ["Sebastian Thiel "] repository = "https://github.com/Byron/yup-oauth2" description = "A partial oauth2 implementation, providing the 'device' authorization flow" diff --git a/changelog.md b/changelog.md index d1d7bae..45ccca0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,13 @@ + +### v0.5.4 (2016-01-30) + + +#### Bug Fixes + +* **rustup:** use std::time::Duration and Thread::sleep ([c2bb59b4](https://github.com/Byron/yup-oauth2/commit/c2bb59b4c5ad3b8a272712b53044624be3a531e0)) + + + ## v0.5.2 (2015-08-08)