diff --git a/apps/emqx/rebar.config b/apps/emqx/rebar.config index 8e68fefc6..ad711a709 100644 --- a/apps/emqx/rebar.config +++ b/apps/emqx/rebar.config @@ -66,7 +66,6 @@ {plt_location, "."}, {plt_prefix, "emqx_dialyzer"}, {plt_apps, all_apps}, - {plt_extra_apps, [hocon,mnesia,bcrypt,os_mon,pbkdf2,emqx_http_lib, recon]}, {statistics, true} ]}. diff --git a/apps/emqx/rebar.config.script b/apps/emqx/rebar.config.script index 8f9de344c..66520b7f7 100644 --- a/apps/emqx/rebar.config.script +++ b/apps/emqx/rebar.config.script @@ -28,8 +28,7 @@ Quicer = {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.308"}}}. Dialyzer = fun(Config) -> {dialyzer, OldDialyzerConfig} = lists:keyfind(dialyzer, 1, Config), - {plt_extra_apps, OldExtra} = lists:keyfind(plt_extra_apps, 1, OldDialyzerConfig), - Extra = OldExtra ++ [quicer || IsQuicSupp()], + Extra = [quicer || IsQuicSupp()], NewDialyzerConfig = [{plt_extra_apps, Extra} | OldDialyzerConfig], lists:keystore( dialyzer, diff --git a/apps/emqx/src/emqx.app.src b/apps/emqx/src/emqx.app.src index c7c5aaef2..e73e96808 100644 --- a/apps/emqx/src/emqx.app.src +++ b/apps/emqx/src/emqx.app.src @@ -10,6 +10,7 @@ stdlib, gproc, gen_rpc, + mnesia, mria, ekka, esockd, @@ -17,7 +18,12 @@ sasl, lc, hocon, - emqx_durable_storage + emqx_durable_storage, + bcrypt, + pbkdf2, + emqx_http_lib, + recon, + os_mon ]}, {mod, {emqx_app, []}}, {env, []}, diff --git a/apps/emqx_gateway/src/emqx_gateway_conf.erl b/apps/emqx_gateway/src/emqx_gateway_conf.erl index 30c386f44..accd09a23 100644 --- a/apps/emqx_gateway/src/emqx_gateway_conf.erl +++ b/apps/emqx_gateway/src/emqx_gateway_conf.erl @@ -132,7 +132,7 @@ maps_key_take([K | Ks], M, Acc) -> validate_listener_name(Name) -> try - {match, _} = re:run(Name, "^[0-9a-zA-Z_-]+$"), + {match, _} = re:run(Name, "^[a-zA-Z][0-9a-zA-Z_-]*$"), ok catch _:_ -> @@ -140,7 +140,7 @@ validate_listener_name(Name) -> {badconf, #{ key => name, value => Name, - reason => illegal_listener_name + reason => bad_listener_name }} ) end. diff --git a/apps/emqx_gateway_exproto/src/emqx_gateway_exproto.erl b/apps/emqx_gateway_exproto/src/emqx_gateway_exproto.erl index 4b4c2337d..17180cdb6 100644 --- a/apps/emqx_gateway_exproto/src/emqx_gateway_exproto.erl +++ b/apps/emqx_gateway_exproto/src/emqx_gateway_exproto.erl @@ -166,7 +166,7 @@ start_grpc_server(GwName, Options = #{bind := ListenOn}) -> {badconf, #{ key => server, value => Options, - reason => illegal_grpc_server_confs + reason => invalid_grpc_server_confs }} ) end; @@ -175,7 +175,7 @@ start_grpc_server(_GwName, Options) -> {badconf, #{ key => server, value => Options, - reason => illegal_grpc_server_confs + reason => invalid_grpc_server_confs }} ). @@ -196,7 +196,7 @@ start_grpc_client_channel( {badconf, #{ key => address, value => Address, - reason => illegal_grpc_address + reason => invalid_grpc_address }} ) end, @@ -222,7 +222,7 @@ start_grpc_client_channel(_GwName, Options) -> {badconf, #{ key => handler, value => Options, - reason => ililegal_grpc_client_confs + reason => invalid_grpc_client_confs }} ). diff --git a/apps/emqx_gateway_ocpp/src/emqx_ocpp_connection.erl b/apps/emqx_gateway_ocpp/src/emqx_ocpp_connection.erl index 6eadb169c..3147324f7 100644 --- a/apps/emqx_gateway_ocpp/src/emqx_ocpp_connection.erl +++ b/apps/emqx_gateway_ocpp/src/emqx_ocpp_connection.erl @@ -250,7 +250,7 @@ init_state_and_channel([Req, Opts, _WsOpts], _State = undefined) -> cowboy_req:parse_cookies(Req) catch error:badarg -> - ?SLOG(error, #{msg => "illegal_cookie"}), + ?SLOG(error, #{msg => "bad_cookie"}), undefined; Error:Reason -> ?SLOG(error, #{ diff --git a/mix.exs b/mix.exs index 350800add..415db4331 100644 --- a/mix.exs +++ b/mix.exs @@ -98,11 +98,12 @@ defmodule EMQXUmbrella.MixProject do # set by hackney (dependency) {:ssl_verify_fun, "1.1.7", override: true}, {:rfc3339, github: "emqx/rfc3339", tag: "0.2.3", override: true}, + {:bcrypt, github: "emqx/erlang-bcrypt", tag: "0.6.1", override: true}, {:uuid, github: "okeuday/uuid", tag: "v2.0.6", override: true}, {:quickrand, github: "okeuday/quickrand", tag: "v2.0.6", override: true} ] ++ emqx_apps(profile_info, version) ++ - enterprise_deps(profile_info) ++ bcrypt_dep() ++ jq_dep() ++ quicer_dep() + enterprise_deps(profile_info) ++ jq_dep() ++ quicer_dep() end defp emqx_apps(profile_info, version) do @@ -374,10 +375,8 @@ defmodule EMQXUmbrella.MixProject do %{ mnesia_rocksdb: enable_rocksdb?(), quicer: enable_quicer?(), - bcrypt: enable_bcrypt?(), jq: enable_jq?(), - observer: is_app?(:observer), - os_mon: enable_os_mon?() + observer: is_app?(:observer) } |> Enum.reject(&elem(&1, 1)) |> Enum.map(&elem(&1, 0)) @@ -786,12 +785,6 @@ defmodule EMQXUmbrella.MixProject do defp emqx_schema_mod(:enterprise), do: :emqx_enterprise_schema defp emqx_schema_mod(:community), do: :emqx_conf_schema - defp bcrypt_dep() do - if enable_bcrypt?(), - do: [{:bcrypt, github: "emqx/erlang-bcrypt", tag: "0.6.1", override: true}], - else: [] - end - defp jq_dep() do if enable_jq?(), do: [{:jq, github: "emqx/jq", tag: "v0.3.12", override: true}], @@ -805,35 +798,25 @@ defmodule EMQXUmbrella.MixProject do else: [] end - defp enable_bcrypt?() do - not win32?() - end - - defp enable_os_mon?() do - not win32?() - end - defp enable_jq?() do not Enum.any?([ - build_without_jq?(), - win32?() - ]) or "1" == System.get_env("BUILD_WITH_JQ") + build_without_jq?() + ]) end defp enable_quicer?() do - not Enum.any?([ - build_without_quic?(), - win32?(), - centos6?(), - macos?() - ]) or "1" == System.get_env("BUILD_WITH_QUIC") + "1" == System.get_env("BUILD_WITH_QUIC") or + not Enum.any?([ + macos?(), + build_without_quic?() + ]) end defp enable_rocksdb?() do not Enum.any?([ - build_without_rocksdb?(), - raspbian?() - ]) or "1" == System.get_env("BUILD_WITH_ROCKSDB") + raspbian?(), + build_without_rocksdb?() + ]) end defp pkg_vsn() do @@ -848,19 +831,6 @@ defmodule EMQXUmbrella.MixProject do String.trim(str) end - defp win32?(), - do: match?({:win_32, _}, :os.type()) - - defp centos6?() do - case File.read("/etc/centos-release") do - {:ok, "CentOS release 6" <> _} -> - true - - _ -> - false - end - end - defp macos?() do {:unix, :darwin} == :os.type() end diff --git a/rebar.config b/rebar.config index d66a1a520..6e5cad59f 100644 --- a/rebar.config +++ b/rebar.config @@ -97,6 +97,7 @@ , {uuid, {git, "https://github.com/okeuday/uuid.git", {tag, "v2.0.6"}}} , {ssl_verify_fun, "1.1.7"} , {rfc3339, {git, "https://github.com/emqx/rfc3339.git", {tag, "0.2.3"}}} + , {bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {tag, "0.6.1"}}} ]}. {xref_ignores, diff --git a/rebar.config.erl b/rebar.config.erl index fc350aa5d..76a1f824b 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -35,9 +35,6 @@ assert_otp() -> ok end. -bcrypt() -> - {bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {tag, "0.6.1"}}}. - quicer() -> {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.308"}}}. @@ -47,8 +44,7 @@ jq() -> deps(Config) -> {deps, OldDeps} = lists:keyfind(deps, 1, Config), MoreDeps = - [bcrypt() || provide_bcrypt_dep()] ++ - [jq() || is_jq_supported()] ++ + [jq() || is_jq_supported()] ++ [quicer() || is_quicer_supported()], lists:keystore(deps, 1, Config, {deps, OldDeps ++ MoreDeps}). @@ -121,45 +117,41 @@ is_community_umbrella_app("apps/emqx_gateway_jt808") -> false; is_community_umbrella_app("apps/emqx_bridge_syskeeper") -> false; is_community_umbrella_app(_) -> true. +%% BUILD_WITHOUT_JQ +%% BUILD_WITHOUT_QUIC +%% BUILD_WITHOUT_ROCKSDB +is_build_without(Name) -> + "1" =:= os:getenv("BUILD_WITHOUT_" ++ Name). + +%% BUILD_WITH_QUIC +is_build_with(Name) -> + "1" =:= os:getenv("BUILD_WITH_" ++ Name). + is_jq_supported() -> - not (false =/= os:getenv("BUILD_WITHOUT_JQ") orelse - is_win32()) orelse - "1" == os:getenv("BUILD_WITH_JQ"). + not is_build_without("JQ"). is_quicer_supported() -> - not (false =/= os:getenv("BUILD_WITHOUT_QUIC") orelse - is_macos() orelse - is_win32() orelse is_centos_6()) orelse - "1" == os:getenv("BUILD_WITH_QUIC"). + %% for ones who want to build QUIC on macos + %% export BUILD_WITH_QUIC=1 + is_build_with("QUIC") orelse + is_quicer_supported(os:type()). + +is_quicer_supported({unix, darwin}) -> + %% no quic on macos so far + false; +is_quicer_supported(_) -> + not is_build_without("QUIC"). is_rocksdb_supported() -> - not (false =/= os:getenv("BUILD_WITHOUT_ROCKSDB") orelse - is_raspbian()) orelse - "1" == os:getenv("BUILD_WITH_ROCKSDB"). + %% there is no way one can build rocksdb on raspbian + %% so no need to check is_build_with + Distro = os_cmd("./scripts/get-distro.sh"), + is_rocksdb_supported(Distro). -is_macos() -> - {unix, darwin} =:= os:type(). - -is_centos_6() -> - %% reason: - %% glibc is too old - case file:read_file("/etc/centos-release") of - {ok, <<"CentOS release 6", _/binary>>} -> - true; - _ -> - false - end. - -is_raspbian() -> - case os_cmd("./scripts/get-distro.sh") of - "raspbian" ++ _ -> - true; - _ -> - false - end. - -is_win32() -> - win32 =:= element(1, os:type()). +is_rocksdb_supported("respbian" ++ _) -> + false; +is_rocksdb_supported(_) -> + not is_build_without("ROCKSDB"). project_app_dirs() -> project_app_dirs(get_edition_from_profile_env()). @@ -421,14 +413,12 @@ relx_apps(ReleaseType, Edition) -> [{App, load} || App <- BusinessApps]), lists:foldl(fun proplists:delete/2, Apps, excluded_apps(ReleaseType)). -excluded_apps(ReleaseType) -> +excluded_apps(_ReleaseType) -> OptionalApps = [ {quicer, is_quicer_supported()}, - {bcrypt, provide_bcrypt_release(ReleaseType)}, {jq, is_jq_supported()}, {observer, is_app(observer)}, - {mnesia_rocksdb, is_rocksdb_supported()}, - {os_mon, provide_os_mon_release()} + {mnesia_rocksdb, is_rocksdb_supported()} ], [App || {App, false} <- OptionalApps]. @@ -531,15 +521,6 @@ is_debug(VarName) -> _ -> true end. -provide_bcrypt_dep() -> - not is_win32(). - -provide_os_mon_release() -> - not is_win32(). - -provide_bcrypt_release(ReleaseType) -> - provide_bcrypt_dep() andalso ReleaseType =:= cloud. - erl_opts_i() -> [{i, "apps"}] ++ [{i, Dir} || Dir <- filelib:wildcard(filename:join(["apps", "*", "include"]))]. @@ -562,8 +543,7 @@ dialyzer(Config) -> AppsToExclude = AppNames -- KnownApps, Extra = - [os_mon, system_monitor, tools, covertool] ++ - [bcrypt || provide_bcrypt_dep()] ++ + [system_monitor, tools, covertool] ++ [jq || is_jq_supported()] ++ [quicer || is_quicer_supported()], NewDialyzerConfig =