Introduce definition file checksum settings

This commit is contained in:
Michael Klishin 2022-01-13 16:09:17 +03:00
parent 8c9f417959
commit 462ac3d906
No known key found for this signature in database
GPG Key ID: E80EDCFA0CDB21EE
2 changed files with 29 additions and 1 deletions

View File

@ -154,6 +154,12 @@ fun(Conf) ->
end
end}.
{mapping, "definitions.checksum.use_checksum", "rabbit.definitions.use_checksum", [
{datatype, {enum, [true, false]}}]}.
{mapping, "definitions.checksum.checksum_algorithm", "rabbit.definitions.checksum_algorithm", [
{datatype, {enum, [sha, sha224, sha256, sha384, sha512]}}]}.
%% Load definitions from a remote URL over HTTPS. See
%% https://www.rabbitmq.com/management.html#load-definitions
{mapping, "definitions.https.url", "rabbit.definitions.url",

View File

@ -19,7 +19,8 @@
]).
%% import
-export([import_raw/1, import_raw/2, import_parsed/1, import_parsed/2,
apply_defs/2, apply_defs/3, apply_defs/4, apply_defs/5]).
apply_defs/2, apply_defs/3, apply_defs/4, apply_defs/5,
should_use_checksum/0, checksum_algorithm/0]).
-export([all_definitions/0]).
-export([
@ -232,6 +233,27 @@ atomise_map_keys(Decoded) ->
Acc#{rabbit_data_coercion:to_atom(K, utf8) => V}
end, Decoded, Decoded).
-spec should_use_checksum() -> boolean().
should_use_checksum() ->
case application:get_env(rabbit, definitions) of
undefined -> false;
{ok, none} -> false;
{ok, []} -> false;
{ok, Proplist} ->
pget(use_checksum, Proplist, false)
end.
-spec checksum_algorithm() -> {ok, crypto:sha1() | crypto:sha2()}.
checksum_algorithm() ->
case application:get_env(rabbit, definitions) of
undefined -> undefined;
{ok, none} -> undefined;
{ok, []} -> undefined;
{ok, Proplist} ->
pget(checksum_algorithm, Proplist, sha256)
end.
-spec apply_defs(Map :: #{atom() => any()}, ActingUser :: rabbit_types:username()) -> 'ok' | {error, term()}.
apply_defs(Map, ActingUser) ->