chore(format): format some code

This commit is contained in:
zhanghongtong 2021-01-27 22:52:46 +08:00 committed by JianBo He
parent e283a3d165
commit 6a83cf3f35
18 changed files with 77 additions and 95 deletions

View File

@ -133,9 +133,9 @@ jobs:
run: |
docker-compose -f .ci/compatibility_tests/docker-compose-mysql-tls.yaml up -d
sed -i 's|^[#[:space:]]*auth.mysql.ssl[[:space:]]*=.*|auth.mysql.ssl = on|g' apps/emqx_auth_mysql/etc/emqx_auth_mysql.conf
sed -i 's|^[#[:space:]]*auth.mysql.cacertfile[[:space:]]*=.*|auth.mysql.cacertfile = /emqx/apps/emqx_auth_mysql/test/emqx_auth_mysql_SUITE_data/ca.pem|g' apps/emqx_auth_mysql/etc/emqx_auth_mysql.conf
sed -i 's|^[#[:space:]]*auth.mysql.certfile[[:space:]]*=.*|auth.mysql.certfile = /emqx/apps/emqx_auth_mysql/test/emqx_auth_mysql_SUITE_data/client-cert.pem|g' apps/emqx_auth_mysql/etc/emqx_auth_mysql.conf
sed -i 's|^[#[:space:]]*auth.mysql.keyfile[[:space:]]*=.*|auth.mysql.keyfile = /emqx/apps/emqx_auth_mysql/test/emqx_auth_mysql_SUITE_data/client-key.pem|g' apps/emqx_auth_mysql/etc/emqx_auth_mysql.conf
# sed -i 's|^[#[:space:]]*auth.mysql.ssl.cacertfile[[:space:]]*=.*|auth.mysql.ssl.cacertfile = /emqx/apps/emqx_auth_mysql/test/emqx_auth_mysql_SUITE_data/ca.pem|g' apps/emqx_auth_mysql/etc/emqx_auth_mysql.conf
# sed -i 's|^[#[:space:]]*auth.mysql.ssl.certfile[[:space:]]*=.*|auth.mysql.ssl.certfile = /emqx/apps/emqx_auth_mysql/test/emqx_auth_mysql_SUITE_data/client-cert.pem|g' apps/emqx_auth_mysql/etc/emqx_auth_mysql.conf
# sed -i 's|^[#[:space:]]*auth.mysql.ssl.keyfile[[:space:]]*=.*|auth.mysql.ssl.keyfile = /emqx/apps/emqx_auth_mysql/test/emqx_auth_mysql_SUITE_data/client-key.pem|g' apps/emqx_auth_mysql/etc/emqx_auth_mysql.conf
- name: setup
env:
MYSQL_TAG: ${{ matrix.mysql_tag }}

View File

@ -197,10 +197,10 @@ validate([K|Keys], [V|Values]) ->
do_validation(login, all) ->
true;
do_validation(login, {clientid, V}) when is_binary(V)
andalso byte_size(V) > 0->
andalso byte_size(V) > 0 ->
true;
do_validation(login, {username, V}) when is_binary(V)
andalso byte_size(V) > 0->
andalso byte_size(V) > 0 ->
true;
do_validation(topic, V) when is_binary(V)
andalso byte_size(V) > 0 ->

View File

