diff --git a/src/emqx_auth_http.app.src b/src/emqx_auth_http.app.src index ee01818..eaabdb3 100644 --- a/src/emqx_auth_http.app.src +++ b/src/emqx_auth_http.app.src @@ -3,7 +3,7 @@ {vsn, "git"}, {modules, []}, {registered, [emqx_auth_http_sup]}, - {applications, [kernel,stdlib,clique]}, + {applications, [kernel,stdlib]}, {mod, {emqx_auth_http_app, []}}, {env, []}, {licenses, ["Apache-2.0"]}, diff --git a/src/emqx_auth_http_app.erl b/src/emqx_auth_http_app.erl index b171e60..104610b 100644 --- a/src/emqx_auth_http_app.erl +++ b/src/emqx_auth_http_app.erl @@ -35,7 +35,6 @@ start(_StartType, _StartArgs) -> with_env(auth_req, fun load_auth_hook/1), with_env(acl_req, fun load_acl_hook/1), - emqx_auth_http_cfg:register(), supervisor:start_link({local, ?MODULE}, ?MODULE, []). load_auth_hook(AuthReq) -> @@ -60,8 +59,7 @@ load_acl_hook(AclReq) -> stop(_State) -> emqx:unhook('client.authenticate', fun emqx_auth_http:check/3), - emqx:unhook('client.check_acl', fun emqx_acl_http:check_acl/5), - emqx_auth_http_cfg:unregister(). + emqx:unhook('client.check_acl', fun emqx_acl_http:check_acl/5). %%-------------------------------------------------------------------- %% Dummy supervisor diff --git a/src/emqx_auth_http_cfg.erl b/src/emqx_auth_http_cfg.erl deleted file mode 100644 index 770a6cb..0000000 --- a/src/emqx_auth_http_cfg.erl +++ /dev/null @@ -1,96 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%%-------------------------------------------------------------------- - --module(emqx_auth_http_cfg). - --include("emqx_auth_http.hrl"). - --export([ register/0 - , unregister/0 - ]). - -register() -> - clique_config:load_schema([code:priv_dir(?APP)], ?APP), - register_formatter(), - register_config(). - -unregister() -> - unregister_formatter(), - unregister_config(), - clique_config:unload_schema(?APP). - -register_formatter() -> - [clique:register_formatter( - cuttlefish_variable:tokenize(Key), fun formatter_callback/2) - || Key <- keys()]. - -formatter_callback([_, _, _], Params) -> - proplists:get_value(url, Params); -formatter_callback([_, _, _, "params"], Params) -> - format(proplists:get_value(params, Params)); -formatter_callback([_, _, _, Key], Params) -> - proplists:get_value(list_to_atom(Key), Params). - -unregister_formatter() -> - [clique:unregister_formatter(cuttlefish_variable:tokenize(Key)) || Key <- keys()]. - -register_config() -> - Keys = keys(), - [clique:register_config(Key , fun config_callback/2) || Key <- Keys], - clique:register_config_whitelist(Keys, ?APP). - -config_callback([_, _, Key0], Value) -> - Key = list_to_atom(Key0), - {ok, Env} = application:get_env(?APP, Key), - application:set_env(?APP, Key, lists:keyreplace(url, 1, Env, {url, Value})), - " successfully\n"; -config_callback([_, _, Key0, "params"], Value0) -> - Key = list_to_atom(Key0), - {ok, Env} = application:get_env(?APP, Key), - Value = [list_to_tuple(string:tokens(S, "=")) || S <- string:tokens(Value0, ",")], - application:set_env(?APP, Key, lists:keyreplace(params, 1, Env, {params, Value})), - " successfully\n"; -config_callback([_, _, Key0, Key1], Value) -> - Key2 = list_to_atom(Key0), - Key3 = list_to_atom(Key1), - {ok, Env} = application:get_env(?APP, Key2), - application:set_env(?APP, Key2, lists:keyreplace(Key3, 1, Env, {Key3, Value})), - " successfully\n". - -unregister_config() -> - Keys = keys(), - [clique:unregister_config(Key) || Key <- Keys], - clique:unregister_config_whitelist(Keys, ?APP). - -format(Params) -> - format(Params, ""). -format([{Key, Value}], Acc) -> - Acc ++ lists:concat([Key, "=", Value]); -format([{Key, Value} | Params], Acc) -> - format(Params, Acc ++ lists:concat([Key, "=", Value, ","])). - -keys() -> - ["auth.http.auth_req", - "auth.http.auth_req.method", - "auth.http.auth_req.params", - "auth.http.super_req", - "auth.http.super_req.method", - "auth.http.super_req.params", - "auth.http.acl_req", - "auth.http.acl_req.method", - "auth.http.acl_req.params" - ]. -