summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <klishinm@vmware.com>2022-08-01 19:04:10 +0400
committerMichael Klishin <klishinm@vmware.com>2022-08-01 19:04:10 +0400
commit83676fa74b9cee6550956e2d25bf907d0f200110 (patch)
treed693b717a332d526c80ce899e6f69029b8b2bbfc
parent2c4c51d62dbdcca3c6a0ea5034458c190e31fbfb (diff)
downloadrabbitmq-server-git-83676fa74b9cee6550956e2d25bf907d0f200110.tar.gz
Validate the feature flag behind user-provided queue type on the server end
-rw-r--r--deps/rabbit/src/rabbit_queue_type.erl12
-rw-r--r--deps/rabbit/src/rabbit_vhost.erl10
-rw-r--r--deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/add_vhost_command.ex6
3 files changed, 24 insertions, 4 deletions
diff --git a/deps/rabbit/src/rabbit_queue_type.erl b/deps/rabbit/src/rabbit_queue_type.erl
index d3a42c99bb..24189ae308 100644
--- a/deps/rabbit/src/rabbit_queue_type.erl
+++ b/deps/rabbit/src/rabbit_queue_type.erl
@@ -13,6 +13,7 @@
init/0,
close/1,
discover/1,
+ feature_flag_name/1,
default/0,
is_enabled/1,
is_compatible/4,
@@ -223,7 +224,7 @@
-callback notify_decorators(amqqueue:amqqueue()) ->
ok.
-%% TODO: this should be controlled by a registry that is populated on boot
+%% TODO: should this use a registry that's populated on boot?
discover(<<"quorum">>) ->
rabbit_quorum_queue;
discover(<<"classic">>) ->
@@ -231,6 +232,15 @@ discover(<<"classic">>) ->
discover(<<"stream">>) ->
rabbit_stream_queue.
+feature_flag_name(<<"quorum">>) ->
+ quorum_queue;
+feature_flag_name(<<"classic">>) ->
+ undefined;
+feature_flag_name(<<"stream">>) ->
+ stream_queue;
+feature_flag_name(_) ->
+ undefined.
+
default() ->
rabbit_classic_queue.
diff --git a/deps/rabbit/src/rabbit_vhost.erl b/deps/rabbit/src/rabbit_vhost.erl
index 87c7375730..72a067bdae 100644
--- a/deps/rabbit/src/rabbit_vhost.erl
+++ b/deps/rabbit/src/rabbit_vhost.erl
@@ -166,9 +166,17 @@ do_add(Name, Metadata, ActingUser) ->
%% validate default_queue_type
case Metadata of
#{default_queue_type := DQT} ->
+ %% check that the queue type is known
try rabbit_queue_type:discover(DQT) of
_ ->
- ok
+ case rabbit_queue_type:feature_flag_name(DQT) of
+ undefined -> ok;
+ Flag when is_atom(Flag) ->
+ case rabbit_feature_flags:is_enabled(Flag) of
+ true -> ok;
+ false -> throw({error, queue_type_feature_flag_is_not_enabled})
+ end
+ end
catch _:_ ->
throw({error, invalid_queue_type})
end;
diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/add_vhost_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/add_vhost_command.ex
index 7ef7c430d5..da4b06b999 100644
--- a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/add_vhost_command.ex
+++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/add_vhost_command.ex
@@ -5,7 +5,7 @@
## Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved.
defmodule RabbitMQ.CLI.Ctl.Commands.AddVhostCommand do
- alias RabbitMQ.CLI.Core.{DocGuide, ErrorCodes, FeatureFlags, Helpers}
+ alias RabbitMQ.CLI.Core.{DocGuide, ExitCodes, FeatureFlags, Helpers}
@behaviour RabbitMQ.CLI.CommandBehaviour
@@ -44,7 +44,9 @@ defmodule RabbitMQ.CLI.Ctl.Commands.AddVhostCommand do
def run([vhost], %{node: node_name}) do
:rabbit_misc.rpc_call(node_name, :rabbit_vhost, :add, [vhost, Helpers.cli_acting_user()])
end
-
+ def output({:error, :invalid_queue_type}, _opts) do
+ {:error, ExitCodes.exit_usage, "Unsupported default queue type"}
+ end
use RabbitMQ.CLI.DefaultOutput
def usage, do: "add_vhost <vhost> [--description <description> --tags \"<tag1>,<tag2>,<...>\" --default-queue-type <quorum|classic|stream>]"