@ -36,7 +36,7 @@
%%--------------------------------------------------------------------
%% @doc Add Acls
-spec(add_acl(login() |all, emqx_topic:topic(), pub | sub| pubsub, allow | deny) ->
-spec(add_acl(login() | all, emqx_topic:topic(), pub | sub | pubsub, allow | deny) ->
ok | {error, any()}).
add_acl(Login, Topic, Action, Access) ->
Acls = #?TABLE{

View File

@ -33,7 +33,7 @@
]).
init(#{clientid_list := ClientidList, username_list := UsernameList}) ->
ok = ekka_mnesia:create_table(emqx_user, [
ok = ekka_mnesia:create_table(?TABLE, [
{disc_copies, [node()]},
{attributes, record_info(fields, emqx_user)},
{storage_properties, [{ets, [{read_concurrency, true}]}]}]),
@ -41,7 +41,7 @@ init(#{clientid_list := ClientidList, username_list := UsernameList}) ->
|| {Clientid, Password} <- ClientidList],
_ = [ add_default_user({{username, iolist_to_binary(Username)}, iolist_to_binary(Password)})
|| {Username, Password} <- UsernameList],
ok = ekka_mnesia:copy_table(emqx_user, disc_copies).
ok = ekka_mnesia:copy_table(?TABLE, disc_copies).
%% @private
add_default_user({Login, Password}) when is_tuple(Login) ->
@ -55,8 +55,8 @@ check(ClientInfo = #{ clientid := Clientid
, password := NPassword
}, AuthResult, #{hash_type := HashType}) ->
Username = maps:get(username, ClientInfo, undefined),
MatchSpec = ets:fun2ms(fun({?TABLE, {clientid, X }, Password, InterTime}) when X =:= Clientid-> Password;
({?TABLE, {username, X }, Password, InterTime}) when X =:= Username andalso X =/= undefined -> Password
MatchSpec = ets:fun2ms(fun({?TABLE, {clientid, X}, Password, InterTime}) when X =:= Clientid-> Password;
({?TABLE, {username, X}, Password, InterTime}) when X =:= Username andalso X =/= undefined -> Password
end),
case ets:select(?TABLE, MatchSpec) of
[] ->

View File

@ -128,7 +128,7 @@ add_clientid(_Bindings, Params) ->
Re = do_add_clientid(Params),
case Re of
ok -> return(ok);
{error, Error} -> {error, format_msg(Error)}
{error, Error} -> return({error, format_msg(Error)})
end
end.
@ -177,7 +177,7 @@ add_username(_Bindings, Params) ->
false ->
case do_add_username(Params) of
ok -> return(ok);
{error, Error} -> {error, format_msg(Error)}
{error, Error} -> return({error, format_msg(Error)})
end
end.

View File

@ -23,12 +23,10 @@
%% FIXME: compatible with 4.0-4.2 version format, plan to delete in 5.0
{mapping, "auth.mongo.login", "emqx_auth_mongo.server", [
{default, ""},
{datatype, string}
]}.
{mapping, "auth.mongo.username", "emqx_auth_mongo.server", [
{default, ""},
{datatype, string}
]}.
@ -100,7 +98,7 @@
Pool = cuttlefish:conf_get("auth.mongo.pool", Conf),
%% FIXME: compatible with 4.0-4.2 version format, plan to delete in 5.0
Login = cuttlefish:conf_get("auth.mongo.username", Conf,
cuttlefish:conf_get("auth.mongo.login", Conf)
cuttlefish:conf_get("auth.mongo.login", Conf, "")
),
Passwd = cuttlefish:conf_get("auth.mongo.password", Conf),
DB = cuttlefish:conf_get("auth.mongo.database", Conf),
@ -131,17 +129,11 @@
{cacertfile, cuttlefish:conf_get(Prefix ++ ".cacertfile", Conf, undefined)}])
end,
%% FIXME: compatible with 4.0-4.2 version format, plan to delete in 5.0
GenSsl = case cuttlefish:conf_get("auth.mongo.ssl.cacertfile", Conf, undefined) of
undefined -> [{ssl, true}, {ssl_opts, SslOpts("auth.mongo.ssl_opts")}];
_ -> [{ssl, true}, {ssl_opts, SslOpts("auth.mongo.ssl")}]
end,
%% FIXME: compatible with 4.0-4.2 version format, plan to delete in 5.0
Ssl = case cuttlefish:conf_get("auth.mongo.ssl", Conf) of
on -> GenSsl;
on -> [{ssl, true}, {ssl_opts, SslOpts("auth.mongo.ssl")}];
off -> [];
true -> GenSsl;
true -> [{ssl, true}, {ssl_opts, SslOpts("auth.mongo.ssl_opts")}];
false -> []
end,

View File

@ -17,12 +17,12 @@ auth.mysql.pool = 8
## MySQL username.
##
## Value: String
# auth.mysql.username =
#auth.mysql.username =
## MySQL password.
##
## Value: String
# auth.mysql.password =
#auth.mysql.password =
## MySQL database.
##
@ -98,19 +98,19 @@ auth.mysql.acl_query = select allow, ipaddr, username, clientid, access, topic f
## Mysql ssl configuration.
##
## Value: on | off
## auth.mysql.ssl = off
#auth.mysql.ssl = off
## CA certificate.
##
## Value: File
# auth.mysql.ssl.cacertfile = /path/to/ca.pem
#auth.mysql.ssl.cacertfile = /path/to/ca.pem
## Client ssl certificate.
##
## Value: File
## auth.mysql.ssl.certfile = path to your clientcert file
#auth.mysql.ssl.certfile = /path/to/your/clientcert.pem
## Client ssl keyfile.
##
## Value: File
## auth.mysql.ssl.keyfile = path to your clientkey file
#auth.mysql.ssl.keyfile = /path/to/your/clientkey.pem

View File

@ -36,23 +36,19 @@
]}.
{mapping, "auth.mysql.ssl.cafile", "emqx_auth_mysql.server", [
{default, ""},
{datatype, string}
]}.
{mapping, "auth.mysql.ssl.cacertfile", "emqx_auth_mysql.server", [
{default, ""},
{datatype, string}
]}.
%% FIXME: compatible with 4.0-4.2 version format, plan to delete in 5.0
{mapping, "auth.mysql.ssl.certfile", "emqx_auth_mysql.server", [
{default, ""},
{datatype, string}
]}.
{mapping, "auth.mysql.ssl.keyfile", "emqx_auth_mysql.server", [
{default, ""},
{datatype, string}
]}.
@ -78,28 +74,31 @@
end
end,
Options = [{pool_size, Pool},
{auto_reconnect, 1},
{host, MyHost},
{port, MyPort},
{user, Username},
{password, Passwd},
{database, DB},
{encoding, utf8},
{query_timeout, Timeout},
{keep_alive, true}],
{auto_reconnect, 1},
{host, MyHost},
{port, MyPort},
{user, Username},
{password, Passwd},
{database, DB},
{encoding, utf8},
{query_timeout, Timeout},
{keep_alive, true}],
Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
Options1 =
case cuttlefish:conf_get("auth.mysql.ssl", Conf) of
true ->
%% FIXME: compatible with 4.0-4.2 version format, plan to delete in 5.0
CA = cuttlefish:conf_get("auth.mysql.ssl.cacertfile", Conf,
cuttlefish:conf_get("auth.mysql.ssl.cafile", Conf)
),
Cert = cuttlefish:conf_get("auth.mysql.ssl.certfile", Conf),
Key = cuttlefish:conf_get("auth.mysql.ssl.keyfile", Conf),
Options ++ [{ssl, {server_name_indication, disable},
{cacertfile, CA},
{certfile, Cert},
{keyfile, Key}}];
CA = cuttlefish:conf_get(
"auth.mysql.ssl.cacertfile", Conf,
cuttlefish:conf_get("auth.mysql.ssl.cafile", Conf, undefined)
),
Cert = cuttlefish:conf_get("auth.mysql.ssl.certfile", Conf, undefined),
Key = cuttlefish:conf_get("auth.mysql.ssl.keyfile", Conf, undefined),
Options ++ [{ssl, Filter([{server_name_indication, disable},
{cacertfile, CA},
{certfile, Cert},
{keyfile, Key}])
}];
_ ->
Options
end,

