Merge pull request #371 from rabbitmq/vhost-description
Use new 'description' and 'tag' items on list vhosts
This commit is contained in:
commit
32030ed581
|
|
@ -18,21 +18,32 @@ defmodule RabbitMQ.CLI.Ctl.Commands.AddVhostCommand do
|
|||
|
||||
@behaviour RabbitMQ.CLI.CommandBehaviour
|
||||
|
||||
use RabbitMQ.CLI.Core.MergesNoDefaults
|
||||
def switches(), do: [description: :string,
|
||||
tags: :string]
|
||||
def aliases(), do: [d: :description]
|
||||
|
||||
def merge_defaults(args, opts) do
|
||||
{args, Map.merge(%{description: "", tags: ""}, opts)}
|
||||
end
|
||||
use RabbitMQ.CLI.Core.AcceptsOnePositionalArgument
|
||||
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
|
||||
|
||||
def run([vhost], %{node: node_name, description: desc, tags: tags}) do
|
||||
:rabbit_misc.rpc_call(node_name, :rabbit_vhost, :add, [vhost, desc, parse_tags(tags), Helpers.cli_acting_user()])
|
||||
end
|
||||
def run([vhost], %{node: node_name}) do
|
||||
:rabbit_misc.rpc_call(node_name, :rabbit_vhost, :add, [vhost, Helpers.cli_acting_user()])
|
||||
end
|
||||
|
||||
use RabbitMQ.CLI.DefaultOutput
|
||||
|
||||
def usage, do: "add_vhost <vhost>"
|
||||
def usage, do: "add_vhost <vhost> [--description <description> --tags \"<tag1>,<tag2>,<...>\"]"
|
||||
|
||||
def usage_additional() do
|
||||
[
|
||||
["<vhost>", "Virtual host name"]
|
||||
["<vhost>", "Virtual host name"],
|
||||
["--description <description>", "Virtual host description"],
|
||||
["--tags <tags>", "Command separated list of tags"]
|
||||
]
|
||||
end
|
||||
|
||||
|
|
@ -47,4 +58,14 @@ defmodule RabbitMQ.CLI.Ctl.Commands.AddVhostCommand do
|
|||
def description(), do: "Creates a virtual host"
|
||||
|
||||
def banner([vhost], _), do: "Adding vhost \"#{vhost}\" ..."
|
||||
|
||||
#
|
||||
# Implementation
|
||||
#
|
||||
|
||||
def parse_tags(tags) do
|
||||
String.split(tags, ",", trim: true)
|
||||
|> Enum.map(&String.trim/1)
|
||||
|> Enum.map(&String.to_atom/1)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListVhostsCommand do
|
|||
@behaviour RabbitMQ.CLI.CommandBehaviour
|
||||
use RabbitMQ.CLI.DefaultOutput
|
||||
|
||||
@info_keys ~w(name tracing cluster_state)a
|
||||
@info_keys ~w(name description tags tracing cluster_state)a
|
||||
|
||||
def info_keys(), do: @info_keys
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ReportCommand do
|
|||
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
|
||||
|
||||
def run([], %{node: node_name} = opts) do
|
||||
case :rabbit_misc.rpc_call(node_name, :rabbit_vhost, :list, []) do
|
||||
case :rabbit_misc.rpc_call(node_name, :rabbit_vhost, :list_names, []) do
|
||||
{:badrpc, _} = err ->
|
||||
err
|
||||
|
||||
|
|
|
|||
|
|
@ -31,11 +31,20 @@ defmodule AddVhostCommandTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
test "validate: wrong number of arguments results in arg count errors" do
|
||||
test "validate: no arguments fails validation" do
|
||||
assert @command.validate([], %{}) == {:validation_failure, :not_enough_args}
|
||||
end
|
||||
|
||||
test "validate: too many arguments fails validation" do
|
||||
assert @command.validate(["test", "extra"], %{}) == {:validation_failure, :too_many_args}
|
||||
end
|
||||
|
||||
test "validate: one argument passes validation" do
|
||||
assert @command.validate(["new-vhost"], %{}) == :ok
|
||||
assert @command.validate(["new-vhost"], %{description: "Used by team A"}) == :ok
|
||||
assert @command.validate(["new-vhost"], %{description: "Used by team A for QA purposes", tags: "qa,team-a"}) == :ok
|
||||
end
|
||||
|
||||
@tag vhost: @vhost
|
||||
test "run: passing a valid vhost name to a running RabbitMQ node succeeds", context do
|
||||
assert @command.run([context[:vhost]], context[:opts]) == :ok
|
||||
|
|
|
|||
Loading…
Reference in New Issue