Skip to content

Commit

Permalink
Add Riak defaults to mod_vcard config
Browse files Browse the repository at this point in the history
The values are used only when the Riak backend is specified.
  • Loading branch information
gustawlippa committed Feb 22, 2022
1 parent 4004b58 commit b1ee098
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
9 changes: 8 additions & 1 deletion big_tests/tests/gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,14 @@ pick_enabled_backend() ->


vcard_required_modules() ->
[{mod_vcard, config_parser_helper:mod_config(mod_vcard, #{backend => pick_enabled_backend()})}].
Backend = pick_enabled_backend(),
[{mod_vcard, config_parser_helper:mod_config(mod_vcard, vcard_backend_opts(Backend))}].

vcard_backend_opts(riak) ->
#{backend => riak, riak => #{bucket_type => <<"vcard">>,
search_index => <<"vcard">>}};
vcard_backend_opts(Backend) ->
#{backend => Backend}.

offline_required_modules() ->
[{mod_offline, [{backend, pick_enabled_backend()}]}].
Expand Down
11 changes: 9 additions & 2 deletions src/vcard/mod_vcard.erl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ config_spec() ->
<<"ldap_search_operator">> => 'and',
<<"ldap_binary_search_fields">> => []
},
format_items = map
format_items = map,
process = fun remove_unused_backend_opts/1
}.

ldap_vcard_map_spec() ->
Expand Down Expand Up @@ -295,7 +296,10 @@ riak_config_spec() ->
<<"search_index">> => #option{type = binary,
validate = non_empty}
},
wrap = none
include = always,
format_items = map,
defaults = #{<<"bucket_type">> => <<"vcard">>,
<<"search_index">> => <<"vcard">>}
}.

process_map_spec(KVs) ->
Expand All @@ -313,6 +317,9 @@ process_search_reported_spec(KVs) ->
proplists:split(KVs, [search_field, vcard_field]),
{SF, VF}.

remove_unused_backend_opts(Opts = #{backend := riak}) -> Opts;
remove_unused_backend_opts(Opts) -> maps:remove(riak, Opts).

%%--------------------------------------------------------------------
%% mongoose_packet_handler callbacks for search
%%--------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/vcard/mod_vcard_riak.erl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ extract_field(Props, {_, Field}) ->


bucket_type(HostType, LServer) ->
{gen_mod:get_module_opt(HostType, mod_vcard, bucket_type, <<"vcard">>), <<"vcard_", LServer/binary>>}.
{gen_mod:get_module_opt(HostType, mod_vcard, [riak, bucket_type]), <<"vcard_", LServer/binary>>}.

yz_vcard_index(HostType) ->
gen_mod:get_module_opt(HostType, mod_vcard, search_index, <<"vcard">>).
gen_mod:get_module_opt(HostType, mod_vcard, [riak, search_index]).
8 changes: 4 additions & 4 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2954,10 +2954,10 @@ mod_vcard(_Config) ->
?cfgh(P ++ [ldap_binary_search_fields], [<<"PHOTO">>],
T(#{<<"ldap_binary_search_fields">> => [<<"PHOTO">>]})),
%% riak
?cfgh(P ++ [bucket_type], <<"vcard">>,
T(#{<<"riak">> => #{<<"bucket_type">> => <<"vcard">>}})),
?cfgh(P ++ [search_index], <<"vcard">>,
T(#{<<"riak">> => #{<<"search_index">> => <<"vcard">>}})),
?cfgh(P ++ [riak, bucket_type], <<"vcard">>,
T(#{<<"backend">> => <<"riak">>, <<"riak">> => #{<<"bucket_type">> => <<"vcard">>}})),
?cfgh(P ++ [riak, search_index], <<"vcard">>,
T(#{<<"backend">> => <<"riak">>, <<"riak">> => #{<<"search_index">> => <<"vcard">>}})),

?errh(T(#{<<"host">> => 1})),
?errh(T(#{<<"host">> => <<"is this a host? no.">>})),
Expand Down

0 comments on commit b1ee098

Please sign in to comment.