From 9906fdc25e3769d07b0de78a18501c7a681e6dc9 Mon Sep 17 00:00:00 2001 From: CarlosEDP Date: Wed, 1 Jul 2015 13:58:40 -0300 Subject: Added support to http and https proxies on bootstrap. Variables are read from environment vars http_proxy and https_proxy. --- bootstrap | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'bootstrap') diff --git a/bootstrap b/bootstrap index 41d9725..ca40489 100755 --- a/bootstrap +++ b/bootstrap @@ -82,6 +82,7 @@ extract(Binary) -> {ok, Contents}. request(Url) -> + setHttpcOptions(), case httpc:request(get, {Url, []}, [{relaxed, true}], [{body_format, binary}]) of @@ -91,6 +92,47 @@ request(Url) -> Error end. +setHttpcOptions() -> + %% Get http_proxy and https_proxy environment variables + case os:getenv("http_proxy") of + false -> + Http = ""; + Http -> + Http + end, + case os:getenv("https_proxy") of + false -> + Https = ""; + Https -> + Https + end, + + %% Parse the variables to extract host and port + Opts = [], + case http_uri:parse(Http) of + {ok,{_, [], Host, Port, _, []}} -> + Opts1 = Opts ++ [{proxy, {{Host, Port}, []}}]; + {error, _} -> + Opts1 = Opts + end, + + case http_uri:parse(Https) of + {ok,{_, [], Host2, Port2, _, []}} -> + Opts2 = Opts1 ++ [{https_proxy, {{Host2, Port2}, []}}]; + {error, _} -> + Opts2 = Opts1 + end, + + io:format("Opts: ~p~n", [Opts2]), + + case Opts2 of + [] -> + ok; + _ -> + httpc:set_options(Opts2), + ok + end. + compile(App, FirstFiles) -> Dir = filename:join(filename:absname("_build/default/lib/"), App), filelib:ensure_dir(filename:join([Dir, "ebin", "dummy.beam"])), -- cgit v1.1 From 8de84f1af04a716357dbc5473f7daf74cb31f44a Mon Sep 17 00:00:00 2001 From: CarlosEDP Date: Wed, 1 Jul 2015 14:13:43 -0300 Subject: Added support for proxy on rebar3 based on environment variables. --- bootstrap | 2 -- 1 file changed, 2 deletions(-) (limited to 'bootstrap') diff --git a/bootstrap b/bootstrap index ca40489..1e56263 100755 --- a/bootstrap +++ b/bootstrap @@ -123,8 +123,6 @@ setHttpcOptions() -> Opts2 = Opts1 end, - io:format("Opts: ~p~n", [Opts2]), - case Opts2 of [] -> ok; -- cgit v1.1 From 60265aba3497aa97a35b706e00a2526e100733bd Mon Sep 17 00:00:00 2001 From: CarlosEDP Date: Wed, 1 Jul 2015 18:01:35 -0300 Subject: Get proxy vars from ~/.config/rebar3/rebar.config. Variable format is {http_proxy, http://host:port} or {http_proxy, http://host:port} --- bootstrap | 59 ++++++++++++++++++++++------------------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) (limited to 'bootstrap') diff --git a/bootstrap b/bootstrap index 1e56263..ad94561 100755 --- a/bootstrap +++ b/bootstrap @@ -82,7 +82,7 @@ extract(Binary) -> {ok, Contents}. request(Url) -> - setHttpcOptions(), + set_httpc_options(), case httpc:request(get, {Url, []}, [{relaxed, true}], [{body_format, binary}]) of @@ -92,45 +92,30 @@ request(Url) -> Error end. -setHttpcOptions() -> - %% Get http_proxy and https_proxy environment variables - case os:getenv("http_proxy") of - false -> - Http = ""; - Http -> - Http - end, - case os:getenv("https_proxy") of - false -> - Https = ""; - Https -> - Https - end, - - %% Parse the variables to extract host and port - Opts = [], - case http_uri:parse(Http) of - {ok,{_, [], Host, Port, _, []}} -> - Opts1 = Opts ++ [{proxy, {{Host, Port}, []}}]; - {error, _} -> - Opts1 = Opts - end, - - case http_uri:parse(Https) of - {ok,{_, [], Host2, Port2, _, []}} -> - Opts2 = Opts1 ++ [{https_proxy, {{Host2, Port2}, []}}]; - {error, _} -> - Opts2 = Opts1 - end, - - case Opts2 of - [] -> - ok; +get_http_var() -> + {ok, [[Home]]} = init:get_argument(home), + ConfDir = filename:join(Home, ".config/rebar3"), + case file:consult(filename:join(ConfDir, "rebar.config")) of + {ok, Config} -> + Config; _ -> - httpc:set_options(Opts2), - ok + [] end. +get_http(Scheme) -> + proplists:get_value(Scheme, get_http_var(), ""). + +set_httpc_options() -> + set_httpc_options(https_proxy, get_http(https_proxy)), + set_httpc_options(proxy, get_http(http_proxy)). + +set_httpc_options(_, []) -> + ok; + +set_httpc_options(Scheme, Proxy) -> + {ok, {_, _, Host, Port, _, _}} = http_uri:parse(Proxy), + httpc:set_options([{Scheme, {{Host, Port}, []}}]). + compile(App, FirstFiles) -> Dir = filename:join(filename:absname("_build/default/lib/"), App), filelib:ensure_dir(filename:join([Dir, "ebin", "dummy.beam"])), -- cgit v1.1 From 46ca2bb6b0e9c99c7a5b4efb7b9efc310c0982b8 Mon Sep 17 00:00:00 2001 From: CarlosEDP Date: Thu, 2 Jul 2015 10:42:46 -0300 Subject: Fix for cases with no proxy configured. --- bootstrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bootstrap') diff --git a/bootstrap b/bootstrap index ad94561..8a0afd6 100755 --- a/bootstrap +++ b/bootstrap @@ -103,7 +103,7 @@ get_http_var() -> end. get_http(Scheme) -> - proplists:get_value(Scheme, get_http_var(), ""). + proplists:get_value(Scheme, get_http_var(), []). set_httpc_options() -> set_httpc_options(https_proxy, get_http(https_proxy)), -- cgit v1.1 From 38cc32c40afdf8e999d8705501acd7e13918cdc9 Mon Sep 17 00:00:00 2001 From: CarlosEDP Date: Thu, 2 Jul 2015 11:59:00 -0300 Subject: Added rebar profile to httpc initialization and calls. --- bootstrap | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bootstrap') diff --git a/bootstrap b/bootstrap index 8a0afd6..4fed22a 100755 --- a/bootstrap +++ b/bootstrap @@ -9,6 +9,8 @@ main(_Args) -> application:start(public_key), application:start(ssl), inets:start(), + inets:start(httpc, [{profile, rebar}]), + set_httpc_options(), %% Fetch and build deps required to build rebar3 BaseDeps = [{providers, []} @@ -82,10 +84,10 @@ extract(Binary) -> {ok, Contents}. request(Url) -> - set_httpc_options(), case httpc:request(get, {Url, []}, [{relaxed, true}], - [{body_format, binary}]) of + [{body_format, binary}], + rebar) of {ok, {{_Version, 200, _Reason}, _Headers, Body}} -> {ok, Body}; Error -> @@ -114,7 +116,7 @@ set_httpc_options(_, []) -> set_httpc_options(Scheme, Proxy) -> {ok, {_, _, Host, Port, _, _}} = http_uri:parse(Proxy), - httpc:set_options([{Scheme, {{Host, Port}, []}}]). + httpc:set_options([{Scheme, {{Host, Port}, []}}], rebar). compile(App, FirstFiles) -> Dir = filename:join(filename:absname("_build/default/lib/"), App), -- cgit v1.1 From 4a25a4d9d5f968fe2445707e8077a6efda596192 Mon Sep 17 00:00:00 2001 From: CarlosEDP Date: Thu, 2 Jul 2015 11:59:39 -0300 Subject: Renamed functions. --- bootstrap | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bootstrap') diff --git a/bootstrap b/bootstrap index 4fed22a..71c44da 100755 --- a/bootstrap +++ b/bootstrap @@ -94,7 +94,7 @@ request(Url) -> Error end. -get_http_var() -> +get_rebar_config() -> {ok, [[Home]]} = init:get_argument(home), ConfDir = filename:join(Home, ".config/rebar3"), case file:consult(filename:join(ConfDir, "rebar.config")) of @@ -104,12 +104,12 @@ get_http_var() -> [] end. -get_http(Scheme) -> - proplists:get_value(Scheme, get_http_var(), []). +get_http_vars(Scheme) -> + proplists:get_value(Scheme, get_rebar_config(), []). set_httpc_options() -> - set_httpc_options(https_proxy, get_http(https_proxy)), - set_httpc_options(proxy, get_http(http_proxy)). + set_httpc_options(https_proxy, get_http_vars(https_proxy)), + set_httpc_options(proxy, get_http_vars(http_proxy)). set_httpc_options(_, []) -> ok; -- cgit v1.1