Skip to content

Commit

Permalink
Require --force to enable experimental FF
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuratczyk committed Aug 14, 2024
1 parent 6e83500 commit a8da7bc
Showing 1 changed file with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
defmodule RabbitMQ.CLI.Ctl.Commands.EnableFeatureFlagCommand do
@behaviour RabbitMQ.CLI.CommandBehaviour

def merge_defaults(args, opts), do: {args, opts}
def switches(), do: [force: :boolean]
def aliases(), do: [f: :force]

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

def validate([""], _),
def validate([], _opts), do: {:validation_failure, :not_enough_args}
def validate([_ | _] = args, _opts) when length(args) > 1, do: {:validation_failure, :too_many_args}

def validate([""], _opts),
do: {:validation_failure, {:bad_argument, "feature_flag cannot be an empty string."}}

def validate([_], _), do: :ok
def validate([_], _opts), do: :ok

use RabbitMQ.CLI.Core.RequiresRabbitAppRunning

Expand All @@ -29,32 +32,43 @@ defmodule RabbitMQ.CLI.Ctl.Commands.EnableFeatureFlagCommand do
end
end

def run([feature_flag], %{node: node_name}) do
case :rabbit_misc.rpc_call(node_name, :rabbit_feature_flags, :enable, [
String.to_atom(feature_flag)
]) do
# Server does not support feature flags, consider none are available.
# See rabbitmq/rabbitmq-cli#344 for context. MK.
{:badrpc, {:EXIT, {:undef, _}}} -> {:error, :unsupported}
{:badrpc, _} = err -> err
other -> other
def run([feature_flag], %{node: node_name, force: force}) do
case {force, :rabbit_misc.rpc_call(node_name, :rabbit_feature_flags, :get_stability, [
String.to_atom(feature_flag)
])} do
{false, :experimental} ->
IO.puts("Feature flag #{feature_flag} is experimental and requires --force to enable it.")
_ ->
case :rabbit_misc.rpc_call(node_name, :rabbit_feature_flags, :enable, [
String.to_atom(feature_flag)
]) do
# Server does not support feature flags, consider none are available.
# See rabbitmq/rabbitmq-cli#344 for context. MK.
{:badrpc, {:EXIT, {:undef, _}}} -> {:error, :unsupported}
{:badrpc, _} = err -> err
other -> other
end
end
end

def output({:error, :unsupported}, %{node: node_name}) do
{:error, RabbitMQ.CLI.Core.ExitCodes.exit_usage(),
"This feature flag is not supported by node #{node_name}"}
"This feature flag is not supported by node #{node_name}"}
end

use RabbitMQ.CLI.DefaultOutput

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

def usage_additional() do
[
[
"<feature_flag>",
"name of the feature flag to enable, or \"all\" to enable all supported flags"
],
[
"--force",
"required to enable experimental feature flags (make sure you understand the risks!))"
]
]
end
Expand Down

0 comments on commit a8da7bc

Please sign in to comment.