1## This Source Code Form is subject to the terms of the Mozilla Public
2## License, v. 2.0. If a copy of the MPL was not distributed with this
3## file, You can obtain one at https://mozilla.org/MPL/2.0/.
4##
5## Copyright (c) 2007-2021 VMware, Inc. or its affiliates.  All rights reserved.
6
7defmodule RabbitMQ.CLI.Diagnostics.Commands.TlsVersionsCommand do
8  @behaviour RabbitMQ.CLI.CommandBehaviour
9
10  use RabbitMQ.CLI.Core.AcceptsDefaultSwitchesAndTimeout
11  use RabbitMQ.CLI.Core.MergesNoDefaults
12  use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments
13  use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
14
15  def run([], %{node: node_name, timeout: timeout} = _opts) do
16    :rabbit_misc.rpc_call(node_name, :ssl, :versions, [], timeout)
17  end
18
19  def banner([], %{}), do: "Listing all TLS versions supported by the runtime..."
20
21  def output(result, %{formatter: "json"}) do
22    vs = Map.new(result) |> Map.get(:available)
23
24    {:ok, %{versions: vs}}
25  end
26
27  def output(result, _opts) do
28    vs = Map.new(result) |> Map.get(:available)
29    {:ok, vs}
30  end
31
32  def help_section(), do: :observability_and_health_checks
33
34  def description(), do: "Lists TLS versions supported (but not necessarily allowed) on the target node"
35
36  def usage, do: "tls_versions"
37
38  def formatter(), do: RabbitMQ.CLI.Formatters.StringPerLine
39end
40