chore(auth): simplify schema injection
This commit is contained in:
parent
8a3e8ee528
commit
f00f4568dc
|
@ -222,7 +222,7 @@ roots(high) ->
|
||||||
ref(?EMQX_AUTHORIZATION_CONFIG_ROOT_NAME),
|
ref(?EMQX_AUTHORIZATION_CONFIG_ROOT_NAME),
|
||||||
#{importance => ?IMPORTANCE_HIDDEN}
|
#{importance => ?IMPORTANCE_HIDDEN}
|
||||||
)}
|
)}
|
||||||
] ++ emqx_schema_hooks:injection_point('roots.high');
|
] ++ emqx_schema_hooks:injection_point('authentication');
|
||||||
roots(medium) ->
|
roots(medium) ->
|
||||||
[
|
[
|
||||||
{"broker",
|
{"broker",
|
||||||
|
@ -1749,7 +1749,7 @@ mqtt_listener(Bind) ->
|
||||||
default => <<"3s">>
|
default => <<"3s">>
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
] ++ emqx_schema_hooks:injection_point('mqtt.listener').
|
] ++ emqx_schema_hooks:injection_point('listeners.authentication').
|
||||||
|
|
||||||
base_listener(Bind) ->
|
base_listener(Bind) ->
|
||||||
[
|
[
|
||||||
|
|
|
@ -28,9 +28,7 @@
|
||||||
-define(MODULE_PT_KEY(MOD_NAME), {?MODULE, mod, MOD_NAME}).
|
-define(MODULE_PT_KEY(MOD_NAME), {?MODULE, mod, MOD_NAME}).
|
||||||
|
|
||||||
-export([
|
-export([
|
||||||
inject_fields/3,
|
|
||||||
injection_point/1,
|
injection_point/1,
|
||||||
|
|
||||||
inject_fields_from_mod/1
|
inject_fields_from_mod/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
@ -45,17 +43,7 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
injection_point(PointName) ->
|
injection_point(PointName) ->
|
||||||
InjectedFields = persistent_term:get(?HOOKPOINT_PT_KEY(PointName), #{}),
|
persistent_term:get(?HOOKPOINT_PT_KEY(PointName), []).
|
||||||
lists:concat(maps:values(InjectedFields)).
|
|
||||||
|
|
||||||
inject_fields(PointName, Name, Fields) ->
|
|
||||||
Key = ?HOOKPOINT_PT_KEY(PointName),
|
|
||||||
InjectedFields = persistent_term:get(Key, #{}),
|
|
||||||
persistent_term:put(Key, InjectedFields#{Name => Fields}).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Internal API
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
inject_fields_from_mod(Module) ->
|
inject_fields_from_mod(Module) ->
|
||||||
case persistent_term:get(?MODULE_PT_KEY(Module), false) of
|
case persistent_term:get(?MODULE_PT_KEY(Module), false) of
|
||||||
|
@ -105,10 +93,14 @@ do_inject_fields_from_mod(Module) ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_inject_fields_from_mod(Module, HookFields) ->
|
do_inject_fields_from_mod(_Module, HookFields) ->
|
||||||
maps:foreach(
|
maps:foreach(
|
||||||
fun(PointName, Fields) ->
|
fun(PointName, Fields) ->
|
||||||
inject_fields(PointName, Module, Fields)
|
inject_fields(PointName, Fields)
|
||||||
end,
|
end,
|
||||||
HookFields
|
HookFields
|
||||||
).
|
).
|
||||||
|
|
||||||
|
inject_fields(PointName, Fields) ->
|
||||||
|
Key = ?HOOKPOINT_PT_KEY(PointName),
|
||||||
|
persistent_term:put(Key, Fields).
|
||||||
|
|
|
@ -42,8 +42,8 @@ roots() -> [].
|
||||||
|
|
||||||
injected_fields() ->
|
injected_fields() ->
|
||||||
#{
|
#{
|
||||||
'roots.high' => global_auth_fields(),
|
'authentication' => global_auth_fields(),
|
||||||
'mqtt.listener' => mqtt_listener_auth_fields()
|
'listeners.authentication' => mqtt_listener_auth_fields()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
tags() ->
|
tags() ->
|
||||||
|
|
Loading…
Reference in New Issue