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.ErlangCookieHashCommand 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
14  def run([], %{node: node_name, timeout: timeout}) do
15    :rabbit_data_coercion.to_binary(
16      :rabbit_misc.rpc_call(node_name, :rabbit_nodes_common, :cookie_hash, [], timeout))
17  end
18
19  def output(result, %{formatter: "json"}) do
20    {:ok, %{"result" => "ok", "value" => result}}
21  end
22  def output(result, _options) when is_bitstring(result) do
23    {:ok, result}
24  end
25
26  def help_section(), do: :configuration
27
28  def description(), do: "Displays a hash of the Erlang cookie (shared secret) used by the target node"
29
30  def usage, do: "erlang_cookie_hash"
31
32  def banner([], %{node: node_name}) do
33    "Asking node #{node_name} its Erlang cookie hash..."
34  end
35end
36