feat(pulsar): use an union member selector for better error messages
This commit is contained in:
parent
dcccc0910a
commit
659cf64ad7
|
@ -45,16 +45,19 @@ fields(config) ->
|
||||||
}
|
}
|
||||||
)},
|
)},
|
||||||
{authentication,
|
{authentication,
|
||||||
mk(hoconsc:union([none, ref(auth_basic), ref(auth_token)]), #{
|
mk(
|
||||||
default => none,
|
hoconsc:union(fun auth_union_member_selector/1),
|
||||||
%% must mark this whole union as sensitive because
|
#{
|
||||||
%% hocon ignores the `sensitive' metadata in struct
|
default => none,
|
||||||
%% fields... Also, when trying to type check a struct
|
%% must mark this whole union as sensitive because
|
||||||
%% that doesn't match the intended type, it won't have
|
%% hocon ignores the `sensitive' metadata in struct
|
||||||
%% sensitivity information from sibling types.
|
%% fields... Also, when trying to type check a struct
|
||||||
sensitive => true,
|
%% that doesn't match the intended type, it won't have
|
||||||
desc => ?DESC("authentication")
|
%% sensitivity information from sibling types.
|
||||||
})}
|
sensitive => true,
|
||||||
|
desc => ?DESC("authentication")
|
||||||
|
}
|
||||||
|
)}
|
||||||
] ++ emqx_connector_schema_lib:ssl_fields();
|
] ++ emqx_connector_schema_lib:ssl_fields();
|
||||||
fields(producer_opts) ->
|
fields(producer_opts) ->
|
||||||
[
|
[
|
||||||
|
@ -233,3 +236,21 @@ override_default(OriginalFn, NewDefault) ->
|
||||||
(default) -> NewDefault;
|
(default) -> NewDefault;
|
||||||
(Field) -> OriginalFn(Field)
|
(Field) -> OriginalFn(Field)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
auth_union_member_selector(all_union_members) ->
|
||||||
|
[none, ref(auth_basic), ref(auth_token)];
|
||||||
|
auth_union_member_selector({value, V}) ->
|
||||||
|
case V of
|
||||||
|
#{<<"password">> := _} ->
|
||||||
|
[ref(auth_basic)];
|
||||||
|
#{<<"jwt">> := _} ->
|
||||||
|
[ref(auth_token)];
|
||||||
|
<<"none">> ->
|
||||||
|
[none];
|
||||||
|
_ ->
|
||||||
|
Expected = "none | basic | token",
|
||||||
|
throw(#{
|
||||||
|
field_name => authentication,
|
||||||
|
expected => Expected
|
||||||
|
})
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue