Skip to content

Commit d25e0f8

Browse files
Refactoring
- Use rabbit_oauth2 prefix for modules which do not have it - Ensure most lines stick to 80 column
1 parent ea6f194 commit d25e0f8

17 files changed

+639
-454
lines changed

deps/rabbitmq_auth_backend_oauth2/app.bzl

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ def all_beam_files(name = "all_beam_files"):
1313
"src/Elixir.RabbitMQ.CLI.Ctl.Commands.AddUaaKeyCommand.erl",
1414
"src/rabbit_auth_backend_oauth2.erl",
1515
"src/rabbit_auth_backend_oauth2_app.erl",
16-
"src/oauth_provider.erl",
17-
"src/resource_server.erl",
18-
"src/rar.erl",
19-
"src/keycloak.erl",
20-
"src/oauth2_schema.erl",
16+
"src/rabbit_oauth2_provider.erl",
17+
"src/rabbit_oauth2_resource_server.erl",
18+
"src/rabbit_oauth2_rar.erl",
19+
"src/rabbit_oauth2_keycloak.erl",
20+
"src/rabbit_oauth2_schema.erl",
2121
"src/rabbit_oauth2_scope.erl",
2222
"src/uaa_jwks.erl",
2323
"src/uaa_jwt.erl",
@@ -51,11 +51,11 @@ def all_test_beam_files(name = "all_test_beam_files"):
5151
"src/Elixir.RabbitMQ.CLI.Ctl.Commands.AddUaaKeyCommand.erl",
5252
"src/rabbit_auth_backend_oauth2.erl",
5353
"src/rabbit_auth_backend_oauth2_app.erl",
54-
"src/resource_server.erl",
55-
"src/oauth_provider.erl",
56-
"src/oauth2_schema.erl",
57-
"src/rar.erl",
58-
"src/keycloak.erl",
54+
"src/rabbit_oauth2_resource_server.erl",
55+
"src/rabbit_oauth2_provider.erl",
56+
"src/rabbit_oauth2_schema.erl",
57+
"src/rabbit_oauth2_rar.erl",
58+
"src/rabbit_oauth2_keycloak.erl",
5959
"src/rabbit_oauth2_scope.erl",
6060
"src/uaa_jwks.erl",
6161
"src/uaa_jwt.erl",
@@ -101,11 +101,11 @@ def all_srcs(name = "all_srcs"):
101101
"src/Elixir.RabbitMQ.CLI.Ctl.Commands.AddUaaKeyCommand.erl",
102102
"src/rabbit_auth_backend_oauth2.erl",
103103
"src/rabbit_auth_backend_oauth2_app.erl",
104-
"src/oauth_provider.erl",
105-
"src/resource_server.erl",
106-
"src/oauth2_schema.erl",
107-
"src/rar.erl",
108-
"src/keycloak.erl",
104+
"src/rabbit_oauth2_provider.erl",
105+
"src/rabbit_oauth2_resource_server.erl",
106+
"src/rabbit_oauth2_schema.erl",
107+
"src/rabbit_oauth2_rar.erl",
108+
"src/rabbit_oauth2_keycloak.erl",
109109
"src/rabbit_oauth2_scope.erl",
110110
"src/uaa_jwks.erl",
111111
"src/uaa_jwt.erl",
@@ -169,10 +169,10 @@ def test_suite_beam_files(name = "test_suite_beam_files"):
169169
deps = ["//deps/rabbit_common:erlang_app"],
170170
)
171171
erlang_bytecode(
172-
name = "oauth2_schema_SUITE_beam_files",
172+
name = "rabbit_oauth2_schema_SUITE_beam_files",
173173
testonly = True,
174-
srcs = ["test/oauth2_schema_SUITE.erl"],
175-
outs = ["test/oauth2_schema_SUITE.beam"],
174+
srcs = ["test/rabbit_oauth2_schema_SUITE.erl"],
175+
outs = ["test/rabbit_oauth2_schema_SUITE.beam"],
176176
app_name = "rabbitmq_auth_backend_oauth2",
177177
erlc_opts = "//:test_erlc_opts",
178178
deps = ["//deps/rabbit_common:erlang_app"],
@@ -248,20 +248,20 @@ def test_suite_beam_files(name = "test_suite_beam_files"):
248248
erlc_opts = "//:test_erlc_opts",
249249
)
250250
erlang_bytecode(
251-
name = "oauth_provider_SUITE_beam_files",
251+
name = "rabbit_oauth2_provider_SUITE_beam_files",
252252
testonly = True,
253-
srcs = ["test/oauth_provider_SUITE.erl"],
254-
outs = ["test/oauth_provider_SUITE.beam"],
253+
srcs = ["test/rabbit_oauth2_provider_SUITE.erl"],
254+
outs = ["test/rabbit_oauth2_provider_SUITE.beam"],
255255
hdrs = ["include/oauth2.hrl"],
256256
app_name = "rabbitmq_auth_backend_oauth2",
257257
erlc_opts = "//:test_erlc_opts",
258258
deps = ["//deps/oauth2_client:erlang_app"],
259259
)
260260
erlang_bytecode(
261-
name = "resource_server_SUITE_beam_files",
261+
name = "rabbit_oauth2_resource_server_SUITE_beam_files",
262262
testonly = True,
263-
srcs = ["test/resource_server_SUITE.erl"],
264-
outs = ["test/resource_server_SUITE.beam"],
263+
srcs = ["test/rabbit_oauth2_resource_server_SUITE.erl"],
264+
outs = ["test/rabbit_oauth2_resource_server_SUITE.beam"],
265265
hdrs = ["include/oauth2.hrl"],
266266
app_name = "rabbitmq_auth_backend_oauth2",
267267
erlc_opts = "//:test_erlc_opts",

deps/rabbitmq_auth_backend_oauth2/priv/schema/rabbitmq_auth_backend_oauth2.schema

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
{translation,
131131
"rabbitmq_auth_backend_oauth2.key_config.signing_keys",
132132
fun(Conf) ->
133-
oauth2_schema:translate_signing_keys(Conf)
133+
rabbit_oauth2_schema:translate_signing_keys(Conf)
134134
end}.
135135

136136
{mapping,
@@ -170,7 +170,7 @@
170170

171171
{translation, "rabbitmq_auth_backend_oauth2.discovery_endpoint_params",
172172
fun(Conf) ->
173-
oauth2_schema:translate_endpoint_params("discovery_endpoint_params", Conf)
173+
rabbit_oauth2_schema:translate_endpoint_params("discovery_endpoint_params", Conf)
174174
end}.
175175

176176
{mapping,
@@ -190,7 +190,7 @@
190190

191191
{translation, "rabbitmq_auth_backend_oauth2.oauth_providers",
192192
fun(Conf) ->
193-
oauth2_schema:translate_oauth_providers(Conf)
193+
rabbit_oauth2_schema:translate_oauth_providers(Conf)
194194
end}.
195195

196196
{mapping,
@@ -327,7 +327,7 @@
327327

328328
{translation, "rabbitmq_auth_backend_oauth2.oauth_providers",
329329
fun(Conf) ->
330-
oauth2_schema:translate_oauth_providers(Conf)
330+
rabbit_oauth2_schema:translate_oauth_providers(Conf)
331331
end}.
332332

333333
{mapping,
@@ -369,5 +369,5 @@
369369

370370
{translation, "rabbitmq_auth_backend_oauth2.resource_servers",
371371
fun(Conf) ->
372-
oauth2_schema:translate_resource_servers(Conf)
372+
rabbit_oauth2_schema:translate_resource_servers(Conf)
373373
end}.

deps/rabbitmq_auth_backend_oauth2/src/rabbit_auth_backend_oauth2.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
get_scope/1, set_scope/2,
2929
resolve_resource_server/1]).
3030

31-
-import(keycloak, [has_keycloak_scopes/1, extract_scopes_from_keycloak_format/1]).
32-
-import(rar, [extract_scopes_from_rich_auth_request/2, has_rich_auth_request_scopes/1]).
31+
-import(rabbit_oauth2_keycloak, [has_keycloak_scopes/1, extract_scopes_from_keycloak_format/1]).
32+
-import(rabbit_oauth2_rar, [extract_scopes_from_rich_auth_request/2, has_rich_auth_request_scopes/1]).
3333

3434
-import(rabbit_oauth2_scope, [filter_matching_scope_prefix_and_drop_it/2]).
3535

deps/rabbitmq_auth_backend_oauth2/src/keycloak.erl renamed to deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_keycloak.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
66
%%
77

8-
-module(keycloak).
8+
-module(rabbit_oauth2_keycloak).
99

1010
-include("oauth2.hrl").
1111

deps/rabbitmq_auth_backend_oauth2/src/oauth_provider.erl renamed to deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_provider.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
66
%%
77

8-
-module(oauth_provider).
8+
-module(rabbit_oauth2_provider).
99

1010
-include("oauth2.hrl").
1111

deps/rabbitmq_auth_backend_oauth2/src/rar.erl renamed to deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_rar.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
%%
77

88
% Rich Authorization Request
9-
-module(rar).
9+
-module(rabbit_oauth2_rar).
1010

1111
-include("oauth2.hrl").
1212
-import(uaa_jwt, [get_scope/1, set_scope/2]).

deps/rabbitmq_auth_backend_oauth2/src/resource_server.erl renamed to deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_resource_server.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
66
%%
77

8-
-module(resource_server).
8+
-module(rabbit_oauth2_resource_server).
99

1010
-include("oauth2.hrl").
1111

deps/rabbitmq_auth_backend_oauth2/src/oauth2_schema.erl renamed to deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_schema.erl

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
66
%%
77

8-
-module(oauth2_schema).
8+
-module(rabbit_oauth2_schema).
99

1010

1111
-export([
@@ -20,7 +20,8 @@ extract_value({_Name,V}) -> V.
2020

2121
-spec translate_resource_servers([{list(), binary()}]) -> map().
2222
translate_resource_servers(Conf) ->
23-
Settings = cuttlefish_variable:filter_by_prefix("auth_oauth2.resource_servers", Conf),
23+
Settings = cuttlefish_variable:filter_by_prefix("auth_oauth2.resource_servers",
24+
Conf),
2425
Map = merge_list_of_maps([
2526
extract_resource_server_properties(Settings),
2627
extract_resource_server_preferred_username_claims(Settings)
@@ -31,25 +32,30 @@ translate_resource_servers(Conf) ->
3132
_ -> V
3233
end end, Map),
3334
ResourceServers = maps:values(Map0),
34-
lists:foldl(fun(Elem,AccMap)-> maps:put(proplists:get_value(id, Elem), Elem, AccMap) end, #{},
35+
lists:foldl(fun(Elem,AccMap) ->
36+
maps:put(proplists:get_value(id, Elem), Elem, AccMap) end, #{},
3537
ResourceServers).
3638

3739
-spec translate_oauth_providers([{list(), binary()}]) -> map().
3840
translate_oauth_providers(Conf) ->
39-
Settings = cuttlefish_variable:filter_by_prefix("auth_oauth2.oauth_providers", Conf),
41+
Settings = cuttlefish_variable:filter_by_prefix("auth_oauth2.oauth_providers",
42+
Conf),
4043

4144
merge_list_of_maps([
4245
extract_oauth_providers_properties(Settings),
43-
extract_oauth_providers_endpoint_params(discovery_endpoint_params, Settings),
46+
extract_oauth_providers_endpoint_params(discovery_endpoint_params,
47+
Settings),
4448
extract_oauth_providers_algorithm(Settings),
4549
extract_oauth_providers_https(Settings),
4650
extract_oauth_providers_signing_keys(Settings)
4751
]).
4852

4953
-spec translate_signing_keys([{list(), binary()}]) -> map().
5054
translate_signing_keys(Conf) ->
51-
Settings = cuttlefish_variable:filter_by_prefix("auth_oauth2.signing_keys", Conf),
52-
ListOfKidPath = lists:map(fun({Id, Path}) -> {list_to_binary(lists:last(Id)), Path} end, Settings),
55+
Settings = cuttlefish_variable:filter_by_prefix("auth_oauth2.signing_keys",
56+
Conf),
57+
ListOfKidPath = lists:map(fun({Id, Path}) -> {
58+
list_to_binary(lists:last(Id)), Path} end, Settings),
5359
translate_list_of_signing_keys(ListOfKidPath).
5460

5561
-spec translate_list_of_signing_keys([{list(), list()}]) -> map().
@@ -61,15 +67,20 @@ translate_list_of_signing_keys(ListOfKidPath) ->
6167
string:trim(Bin, trailing, "\n");
6268
_Error ->
6369
%% this throws and makes Cuttlefish treak the key as invalid
64-
cuttlefish:invalid("file does not exist or cannot be read by the node")
70+
cuttlefish:invalid("file does not exist or cannot be " ++
71+
"read by the node")
6572
end
6673
end,
67-
maps:map(fun(_K, Path) -> {pem, TryReadingFileFun(Path)} end, maps:from_list(ListOfKidPath)).
74+
maps:map(fun(_K, Path) -> {pem, TryReadingFileFun(Path)} end,
75+
maps:from_list(ListOfKidPath)).
6876

69-
-spec translate_endpoint_params(list(), [{list(), binary()}]) -> [{binary(), binary()}].
77+
-spec translate_endpoint_params(list(), [{list(), binary()}]) ->
78+
[{binary(), binary()}].
7079
translate_endpoint_params(Variable, Conf) ->
71-
Params0 = cuttlefish_variable:filter_by_prefix("auth_oauth2." ++ Variable, Conf),
72-
[{list_to_binary(Param), list_to_binary(V)} || {["auth_oauth2", _, Param], V} <- Params0].
80+
Params0 = cuttlefish_variable:filter_by_prefix("auth_oauth2." ++ Variable,
81+
Conf),
82+
[{list_to_binary(Param), list_to_binary(V)} || {["auth_oauth2", _, Param], V}
83+
<- Params0].
7384

7485
validator_file_exists(Attr, Filename) ->
7586
case file:read_file(Filename) of
@@ -78,7 +89,8 @@ validator_file_exists(Attr, Filename) ->
7889
_Error ->
7990
%% this throws and makes Cuttlefish treak the key as invalid
8091
cuttlefish:invalid(io_lib:format(
81-
"Invalid attribute (~p) value: file ~p does not exist or cannot be read by the node", [Attr, Filename]))
92+
"Invalid attribute (~p) value: file ~p does not exist or " ++
93+
"cannot be read by the node", [Attr, Filename]))
8294
end.
8395

8496
validator_uri(Attr, Uri) when is_binary(Uri) ->
@@ -99,7 +111,8 @@ validator_https_uri(Attr, Uri) when is_list(Uri) ->
99111
true -> Uri;
100112
false ->
101113
cuttlefish:invalid(io_lib:format(
102-
"Invalid attribute (~p) value: uri ~p must be a valid https uri", [Attr, Uri]))
114+
"Invalid attribute (~p) value: uri ~p must be a valid https uri",
115+
[Attr, Uri]))
103116
end.
104117

105118
merge_list_of_maps(ListOfMaps) ->
@@ -110,7 +123,8 @@ extract_oauth_providers_properties(Settings) ->
110123
KeyFun = fun extract_key_as_binary/1,
111124
ValueFun = fun extract_value/1,
112125

113-
OAuthProviders = [{Name, mapOauthProviderProperty({list_to_atom(Key), list_to_binary(V)})}
126+
OAuthProviders = [
127+
{Name, mapOauthProviderProperty({list_to_atom(Key), list_to_binary(V)})}
114128
|| {["auth_oauth2", "oauth_providers", Name, Key], V} <- Settings],
115129
maps:groups_from_list(KeyFun, ValueFun, OAuthProviders).
116130

@@ -133,7 +147,8 @@ mapOauthProviderProperty({Key, Value}) ->
133147
discovery_endpoint_path -> validator_uri(Key, Value);
134148
discovery_endpoint_params ->
135149
cuttlefish:invalid(io_lib:format(
136-
"Invalid attribute (~p) value: should be a map of Key,Value pairs", [Key]));
150+
"Invalid attribute (~p) value: should be a map of Key,Value pairs",
151+
[Key]));
137152
_ -> Value
138153
end}.
139154

@@ -144,7 +159,8 @@ extract_oauth_providers_https(Settings) ->
144159
{["auth_oauth2","oauth_providers", Name, "https", Key], V} <- Settings ],
145160

