Merge pull request #8293 from terry-xiaoyu/disabled_authn_resource_started_after_reboot

fix: disabled resources for authz/authn started after emqx reboot
This commit is contained in:
Xinyu Liu 2022-06-22 15:55:08 +08:00 committed by GitHub
commit 466fd52168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 22 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_authn, [
{description, "EMQX Authentication"},
{vsn, "0.1.0"},
{vsn, "0.1.1"},
{modules, []},
{registered, [emqx_authn_sup, emqx_authn_registry]},
{applications, [kernel, stdlib, emqx_resource, ehttpc, epgsql, mysql, jose]},

View File

@ -0,0 +1,8 @@
%% Unless you know what you are doing, DO NOT edit manually!!
{VSN,
[{"0.1.0",
[{load_module,emqx_authz_utils,brutal_purge,soft_purge,[]}]},
{<<".*">>,[]}],
[{"0.1.0",
[{load_module,emqx_authz_utils,brutal_purge,soft_purge,[]}]},
{<<".*">>,[]}]}.

View File

@ -50,22 +50,24 @@
%%------------------------------------------------------------------------------
create_resource(ResourceId, Module, Config) ->
{ok, _Data} = emqx_resource:create_local(
Result = emqx_resource:create_local(
ResourceId,
?RESOURCE_GROUP,
Module,
Config,
#{}
).
#{start_after_created => false}
),
start_resource_if_enabled(Result, ResourceId, Config).
update_resource(Module, Config, ResourceId) ->
Opts = #{start_after_created => false},
Result = emqx_resource:recreate_local(ResourceId, Module, Config, Opts),
_ =
case Config of
#{enable := true} -> emqx_resource:start(ResourceId);
#{enable := false} -> ok
end,
start_resource_if_enabled(Result, ResourceId, Config).
start_resource_if_enabled({ok, _} = Result, ResourceId, #{enable := true}) ->
_ = emqx_resource:start(ResourceId),
Result;
start_resource_if_enabled(Result, _ResourceId, _Config) ->
Result.
check_password_from_selected_map(_Algorithm, _Selected, undefined) ->

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_authz, [
{description, "An OTP application"},
{vsn, "0.1.1"},
{vsn, "0.1.2"},
{registered, []},
{mod, {emqx_authz_app, []}},
{applications, [

View File

@ -0,0 +1,8 @@
%% Unless you know what you are doing, DO NOT edit manually!!
{VSN,
[{"0.1.1",
[{load_module,emqx_authn_utils,brutal_purge,soft_purge,[]}]},
{<<".*">>,[]}],
[{"0.1.1",
[{load_module,emqx_authn_utils,brutal_purge,soft_purge,[]}]},
{<<".*">>,[]}]}.

View File

@ -43,33 +43,35 @@ create_resource(Module, Config) ->
create_resource(ResourceId, Module, Config).
create_resource(ResourceId, Module, Config) ->
{ok, _Data} = emqx_resource:create_local(
Result = emqx_resource:create_local(
ResourceId,
?RESOURCE_GROUP,
Module,
Config,
#{}
).
#{start_after_created => false}
),
start_resource_if_enabled(Result, ResourceId, Config).
update_resource(Module, #{annotations := #{id := ResourceId}} = Source) ->
update_resource(Module, #{annotations := #{id := ResourceId}} = Config) ->
Result =
case
emqx_resource:recreate_local(
ResourceId,
Module,
Source
Config,
#{start_after_created => false}
)
of
{ok, _} -> {ok, ResourceId};
{error, Reason} -> {error, Reason}
end,
case Source of
#{enable := true} ->
start_resource_if_enabled(Result, ResourceId, Config).
start_resource_if_enabled({ok, _} = Result, ResourceId, #{enable := true}) ->
_ = emqx_resource:start(ResourceId),
Result;
#{enable := false} ->
ok = emqx_resource:stop(ResourceId),
Result
end.
start_resource_if_enabled(Result, _ResourceId, _Config) ->
Result.
cleanup_resources() ->
lists:foreach(