Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'format_items = map' by default for config sections #3655

Merged
merged 2 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/mongoose_config_spec.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
validate_keys = any :: mongoose_config_validator:validator(),
required = [] :: [mongoose_config_parser_toml:toml_key()] | all,
validate = any :: mongoose_config_validator:section_validator(),
format_items = none :: mongoose_config_spec:format_items(),
format_items = map :: mongoose_config_spec:format_items(),
process :: undefined | mongoose_config_parser_toml:list_processor(),
defaults = #{} :: #{mongoose_config_parser_toml:toml_key() =>
mongoose_config_parser_toml:config_part()},
Expand All @@ -15,7 +15,7 @@

-record(list, {items :: mongoose_config_spec:config_node(),
validate = any :: mongoose_config_validator:list_validator(),
format_items = none :: mongoose_config_spec:format_items(),
format_items = list :: mongoose_config_spec:format_items(),
process :: undefined | mongoose_config_parser_toml:list_processor(),
wrap = default :: mongoose_config_spec:wrapper()}).

Expand Down
3 changes: 1 addition & 2 deletions src/admin_extra/service_admin_extra.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ config_spec() ->
validate = {enum, ?SUBMODS}},
validate = unique}
},
defaults = #{<<"submods">> => ?SUBMODS},
format_items = map
defaults = #{<<"submods">> => ?SUBMODS}
}.

mod_name(ModAtom) ->
Expand Down
3 changes: 1 addition & 2 deletions src/auth/ejabberd_auth_anonymous.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ config_spec() ->
validate = {enum, [sasl_anon, login_anon, both]}}
},
defaults = #{<<"allow_multiple_connections">> => false,
<<"protocol">> => sasl_anon},
format_items = map
<<"protocol">> => sasl_anon}
}.

%% @doc Return true if multiple connections have been allowed in the config file
Expand Down
3 changes: 1 addition & 2 deletions src/auth/ejabberd_auth_dummy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ config_spec() ->
<<"variance">> => #option{type = integer,
validate = positive}},
defaults = #{<<"base_time">> => 50,
<<"variance">> => 450},
format_items = map
<<"variance">> => 450}
}.

authorize(Creds) ->
Expand Down
3 changes: 1 addition & 2 deletions src/auth/ejabberd_auth_external.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ config_spec() ->
validate = non_empty}
},
required = [<<"program">>],
defaults = #{<<"instances">> => 1},
format_items = map
defaults = #{<<"instances">> => 1}
}.

-spec check_cache_last_options(mongooseim:host_type()) -> 'cache' | 'no_cache'.
Expand Down
5 changes: 1 addition & 4 deletions src/auth/ejabberd_auth_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ stop(_HostType) ->

-spec config_spec() -> mongoose_config_spec:config_section().
config_spec() ->
#section{
items = #{<<"basic_auth">> => #option{type = string}},
format_items = map
}.
#section{items = #{<<"basic_auth">> => #option{type = string}}}.

-spec supports_sasl_module(mongooseim:host_type(), cyrsasl:sasl_module()) -> boolean().
supports_sasl_module(_HostType, cyrsasl_plain) -> true;
Expand Down
4 changes: 2 additions & 2 deletions src/auth/ejabberd_auth_jwt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ config_spec() ->
<<"username_key">> => #option{type = atom,
validate = non_empty}
},
required = all,
format_items = map
required = all
}.

jwt_secret_config_spec() ->
Expand All @@ -81,6 +80,7 @@ jwt_secret_config_spec() ->
<<"env">> => #option{type = string,
validate = non_empty},
<<"value">> => #option{type = string}},
format_items = list,
process = fun ?MODULE:process_jwt_secret/1
}.

Expand Down
3 changes: 1 addition & 2 deletions src/auth/ejabberd_auth_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ stop(_HostType) ->
config_spec() ->
#section{
items = #{<<"users_number_estimate">> => #option{type = boolean}},
defaults = #{<<"users_number_estimate">> => false},
format_items = map
defaults = #{<<"users_number_estimate">> => false}
}.

-spec supports_sasl_module(mongooseim:host_type(), cyrsasl:sasl_module()) -> boolean().
Expand Down
3 changes: 1 addition & 2 deletions src/auth/ejabberd_auth_riak.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ config_spec() ->
#section{
items = #{<<"bucket_type">> => #option{type = binary,
validate = non_empty}},
defaults = #{<<"bucket_type">> => <<"users">>},
format_items = map
defaults = #{<<"bucket_type">> => <<"users">>}
}.

-spec supports_sasl_module(mongooseim:host_type(), cyrsasl:sasl_module()) -> boolean().
Expand Down
3 changes: 1 addition & 2 deletions src/auth/mongoose_gen_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ stop(Mod, HostType) ->
config_spec(Mod) ->
case is_exported(Mod, config_spec, 0) of
true -> Mod:config_spec();
false -> #section{items = #{},
format_items = map}
false -> #section{}
end.

-spec supports_sasl_module(ejabberd_auth:authmodule(), mongooseim:host_type(),
Expand Down
7 changes: 4 additions & 3 deletions src/config/mongoose_config_parser_toml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ parse_list(Path, L, #list{items = ItemSpec}) ->
end, L).

-spec handle(path(), toml_value(), mongoose_config_spec:config_node()) -> [config_part()].
handle(Path, Value, Spec = #option{}) ->
handle(Path, Value, Spec, [parse, validate, process, wrap]);
handle(Path, Value, Spec) ->
handle(Path, Value, Spec, [parse, validate, format_items, process, wrap]).

Expand Down Expand Up @@ -184,15 +186,14 @@ validate_keys(#section{validate_keys = Validator}, Section) ->

-spec format_items_spec(mongoose_config_spec:config_node()) -> mongoose_config_spec:format_items().
format_items_spec(#section{format_items = FormatItems}) -> FormatItems;
format_items_spec(#list{format_items = FormatItems}) -> FormatItems;
format_items_spec(#option{}) -> none.
format_items_spec(#list{format_items = FormatItems}) -> FormatItems.

-spec format_items(config_part(), mongoose_config_spec:format_items()) -> config_part().
format_items(KVs, map) ->
Keys = lists:map(fun({K, _}) -> K end, KVs),
mongoose_config_validator:validate_list(Keys, unique),
maps:from_list(KVs);
format_items(Value, none) ->
format_items(Value, list) when is_list(Value) ->
Value.

-spec validate(config_part(), mongoose_config_spec:config_node()) -> any().
Expand Down
Loading