146161
maps:map(fun(_K,V)-> [{https, V}] end,
147-
maps:groups_from_list(ExtractProviderNameFun, fun({_, V}) -> V end, AttributesPerProvider)).
162+
maps:groups_from_list(ExtractProviderNameFun, fun({_, V}) -> V end,
163+
AttributesPerProvider)).
148164

149165
mapHttpProperty({Key, Value}) ->
150166
{Key, case Key of
@@ -156,8 +172,10 @@ extract_oauth_providers_algorithm(Settings) ->
156172
KeyFun = fun extract_key_as_binary/1,
157173

158174
IndexedAlgorithms = [{Name, {Index, list_to_binary(V)}} ||
159-
{["auth_oauth2","oauth_providers", Name, "algorithms", Index], V} <- Settings ],
160-
SortedAlgorithms = lists:sort(fun({_,{AI,_}},{_,{BI,_}}) -> AI < BI end, IndexedAlgorithms),
175+
{["auth_oauth2","oauth_providers", Name, "algorithms", Index], V}
176+
<- Settings ],
177+
SortedAlgorithms = lists:sort(fun({_,{AI,_}},{_,{BI,_}}) -> AI < BI end,
178+
IndexedAlgorithms),
161179
Algorithms = [{Name, V} || {Name, {_I, V}} <- SortedAlgorithms],
162180
maps:map(fun(_K,V)-> [{algorithms, V}] end,
163181
maps:groups_from_list(KeyFun, fun({_, V}) -> V end, Algorithms)).
@@ -166,8 +184,10 @@ extract_resource_server_preferred_username_claims(Settings) ->
166184
KeyFun = fun extract_key_as_binary/1,
167185

