HTTP proxy support
Proxy options can be passed to the trust store to set in the httpc profile. Proxy options are described in: http://erlang.org/doc/man/httpc.html#set_options-2 Example: ``` [{rabbitmq_trust_store, [{proxy_options, [ {proxy, {{"127.0.0.1", 8080},[]}}, {https_proxy, {{"127.0.0.1", 8080},[]}} ] }] }]. ```
This commit is contained in:
parent
78a6ec7952
commit
037cc53542
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
-behaviour(rabbit_trust_store_certificate_provider).
|
-behaviour(rabbit_trust_store_certificate_provider).
|
||||||
|
|
||||||
|
-define(PROFILE, ?MODULE).
|
||||||
|
|
||||||
-export([list_certs/1, list_certs/2, load_cert/3]).
|
-export([list_certs/1, list_certs/2, load_cert/3]).
|
||||||
|
|
||||||
-record(http_state,{
|
-record(http_state,{
|
||||||
|
|
@ -13,14 +15,14 @@
|
||||||
}).
|
}).
|
||||||
|
|
||||||
list_certs(Config) ->
|
list_certs(Config) ->
|
||||||
init(),
|
init(Config),
|
||||||
State = init_state(Config),
|
State = init_state(Config),
|
||||||
list_certs(Config, State).
|
list_certs(Config, State).
|
||||||
|
|
||||||
list_certs(_, #http_state{url = Url,
|
list_certs(_, #http_state{url = Url,
|
||||||
http_options = HttpOptions,
|
http_options = HttpOptions,
|
||||||
headers = Headers} = State) ->
|
headers = Headers} = State) ->
|
||||||
Res = httpc:request(get, {Url, Headers}, HttpOptions, [{body_format, binary}]),
|
Res = httpc:request(get, {Url, Headers}, HttpOptions, [{body_format, binary}], ?PROFILE),
|
||||||
case Res of
|
case Res of
|
||||||
{ok, {{_, 200, _}, RespHeaders, Body}} ->
|
{ok, {{_, 200, _}, RespHeaders, Body}} ->
|
||||||
Certs = decode_cert_list(Body),
|
Certs = decode_cert_list(Body),
|
||||||
|
|
@ -40,7 +42,8 @@ load_cert(_, Attributes, Config) ->
|
||||||
Res = httpc:request(get,
|
Res = httpc:request(get,
|
||||||
{Url, Headers},
|
{Url, Headers},
|
||||||
HttpOptions,
|
HttpOptions,
|
||||||
[{body_format, binary}, {full_result, false}]),
|
[{body_format, binary}, {full_result, false}],
|
||||||
|
?PROFILE),
|
||||||
case Res of
|
case Res of
|
||||||
{ok, {200, Body}} ->
|
{ok, {200, Body}} ->
|
||||||
[{'Certificate', Cert, not_encrypted}] = public_key:pem_decode(Body),
|
[{'Certificate', Cert, not_encrypted}] = public_key:pem_decode(Body),
|
||||||
|
|
@ -54,9 +57,11 @@ join_url(BaseUrl, CertPath) ->
|
||||||
++ "/" ++
|
++ "/" ++
|
||||||
string:strip(rabbit_data_coercion:to_list(CertPath), left, $/).
|
string:strip(rabbit_data_coercion:to_list(CertPath), left, $/).
|
||||||
|
|
||||||
init() ->
|
init(Config) ->
|
||||||
inets:start(),
|
inets:start(httpc, [{profile, ?PROFILE}]),
|
||||||
ssl:start().
|
ssl:start(),
|
||||||
|
Options = proplists:get_value(proxy_options, Config, []),
|
||||||
|
httpc:set_options(Options, ?PROFILE).
|
||||||
|
|
||||||
init_state(Config) ->
|
init_state(Config) ->
|
||||||
Url = proplists:get_value(url, Config),
|
Url = proplists:get_value(url, Config),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue