Skip to content

Commit

Permalink
Use https_proxy for version check
Browse files Browse the repository at this point in the history
  • Loading branch information
sam701 committed Oct 17, 2019
1 parent f4526af commit ef45da4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "awscredx"
version = "0.5.3"
version = "0.5.4"
authors = ["Alexei Samokvalov <[email protected]>"]
edition = "2018"

Expand Down
9 changes: 2 additions & 7 deletions src/assume/assumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -111,16 +112,10 @@ fn create_client(credentials: Cred, region: Region) -> Result<StsClient, String>
))
}

fn get_https_proxy() -> Option<String> {
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<ProxyConnector<HttpsConnector<HttpConnector>>, 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::<Uri>()
.map_err(|e| format!("cannot parse proxy URL({}): {}", &proxy_url, e))?;
Expand Down
8 changes: 7 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ pub fn set_permissions(path: &PathBuf, mode: u32) {
}

#[cfg(target_family = "windows")]
pub fn set_permissions(_path: &PathBuf, _mode: u32) {}
pub fn set_permissions(_path: &PathBuf, _mode: u32) {}

pub fn get_https_proxy() -> Option<String> {
std::env::var_os("https_proxy")
.or(std::env::var_os("HTTPS_PROXY"))
.map(|x| x.into_string().expect("https_proxy is utf8"))
}
17 changes: 16 additions & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -51,8 +53,21 @@ fn os_name() -> &'static str {
TRAVIS_OS_NAME_OPT.unwrap_or("osx")
}

fn get_http_client() -> Result<reqwest::Client, String> {
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<Option<PublishedVersion>, 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))?;
Expand Down

0 comments on commit ef45da4

Please sign in to comment.