Skip to content

Commit

Permalink
Log helpful error when deleting non-system_config ACL via SUP (2600hz…
Browse files Browse the repository at this point in the history
  • Loading branch information
harenson authored and jamesaimonetti committed Apr 8, 2020
1 parent aa3d7ef commit 2ecdd40
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 24 additions & 16 deletions applications/ecallmgr/src/ecallmgr_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ has_acl(Name, Action, ACLs) ->
-spec reload_acls() -> 'no_return'.
reload_acls() ->
_ = [begin
io:format("issued reload ACLs to ~s~n", [Node]),
lager:info("issued reload ACLs to ~s", [Node]),
print_and_log("issued reload ACLs to ~s", [Node]),
freeswitch:bgapi(Node, 'reloadacl', "")
end
|| Node <- ecallmgr_fs_nodes:connected()
Expand Down Expand Up @@ -574,18 +573,12 @@ modify_acls(Name, IP0, ACLS, ACLFun, ConfigFun) ->
'no_return';
[IP | _] ->
ACL = ACLFun(IP),
io:format("updating ~s ACLs ~s(~s) to ~s traffic~n"
,[kz_json:get_value(<<"network-list-name">>, ACL)
,Name
,kz_json:get_value(<<"cidr">>, ACL)
,kz_json:get_value(<<"type">>, ACL)
]),
lager:info("updating ~s ACLs ~s(~s) to ~s traffic~n"
,[kz_json:get_value(<<"network-list-name">>, ACL)
,Name
,kz_json:get_value(<<"cidr">>, ACL)
,kz_json:get_value(<<"type">>, ACL)
]),
print_and_log("updating ~s ACLs ~s(~s) to ~s traffic"
,[kz_json:get_value(<<"network-list-name">>, ACL)
,Name
,kz_json:get_value(<<"cidr">>, ACL)
,kz_json:get_value(<<"type">>, ACL)
]),
_ = run_config_fun(ConfigFun, <<"acls">>, kz_json:set_value(Name, ACL, filter_acls(ACLS))),
maybe_reload_acls(Name, 'modify', 4)
end.
Expand All @@ -602,7 +595,10 @@ run_config_fun(ConfigFun, Key, Value) when is_function(ConfigFun, 4) ->
remove_acl(Name, ACLs, ConfigFun) ->
FilteredACLs = filter_acls(ACLs),
_ = case kz_json:get_value(Name, FilteredACLs) of
'undefined' -> io:format("no ACL named ~s found~n", [Name]);
'undefined' ->
not_system_config_acl(Name
,kz_json:get_value([Name, <<"authorizing_type">>], ACLs)
);
ACL ->
io:format("removing ~s ACLs ~s(~s) from ecallmgr system config~n"
,[kz_json:get_value(<<"network-list-name">>, ACL)
Expand All @@ -624,7 +620,7 @@ list_acls(ACLs, Network) ->
Props = kz_json:foldl(fun(Name, ACL, Acc) ->
[{kz_json:get_value(<<"network-list-name">>, ACL)
,kz_json:set_value(<<"name">>, Name, ACL)}
| Acc
| Acc
]
end, [], ACLs),
_ = [maybe_print_acl(Network, FormatString, ACL)
Expand Down Expand Up @@ -738,3 +734,15 @@ hangup(UUID) ->
freeswitch:api(Node, 'uuid_kill', UUID);
_ -> io:format("channel ~s not found~n", [UUID])
end.

-spec not_system_config_acl(kz_term:ne_binary(), kz_term:ne_binary()) -> 'ok'.
not_system_config_acl(Name, 'undefined') ->
io:format("no ACL named ~s found~n", [Name]);
not_system_config_acl(Name, AuthType) ->
io:format("~s is not managed by ecallmgr. It is of type ~s; please use the APIs to manage it.~n"
,[Name, AuthType]
).

-spec print_and_log(string(), [any()]) -> 'ok'.
print_and_log(FormatStr, Args) ->
?SUP_LOG_INFO(FormatStr, Args).
2 changes: 1 addition & 1 deletion core/kazoo_stdlib/include/kz_log.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
-define(LOG_INFO(F, A), io:format('user', "~s:~p " ++ F ++ "\n", [?MODULE, ?LINE | A])).
-define(LOG_NOTICE(F, A), io:format('user', "~s:~p " ++ F ++ "\n", [?MODULE, ?LINE | A])).
-define(LOG_WARNING(F, A), io:format('user', "~s:~p " ++ F ++ "\n", [?MODULE, ?LINE | A])).
-define(LOG_DEV(F, A), io:format(user, "~s:~p " ++ F ++ "\n", [?MODULE, ?LINE | A])).
-define(LOG_DEV(F, A), io:format('user', "~s:~p " ++ F ++ "\n", [?MODULE, ?LINE | A])).

-define(LOG_ALERT(F), ?LOG_ALERT(F, [])).
-define(LOG_CRITICAL(F), ?LOG_CRITICAL(F, [])).
Expand Down

0 comments on commit 2ecdd40

Please sign in to comment.