Compare commits

...

114 Commits

Author SHA1 Message Date
Thales Macedo Garitezi ccd8a2f9d7
fixing machine boot 2021-12-19 15:23:07 -03:00
Thales Macedo Garitezi 757a944ade
more wip 2021-12-15 18:13:18 -03:00
Thales Macedo Garitezi eaa05d7227
wip 2021-12-08 16:58:29 -03:00
Thales Macedo Garitezi 9edb7ac3ed
it lives?!?! 2021-12-08 15:50:59 -03:00
Thales Macedo Garitezi 05c638219c
wip 2021-12-07 15:29:57 -03:00
Thales Macedo Garitezi 51bd361b16
Merge remote-tracking branch 'origin/master' into build-with-mix 2021-12-07 15:09:09 -03:00
Thales Macedo Garitezi 2e5596f6ee
Merge remote-tracking branch 'origin/master' into build-with-mix 2021-11-29 11:28:22 -03:00
Thales Macedo Garitezi f6d0159371
Merge remote-tracking branch 'origin/master' into build-with-mix 2021-11-23 16:19:11 -03:00
x1001100011 23d72b334e feat: fix runtime issues after merge master 2021-10-28 20:04:41 -07:00
x1001100011 0f57fb9599 feat: fix runtime issues after merge master 2021-10-27 22:38:49 -07:00
x1001100011 5d31c7eb6b Merge branch 'master' into EMQX-782 2021-10-27 21:49:24 -07:00
Zaiming (Stone) Shi 44446bb762 refactor(dashboard): rename 'password' field to 'pwdhash' (#5990)
* refactor(dashboard): rename 'password' field to 'pwdhash'

rename as it is not plaintext password stored in db

* refactor(emqx_dashboard): rename records

* test(emqx_dashboard_token): add test case to cover match specs
2021-10-27 21:48:00 -07:00
JimMoen c5241670e0 refactor(paginate): use exported fun call `{M,F}` 2021-10-27 21:47:59 -07:00
JimMoen f936aba6b7 fix(authn): users pagination on spec listener_id and authn_id 2021-10-27 21:47:59 -07:00
JimMoen 295b1312be feat(authn_scram): authn_scram users page query 2021-10-27 21:47:59 -07:00
JimMoen c6ea575d35 feat(authn): authn users page query 2021-10-27 21:47:59 -07:00
JimMoen 36fd7369e0 fix(authn): api description using binary string 2021-10-27 21:47:59 -07:00
JimMoen 2b46e16d74 fix(authz): add license headers 2021-10-27 21:47:59 -07:00
JimMoen 7a4edc0104 chore(authz): fix test suite page params 2021-10-27 21:47:59 -07:00
JimMoen c1b737a9b2 fix(authz): authz rules page query 2021-10-27 21:47:59 -07:00
JianBo He 2ded7fbe8c fix(api): escape the searching string 2021-10-27 21:47:59 -07:00
Zaiming (Stone) Shi 4eb966549e fix: typo in apps/emqx_authz/src/emqx_authz.erl
Co-authored-by: Rory Z <Rory-Z@outlook.com>
2021-10-27 21:47:59 -07:00
Zaiming Shi 70491aee07 fix(authn): save certificates to certs dir 2021-10-27 21:47:59 -07:00
Zaiming Shi bc99d5c1a6 refactor(authz): call emqx_tls_lib to save & read SSL files 2021-10-27 21:47:59 -07:00
Zaiming Shi fdf439bc7b refactor(tls): move ssl files handling to emqx_tls_lib
This is an attempt ot make it more generic for other APPs to use.
Aslo added test cases to cover most of the code paths.
2021-10-27 21:47:59 -07:00
zhanghongtong d796f815d7 chore(authz): add more test case 2021-10-27 21:47:59 -07:00
zhanghongtong b8de05891e chore(authz): implement create_dry_run in other function clause
Signed-off-by: zhanghongtong <rory-z@outlook.com>
2021-10-27 21:47:59 -07:00
zhanghongtong 74b63f7d68 fix(emqx_resource): fix InstId type error 2021-10-27 21:47:59 -07:00
zhanghongtong 2def7e4ac2 fix(authz): fix configuration could be updated with incorrect values
when updating the configuration, first check with emqx_resouce:create_dry_run/2

Signed-off-by: zhanghongtong <rory-z@outlook.com>
2021-10-27 21:47:59 -07:00
zhouzb ddcf73f465 fix(authn): fix handling of pgsql response 2021-10-27 21:47:59 -07:00
zhouzb cc5b995cf2 fix(authn): no longer use single quotes to wrap placeholders 2021-10-27 21:47:59 -07:00
zhouzb ab201625c3 fix(authn): fix sql parse for mysql 2021-10-27 21:47:59 -07:00
firest 1c144d7d67 fix(emqx_telemetry): add default value to get_value 2021-10-27 21:47:59 -07:00
Zaiming Shi 92d5f4b3b2 test: fix emqx_config_SUITE 2021-10-27 21:47:59 -07:00
Zaiming Shi 54223e4fe6 fix(schema): add roots for emqx_zone_schema
emqx_zone_schema is never used at root level, but for config doc
generation, it needs the roots.
2021-10-27 21:47:59 -07:00
Zaiming Shi 0531a1925c docs: authenticator_config ref link to the struct 2021-10-27 21:47:59 -07:00
Zaiming Shi 1b56fba471 chore: pin hocon 0.20.5
for two changes:
default string values are filled with binary() instead of [integer()]
better reference links in config document
2021-10-27 21:47:59 -07:00
JimMoen 147e2e911f chore(dashboard): update version for dashboard 2021-10-27 21:47:59 -07:00
zhongwencool 1d24e46ece Rewrite http api with hocon schema (#5980)
* feat: rewrite http api with hocon

* fix: crash when default_username is empty

* chore: udpate rewrite api with emqx_conf's cluster_rpc

* fix: spec wrong
2021-10-27 21:47:59 -07:00
zhanghongtong d78fbc5a8a chore(CI): rename image 2021-10-27 21:47:59 -07:00
zhanghongtong 595598916f chore(CI): fix build docker error 2021-10-27 21:47:59 -07:00
zhanghongtong cde614aad8 build(docker): use ghcr image for build docker 2021-10-27 21:47:59 -07:00
zhanghongtong 7364e821b8 chore(CI): change otp version for docker compose file
Signed-off-by: zhanghongtong <rory-z@outlook.com>
2021-10-27 21:47:59 -07:00
zhanghongtong 2b7e93f55f chore(CI): use concurrency to cancel in-progress workflows 2021-10-27 21:47:59 -07:00
zhanghongtong b0e579fcd8 chore(CI): change otp version for workflows 2021-10-27 21:47:59 -07:00
k32 15205942e0 chore(xref): Extend the list of forbidden Mnesia APIs 2021-10-27 21:47:59 -07:00
Ilya Averyanov c9a0c37dbb style(behaviour attrs): unify behaviour declarations 2021-10-27 21:47:59 -07:00
zhongwencool d2fc66f436 emqx_conf (#5939)
* feat(emqx_conf): move conf manager for emqx_machine to emqx_conf

* chore(emqx_conf): change emqx:get_config/2 to emqx_conf:get/2

* fix: common test failed

* fix: badmatch by typo wrong key

* fix(emqx_conf): get the wrong core nodes

* fix(emqx_conf): get core node's tnx_id not latest tnx_id

* fix: add ro_transation when copy conf file

* fix: delete debug info

* fix: change ekka_rlog to mria_rlog

* fix: remove cluster_rpc from emqx_machine.

* fix: don't call ekka:start/0 explicitly

* fix: ekka should be start in emqx_machine
2021-10-27 21:47:59 -07:00
k32 6697b9fa42 fix(emqx_machine): Fix start/stop callbacks (#5969)
* fix(emqx_machine): Fix start/stop callbacks

* chore(ekka): Bump version to 0.11.1

* fix(router): Wait for the tables

* fix(emqx_cluster_rpc): Stop cluster RPC when joining a cluster

* fix(emqx_app): Fix a deadlock when joining the cluster

* fix(emqx_telemetry): Wait for mnesia tables

* test(ct_helper): Start ekka before emqx
2021-10-27 21:47:59 -07:00
Zaiming Shi 2f2a093150 refactor(authn): make schema doc generation work 2021-10-27 21:47:59 -07:00
Zaiming Shi efca545d3d fix(authn): allow single authenticator instance from config 2021-10-27 21:47:59 -07:00
Zaiming Shi 1c22c0d596 fix(authn): rename config key http-server to http 2021-10-27 21:47:59 -07:00
Zaiming Shi c0364ad5a2 refactor(emqx_config_handler): async remove 2021-10-27 21:47:59 -07:00
Zaiming Shi 6d9b3ed341 feat: support check_config callback for authenticator provider 2021-10-27 21:47:59 -07:00
Zaiming Shi 494bac419d fix: fill string fields' default value with binary 2021-10-27 21:47:59 -07:00
Zaiming Shi 835539364e refactor(authn): check authenticator config with provider module
mainly two changes:

1. the schema is simplified at root level, per-authenticator checks
   are done after the type can be identified
2. the config handling part is split out from emqx_authentication
   module to emqx_authentication_config module
2021-10-27 21:47:59 -07:00
zhouzb 4b8bd8e562 chore(deps): unify version of hocon 2021-10-27 21:47:59 -07:00
zhouzb fc1e4893a8 chore(deps): update version of hocon 2021-10-27 21:47:59 -07:00
zhouzb 257bc353a4 fix(authn): fix placeholders are not replaced correctly 2021-10-27 21:47:59 -07:00
William Yang 0d38b75bb2 feat(olp): bump to 0.1.2
remove noop logging
2021-10-27 21:47:59 -07:00
k32 6ef68f8e2c fix(mria): Replace mnesia calls with mria 2021-10-27 21:47:59 -07:00
k32 fca7fd755d fix(emqx_alarm): Wait for tables 2021-10-27 21:47:59 -07:00
k32 760d896d9d fix(dialyzer): Fix problems found by dialyzer 2021-10-27 21:47:59 -07:00
k32 69126fede6 fix(mria): Fix startup sequence 2021-10-27 21:47:59 -07:00
k32 887544c3c1 chore(ct): ekka_mnesia -> mria_mnesia 2021-10-27 21:47:59 -07:00
k32 d224687de2 fix(mria): Hook up mria to emqx_machine 2021-10-27 21:47:58 -07:00
k32 e182a5f38c chore(mria): Remove the obsolete annotiation 2021-10-27 21:47:58 -07:00
k32 1a473bb73b chore(mria): ekka_rlog -> mria_rlog 2021-10-27 21:47:58 -07:00
k32 3e8b9ff76a chore(mria): Get rid of copy_mnesia callback 2021-10-27 21:47:58 -07:00
k32 22858eb845 chore(mria): ekka_mnesia:start/stop -> mria:start/stop 2021-10-27 21:47:58 -07:00
k32 814623edae chore(mria): ekka_mnesia:create_table -> mria:create_table 2021-10-27 21:47:58 -07:00
k32 75c9267473 chore(mria): Fix clear_table and ro_transaction calls 2021-10-27 21:47:58 -07:00
k32 ae71bdc0fe chore(mria): ekka_mnesia:running_nodes -> mria:running_nodes 2021-10-27 21:47:58 -07:00
k32 fd482e2ec0 chore(mria): Rename module: ekka_mnesia -> mria 2021-10-27 21:47:58 -07:00
zhanghongtong 591b704f65 chore(CI): better build docker image 2021-10-27 21:47:58 -07:00
x1001100011 dbe45d9d6f Merge branch 'master' into EMQX-782 2021-10-20 00:01:07 -07:00
x1001100011 783a10c5a1 refactor: reuse overlay dsl in application 2021-10-19 23:56:27 -07:00
x1001100011 6a4b437446
feat: remove debug changes 2021-10-18 00:06:25 -07:00
x1001100011 d0b54ac365
feat: emqx_gateway version
Co-authored-by: JianBo He <heeejianbo@163.com>
2021-10-18 00:05:26 -07:00
x1001100011 b76334ea01 feat: patch after merge master branch 2021-10-17 21:04:46 -07:00
x1001100011 0312f07b11 Merge branch 'master' into EMQX-782 2021-10-17 20:57:01 -07:00
x1001100011 93532615c1 feat: add protos compiler 2021-10-13 21:41:19 -07:00
x1001100011 2d25e895a8 feat: fix applications start order issue 2021-10-12 00:00:57 -07:00
x1001100011 f20d5b5395 Merge branch 'master' into EMQX-782 2021-10-11 23:44:44 -07:00
x1001100011 ddb79f51ae feat: lock deps version 2021-09-23 21:21:17 -07:00
x1001100011 7e2c035562 style: auto format 2021-09-23 00:16:32 -07:00
x1001100011 df1cbb0bab Merge branch 'master' into EMQX-871-872 2021-09-23 00:12:57 -07:00
x1001100011 e3437d5b9e feat: refactor script 2021-09-22 23:50:02 -07:00
x1001100011 c14319e5bd feat: remove emqx_release_helper 2021-09-22 21:52:20 -07:00
x1001100011 188f44ad50 feat: refactor call_hocon to use escript 2021-09-19 19:15:05 -07:00
x1001100011 13e146d1ee feat: bin/emqx start_iex works 2021-09-14 00:06:16 -07:00
x1001100011 5e812a1add feat: sync with master 2021-09-12 15:32:03 -07:00
x1001100011 7a7cccb337 Merge branch 'master' into EMQX-871-872 2021-09-12 15:21:10 -07:00
x1001100011 69673613d6 Merge branch 'master' into EMQX-871-872 2021-09-09 23:38:38 -07:00
x1001100011 22b2a3902e feat: add mix bin/emqx 2021-09-09 22:35:34 -07:00
x1001100011 1ef7f4e2a0 feat: add emqx_machine application 2021-08-31 19:32:39 -07:00
x1001100011 5dd7f53662 Merge branch 'master' into EMQX-871-872 2021-08-11 21:54:59 -07:00
x1001100011 19e92d7936 feat: make mix release works 2021-08-11 00:49:15 -07:00
x1001100011 3c4430c252 feat: update depends 2021-08-09 22:22:50 -07:00
x1001100011 2c6e8204b8 Merge branch 'master' into EMQX-871-872 2021-08-09 22:02:43 -07:00
x1001100011 e4eeb585cb Merge branch 'master' into EMQX-871-872 2021-08-03 23:40:46 -07:00
x1001100011 25f03ed87a Merge branch 'master' into EMQX-871-872 2021-07-31 08:26:06 -07:00
x1001100011 d33465052f feat: rename plugin to application 2021-07-23 22:51:27 -07:00
x1001100011 bd3760d5c7 feat: run the package released by mix 2021-07-21 23:01:07 -07:00
x1001100011 4c1e03bbcd feat: add emqx_config_helper 2021-07-18 22:00:34 -07:00
x1001100011 ef4c30b2fd feat: set emqx in umbrella depend runtime false 2021-07-18 18:48:10 -07:00
x1001100011 9fc635826c feat: remove unused file 2021-07-11 15:38:21 -07:00
x1001100011 e83217fb09 feat: remove unused file 2021-07-11 15:37:15 -07:00
x1001100011 6905eb4ac1 feat: emqx_release_helper 2021-07-11 15:31:01 -07:00
x1001100011 c940ab9e0a
Merge pull request #5114 from x1001100011/EMQX-788
[EMQX-788] remove emqx_lua_hook and rename Emqx -> EMQX
2021-06-27 23:38:07 -07:00
x1001100011 e40148a6dd feat: Emqx -> EMQX 2021-06-27 23:35:52 -07:00
x1001100011 ba002bb1b5 fix: remove mix files for emqx_lua_hook 2021-06-27 23:25:51 -07:00
x1001100011 ed34783dd7 Merge branch 'master' into EMQX-788 2021-06-27 23:20:47 -07:00
x1001100011 8ec83705ad feat: add mix.exs for all applications 2021-06-26 19:53:18 -07:00
130 changed files with 7329 additions and 44 deletions

5
.formatter.exs Normal file
View File

@ -0,0 +1,5 @@
# Used by "mix format"
[
inputs: ["mix.exs", "config/*.exs"],
subdirectories: ["apps/*"]
]

4
apps/emqx/.formatter.exs Normal file
View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

View File

@ -24,4 +24,5 @@
%% NOTE: This version number should be manually bumped for each release
-define(EMQX_RELEASE, "5.0-beta.2").
%% FIXME!!!
-define(EMQX_RELEASE, "5.0-beta.2-3fdc075b").

45
apps/emqx/mix.exs Normal file
View File

@ -0,0 +1,45 @@
defmodule EMQX.MixProject do
use Mix.Project
Code.require_file("../../lib/emqx/mix/common.ex")
def project do
[
app: :emqx,
version: "5.0.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X"
]
end
def application do
[
mod: {:emqx_app, []},
applications: EMQX.Mix.Common.erl_apps(:emqx),
extra_applications: [:logger, :os_mon, :syntax_tools]
]
end
defp deps do
[
# {:gproc, "0.9.0"},
# {:recon, "2.5.2"},
{:cowboy, github: "emqx/cowboy", tag: "2.8.3"},
{:esockd, github: "emqx/esockd", tag: "5.9.0"},
{:gproc, github: "uwiger", tag: "0.8.0"},
{:ekka, github: "emqx/ekka", tag: "0.11.1"},
# {:gen_rpc, github: "emqx/gen_rpc", tag: "2.5.1"},
# {:cuttlefish, github: "emqx/cuttlefish", tag: "v4.0.1"},
{:hocon, github: "emqx/hocon", tag: "0.22.0", runtime: false},
# {:pbkdf2, github: "emqx/erlang-pbkdf2", tag: "2.0.4"},
# {:snabbkaffe, github: "kafka4beam/snabbkaffe", tag: "0.14.0"},
# {:jiffy, github: "emqx/jiffy", tag: "1.0.5"},
{:lc, github: "qzhuyan/lc", tag: "0.1.2"},
]
end
end

View File

@ -17,8 +17,8 @@ IsQuicSupp = fun() ->
)
end,
Bcrypt = {bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {branch, "0.6.0"}}},
Quicer = {quicer, {git, "https://github.com/emqx/quic.git", {branch, "0.0.9"}}},
Bcrypt = {bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {tag, "0.6.0"}}},
Quicer = {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.9"}}},
ExtraDeps = fun(C) ->
{deps, Deps0} = lists:keyfind(deps, 1, C),

View File

@ -22,7 +22,6 @@
-include("logger.hrl").
-include_lib("lc/include/lc.hrl").
%% gen_event callbacks
-export([ init/1
, handle_event/2

View File

@ -245,6 +245,10 @@ put_raw(KeyPath, Config) -> do_put(?RAW_CONF, KeyPath, Config).
%%============================================================================
init_load(SchemaMod) ->
ConfFiles = application:get_env(emqx, config_files, []),
?SLOG(warning, #{ msg => ">>>>>>>>> config:init_load enter"
, schema_mod => SchemaMod
, conf_files => ConfFiles
}),
init_load(SchemaMod, ConfFiles).
%% @doc Initial load of the given config files.
@ -258,7 +262,9 @@ init_load(SchemaMod, Conf) when is_list(Conf) orelse is_binary(Conf) ->
true -> fun hocon:binary/2;
false -> fun hocon:files/2
end,
case Parser(Conf, ParseOptions) of
Res = Parser(Conf, ParseOptions),
%% io:format(user, "~n>>>>>>>>>>>>>>>>>> config:init_load parse res ~120p ~n", [Res]),
case Res of
{ok, RawRichConf} ->
init_load(SchemaMod, RawRichConf);
{error, Reason} ->
@ -269,6 +275,8 @@ init_load(SchemaMod, Conf) when is_list(Conf) orelse is_binary(Conf) ->
error(failed_to_load_hocon_conf)
end;
init_load(SchemaMod, RawConf) when is_map(RawConf) ->
%% io:format(user, ">>>>>>>>>> config:init_load is_map ~p ~100p ~n",
%% [SchemaMod, RawConf]),
ok = save_schema_mod_and_names(SchemaMod),
%% check configs agains the schema, with environment variables applied on top
{_AppEnvs, CheckedConf} =
@ -382,6 +390,8 @@ save_to_app_env(AppEnvs) ->
-spec save_to_config_map(config(), raw_config()) -> ok.
save_to_config_map(Conf, RawConf) ->
%% io:format(user, ">>>>>>> config:save_to_config_map ~p ~100p ~n",
%% [Conf, RawConf]),
?MODULE:put(Conf),
?MODULE:put_raw(RawConf).

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

38
apps/emqx_authn/mix.exs Normal file
View File

@ -0,0 +1,38 @@
defmodule EMQXAuthn.MixProject do
use Mix.Project
def project do
[
app: :emqx_authn,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Authentication"
]
end
def application do
[
registered: [:emqx_authn_sup, :emqx_authn_registry],
mod: {:emqx_authn_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
{:emqx_resource, in_umbrella: true},
# {:emqx_http_lib, github: "emqx/emqx_http_lib", tag: "0.2.1"},
# {:esasl, github: "emqx/esasl", tag: "0.1.0"},
# {:epgsql, github: "epgsql/epgsql", tag: "4.4.0"},
# {:mysql, github: "emqx/mysql-otp", tag: "1.7.1"},
{:jose, "1.11.2"},
]
end
end

38
apps/emqx_authn/mix.exs2 Normal file
View File

@ -0,0 +1,38 @@
defmodule EMQXAuthn.MixProject do
use Mix.Project
def project do
[
app: :emqx_authn,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Authentication"
]
end
def application do
[
registered: [:emqx_authn_sup, :emqx_authn_registry],
mod: {:emqx_authn_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
{:emqx_resource, in_umbrella: true},
{:emqx_http_lib, github: "emqx/emqx_http_lib", tag: "0.2.1"},
{:esasl, github: "emqx/esasl", tag: "0.1.0"},
{:epgsql, github: "epgsql/epgsql", tag: "4.4.0"},
{:mysql, github: "emqx/mysql-otp", tag: "1.7.1"},
{:jose, "1.11.2"}
]
end
end

View File

@ -1,4 +1,6 @@
{deps, []}.
{deps, [
{jose, "1.11.2"}
]}.
{edoc_opts, [{preprocess, true}]}.
{erl_opts, [warn_unused_vars,

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

34
apps/emqx_authz/mix.exs Normal file
View File

@ -0,0 +1,34 @@
defmodule EMQXAuthz.MixProject do
use Mix.Project
Code.require_file("../../lib/emqx/mix/common.ex")
@app :emqx_authz
def project do
[
app: @app,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
mod: EMQX.Mix.Common.from_erl!(@app, :mod),
applications: EMQX.Mix.Common.from_erl!(@app, :applications),
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx_connector, in_umbrella: true, runtime: false}
]
end
end

29
apps/emqx_authz/mix.exs2 Normal file
View File

@ -0,0 +1,29 @@
defmodule EMQXAuthz.MixProject do
use Mix.Project
def project do
[
app: :emqx_authz,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx_connector, in_umbrella: true}
]
end
end

View File

@ -0,0 +1,32 @@
defmodule EMQXAutoSubscribe.MixProject do
use Mix.Project
def project do
[
app: :emqx_auto_subscribe,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Auto Subscribe"
]
end
def application do
[
registered: [],
mod: {:emqx_auto_subscribe_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false}
]
end
end

View File

@ -0,0 +1,32 @@
defmodule EMQXAutoSubscribe.MixProject do
use Mix.Project
def project do
[
app: :emqx_auto_subscribe,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Auto Subscribe"
]
end
def application do
[
registered: [],
mod: {:emqx_auto_subscribe_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false}
]
end
end

35
apps/emqx_bridge/mix.exs Normal file
View File

@ -0,0 +1,35 @@
defmodule EMQXBridge.MixProject do
use Mix.Project
Code.require_file("../../lib/emqx/mix/common.ex")
def project do
[
app: :emqx_bridge,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Bridge"
]
end
def application do
[
registered: [],
mod: {:emqx_bridge_app, []},
applications: EMQX.Mix.Common.from_erl!(:emqx_bridge, :applications),
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
# {:emqx_connector, in_umbrella: true}
]
end
end

33
apps/emqx_bridge/mix.exs2 Normal file
View File

@ -0,0 +1,33 @@
defmodule EMQXBridge.MixProject do
use Mix.Project
def project do
[
app: :emqx_bridge,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Bridge"
]
end
def application do
[
registered: [],
mod: {:emqx_bridge_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
{:emqx_connector, in_umbrella: true}
]
end
end

35
apps/emqx_conf/mix.exs Normal file
View File

@ -0,0 +1,35 @@
defmodule EMQXConf.MixProject do
use Mix.Project
Code.require_file("../../lib/emqx/mix/common.ex")
def project do
[
app: :emqx_conf,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Configuration Management"
]
end
def application do
[
mod: {:emqx_conf_app, []},
# applications: EMQX.Mix.Common.erl_apps(:emqx_conf),
# included_applications: [:hocon],
# extra_applications: [:logger, :os_mon, :syntax_tools]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
{:hocon, github: "emqx/hocon", tag: "0.22.0"},
]
end
end

32
apps/emqx_conf/mix.exs2 Normal file
View File

@ -0,0 +1,32 @@
defmodule EMQXConf.MixProject do
use Mix.Project
def project do
[
app: :emqx_conf,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Configuration Management"
]
end
def application do
[
mod: {:emqx_conf_app, []},
extra_applications: [:logger, :os_mon, :syntax_tools]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
{:hocon, github: "emqx/hocon"}
]
end
end

View File

@ -25,7 +25,11 @@
-include("emqx_conf.hrl").
start(_StartType, _StartArgs) ->
?SLOG(warning, #{ msg => ">>>>>>>>>>>>>> emqx_conf_app starting <<<<<<<<<<<~n"
}),
init_conf(),
?SLOG(warning, #{ msg => ">>>>>>>>>>>>>> emqx_conf_app conf init done <<<<<<<<<<<~n"
}),
emqx_conf_sup:start_link().
stop(_State) ->

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

View File

@ -0,0 +1,39 @@
defmodule EMQXConnector.MixProject do
use Mix.Project
Code.require_file("../../lib/emqx/mix/common.ex")
def project do
[
app: :emqx_connector,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
mod: {:emqx_connector_app, []},
applications: EMQX.Mix.Common.from_erl!(:emqx_connector, :applications),
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx_resource, in_umbrella: true, runtime: false},
{:epgsql, github: "epgsql/epgsql", tag: "4.4.0"},
{:mysql, github: "emqx/mysql-otp", tag: "1.7.1"},
{:emqtt, github: "emqx/emqtt", tag: "1.4.3"},
{:eredis_cluster, github: "emqx/eredis_cluster", tag: "0.6.7"},
{:mongodb, github: "emqx/mongodb-erlang", tag: "v3.0.10"},
# {:ecpool, github: "emqx/ecpool", tag: "0.5.1"},
# {:emqtt, github: "emqx/emqtt", tag: "1.4.3"}
]
end
end

View File

@ -0,0 +1,33 @@
defmodule EMQXConnector.MixProject do
use Mix.Project
def project do
[
app: :emqx_connector,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
mod: {:emqx_connector_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx_resource, in_umbrella: true},
{:mysql, github: "emqx/mysql-otp", tag: "1.7.1"},
{:ecpool, github: "emqx/ecpool", tag: "0.5.1"},
{:emqtt, github: "emqx/emqtt", tag: "1.4.3"}
]
end
end

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

View File

@ -0,0 +1,35 @@
defmodule EMQXDashboard.MixProject do
use Mix.Project
Code.require_file("../../lib/emqx/mix/common.ex")
def project do
[
app: :emqx_dashboard,
version: "4.4.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Web Dashboard"
]
end
def application do
[
registered: [:emqx_dashboard_sup],
mod: {:emqx_dashboard_app, []},
applications: EMQX.Mix.Common.from_erl!(:emqx_dashboard, :applications),
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
# {:minirest, github: "emqx/minirest", tag: "1.2.4"}
]
end
end

View File

@ -0,0 +1,33 @@
defmodule EMQXDashboard.MixProject do
use Mix.Project
def project do
[
app: :emqx_dashboard,
version: "4.4.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Web Dashboard"
]
end
def application do
[
registered: [:emqx_dashboard_sup],
mod: {:emqx_dashboard_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
{:minirest, github: "emqx/minirest", tag: "1.2.4"}
]
end
end

View File

@ -212,13 +212,17 @@ sha256(SaltBin, Password) ->
crypto:hash('sha256', <<SaltBin/binary, Password/binary>>).
add_default_user() ->
io:format(user, "~n>>>>>>>>>>> add_default_user/0~n", []),
add_default_user(binenv(default_username), binenv(default_password)).
binenv(Key) ->
iolist_to_binary(emqx_conf:get([emqx_dashboard, Key], "")).
add_default_user(Username, Password) when ?EMPTY_KEY(Username) orelse ?EMPTY_KEY(Password) ->
ok;
%% FIXME!!!
io:format(user, "~n>>>>>>>>>>> add_default_user empty ~n", []),
{ok, empty};
%% ok;
add_default_user(Username, Password) ->
case lookup_user(Username) of

59
apps/emqx_exhook/mix.exs Normal file
View File

@ -0,0 +1,59 @@
defmodule EMQXExhook.MixProject do
use Mix.Project
def project do
[
app: :emqx_exhook,
version: "5.0.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
compilers: [:protos | Mix.compilers()],
aliases: ["compile.protos": &protos/1],
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Extension for Hook"
]
end
def application do
[
registered: [],
mod: {:emqx_exhook_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true},
{:grpc, github: "emqx/grpc-erl", tag: "0.6.2"},
]
end
defp protos(_args) do
app_path = Path.expand("..", __ENV__.file)
config = [
:use_packages,
:maps,
:strings_as_binaries,
rename: {:msg_name, :snake_case},
rename: {:msg_fqname, :base_name},
i: '.',
report_errors: false,
o: app_path |> Path.join("src") |> to_charlist(),
module_name_prefix: 'emqx_',
module_name_suffix: '_pb'
]
app_path
|> Path.join("priv/protos/*.proto")
|> Path.wildcard()
|> Enum.map(&to_charlist/1)
|> Enum.each(&:gpb_compile.file(&1, config))
:ok
end
end

59
apps/emqx_exhook/mix.exs2 Normal file
View File

@ -0,0 +1,59 @@
defmodule EMQXExhook.MixProject do
use Mix.Project
def project do
[
app: :emqx_exhook,
version: "5.0.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
compilers: [:protos | Mix.compilers()],
aliases: ["compile.protos": &protos/1],
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Extension for Hook"
]
end
def application do
[
registered: [],
mod: {:emqx_exhook_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
{:grpc, github: "emqx/grpc-erl", tag: "0.6.2"}
]
end
defp protos(_args) do
app_path = Path.expand("..", __ENV__.file)
config = [
:use_packages,
:maps,
:strings_as_binaries,
rename: {:msg_name, :snake_case},
rename: {:msg_fqname, :base_name},
i: '.',
report_errors: false,
o: app_path |> Path.join("src") |> to_charlist(),
module_name_prefix: 'emqx_',
module_name_suffix: '_pb'
]
app_path
|> Path.join("priv/protos/*.proto")
|> Path.wildcard()
|> Enum.map(&to_charlist/1)
|> Enum.each(&:gpb_compile.file(&1, config))
:ok
end
end

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

64
apps/emqx_gateway/mix.exs Normal file
View File

@ -0,0 +1,64 @@
defmodule EMQXGateway.MixProject do
use Mix.Project
Code.require_file("../../lib/emqx/mix/common.ex")
def project do
[
app: :emqx_gateway,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
compilers: [:protos | Mix.compilers()],
aliases: ["compile.protos": &protos/1],
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "The Gateway Management Application"
]
end
def application do
[
registered: [],
mod: {:emqx_gateway_app, []},
applications: EMQX.Mix.Common.from_erl!(:emqx_gateway, :applications),
extra_applications: [:logger]
]
end
defp protos(_args) do
app_path = Path.expand("..", __ENV__.file)
config = [
:use_packages,
:maps,
:strings_as_binaries,
rename: {:msg_name, :snake_case},
rename: {:msg_fqname, :base_name},
i: '.',
report_errors: false,
o: app_path |> Path.join("src/exproto") |> to_charlist(),
module_name_prefix: 'emqx_',
module_name_suffix: '_pb'
]
app_path
|> Path.join("src/exproto/protos/*.proto")
|> Path.wildcard()
|> Enum.map(&to_charlist/1)
|> Enum.each(&:gpb_compile.file(&1, config))
:ok
end
defp deps do
[
# {:gpb, "4.19.1", runtime: false},
{:emqx, in_umbrella: true, runtime: false},
{:grpc, github: "emqx/grpc-erl", tag: "0.6.2"},
# {:lwm2m_coap, github: "emqx/lwm2m-coap", tag: "v2.0.0"},
# {:esockd, github: "emqx/esockd", tag: "5.7.4"}
]
end
end

View File

@ -0,0 +1,62 @@
defmodule EMQXGateway.MixProject do
use Mix.Project
def project do
[
app: :emqx_gateway,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
compilers: [:protos | Mix.compilers()],
aliases: ["compile.protos": &protos/1],
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "The Gateway Management Application"
]
end
def application do
[
registered: [],
mod: {:emqx_gateway_app, []},
extra_applications: [:logger]
]
end
defp protos(_args) do
app_path = Path.expand("..", __ENV__.file)
config = [
:use_packages,
:maps,
:strings_as_binaries,
rename: {:msg_name, :snake_case},
rename: {:msg_fqname, :base_name},
i: '.',
report_errors: false,
o: app_path |> Path.join("src/exproto") |> to_charlist(),
module_name_prefix: 'emqx_',
module_name_suffix: '_pb'
]
app_path
|> Path.join("src/exproto/protos/*.proto")
|> Path.wildcard()
|> Enum.map(&to_charlist/1)
|> Enum.each(&:gpb_compile.file(&1, config))
:ok
end
defp deps do
[
{:gpb, "4.19.1", runtime: false},
{:emqx, in_umbrella: true},
{:lwm2m_coap, github: "emqx/lwm2m-coap", tag: "v2.0.0"},
{:grpc, github: "emqx/grpc-erl", tag: "0.6.2"},
{:esockd, github: "emqx/esockd", tag: "5.7.4"}
]
end
end

View File

@ -18,7 +18,7 @@
-behaviour(minirest_api).
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include("emqx_coap.hrl").
%% API
-export([api_spec/0]).

View File

@ -41,8 +41,9 @@
-export_type([channel/0]).
-include("emqx_coap.hrl").
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
%% -include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include_lib("emqx/include/emqx_authentication.hrl").
-define(AUTHN, ?EMQX_AUTHENTICATION_CONFIG_ROOT_NAME_ATOM).

View File

@ -30,8 +30,8 @@
%% API
-export([]).
-include("include/emqx_coap.hrl").
-include("apps/emqx/include/types.hrl").
-include_lib("emqx/include/types.hrl").
-include("emqx_coap.hrl").
-define(VERSION, 1).

View File

@ -20,7 +20,7 @@
-module(emqx_coap_medium).
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include("emqx_coap.hrl").
%% API
-export([ empty/0, reset/1, reset/2

View File

@ -34,7 +34,7 @@
-export([ set/3, set_payload/2, get_option/2
, get_option/3, set_payload_block/3, set_payload_block/4]).
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include("emqx_coap.hrl").
request(Type, Method) ->
request(Type, Method, <<>>, []).

View File

@ -18,7 +18,7 @@
-include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/emqx_mqtt.hrl").
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include("emqx_coap.hrl").
%% API
-export([ new/0

View File

@ -28,7 +28,7 @@
-export_type([manager/0, event_result/1]).
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include("emqx_coap.hrl").
-type direction() :: in | out.

View File

@ -1,7 +1,7 @@
-module(emqx_coap_transport).
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include("emqx_coap.hrl").
-define(ACK_TIMEOUT, 2000).
-define(ACK_RANDOM_FACTOR, 1000).

View File

@ -16,7 +16,7 @@
-module(emqx_coap_mqtt_handler).
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include("emqx_coap.hrl").
-export([handle_request/4]).
-import(emqx_coap_message, [response/2, response/3]).

View File

@ -18,7 +18,7 @@
-module(emqx_coap_pubsub_handler).
-include_lib("emqx/include/emqx_mqtt.hrl").
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include("emqx_coap.hrl").
-export([handle_request/4]).

View File

@ -15,7 +15,7 @@
%%--------------------------------------------------------------------
-module(emqx_exproto_channel).
-include("src/exproto/include/emqx_exproto.hrl").
-include("emqx_exproto.hrl").
-include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/emqx_mqtt.hrl").
-include_lib("emqx/include/types.hrl").

View File

@ -19,7 +19,7 @@
% -behaviour(emqx_exproto_v_1_connection_adapter_bhvr).
-include("src/exproto/include/emqx_exproto.hrl").
-include("emqx_exproto.hrl").
-include_lib("emqx/include/logger.hrl").
-define(IS_QOS(X), (X =:= 0 orelse X =:= 1 orelse X =:= 2)).

View File

@ -17,8 +17,8 @@
-module(emqx_lwm2m_channel).
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include_lib("emqx_gateway/src/lwm2m/include/emqx_lwm2m.hrl").
-include("emqx_coap.hrl").
-include("emqx_lwm2m.hrl").
%% API
-export([ info/1

View File

@ -17,8 +17,8 @@
-module(emqx_lwm2m_cmd).
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include_lib("emqx_gateway/src/lwm2m/include/emqx_lwm2m.hrl").
-include("emqx_coap.hrl").
-include("emqx_lwm2m.hrl").
-export([ mqtt_to_coap/2
, coap_to_mqtt/4

View File

@ -23,7 +23,7 @@
, translate_json/1
]).
-include("src/lwm2m/include/emqx_lwm2m.hrl").
-include("emqx_lwm2m.hrl").
tlv_to_json(BaseName, TlvData) ->
DecodedTlv = emqx_lwm2m_tlv:parse(TlvData),

View File

@ -18,8 +18,8 @@
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/emqx_mqtt.hrl").
-include_lib("emqx_gateway/src/coap/include/emqx_coap.hrl").
-include_lib("emqx_gateway/src/lwm2m/include/emqx_lwm2m.hrl").
-include("emqx_coap.hrl").
-include("emqx_lwm2m.hrl").
%% API
-export([ new/0, init/4, update/3, parse_object_list/1

View File

@ -25,7 +25,7 @@
-export([binary_to_hex_string/1]).
-endif.
-include("src/lwm2m/include/emqx_lwm2m.hrl").
-include("emqx_lwm2m.hrl").
-define(TLV_TYPE_OBJECT_INSTANCE, 0).
-define(TLV_TYPE_RESOURCE_INSTANCE, 1).
@ -158,4 +158,3 @@ encode_value(Value) ->
binary_to_hex_string(Data) ->
lists:flatten([io_lib:format("~2.16.0B ",[X]) || <<X:8>> <= Data ]).
-endif.

View File

@ -16,8 +16,8 @@
-module(emqx_lwm2m_xml_object).
-include_lib("emqx_gateway/src/lwm2m/include/emqx_lwm2m.hrl").
-include_lib("xmerl/include/xmerl.hrl").
-include("emqx_lwm2m.hrl").
-export([ get_obj_def/2
, get_object_id/1

View File

@ -16,9 +16,9 @@
-module(emqx_lwm2m_xml_object_db).
-include_lib("emqx_gateway/src/lwm2m/include/emqx_lwm2m.hrl").
-include_lib("xmerl/include/xmerl.hrl").
-include_lib("emqx/include/logger.hrl").
-include("emqx_lwm2m.hrl").
% This module is for future use. Disabled now.

View File

@ -18,7 +18,7 @@
-behaviour(gen_server).
-include("src/mqttsn/include/emqx_sn.hrl").
-include("emqx_sn.hrl").
-include_lib("emqx/include/logger.hrl").
-export([ start_link/2
@ -106,4 +106,3 @@ send_advertise(#state{gwid = GwId, sock = Sock, port = Port,
boradcast_addrs() ->
lists:usort([Addr || {ok, IfList} <- [inet:getiflist()], If <- IfList,
{ok, [{broadaddr, Addr}]} <- [inet:ifget(If, [broadaddr])]]).

View File

@ -18,7 +18,7 @@
-behaviour(emqx_gateway_channel).
-include("src/mqttsn/include/emqx_sn.hrl").
-include("emqx_sn.hrl").
-include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/emqx_mqtt.hrl").
-include_lib("emqx/include/logger.hrl").

View File

@ -20,7 +20,7 @@
-behaviour(emqx_gateway_frame).
-include("src/mqttsn/include/emqx_sn.hrl").
-include("emqx_sn.hrl").
-export([ initial_parse_state/1
, serialize_opts/0

View File

@ -21,7 +21,7 @@
-behaviour(gen_server).
-include("src/mqttsn/include/emqx_sn.hrl").
-include("emqx_sn.hrl").
-include_lib("emqx/include/logger.hrl").
-export([ start_link/2

View File

@ -18,7 +18,7 @@
-behaviour(emqx_gateway_channel).
-include("src/stomp/include/emqx_stomp.hrl").
-include("emqx_stomp.hrl").
-include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/logger.hrl").

View File

@ -70,7 +70,7 @@
-behaviour(emqx_gateway_frame).
-include("src/stomp/include/emqx_stomp.hrl").
-include("emqx_stomp.hrl").
-export([ initial_parse_state/1
, parse/2

View File

@ -17,7 +17,7 @@
%% @doc Stomp heartbeat.
-module(emqx_stomp_heartbeat).
-include("src/stomp/include/emqx_stomp.hrl").
-include("emqx_stomp.hrl").
-export([ init/1
, check/3

32
apps/emqx_limiter/mix.exs Normal file
View File

@ -0,0 +1,32 @@
defmodule EMQXLimiter.MixProject do
use Mix.Project
def project do
[
app: :emqx_limiter,
version: "1.0.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Hierachical Limiter"
]
end
def application do
[
registered: [:emqx_limiter_sup],
mod: {:emqx_limiter_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
]
end
end

View File

@ -0,0 +1,32 @@
defmodule EMQXLimiter.MixProject do
use Mix.Project
def project do
[
app: :emqx_limiter,
version: "1.0.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Hierachical Limiter"
]
end
def application do
[
registered: [:emqx_limiter_sup],
mod: {:emqx_limiter_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false}
]
end
end

30
apps/emqx_machine/mix.exs Normal file
View File

@ -0,0 +1,30 @@
defmodule EMQXMachine.MixProject do
use Mix.Project
def project do
[
app: :emqx_machine,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "The EMQ X Machine"
]
end
def application do
[
registered: [],
mod: {:emqx_machine_app, []},
extra_applications: [:logger]
]
end
defp deps do
[]
end
end

View File

@ -0,0 +1,30 @@
defmodule EMQXMachine.MixProject do
use Mix.Project
def project do
[
app: :emqx_machine,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "The EMQ X Machine"
]
end
def application do
[
registered: [],
mod: {:emqx_machine_app, []},
extra_applications: [:logger]
]
end
defp deps do
[]
end
end

View File

View File

@ -25,6 +25,8 @@
%% @doc EMQ X boot entrypoint.
start() ->
?SLOG(warning, #{ msg => ">>>>>>>>> machine:start enter"
}),
case os:type() of
{win32, nt} -> ok;
_nix ->

View File

@ -27,6 +27,8 @@
-endif.
post_boot() ->
%% io:format(user, ">>>>>>>>>>>>>>>>>>>> roots ~p~n",
%% [emqx_conf_schema:roots()]),
ok = ensure_apps_started(),
_ = emqx_plugins:load(),
ok = print_vsn(),
@ -108,18 +110,49 @@ reboot_apps() ->
sorted_reboot_apps() ->
Apps = [{App, app_deps(App)} || App <- reboot_apps()],
sorted_reboot_apps(Apps).
?SLOG(warning, #{ msg => "sorted_reboot_apps/0 before /1"
, apps => Apps
}),
Res = sorted_reboot_apps(Apps),
io:format(user, "~n>>>>>>>>>>>>>> sorted_reboot_apps~n ~100p~n", [Res]),
Res,
%% FIXME!!!!! For some reason, emqx_conf appears in the
%% `applications` key in resource, but it is not there in the
%% .app.src...
Res0 = [emqx_conf,gproc,esockd,ranch,cowboy,emqx,emqx_prometheus,emqx_modules,emqx_dashboard,
emqx_gateway,emqx_management,emqx_retainer,emqx_statsd,emqx_resource,emqx_connector,emqx_bridge,
emqx_authn,emqx_authz,emqx_exhook],
case true of
true ->
Res;
false ->
Res0
end.
app_deps(App) ->
case application:get_key(App, applications) of
undefined -> [];
{ok, List} -> lists:filter(fun(A) -> lists:member(A, reboot_apps()) end, List)
{ok, List} ->
?SLOG(warning, #{ msg => ">>>>>> machine_boot:add_deps"
, app => App
, apps => List
, included => application:get_key(App, included_applications)
}),
lists:filter(fun(A) ->
lists:member(A, reboot_apps())
end, List)
end.
sorted_reboot_apps(Apps) ->
G = digraph:new(),
try
lists:foreach(fun({App, Deps}) -> add_app(G, App, Deps) end, Apps),
lists:foreach(fun({App, Deps}) ->
?SLOG(warning, #{ msg => ">>>>>> machine_boot:add_app"
, app => App
, deps => Deps
}),
add_app(G, App, Deps)
end, Apps),
case digraph_utils:topsort(G) of
Sorted when is_list(Sorted) ->
Sorted;

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

View File

@ -0,0 +1,38 @@
defmodule EMQXManagement.MixProject do
use Mix.Project
Code.require_file("../../lib/emqx/mix/common.ex")
def project do
[
app: :emqx_management,
version: "4.4.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Management API and CLI"
]
end
def application do
[
registered: [:emqx_management_sup],
mod: {:emqx_mgmt_app, []},
applications: EMQX.Mix.Common.from_erl!(:emqx_management, :applications),
extra_applications: [:logger, :syntax_tools]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
# {:emqx_rule_engine, in_umbrella: true},
# {:ekka, github: "emqx/ekka", tag: "0.11.1", runtime: false},
# {:emqx_http_lib, github: "emqx/emqx_http_lib", tag: "0.2.1"},
{:minirest, github: "emqx/minirest", tag: "1.2.7"},
]
end
end

View File

@ -0,0 +1,35 @@
defmodule EMQXManagement.MixProject do
use Mix.Project
def project do
[
app: :emqx_management,
version: "4.4.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Management API and CLI"
]
end
def application do
[
registered: [:emqx_management_sup],
mod: {:emqx_mgmt_app, []},
extra_applications: [:logger, :syntax_tools]
]
end
defp deps do
[
{:emqx_rule_engine, in_umbrella: true},
{:ekka, github: "emqx/ekka", tag: "0.11.1", runtime: false},
{:emqx_http_lib, github: "emqx/emqx_http_lib", tag: "0.2.1"},
{:minirest, github: "emqx/minirest", tag: "1.2.4"}
]
end
end

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

33
apps/emqx_modules/mix.exs Normal file
View File

@ -0,0 +1,33 @@
defmodule EMQXModules.MixProject do
use Mix.Project
Code.require_file("../../lib/emqx/mix/common.ex")
def project do
[
app: :emqx_modules,
version: "4.3.2",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
registered: [:emqx_mod_sup],
mod: {:emqx_modules_app, []},
applications: EMQX.Mix.Common.from_erl!(:emqx_modules, :applications),
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false},
]
end
end

View File

@ -0,0 +1,29 @@
defmodule EMQXModules.MixProject do
use Mix.Project
def project do
[
app: :emqx_modules,
version: "4.3.2",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
registered: [:emqx_mod_sup],
mod: {:emqx_modules_app, []},
extra_applications: [:logger]
]
end
defp deps do
[]
end
end

View File

@ -24,6 +24,18 @@
start(_Type, _Args) ->
{ok, Sup} = emqx_modules_sup:start_link(),
%% io:format(user, "~n>>>>>>>>>>>> modules_app:start sup children ~p~n",
%% [supervisor:which_children(Sup)]),
%% io:format(user, "~n>>>>>>>>>>>> modules_app:start get_release ~p~n",
%% [emqx_app:get_release()]),
%% io:format(user, "~n>>>>>>>>>>>> modules_app:start official_version ~p~n",
%% [emqx_telemetry:official_version(emqx_app:get_release())]),
%% io:format(user, "~n>>>>>>>>>>>> modules_app:start config files ~p~n",
%% [application:get_env(emqx, config_files, [])]),
%% io:format(user, "~n>>>>>>>>>>>> modules_app:start retainer config ~p~n",
%% [emqx:get_config([emqx_retainer], undefined)]),
%% io:format(user, "~n>>>>>>>>>>>> modules_app:start authz_api_settings:api_spec ~p~n",
%% [emqx_authz_api_settings:api_spec()]),
maybe_enable_modules(),
{ok, Sup}.

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

View File

@ -0,0 +1,28 @@
defmodule EMQXPluginLibs.MixProject do
use Mix.Project
def project do
[
app: :emqx_plugin_libs,
version: "4.3.1",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Plugin utility libs"
]
end
def application do
[
extra_applications: [:logger]
]
end
defp deps do
[]
end
end

View File

@ -0,0 +1,28 @@
defmodule EMQXPluginLibs.MixProject do
use Mix.Project
def project do
[
app: :emqx_plugin_libs,
version: "4.3.1",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X Plugin utility libs"
]
end
def application do
[
extra_applications: [:logger]
]
end
defp deps do
[]
end
end

View File

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

View File

@ -0,0 +1,33 @@
defmodule EMQXPrometheus.MixProject do
use Mix.Project
def project do
[
app: :emqx_prometheus,
version: "4.3.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "Prometheus for EMQ X"
]
end
def application do
[
registered: [:emqx_prometheus_sup],
mod: {:emqx_prometheus_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true},
{:prometheus, github: "emqx/prometheus.erl", tag: "v3.1.1"}
]
end
end

View File

@ -0,0 +1,32 @@
defmodule EMQXPrometheus.MixProject do
use Mix.Project
def project do
[
app: :emqx_prometheus,
version: "4.3.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "Prometheus for EMQ X"
]
end
def application do
[
registered: [:emqx_prometheus_sup],
mod: {:emqx_prometheus_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:prometheus, github: "emqx/prometheus.erl", tag: "v3.1.1"}
]
end
end

32
apps/emqx_psk/mix.exs Normal file
View File

@ -0,0 +1,32 @@
defmodule EmqxPSK.MixProject do
use Mix.Project
def project do
[
app: :emqx_psk,
version: "5.0.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
# start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X PSK"
]
end
def application do
[
registered: [:emqx_psk_sup],
mod: {:emqx_psk_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false}
]
end
end

32
apps/emqx_psk/mix.exs2 Normal file
View File

@ -0,0 +1,32 @@
defmodule EmqxPSK.MixProject do
use Mix.Project
def project do
[
app: :emqx_psk,
version: "5.0.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
description: "EMQ X PSK"
]
end
def application do
[
registered: [:emqx_psk_sup],
mod: {:emqx_psk_app, []},
extra_applications: [:logger]
]
end
defp deps do
[
{:emqx, in_umbrella: true, runtime: false}
]
end
end

View File

@ -0,0 +1,11 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
locals_without_parens: [
start_type: 1,
overlay: 1,
mkdir: 1,
copy: 2,
template: 2
]
]

26
apps/emqx_release_helper/.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
# The directory Mix will write compiled artifacts to.
/_build/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where third-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
emqx_release_helper-*.tar
# Temporary files, for example, from tests.
/tmp/

View File

@ -0,0 +1,21 @@
# EmqxReleaseHelper
**TODO: Add description**
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `emqx_release_helper` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:emqx_release_helper, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/emqx_release_helper](https://hexdocs.pm/emqx_release_helper).

View File

@ -0,0 +1,132 @@
defmodule EmqxReleaseHelper do
def applications do
config = profile_vars()
EmqxReleaseHelper.Applications.__all__()
|> Enum.filter(fn
%{enable?: fun} -> fun.(config)
_ -> true
end)
|> Enum.map(fn %{name: name, start_type: start_type} -> {name, start_type} end)
end
def run(release) do
config = Map.merge(profile_vars(), release_vars(release))
release
|> EmqxReleaseHelper.Script.run(config)
|> EmqxReleaseHelper.Overlay.run(config)
|> EmqxReleaseHelper.Applications.run(config)
end
def profile_vars() do
"RELEASE_PROFILE"
|> System.get_env("emqx")
|> String.to_existing_atom()
|> case do
:emqx ->
%{
release_type: :cloud,
package_type: :bin
}
end
|> Map.merge(%{
erts_vsn: :version |> :erlang.system_info() |> to_string(),
project_path: EMQXUmbrella.MixProject.project_path(),
enable_bcrypt: EMQXUmbrella.MixProject.enable_bcrypt(),
enable_plugin_emqx_modules: false,
enable_plugin_emqx_retainer: true,
apps_paths: Mix.Project.apps_paths(),
built_on_arch: get_arch()
})
|> then(fn %{release_type: release_type} = config ->
Map.merge(config, profile_vars(:release_type, release_type))
end)
|> then(fn %{package_type: package_type} = config ->
Map.merge(config, profile_vars(:package_type, package_type))
end)
end
defp profile_vars(:release_type, :cloud) do
%{
emqx_description: "EMQ X Broker",
enable_plugin_emqx_rule_engine: true,
enable_plugin_emqx_bridge_mqtt: false
}
end
defp profile_vars(:release_type, :edge) do
%{
emqx_description: "EMQ X Edge",
enable_plugin_emqx_rule_engine: false,
enable_plugin_emqx_bridge_mqtt: true
}
end
defp profile_vars(:package_type, :bin) do
%{
platform_bin_dir: "bin",
platform_data_dir: "data",
platform_etc_dir: "etc",
platform_lib_dir: "lib",
platform_log_dir: "log",
platform_plugins_dir: "etc/plugins",
runner_root_dir: "$(cd $(dirname $(readlink $0 || echo $0))/..; pwd -P)",
runner_bin_dir: "$RUNNER_ROOT_DIR/bin",
runner_etc_dir: "$RUNNER_ROOT_DIR/etc",
runner_lib_dir: "$RUNNER_ROOT_DIR/lib",
runner_log_dir: "$RUNNER_ROOT_DIR/log",
runner_data_dir: "$RUNNER_ROOT_DIR/data",
runner_user: ""
}
end
defp profile_vars(:package_type, :pkg) do
%{
platform_bin_dir: "",
platform_data_dir: "/var/lib/emqx",
platform_etc_dir: "/etc/emqx",
platform_lib_dir: "",
platform_log_dir: "/var/log/emqx",
platform_plugins_dir: "/var/lib/emqx/plugins",
runner_root_dir: "/usr/lib/emqx",
runner_bin_dir: "/usr/bin",
runner_etc_dir: "/etc/emqx",
runner_lib_dir: "$RUNNER_ROOT_DIR/lib",
runner_log_dir: "/var/log/emqx",
runner_data_dir: "/var/lib/emqx",
runner_user: "emqx"
}
end
defp release_vars(release) do
%{
release_version: release.version,
release_path: release.path,
release_version_path: release.version_path
}
end
defp get_arch do
major_version = System.otp_release()
otp_release =
[:code.root_dir(), "releases", major_version, "OTP_VERSION"]
|> Path.join()
|> File.read()
|> case do
{:ok, version} -> String.trim(version)
{:error, _} -> major_version
end
wordsize =
try do
:erlang.system_info({:wordsize, :external}) * 8
rescue
_ ->
:erlang.system_info(:wordsize) * 8
end
Enum.join([otp_release, :erlang.system_info(:system_architecture), wordsize], "-")
end
end

View File

@ -0,0 +1,138 @@
defmodule EmqxReleaseHelper.Applications do
use EmqxReleaseHelper.DSL.Application
application :emqx do
start_type :load
overlay %{release_type: release_type} do
copy "etc/certs", "etc/certs"
template "etc/ssl_dist.conf", "etc/ssl_dist.conf"
template "etc/emqx_#{release_type}/vm.args", "etc/vm.args"
end
end
application :emqx_conf do
start_type :load
overlay do
template "etc/emqx.conf.all", "etc/emqx.conf"
end
end
application :lc do
start_type :load
end
application :esasl do
start_type :load
end
application :mria do
start_type :load
end
application :mnesia do
start_type :load
end
application :ekka do
start_type :load
end
application :emqx_plugin_libs do
start_type :load
end
application :emqx_gateway do
start_type :load
overlay do
copy "src/lwm2m/lwm2m_xml", "etc/lwm2m_xml"
end
end
application :emqx_resource do
start_type :load
end
application :emqx_connector do
start_type :load
end
application :emqx_bridge do
start_type :load
end
application :emqx_authn do
start_type :load
end
application :emqx_authz do
start_type :load
overlay do
template "etc/acl.conf", "etc/acl.conf"
end
end
application :emqx_machine do
start_type :permanent
end
application :emqx_auto_subscribe do
start_type :permanent
end
application :emqx_exhook do
start_type :permanent
end
application :emqx_modules do
start_type :permanent
end
application :emqx_dashboard do
start_type :permanent
end
application :emqx_management do
start_type :permanent
end
application :emqx_statsd do
start_type :permanent
end
application :emqx_retainer do
start_type :permanent
end
application :emqx_rule_engine do
start_type :permanent
end
application :emqx_psk do
start_type :permanent
end
application :emqx_limiter do
start_type :permanent
end
application :emqx_prometheus do
start_type :permanent
end
application :bcrypt, %{enable_bcrypt: true, release_type: :cloud} do
start_type :permanent
end
application :xmerl, %{release_type: :cloud} do
start_type :permanent
end
application :observer, %{release_type: :cloud} do
start_type :load
end
end

View File

@ -0,0 +1,83 @@
defmodule EmqxReleaseHelper.DSL.Application do
defmacro __using__(_) do
quote do
import unquote(__MODULE__)
import EmqxReleaseHelper.DSL.Overlay, only: [
overlay: 1,
overlay: 2,
copy: 2,
template: 2
]
Module.register_attribute(__MODULE__, :applications, accumulate: true)
@before_compile unquote(__MODULE__)
@overlay_source_path :app_source_path
end
end
defmacro application(app, condition, do: block) do
func =
Macro.escape(
quote do
fn config -> match?(unquote(condition), config) end
end
)
quote do
@current_application %{name: unquote(app), enable?: unquote(func)}
@overlays []
unquote(block)
overlays = Enum.reverse(@overlays)
@applications Map.put(@current_application, :overlays, overlays)
@current_application nil
@overlays []
end
end
defmacro application(app, do: block) do
quote do
@current_application %{name: unquote(app)}
@overlays []
unquote(block)
overlays = Enum.reverse(@overlays)
@applications Map.put(@current_application, :overlays, overlays)
@current_application nil
@overlays []
end
end
defmacro start_type(type) do
quote do
@current_application Map.put(@current_application, :start_type, unquote(type))
end
end
defmacro __before_compile__(%Macro.Env{module: module}) do
block =
module
|> Module.get_attribute(:applications)
|> Enum.reverse()
|> Enum.map(fn app -> {:%{}, [], Map.to_list(app)} end)
quote do
def __all__, do: unquote(block)
def run(release, config) do
%{project_path: project_path, apps_paths: apps_paths} = config
__all__()
|> Enum.filter(fn %{name: name} -> Map.has_key?(apps_paths, name) end)
|> Enum.filter(fn
%{enable?: fun} -> fun.(config)
_ -> true
end)
|> Enum.each(fn %{name: name, overlays: overlays} ->
app_path = Map.get(apps_paths, name)
config = Map.put(config, :app_source_path, Path.join(project_path, app_path))
Enum.each(overlays, fn overlay -> overlay.(config) end)
end)
release
end
end
end
end

View File

@ -0,0 +1,132 @@
defmodule EmqxReleaseHelper.DSL.Overlay do
defmacro __using__(_) do
quote do
import unquote(__MODULE__)
@before_compile unquote(__MODULE__)
@overlays []
@overlay_source_path :project_path
end
end
defmacro overlay(do: block) do
block =
Macro.escape(
quote do
fn unquote(Macro.var(:config, nil)) ->
unquote(block)
end
end
)
quote do
@overlays [unquote(block) | @overlays]
end
end
defmacro overlay(literal_config, do: block) do
block =
Macro.escape(
quote do
fn unquote(literal_config) = unquote(Macro.var(:config, nil)) ->
unquote(block)
end
end
)
quote do
@overlays [unquote(block) | @overlays]
end
end
defmacro mkdir(path) do
path =
quote do
unquote(Macro.var(:config, nil))
|> Map.get(:release_path)
|> Path.join(unquote(path))
end
quote do
run_mkdir(unquote(path))
end
end
defmacro copy(from_path, to_path) do
from_path =
quote do
unquote(Macro.var(:config, nil))
|> Map.get(@overlay_source_path)
|> Path.join(unquote(from_path))
end
to_path =
quote do
unquote(Macro.var(:config, nil))
|> Map.get(:release_path)
|> Path.join(unquote(to_path))
end
quote do
unquote(__MODULE__).run_copy(unquote(from_path), unquote(to_path))
end
end
defmacro template(from_path, to_path) do
from_path =
quote do
unquote(Macro.var(:config, nil))
|> Map.get(@overlay_source_path)
|> Path.join(unquote(from_path))
end
to_path =
quote do
unquote(Macro.var(:config, nil))
|> Map.get(:release_path)
|> Path.join(unquote(to_path))
end
quote do
unquote(__MODULE__).run_template(
unquote(from_path),
unquote(to_path),
unquote(Macro.var(:config, nil))
)
end
end
def run_mkdir(path) do
File.mkdir_p!(path)
end
def run_copy(from_path, to_path) do
to_path |> Path.dirname() |> File.mkdir_p!()
File.cp_r!(from_path, to_path)
end
def run_template(from_path, to_path, config) do
config = Enum.map(config, fn {key, value} -> {to_charlist(key), value} end)
to_path |> Path.dirname() |> File.mkdir_p!()
content =
from_path
|> File.read!()
|> :bbmustache.render(config)
File.write!(to_path, content)
end
defmacro __before_compile__(%Macro.Env{module: module}) do
block =
module
|> Module.get_attribute(:overlays)
|> Enum.reverse()
quote do
def run(release, config) do
Enum.each(unquote(block), fn overlay -> overlay.(config) end)
release
end
end
end
end

View File

@ -0,0 +1,21 @@
defmodule EmqxReleaseHelper.Overlay do
use EmqxReleaseHelper.DSL.Overlay
overlay %{release_version: release_version} do
mkdir "log"
mkdir "etc"
mkdir "data"
mkdir "data/mnesia"
mkdir "data/configs"
mkdir "data/patches"
mkdir "data/scripts"
copy "bin/install_upgrade.escript", "bin/install_upgrade.escript"
copy "bin/node_dump", "bin/node_dump"
copy "bin/emqx_ctl", "bin/emqx_ctl"
template "data/emqx_vars", "releases/emqx_vars"
template "data/BUILT_ON", "releases/#{release_version}/BUILT_ON"
end
end

View File

@ -0,0 +1,17 @@
defmodule EmqxReleaseHelper.Script do
def run(release, config) do
script_path = Path.join(config.project_path, "scripts")
{_, 0} =
script_path
|> Path.join("merge-config.escript")
|> System.cmd([])
{_, 0} =
script_path
|> Path.join("get-dashboard.sh")
|> System.cmd([], env: [{"EMQX_DASHBOARD_VERSION", "v5.0.0-beta.13"}])
release
end
end

View File

@ -0,0 +1,29 @@
defmodule EMQXReleaseHelper.MixProject do
use Mix.Project
def project do
[
app: :emqx_release_helper,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
extra_applications: [:logger]
]
end
defp deps do
[
{:bbmustache, "1.12.1"}
]
end
end

View File

@ -0,0 +1,8 @@
defmodule EmqxReleaseHelperTest do
use ExUnit.Case
doctest EmqxReleaseHelper
test "greets the world" do
assert EmqxReleaseHelper.hello() == :world
end
end

View File

@ -0,0 +1 @@
ExUnit.start()

View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

Some files were not shown because too many files have changed in this diff Show More