168186
IndexedClaims = [{Name, {Index, list_to_binary(V)}} ||
169-
{["auth_oauth2","resource_servers", Name, "preferred_username_claims", Index], V} <- Settings ],
170-
SortedClaims = lists:sort(fun({_,{AI,_}},{_,{BI,_}}) -> AI < BI end, IndexedClaims),
187+
{["auth_oauth2","resource_servers", Name, "preferred_username_claims",
188+
Index], V} <- Settings ],
189+
SortedClaims = lists:sort(fun({_,{AI,_}},{_,{BI,_}}) -> AI < BI end,
190+
IndexedClaims),
171191
Claims = [{Name, V} || {Name, {_I, V}} <- SortedClaims],
172192
maps:map(fun(_K,V)-> [{preferred_username_claims, V}] end,
173193
maps:groups_from_list(KeyFun, fun({_, V}) -> V end, Claims)).
@@ -185,6 +205,7 @@ extract_oauth_providers_signing_keys(Settings) ->
185205
KeyFun = fun extract_key_as_binary/1,
186206

187207
IndexedSigningKeys = [{Name, {list_to_binary(Kid), list_to_binary(V)}} ||
188-
{["auth_oauth2","oauth_providers", Name, "signing_keys", Kid], V} <- Settings ],
208+
{["auth_oauth2","oauth_providers", Name, "signing_keys", Kid], V}
209+
<- Settings ],
189210
maps:map(fun(_K,V)-> [{signing_keys, translate_list_of_signing_keys(V)}] end,
190211
maps:groups_from_list(KeyFun, fun({_, V}) -> V end, IndexedSigningKeys)).

deps/rabbitmq_auth_backend_oauth2/src/uaa_jwt.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
format_ssl_options/1,
2424
format_oauth_provider_id/1,
2525
get_oauth_provider/2]).
26-
-import(resource_server, [
26+
-import(rabbit_oauth2_resource_server, [
2727
resolve_resource_server_from_audience/1]).
28-
-import(oauth_provider, [
28+
-import(rabbit_oauth2_provider, [
2929
add_signing_key/2, get_signing_key/2,
3030
get_internal_oauth_provider/1,
3131
replace_signing_keys/2]).

0 commit comments

Comments
 (0)