View File

@ -45,30 +45,22 @@ auth.pgsql.ssl = off
## Example:
## tlsv1.1,tlsv1.2,tlsv1.3
##
## auth.pgsql.ssl_opts.tls_versions = tlsv1.2
## TLS version
## You can configure multi-version use "," split,
## default value is :tlsv1.2
## Example:
## tlsv1.1,tlsv1.2,tlsv1.3
##
## auth.pgsql.ssl.tls_versions = tlsv1.2
#auth.pgsql.ssl.tls_versions = tlsv1.2
## SSL keyfile.
##
## Value: File
## auth.pgsql.ssl.keyfile =
#auth.pgsql.ssl.keyfile =
## SSL certfile.
##
## Value: File
## auth.pgsql.ssl.certfile =
#auth.pgsql.ssl.certfile =
## SSL cacertfile.
##
## Value: File
## auth.pgsql.ssl.cacertfile =
#auth.pgsql.ssl.cacertfile =
## Authentication query.
##

View File

@ -97,17 +97,11 @@
||Value <- string:tokens(cuttlefish:conf_get(Prefix ++ ".tls_versions", Conf), " ,")]}}])
end,
%% FIXME: compatible with 4.0-4.2 version format, plan to delete in 5.0
GenSsl = case cuttlefish:conf_get("auth.pgsql.ssl.cacertfile", Conf, undefined) of
undefined -> [{ssl, true}, {ssl_opts, SslOpts("auth.pgsql.ssl_opts")}];
_ -> [{ssl, true}, {ssl_opts, SslOpts("auth.pgsql.ssl")}]
end,
%% FIXME: compatible with 4.0-4.2 version format, plan to delete in 5.0
Ssl = case cuttlefish:conf_get("auth.pgsql.ssl", Conf) of
on -> GenSsl;
on -> [{ssl, true}, {ssl_opts, SslOpts("auth.pgsql.ssl")}];
off -> [];
true -> GenSsl;
true -> [{ssl, true}, {ssl_opts, SslOpts("auth.pgsql.ssl_opts")}];
false -> []
end,

View File

@ -29,7 +29,10 @@
, equery/3
]).
-type client_info() :: #{username:=_, clientid:=_, peerhost:=_, _=>_}.
-type client_info() :: #{username := _,
clientid := _,
peerhost := _,
_ => _}.
%%--------------------------------------------------------------------
%% Avoid SQL Injection: Parse SQL to Parameter Query.

View File

