rabbitmq-server/deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/plugins.ex

251 lines
6.2 KiB
Elixir
Raw Normal View History

2016-10-26 23:25:39 +08:00
## The contents of this file are subject to the Mozilla Public License
## Version 1.1 (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License
URL Cleanup This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener). # HTTP URLs that Could Not Be Fixed These URLs were unable to be fixed. Please review them to see if they can be manually resolved. * http://blog.listincomprehension.com/search/label/procket (200) with 1 occurrences could not be migrated: ([https](https://blog.listincomprehension.com/search/label/procket) result ClosedChannelException). * http://dozzie.jarowit.net/trac/wiki/TOML (200) with 1 occurrences could not be migrated: ([https](https://dozzie.jarowit.net/trac/wiki/TOML) result SSLHandshakeException). * http://dozzie.jarowit.net/trac/wiki/subproc (200) with 1 occurrences could not be migrated: ([https](https://dozzie.jarowit.net/trac/wiki/subproc) result SSLHandshakeException). * http://e2project.org (200) with 1 occurrences could not be migrated: ([https](https://e2project.org) result AnnotatedConnectException). * http://erlang.org/doc/reference_manual/distributed.html (200) with 1 occurrences could not be migrated: ([https](https://erlang.org/doc/reference_manual/distributed.html) result ConnectTimeoutException). * http://nitrogenproject.com/ (200) with 2 occurrences could not be migrated: ([https](https://nitrogenproject.com/) result ConnectTimeoutException). * http://proper.softlab.ntua.gr (200) with 1 occurrences could not be migrated: ([https](https://proper.softlab.ntua.gr) result SSLHandshakeException). * http://yaws.hyber.org (200) with 1 occurrences could not be migrated: ([https](https://yaws.hyber.org) result AnnotatedConnectException). * http://choven.ca (503) with 1 occurrences could not be migrated: ([https](https://choven.ca) result ConnectTimeoutException). # Fixed URLs ## Fixed But Review Recommended These URLs were fixed, but the https status was not OK. However, the https status was the same as the http request or http redirected to an https URL, so they were migrated. Your review is recommended. * http://fixprotocol.org/ (301) with 1 occurrences migrated to: https://fixtrading.org ([https](https://fixprotocol.org/) result SSLHandshakeException). * http://erldb.org (UnknownHostException) with 1 occurrences migrated to: https://erldb.org ([https](https://erldb.org) result UnknownHostException). * http://elixir-lang.org/docs/stable/elixir/OptionParser.html (301) with 1 occurrences migrated to: https://elixir-lang.org/docs/stable/elixir/OptionParser.html ([https](https://elixir-lang.org/docs/stable/elixir/OptionParser.html) result 404). * http://elixir-lang.org/docs/stable/elixir/Stream.html (301) with 1 occurrences migrated to: https://elixir-lang.org/docs/stable/elixir/Stream.html ([https](https://elixir-lang.org/docs/stable/elixir/Stream.html) result 404). ## Fixed Success These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended. * http://cloudi.org/ with 27 occurrences migrated to: https://cloudi.org/ ([https](https://cloudi.org/) result 200). * http://elixir-lang.org with 1 occurrences migrated to: https://elixir-lang.org ([https](https://elixir-lang.org) result 200). * http://elixir-lang.org/ with 2 occurrences migrated to: https://elixir-lang.org/ ([https](https://elixir-lang.org/) result 200). * http://elixir-lang.org/getting-started/typespecs-and-behaviours.html with 1 occurrences migrated to: https://elixir-lang.org/getting-started/typespecs-and-behaviours.html ([https](https://elixir-lang.org/getting-started/typespecs-and-behaviours.html) result 200). * http://elixir-lang.org/install.html with 1 occurrences migrated to: https://elixir-lang.org/install.html ([https](https://elixir-lang.org/install.html) result 200). * http://erlware.org/ with 1 occurrences migrated to: https://erlware.org/ ([https](https://erlware.org/) result 200). * http://inaka.github.io/cowboy-trails/ with 1 occurrences migrated to: https://inaka.github.io/cowboy-trails/ ([https](https://inaka.github.io/cowboy-trails/) result 200). * http://ninenines.eu with 6 occurrences migrated to: https://ninenines.eu ([https](https://ninenines.eu) result 200). * http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html with 1 occurrences migrated to: https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html ([https](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) result 200). * http://www.actordb.com/ with 2 occurrences migrated to: https://www.actordb.com/ ([https](https://www.actordb.com/) result 200). * http://www.cs.kent.ac.uk/projects/wrangler/Home.html with 1 occurrences migrated to: https://www.cs.kent.ac.uk/projects/wrangler/Home.html ([https](https://www.cs.kent.ac.uk/projects/wrangler/Home.html) result 200). * http://www.rebar3.org with 1 occurrences migrated to: https://www.rebar3.org ([https](https://www.rebar3.org) result 200). * http://contributor-covenant.org with 1 occurrences migrated to: https://contributor-covenant.org ([https](https://contributor-covenant.org) result 301). * http://contributor-covenant.org/version/1/3/0/ with 1 occurrences migrated to: https://contributor-covenant.org/version/1/3/0/ ([https](https://contributor-covenant.org/version/1/3/0/) result 301). * http://inaka.github.com/apns4erl with 1 occurrences migrated to: https://inaka.github.com/apns4erl ([https](https://inaka.github.com/apns4erl) result 301). * http://inaka.github.com/edis/ with 1 occurrences migrated to: https://inaka.github.com/edis/ ([https](https://inaka.github.com/edis/) result 301). * http://lasp-lang.org/ with 1 occurrences migrated to: https://lasp-lang.org/ ([https](https://lasp-lang.org/) result 301). * http://rabbitmq.com/documentation.html with 1 occurrences migrated to: https://rabbitmq.com/documentation.html ([https](https://rabbitmq.com/documentation.html) result 301). * http://saleyn.github.com/erlexec with 1 occurrences migrated to: https://saleyn.github.com/erlexec ([https](https://saleyn.github.com/erlexec) result 301). * http://www.mozilla.org/MPL/ with 290 occurrences migrated to: https://www.mozilla.org/MPL/ ([https](https://www.mozilla.org/MPL/) result 301). * http://zhongwencool.github.io/observer_cli with 1 occurrences migrated to: https://zhongwencool.github.io/observer_cli ([https](https://zhongwencool.github.io/observer_cli) result 301).
2019-03-20 16:13:07 +08:00
## at https://www.mozilla.org/MPL/
2016-10-26 23:25:39 +08:00
##
## Software distributed under the License is distributed on an "AS IS"
## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
## the License for the specific language governing rights and
## limitations under the License.
##
## The Original Code is RabbitMQ.
##
## The Initial Developer of the Original Code is GoPivotal, Inc.
2019-01-20 11:10:59 +08:00
## Copyright (c) 2007-2019 Pivotal Software, Inc. All rights reserved.
2018-07-23 13:06:18 +08:00
alias RabbitMQ.CLI.Formatters.FormatterHelpers
2016-10-26 23:25:39 +08:00
defmodule RabbitMQ.CLI.Formatters.Plugins do
2016-11-15 01:52:08 +08:00
@behaviour RabbitMQ.CLI.FormatterBehaviour
2016-10-26 23:25:39 +08:00
2019-01-31 03:20:29 +08:00
def format_output(
%{status: status, format: format, plugins: plugins},
options
) do
2016-10-26 23:25:39 +08:00
legend(status, format, options) ++ format_plugins(plugins, format)
end
2019-01-31 03:20:29 +08:00
def format_output(%{enabled: enabled, mode: _} = output, options) do
case length(enabled) do
2019-01-31 03:20:29 +08:00
0 ->
["Plugin configuration unchanged."]
_ ->
[
"The following plugins have been enabled:"
| for plugin <- enabled do
" #{plugin}"
end
] ++
[""] ++
applying(output, options) ++
log_offline(output)
end
end
2019-01-31 03:20:29 +08:00
def format_output(%{disabled: disabled, mode: _} = output, options) do
case length(disabled) do
2019-01-31 03:20:29 +08:00
0 ->
["Plugin configuration unchanged."]
_ ->
[
"The following plugins have been disabled:"
| for plugin <- disabled do
" #{plugin}"
end
] ++
[""] ++
applying(output, options) ++
log_offline(output)
end
end
2019-01-31 03:20:29 +08:00
2016-12-07 00:18:54 +08:00
## Do not print enabled/disabled for set command
def format_output(%{} = output, options) do
applying(output, options)
end
2019-01-31 03:20:29 +08:00
def format_output([], %{node: node}) do
2019-01-31 03:20:29 +08:00
["All plugins have been disabled.", "Applying plugin configuration to #{node}..."]
end
2019-01-31 03:20:29 +08:00
def format_output(plugins, %{node: node}) when is_list(plugins) do
2019-01-31 03:20:29 +08:00
[
"The following plugins have been configured:"
| for plugin <- plugins do
" #{plugin}"
end
] ++
["Applying plugin configuration to #{node}..."]
end
2019-01-31 03:20:29 +08:00
def format_output(output, _) do
:io_lib.format("~p", [output])
|> to_string
end
2016-10-26 23:25:39 +08:00
def format_stream(stream, options) do
2019-01-31 03:20:29 +08:00
Stream.map(
stream,
FormatterHelpers.without_errors_1(fn element ->
format_output(element, options)
end)
)
2016-10-26 23:25:39 +08:00
end
defp format_plugins(plugins, format) do
2019-01-31 03:20:29 +08:00
max_name_length =
Enum.reduce(plugins, 0, fn %{name: name}, len ->
max(String.length(to_string(name)), len)
end)
2016-10-26 23:25:39 +08:00
for plugin <- plugins do
format_plugin(plugin, format, max_name_length)
end
2019-01-31 03:20:29 +08:00
|> List.flatten()
2016-10-26 23:25:39 +08:00
end
defp format_plugin(%{name: name}, :minimal, _) do
to_string(name)
end
2019-01-31 03:20:29 +08:00
2016-10-26 23:25:39 +08:00
defp format_plugin(plugin, :normal, max_name_length) do
[summary(plugin) <> inline_version(plugin, max_name_length)]
end
2019-01-31 03:20:29 +08:00
2016-10-26 23:25:39 +08:00
defp format_plugin(plugin, :verbose, _) do
[summary(plugin) | verbose(plugin)]
end
defp summary(%{name: name, enabled: enabled, running: running}) do
2019-01-31 03:20:29 +08:00
enabled_sign =
case enabled do
:implicit -> "e"
:enabled -> "E"
:not_enabled -> " "
end
running_sign =
case running do
true -> "*"
false -> " "
end
2016-10-26 23:25:39 +08:00
"[#{enabled_sign}#{running_sign}] #{name}"
end
2016-12-01 00:19:13 +08:00
defp inline_version(%{name: name} = plugin, max_name_length) do
2019-01-31 03:20:29 +08:00
spacing =
String.duplicate(
" ",
max_name_length -
String.length(to_string(name))
)
spacing <> " " <> augment_version(plugin)
2016-10-26 23:25:39 +08:00
end
2019-01-31 03:20:29 +08:00
defp verbose(%{dependencies: dependencies, description: description} = plugin) do
2016-10-26 23:25:39 +08:00
prettified = to_string(:io_lib.format("~p", [dependencies]))
2019-01-31 03:20:29 +08:00
2016-10-26 23:25:39 +08:00
[
" Version: \t#{augment_version(plugin)}",
2016-10-26 23:25:39 +08:00
" Dependencies:\t#{prettified}",
" Description: \t#{description}"
]
end
2019-01-31 03:20:29 +08:00
defp augment_version(%{version: version, running_version: nil}) do
to_string(version)
end
defp augment_version(%{version: version, running_version: version}) do
to_string(version)
end
defp augment_version(%{version: version, running_version: running_version}) do
"#{running_version} (pending upgrade to #{version})"
end
2016-10-26 23:25:39 +08:00
## Do not print legend in minimal mode
defp legend(_, :minimal, _) do
[]
end
2019-01-31 03:20:29 +08:00
2016-10-26 23:25:39 +08:00
defp legend(status, _, %{node: node}) do
2019-01-31 03:20:29 +08:00
[
" Configured: E = explicitly enabled; e = implicitly enabled",
" | Status: #{status_message(status, node)}",
" |/"
]
2016-10-26 23:25:39 +08:00
end
defp status_message(:running, node) do
"* = running on #{node}"
end
2019-01-31 03:20:29 +08:00
2016-10-26 23:25:39 +08:00
defp status_message(:node_down, node) do
"[failed to contact #{node} - status not shown]"
end
defp applying(%{mode: :offline, set: set_plugins}, _) do
2019-01-31 03:20:29 +08:00
set_plugins_message =
case length(set_plugins) do
0 -> "nothing to do"
len -> "set #{len} plugins"
end
[set_plugins_message <> "."]
end
2019-01-31 03:20:29 +08:00
defp applying(%{mode: :offline, enabled: enabled}, _) do
2019-01-31 03:20:29 +08:00
enabled_message =
case length(enabled) do
0 -> "nothing to do"
len -> "enabled #{len} plugins"
end
[enabled_message <> "."]
end
2019-01-31 03:20:29 +08:00
defp applying(%{mode: :offline, disabled: disabled}, _) do
2019-01-31 03:20:29 +08:00
disabled_message =
case length(disabled) do
0 -> "nothing to do"
len -> "disabled #{len} plugins"
end
[disabled_message <> "."]
end
2019-01-31 03:20:29 +08:00
defp applying(%{mode: :online, started: started, stopped: stopped}, _) do
2019-01-31 03:20:29 +08:00
stopped_message =
case length(stopped) do
0 -> []
len -> ["stopped #{len} plugins"]
end
started_message =
case length(started) do
0 -> []
len -> ["started #{len} plugins"]
end
change_message =
case Enum.join(started_message ++ stopped_message, " and ") do
"" -> "nothing to do"
msg -> msg
end
2016-12-07 00:18:54 +08:00
[change_message <> "."]
end
defp log_offline(%{mode: :offline}) do
["Offline change; changes will take effect at broker restart."]
end
2019-01-31 03:20:29 +08:00
defp log_offline(_) do
[]
end
2016-10-29 00:14:34 +08:00
end