Skip to content

Commit

Permalink
HTTP controller API: refactoring
Browse files Browse the repository at this point in the history
Simplify adding config use the same methods as in erGW config
  • Loading branch information
vk committed Oct 5, 2021
1 parent ca3feed commit 03e751a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
6 changes: 4 additions & 2 deletions apps/ergw/src/ergw_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

%% API
-export([load/0, apply/1, serialize_config/1, load_part_of_config/1]).
-export([ergw_core_init/2]).

-ifdef(TEST).
-export([config_meta/0,
Expand Down Expand Up @@ -195,8 +196,9 @@ ergw_core_init(proxy_map, #{proxy_map := Map}) ->
ok = ergw_core:setopts(proxy_map, Map);
ergw_core_init(http_api, #{http_api := Opts}) ->
ergw_http_api:init(Opts);
ergw_core_init(_K, _) ->
ok.
ergw_core_init(_K, Opts) ->
?LOG(warning, "Unhandled config option ~p~n", [Opts]),
{error, unhandled}.

ergw_charging_init(rules, #{rules := Rules}) ->
maps:map(fun ergw_core:add_charging_rule/2, Rules);
Expand Down
18 changes: 3 additions & 15 deletions apps/ergw/src/http_controller_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,10 @@ apply_config(Map) ->
{error, #{type => <<"error">>, message => <<"Unhandled error">>}}
end.

add_config_part(ip_pools, Pools, Acc) ->
Result = maps:map(fun ergw_core:add_ip_pool/2, Pools),
?LOG(info, "Pools ~p added", [Result]),
maps:merge(Acc, Result);
add_config_part(apns, APNs, Acc) ->
Result = maps:map(fun ergw_core:add_apn/2, APNs),
?LOG(info, "APNS ~p added", [Result]),
maps:merge(Acc, Result);
add_config_part(upf_nodes, UP, Acc) ->
ergw_core:setopts(sx_defaults, maps:get(default, UP, #{})),
Result = maps:map(fun ergw_core:add_sx_node/2, maps:get(entries, UP, #{})),
?LOG(info, "UPF nodes ~p added", [Result]),
maps:merge(Acc, Result);
add_config_part(K, V, Acc) ->
?LOG(warning, "Unhandled config parameter ~p with value ~p", [K, V]),
Acc.
Result = ergw_config:ergw_core_init(K, #{K => V}),
?LOG(info, "The ~p added with result ~p", [K, Result]),
maps:merge(Acc, Result).

json_to_map(JsonBin) ->
case catch jsx:decode(JsonBin) of
Expand Down

0 comments on commit 03e751a

Please sign in to comment.