@ -103,7 +103,7 @@ auth.redis.acl_cmd = HGETALL mqtt_acl:%u
## CA certificate.
##
## Value: File
# auth.redis.ssl.cacertfile = path/to/your/cafile.pem
#auth.redis.ssl.cacertfile = path/to/your/cafile.pem
## Client ssl certificate.
##

View File

@ -39,18 +39,14 @@
]}.
{mapping, "auth.redis.ssl.cacertfile", "emqx_auth_redis.options", [
{default, ""},
{datatype, string}
]}.
%% FIXME: compatible with 4.0-4.2 version format, plan to delete in 5.0
{mapping, "auth.redis.ssl.certfile", "emqx_auth_redis.options", [
{default, ""},
{datatype, string}
]}.
{mapping, "auth.redis.ssl.keyfile", "emqx_auth_redis.options", [
{default, ""},
{datatype, string}
]}.
@ -74,19 +70,27 @@
{translation, "emqx_auth_redis.options", fun(Conf) ->
Ssl = cuttlefish:conf_get("auth.redis.ssl", Conf, false),
Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
case Ssl of
true ->
%% FIXME: compatible with 4.0-4.2 version format, plan to delete in 5.0
Prefix = case cuttlefish:conf_get("auth.redis.ssl.cacertfile", Conf, undefined) of
undefined -> "auth.redis";
_ -> "auth.redis.ssl"
end,
CA = cuttlefish:conf_get(Prefix ++ ".cacertfile", Conf),
Cert = cuttlefish:conf_get(Prefix ++ ".certfile", Conf),
Key = cuttlefish:conf_get(Prefix ++ ".keyfile", Conf),
[{options, [{ssl_options, [{cacertfile, CA},
{certfile, Cert},
{keyfile, Key}]}]}];
CA = cuttlefish:conf_get(
"auth.redis.ssl.cacertfile", Conf,
cuttlefish:conf_get("auth.redis.cacertfile", Conf, undefined)
),
Cert = cuttlefish:conf_get(
"auth.redis.ssl.certfile", Conf,
cuttlefish:conf_get("auth.redis.certfile", Conf, undefined)
),
Key = cuttlefish:conf_get(
"auth.redis.ssl.keyfile", Conf,
cuttlefish:conf_get("auth.redis.keyfile", Conf, undefined)
),
[{options, [{ssl_options,
Filter([{cacertfile, CA},
{certfile, Cert},
{keyfile, Key}])
}]}];
_ -> [{options, []}]
end
end}.

View File

@ -192,8 +192,8 @@ do_register_hooks(Hook, ScriptName, _St) ->
?LOG(error, "Discard unknown hook type ~p from ~p", [Hook, ScriptName]).
do_unloadall(Scripts) ->
lists:foreach(fun do_unload/1, Scripts),
ok.
lists:foreach(fun do_unload/1, Scripts).
do_unload(Script) ->
emqx_lua_script:unregister_hooks(Script), ok.
emqx_lua_script:unregister_hooks(Script),
ok.

View File

@ -99,11 +99,11 @@ add_app(AppId, Name, Secret, Desc, Status, Expired) when is_binary(AppId) ->
AddFun = fun() ->
case mnesia:wread({mqtt_app, AppId}) of
[] -> mnesia:write(App);
_ -> mnesia:abort(alread_existed), ok
_ -> mnesia:abort(alread_existed)
end
end,
case mnesia:transaction(AddFun) of
{atomic, _} -> {ok, Secret1};
{atomic, ok} -> {ok, Secret1};
{aborted, Reason} -> {error, Reason}
end.

View File

@ -16,7 +16,6 @@
-module(emqx_sn_proper_types).
%-include("emqx_sn.hrl").
-include_lib("emqx_sn/include/emqx_sn.hrl").
-include_lib("proper/include/proper.hrl").

View File

@ -16,7 +16,6 @@
-module(prop_emqx_sn_frame).
%-include("emqx_sn.hrl").
-include_lib("emqx_sn/include/emqx_sn.hrl").
-include_lib("proper/include/proper.hrl").

View File

@ -68,7 +68,7 @@ set_special_configs_https(_) ->
Path = emqx_ct_helpers:deps_path(emqx_web_hook, "test/emqx_web_hook_SUITE_data/"),
SslOpts = [{keyfile, Path ++ "/client-key.pem"},
{certfile, Path ++ "/client-cert.pem"},
{cafile, Path ++ "/ca.pem"}],
{cacertfile, Path ++ "/ca.pem"}],
application:set_env(emqx_web_hook, ssl, true),
application:set_env(emqx_web_hook, ssloptions, SslOpts),
application:set_env(emqx_web_hook, url, "https://127.0.0.1:8888").