Merge pull request #12211 from zhongwencool/redis-resource-opts
fix: redis resource_opts not working
This commit is contained in:
commit
74f1ce0955
|
@ -11,8 +11,8 @@
|
||||||
action_type_name/0,
|
action_type_name/0,
|
||||||
connector_type_name/0,
|
connector_type_name/0,
|
||||||
schema_module/0,
|
schema_module/0,
|
||||||
bridge_v1_config_to_action_config/2,
|
|
||||||
connector_action_config_to_bridge_v1_config/2,
|
connector_action_config_to_bridge_v1_config/2,
|
||||||
|
bridge_v1_config_to_action_config/2,
|
||||||
bridge_v1_config_to_connector_config/1,
|
bridge_v1_config_to_connector_config/1,
|
||||||
bridge_v1_type_name_fun/1
|
bridge_v1_type_name_fun/1
|
||||||
]).
|
]).
|
||||||
|
@ -28,14 +28,25 @@ connector_type_name() -> redis.
|
||||||
|
|
||||||
schema_module() -> ?SCHEMA_MODULE.
|
schema_module() -> ?SCHEMA_MODULE.
|
||||||
|
|
||||||
|
%% redis_cluster don't have batch options
|
||||||
connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig) ->
|
connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig) ->
|
||||||
maps:merge(
|
Config0 = emqx_utils_maps:deep_merge(
|
||||||
maps:without(
|
maps:without(
|
||||||
[<<"connector">>],
|
[<<"connector">>],
|
||||||
map_unindent(<<"parameters">>, ActionConfig)
|
emqx_utils_maps:unindent(<<"parameters">>, ActionConfig)
|
||||||
),
|
),
|
||||||
map_unindent(<<"parameters">>, ConnectorConfig)
|
emqx_utils_maps:unindent(<<"parameters">>, ConnectorConfig)
|
||||||
).
|
),
|
||||||
|
Config1 =
|
||||||
|
case Config0 of
|
||||||
|
#{<<"resource_opts">> := ResOpts0, <<"redis_type">> := Type} ->
|
||||||
|
Schema = emqx_bridge_redis:fields("creation_opts_redis_" ++ binary_to_list(Type)),
|
||||||
|
ResOpts = maps:with(schema_keys(Schema), ResOpts0),
|
||||||
|
Config0#{<<"resource_opts">> => ResOpts};
|
||||||
|
_ ->
|
||||||
|
Config0
|
||||||
|
end,
|
||||||
|
maps:without([<<"description">>], Config1).
|
||||||
|
|
||||||
bridge_v1_config_to_action_config(BridgeV1Config, ConnectorName) ->
|
bridge_v1_config_to_action_config(BridgeV1Config, ConnectorName) ->
|
||||||
ActionTopLevelKeys = schema_keys(?SCHEMA_MODULE:fields(redis_action)),
|
ActionTopLevelKeys = schema_keys(?SCHEMA_MODULE:fields(redis_action)),
|
||||||
|
@ -81,22 +92,9 @@ v1_type(<<"cluster">>) -> redis_cluster.
|
||||||
|
|
||||||
bridge_v1_type_names() -> [redis_single, redis_sentinel, redis_cluster].
|
bridge_v1_type_names() -> [redis_single, redis_sentinel, redis_cluster].
|
||||||
|
|
||||||
map_unindent(Key, Map) ->
|
|
||||||
maps:merge(
|
|
||||||
maps:get(Key, Map),
|
|
||||||
maps:remove(Key, Map)
|
|
||||||
).
|
|
||||||
|
|
||||||
map_indent(IndentKey, PickKeys, Map) ->
|
|
||||||
maps:put(
|
|
||||||
IndentKey,
|
|
||||||
maps:with(PickKeys, Map),
|
|
||||||
maps:without(PickKeys, Map)
|
|
||||||
).
|
|
||||||
|
|
||||||
schema_keys(Schema) ->
|
schema_keys(Schema) ->
|
||||||
[bin(Key) || {Key, _} <- Schema].
|
[bin(Key) || {Key, _} <- Schema].
|
||||||
|
|
||||||
make_config_map(PickKeys, IndentKeys, Config) ->
|
make_config_map(PickKeys, IndentKeys, Config) ->
|
||||||
Conf0 = maps:with(PickKeys, Config),
|
Conf0 = maps:with(PickKeys, Config),
|
||||||
map_indent(<<"parameters">>, IndentKeys, Conf0).
|
emqx_utils_maps:indent(<<"parameters">>, IndentKeys, Conf0).
|
||||||
|
|
|
@ -356,10 +356,13 @@ configs(put, #{body := Conf, query_string := #{<<"mode">> := Mode}}, _Req) ->
|
||||||
case emqx_conf_cli:load_config(Conf, #{mode => Mode, log => none}) of
|
case emqx_conf_cli:load_config(Conf, #{mode => Mode, log => none}) of
|
||||||
ok ->
|
ok ->
|
||||||
{200};
|
{200};
|
||||||
{error, MsgList} ->
|
%% bad hocon format
|
||||||
|
{error, MsgList = [{_, _} | _]} ->
|
||||||
JsonFun = fun(K, V) -> {K, emqx_utils_maps:binary_string(V)} end,
|
JsonFun = fun(K, V) -> {K, emqx_utils_maps:binary_string(V)} end,
|
||||||
JsonMap = emqx_utils_maps:jsonable_map(maps:from_list(MsgList), JsonFun),
|
JsonMap = emqx_utils_maps:jsonable_map(maps:from_list(MsgList), JsonFun),
|
||||||
{400, #{<<"content-type">> => <<"text/plain">>}, JsonMap}
|
{400, #{<<"content-type">> => <<"text/plain">>}, JsonMap};
|
||||||
|
{error, Msg} ->
|
||||||
|
{400, #{<<"content-type">> => <<"text/plain">>}, Msg}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
find_suitable_accept(Headers, Preferences) when is_list(Preferences), length(Preferences) > 0 ->
|
find_suitable_accept(Headers, Preferences) when is_list(Preferences), length(Preferences) > 0 ->
|
||||||
|
|
Loading…
Reference in New Issue