diff --git a/apps/emqx/src/emqx_release.erl b/apps/emqx/src/emqx_release.erl index ac48d5251..c446c111e 100644 --- a/apps/emqx/src/emqx_release.erl +++ b/apps/emqx/src/emqx_release.erl @@ -24,11 +24,18 @@ version/0, version_with_prefix/0, vsn_compare/1, - vsn_compare/2 + vsn_compare/2, + on_load/0 ]). +-on_load(on_load/0). + -include("emqx_release.hrl"). +-ifndef(EMQX_RELEASE_EDITION). +-define(EMQX_RELEASE_EDITION, ce). +-endif. + -define(EMQX_DESCS, #{ ee => "EMQX Enterprise", ce => "EMQX" @@ -49,6 +56,11 @@ ce => "v" }). +%% @hidden Initialize edition. Almost static. use persistent_term to trick compiler. +-spec on_load() -> ok. +on_load() -> + persistent_term:put('EMQX_RELEASE_EDITION', ?EMQX_RELEASE_EDITION). + %% @doc Return EMQX description. description() -> maps:get(edition(), ?EMQX_DESCS). @@ -57,11 +69,8 @@ description() -> %% Read info from persistent_term at runtime. %% Or meck this function to run tests for another edition. -spec edition() -> ce | ee. --ifdef(EMQX_RELEASE_EDITION). -edition() -> ?EMQX_RELEASE_EDITION. --else. -edition() -> ce. --endif. +edition() -> + persistent_term:get('EMQX_RELEASE_EDITION'). %% @doc Return EMQX version prefix string. edition_vsn_prefix() -> diff --git a/apps/emqx/src/emqx_schema.erl b/apps/emqx/src/emqx_schema.erl index bcb353477..63b77f8d2 100644 --- a/apps/emqx/src/emqx_schema.erl +++ b/apps/emqx/src/emqx_schema.erl @@ -191,8 +191,6 @@ -define(DEFAULT_MULTIPLIER, 1.5). -define(DEFAULT_BACKOFF, 0.75). --define(INJECTING_CONFIGS, [?AUTH_EXT_SCHEMA_MODS]). - namespace() -> emqx. tags() -> diff --git a/apps/emqx_conf/include/emqx_conf.hrl b/apps/emqx_conf/include/emqx_conf.hrl index d79f59bc7..042bf8d3c 100644 --- a/apps/emqx_conf/include/emqx_conf.hrl +++ b/apps/emqx_conf/include/emqx_conf.hrl @@ -37,47 +37,4 @@ -define(READONLY_KEYS, [cluster, rpc, node]). --define(CE_AUTHZ_SOURCE_SCHEMA_MODS, [ - emqx_authz_file_schema, - emqx_authz_mnesia_schema, - emqx_authz_http_schema, - emqx_authz_redis_schema, - emqx_authz_mysql_schema, - emqx_authz_postgresql_schema, - emqx_authz_mongodb_schema, - emqx_authz_ldap_schema -]). - --define(EE_AUTHZ_SOURCE_SCHEMA_MODS, []). - --define(CE_AUTHN_PROVIDER_SCHEMA_MODS, [ - emqx_authn_mnesia_schema, - emqx_authn_mysql_schema, - emqx_authn_postgresql_schema, - emqx_authn_mongodb_schema, - emqx_authn_redis_schema, - emqx_authn_http_schema, - emqx_authn_jwt_schema, - emqx_authn_scram_mnesia_schema, - emqx_authn_ldap_schema -]). - --define(EE_AUTHN_PROVIDER_SCHEMA_MODS, [ - emqx_gcp_device_authn_schema -]). - --if(?EMQX_RELEASE_EDITION == ee). - --define(AUTHZ_SOURCE_SCHEMA_MODS, ?CE_AUTHZ_SOURCE_SCHEMA_MODS ++ ?EE_AUTHZ_SOURCE_SCHEMA_MODS). --define(AUTHN_PROVIDER_SCHEMA_MODS, - (?CE_AUTHN_PROVIDER_SCHEMA_MODS ++ ?EE_AUTHN_PROVIDER_SCHEMA_MODS) -). - --else. - --define(AUTHZ_SOURCE_SCHEMA_MODS, ?CE_AUTHZ_SOURCE_SCHEMA_MODS). --define(AUTHN_PROVIDER_SCHEMA_MODS, ?CE_AUTHN_PROVIDER_SCHEMA_MODS). - --endif. - -endif. diff --git a/apps/emqx_conf/src/emqx_conf_schema.erl b/apps/emqx_conf/src/emqx_conf_schema.erl index 272eda0b4..5c1bab4ff 100644 --- a/apps/emqx_conf/src/emqx_conf_schema.erl +++ b/apps/emqx_conf/src/emqx_conf_schema.erl @@ -71,20 +71,6 @@ emqx_mgmt_api_key_schema ]). --define(AUTH_EXT_SCHEMA_MODS, [emqx_auth_ext_schema]). - --if(defined(EMQX_RELEASE_EDITION) andalso ?EMQX_RELEASE_EDITION == ee). --define(OTHER_INJECTING_CONFIGS, ?AUTH_EXT_SCHEMA_MODS). --else. --define(OTHER_INJECTING_CONFIGS, []). --endif. - --define(INJECTING_CONFIGS, [ - {emqx_authn_schema, ?AUTHN_PROVIDER_SCHEMA_MODS}, - {emqx_authz_schema, ?AUTHZ_SOURCE_SCHEMA_MODS} - | ?OTHER_INJECTING_CONFIGS -]). - %% 1 million default ports counter -define(DEFAULT_MAX_PORTS, 1024 * 1024). @@ -108,7 +94,8 @@ tags() -> [<<"EMQX">>]. roots() -> - ok = emqx_schema_hooks:inject_from_modules(?INJECTING_CONFIGS), + Injections = emqx_conf_schema_inject:schemas(), + ok = emqx_schema_hooks:inject_from_modules(Injections), emqx_schema_high_prio_roots() ++ [ {node, diff --git a/apps/emqx_conf/src/emqx_conf_schema_inject.erl b/apps/emqx_conf/src/emqx_conf_schema_inject.erl new file mode 100644 index 000000000..ec56277ab --- /dev/null +++ b/apps/emqx_conf/src/emqx_conf_schema_inject.erl @@ -0,0 +1,71 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2024 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_conf_schema_inject). + +-export([schemas/0]). + +schemas() -> + schemas(emqx_release:edition()). + +schemas(Edition) -> + auth_ext(Edition) ++ + authn(Edition) ++ + authz() ++ + customized(). + +auth_ext(ce) -> + []; +auth_ext(ee) -> + [emqx_auth_ext_schema]. + +authn(Edition) -> + [{emqx_authn_schema, authn_mods(Edition)}]. + +authn_mods(ce) -> + [ + emqx_authn_mnesia_schema, + emqx_authn_mysql_schema, + emqx_authn_postgresql_schema, + emqx_authn_mongodb_schema, + emqx_authn_redis_schema, + emqx_authn_http_schema, + emqx_authn_jwt_schema, + emqx_authn_scram_mnesia_schema, + emqx_authn_ldap_schema + ]; +authn_mods(ee) -> + authn_mods(ce) ++ + [emqx_gcp_device_authn_schema]. + +authz() -> + [{emqx_authz_schema, authz_mods()}]. + +authz_mods() -> + [ + emqx_authz_file_schema, + emqx_authz_mnesia_schema, + emqx_authz_http_schema, + emqx_authz_redis_schema, + emqx_authz_mysql_schema, + emqx_authz_postgresql_schema, + emqx_authz_mongodb_schema, + emqx_authz_ldap_schema + ]. + +%% Add more schemas here. +customized() -> + [].