diff --git a/Cargo.lock b/Cargo.lock index b8fd58b..d6df2ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,7 +63,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "awscredx" -version = "0.5.3" +version = "0.5.4" dependencies = [ "ansi_term 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index fb9e3da..a78a4c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "awscredx" -version = "0.5.3" +version = "0.5.4" authors = ["Alexei Samokvalov "] edition = "2018" diff --git a/src/assume/assumer.rs b/src/assume/assumer.rs index 26b9183..9f56681 100644 --- a/src/assume/assumer.rs +++ b/src/assume/assumer.rs @@ -9,6 +9,7 @@ use hyper_proxy::{Proxy, Intercept, ProxyConnector}; use hyper_tls::HttpsConnector; use hyper::Uri; use hyper::client::HttpConnector; +use crate::util; pub struct RoleAssumer<'a> { region: Region, @@ -111,16 +112,10 @@ fn create_client(credentials: Cred, region: Region) -> Result )) } -fn get_https_proxy() -> Option { - std::env::var_os("https_proxy") - .or(std::env::var_os("HTTPS_PROXY")) - .map(|x| x.into_string().expect("https_proxy is utf8")) -} - fn get_https_connector() -> Result>, String> { let connector = HttpsConnector::new(2) .expect("connector with 2 threads"); - Ok(match get_https_proxy() { + Ok(match util::get_https_proxy() { Some(proxy_url) => { let url = proxy_url.parse::() .map_err(|e| format!("cannot parse proxy URL({}): {}", &proxy_url, e))?; diff --git a/src/util.rs b/src/util.rs index c4a782f..53ac042 100644 --- a/src/util.rs +++ b/src/util.rs @@ -16,4 +16,10 @@ pub fn set_permissions(path: &PathBuf, mode: u32) { } #[cfg(target_family = "windows")] -pub fn set_permissions(_path: &PathBuf, _mode: u32) {} \ No newline at end of file +pub fn set_permissions(_path: &PathBuf, _mode: u32) {} + +pub fn get_https_proxy() -> Option { + std::env::var_os("https_proxy") + .or(std::env::var_os("HTTPS_PROXY")) + .map(|x| x.into_string().expect("https_proxy is utf8")) +} diff --git a/src/version.rs b/src/version.rs index ee2322b..4d4b058 100644 --- a/src/version.rs +++ b/src/version.rs @@ -2,6 +2,8 @@ use reqwest; use serde::Deserialize; use ansi_term::{Style, Color}; use std::fmt::{self, Display}; +use crate::util; +use reqwest::Proxy; #[derive(Deserialize)] struct GithubVersion { @@ -51,8 +53,21 @@ fn os_name() -> &'static str { TRAVIS_OS_NAME_OPT.unwrap_or("osx") } +fn get_http_client() -> Result { + let mut builder = reqwest::ClientBuilder::new(); + if let Some(proxy_url) = util::get_https_proxy() { + builder = builder.proxy(Proxy::all(&proxy_url) + .map_err(|e| format!("cannot create proxy from URL({}): {}", &proxy_url, e))?); + } + builder + .build() + .map_err(|e| format!("cannot build http client: {}", e)) +} + pub fn check_new_version() -> Result, String> { - let github_version: GithubVersion = reqwest::get("https://api.github.com/repos/sam701/awscredx/releases/latest") + let github_version: GithubVersion = get_http_client()? + .get("https://api.github.com/repos/sam701/awscredx/releases/latest") + .send() .map_err(|e| format!("cannot check new version: {}", e))? .json() .map_err(|e| format!("cannot decode github version response: {}", e))?;