Skip to content

Commit 6fae57e

Browse files
mkuratczykmergify[bot]
authored andcommitted
Require --force to enable experimental FF
(cherry picked from commit 58e0c16)
1 parent 39f28b6 commit 6fae57e

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/enable_feature_flag_command.ex

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77
defmodule RabbitMQ.CLI.Ctl.Commands.EnableFeatureFlagCommand do
88
@behaviour RabbitMQ.CLI.CommandBehaviour
99

10-
def merge_defaults(args, opts), do: {args, opts}
10+
def switches(), do: [force: :boolean]
11+
def aliases(), do: [f: :force]
1112

12-
def validate([], _), do: {:validation_failure, :not_enough_args}
13-
def validate([_ | _] = args, _) when length(args) > 1, do: {:validation_failure, :too_many_args}
13+
def merge_defaults(args, opts), do: { args, Map.merge(%{force: false}, opts) }
1414

15-
def validate([""], _),
15+
def validate([], _opts), do: {:validation_failure, :not_enough_args}
16+
def validate([_ | _] = args, _opts) when length(args) > 1, do: {:validation_failure, :too_many_args}
17+
18+
def validate([""], _opts),
1619
do: {:validation_failure, {:bad_argument, "feature_flag cannot be an empty string."}}
1720

18-
def validate([_], _), do: :ok
21+
def validate([_], _opts), do: :ok
1922

2023
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
2124

@@ -29,32 +32,45 @@ defmodule RabbitMQ.CLI.Ctl.Commands.EnableFeatureFlagCommand do
2932
end
3033
end
3134

32-
def run([feature_flag], %{node: node_name}) do
33-
case :rabbit_misc.rpc_call(node_name, :rabbit_feature_flags, :enable, [
34-
String.to_atom(feature_flag)
35-
]) do
36-
# Server does not support feature flags, consider none are available.
37-
# See rabbitmq/rabbitmq-cli#344 for context. MK.
38-
{:badrpc, {:EXIT, {:undef, _}}} -> {:error, :unsupported}
39-
{:badrpc, _} = err -> err
40-
other -> other
35+
def run([feature_flag], %{node: node_name, force: force}) do
36+
case {force, :rabbit_misc.rpc_call(node_name, :rabbit_feature_flags, :get_stability, [
37+
String.to_atom(feature_flag)
38+
])} do
39+
{_, {:badrpc, {:EXIT, {:undef, _}}}} -> {:error, :unsupported}
40+
{_, {:badrpc, _} = err} -> err
41+
{false, :experimental} ->
42+
IO.puts("Feature flag #{feature_flag} is experimental and requires --force to enable it.")
43+
_ ->
44+
case :rabbit_misc.rpc_call(node_name, :rabbit_feature_flags, :enable, [
45+
String.to_atom(feature_flag)
46+
]) do
47+
# Server does not support feature flags, consider none are available.
48+
# See rabbitmq/rabbitmq-cli#344 for context. MK.
49+
{:badrpc, {:EXIT, {:undef, _}}} -> {:error, :unsupported}
50+
{:badrpc, _} = err -> err
51+
other -> other
52+
end
4153
end
4254
end
4355

4456
def output({:error, :unsupported}, %{node: node_name}) do
4557
{:error, RabbitMQ.CLI.Core.ExitCodes.exit_usage(),
46-
"This feature flag is not supported by node #{node_name}"}
58+
"This feature flag is not supported by node #{node_name}"}
4759
end
4860

4961
use RabbitMQ.CLI.DefaultOutput
5062

51-
def usage, do: "enable_feature_flag <all | feature_flag>"
63+
def usage, do: "enable_feature_flag [--force] <all | feature_flag>"
5264

5365
def usage_additional() do
5466
[
5567
[
5668
"<feature_flag>",
5769
"name of the feature flag to enable, or \"all\" to enable all supported flags"
70+
],
71+
[
72+
"--force",
73+
"required to enable experimental feature flags (make sure you understand the risks!))"
5874
]
5975
]
6076
end

deps/rabbitmq_cli/test/ctl/enable_feature_flag_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule EnableFeatureFlagCommandTest do
3535

3636
{
3737
:ok,
38-
opts: %{node: get_rabbit_hostname()}, feature_flag: @feature_flag
38+
opts: %{node: get_rabbit_hostname(), force: false}, feature_flag: @feature_flag
3939
}
4040
end
4141

@@ -59,7 +59,7 @@ defmodule EnableFeatureFlagCommandTest do
5959
end
6060

6161
test "run: attempt to use an unreachable node returns a nodedown" do
62-
opts = %{node: :jake@thedog, timeout: 200}
62+
opts = %{node: :jake@thedog, timeout: 200, force: false}
6363
assert match?({:badrpc, _}, @command.run(["na"], opts))
6464
end
6565

0 commit comments

Comments
 (0)