fix(authn_ldap): Improve the type inference of method union

This commit is contained in:
firest 2023-12-08 19:26:29 +08:00
parent e57d796df5
commit f4f45cf634
1 changed files with 21 additions and 1 deletions

View File

@ -55,7 +55,7 @@ fields(ldap) ->
[
{method,
?HOCON(
hoconsc:union([?R_REF(hash_method), ?R_REF(bind_method)]),
hoconsc:union(fun method_union_member_selector/1),
#{desc => ?DESC(method)}
)}
];
@ -88,6 +88,26 @@ desc(bind_method) ->
desc(_) ->
undefined.
method_union_member_selector(all_union_members) ->
[?R_REF(hash_method), ?R_REF(bind_method)];
method_union_member_selector({value, Val}) ->
Val2 =
case is_map(Val) of
true -> emqx_utils_maps:binary_key_map(Val);
false -> Val
end,
case Val2 of
#{<<"type">> := <<"bind">>} ->
[?R_REF(bind_method)];
#{<<"type">> := <<"hash">>} ->
[?R_REF(hash_method)];
_ ->
throw(#{
field_name => method,
expected => [bind_method, hash_method]
})
end.
method_type(Type) ->
?HOCON(?ENUM([Type]), #{desc => ?DESC(?FUNCTION_NAME), default => Type}).