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 ().
2222translate_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 ().
3840translate_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 ().
5054translate_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 ()}].
7079translate_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
7485validator_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
8496validator_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
105118merge_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
149165mapHttpProperty ({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 )).
0 commit comments