Skip to content

Commit 70bb3ae

Browse files
Rename mapping functions
1 parent 6e8c4d0 commit 70bb3ae

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

deps/oauth2_client/src/oauth2_client.erl

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
merge_openid_configuration/2,
1414
merge_oauth_provider/2,
1515
extract_ssl_options_as_list/1,
16-
get_httpc_option_proxy_auth_if_any/1,
17-
get_httpc_option_proxy_if_any/1,
18-
get_httpc_option_ssl_options_if_any/1,
19-
get_httpc_option_timeout_of_default/1,
16+
map_proxy_auth_to_httpc_option/1,
17+
map_proxy_to_httpc_option/1,
18+
map_ssl_options_to_httpc_option/1,
19+
map_timeout_to_httpc_option/1,
2020
format_ssl_options/1, format_oauth_provider/1, format_oauth_provider_id/1,
2121
extract_proxy_options_from_url/1
2222
]).
@@ -47,8 +47,9 @@ refresh_access_token(OAuthProvider, Request) ->
4747
Header = [],
4848
Type = ?CONTENT_URLENCODED,
4949
Body = build_refresh_token_request_body(Request),
50-
HTTPOptions = get_httpc_option_ssl_options_if_any(OAuthProvider) ++
51-
get_httpc_option_timeout_of_default(Request#refresh_token_request.timeout),
50+
HTTPOptions =
51+
map_ssl_options_to_httpc_option(OAuthProvider#oauth_porvider.ssl_options) ++
52+
map_timeout_to_httpc_option(Request#refresh_token_request.timeout),
5253
Response = http_post(URL, Header, Type, Body, HTTPOptions,
5354
OAuthProvider#oauth_provider.proxy_options),
5455
parse_access_token_response(Response).
@@ -57,21 +58,21 @@ http_post(URL, Header, Type, Body, HTTPOptions, ProxyOptions) ->
5758
case ProxyOptions of
5859
undefined -> httpc:request(post, {URL, Header, Type, Body}, HTTPOptions, []);
5960
_ ->
60-
case httpc:set_options(get_httpc_option_proxy_if_any(ProxyOptions)) of
61+
case httpc:set_options(map_proxy_to_httpc_option(ProxyOptions)) of
6162
ok ->
6263
httpc:request(post, {URL, Header, Type, Body},
63-
HTTPOptions ++ get_httpc_option_proxy_auth_if_any(ProxyOptions), []);
64+
HTTPOptions ++ map_proxy_auth_to_httpc_option(ProxyOptions), []);
6465
{error, _} = Error -> Error
6566
end
6667
end.
6768
http_get(URL, HTTPOptions, ProxyOptions) ->
6869
case ProxyOptions of
6970
undefined -> httpc:request(get, {URL, []}, HTTPOptions, []);
7071
_ ->
71-
case httpc:set_options(get_httpc_option_proxy_if_any(ProxyOptions)) of
72+
case httpc:set_options(map_proxy_to_httpc_option(ProxyOptions)) of
7273
ok ->
7374
httpc:request(get, {URL, []},
74-
HTTPOptions ++ get_httpc_option_proxy_auth_if_any(ProxyOptions), []);
75+
HTTPOptions ++ map_proxy_auth_to_httpc_option(ProxyOptions), []);
7576
{error, _} = Error -> Error
7677
end
7778
end.
@@ -589,19 +590,19 @@ append_extra_parameters(Request, QueryList) ->
589590
Params -> Params ++ QueryList
590591
end.
591592

592-
get_httpc_option_ssl_options_if_any(OAuthProvider) ->
593-
case OAuthProvider#oauth_provider.ssl_options of
593+
map_ssl_options_to_httpc_option(SslOptions) ->
594+
case SslOptions of
594595
undefined -> [];
595596
Options -> [{ssl, Options}]
596597
end.
597598

598-
get_httpc_option_timeout_of_default(Timeout) ->
599+
map_timeout_to_httpc_option(Timeout) ->
599600
case Timeout of
600601
undefined -> [{timeout, ?DEFAULT_HTTP_TIMEOUT}];
601602
Timeout -> [{timeout, Timeout}]
602603
end.
603604

604-
get_httpc_option_proxy_if_any(ProxyOptions) ->
605+
map_proxy_to_httpc_option(ProxyOptions) ->
605606
case ProxyOptions of
606607
undefined ->
607608
[];
@@ -618,7 +619,7 @@ get_httpc_option_proxy_if_any(ProxyOptions) ->
618619
end
619620
end.
620621

621-
get_httpc_option_proxy_auth_if_any(ProxyOptions) ->
622+
map_proxy_auth_to_httpc_option(ProxyOptions) ->
622623
case ProxyOptions of
623624
undefined ->
624625
[];

deps/rabbitmq_auth_backend_oauth2/src/uaa_jwks.erl

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
-export([get/2, get/3]).
33

44
-import(oauth2_client, [
5-
get_httpc_option_ssl_options_if_any/1,
6-
get_httpc_option_timeout_of_default/1,
7-
get_httpc_option_proxy_auth_if_any/1,
8-
get_httpc_option_proxy_if_any/1]).
5+
map_ssl_options_to_httpc_option/1,
6+
map_timeout_to_httpc_option/1,
7+
map_proxy_auth_to_httpc_option/1,
8+
map_proxy_to_httpc_option/1]).
99

1010
-spec get(uri_string:uri_string(), list()) -> {ok, term()} | {error, term()}.
1111
get(JwksUrl, SslOptions) ->
@@ -18,21 +18,15 @@ get(JwksUrl, SslOptions, undefined) ->
1818
get(JwksUrl, SslOptions, ProxyOptions) ->
1919
http_get(JwksUrl, SslOptions, ProxyOptions).
2020

21-
get_ssl_options_if_any(SslOptions) ->
22-
case SslOptions of
23-
undefined -> [];
24-
Options -> [{ssl, Options}]
25-
end.
26-
2721
http_get(URL, SslOptions, ProxyOptions) ->
28-
HttpOptions = get_httpc_option_timeout_of_default(60000)
29-
++ get_ssl_options_if_any(SslOptions),
22+
HttpOptions = map_timeout_to_httpc_option(60000)
23+
++ map_ssl_options_to_httpc_option(SslOptions),
3024
{HttpProxyOptions, SetOptions} =
3125
case ProxyOptions of
3226
undefined -> {[], ok};
3327
_ ->
34-
case httpc:set_options(get_httpc_option_proxy_if_any(ProxyOptions)) of
35-
ok -> {get_httpc_option_proxy_auth_if_any(ProxyOptions), ok};
28+
case httpc:set_options(map_proxy_to_httpc_option(ProxyOptions)) of
29+
ok -> {map_proxy_auth_to_httpc_option(ProxyOptions), ok};
3630
{error, _} = Error -> {undefined, Error}
3731
end
3832
end,

0 commit comments

Comments
 (0)