diff --git a/BUILD.bazel b/BUILD.bazel index bceab3998862..ff37ed991543 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -53,6 +53,7 @@ exports_files([ # gazelle:exclude deps/gun # gazelle:exclude deps/inet_tcp_proxy # gazelle:exclude deps/jose +# gazelle:exclude deps/json # gazelle:exclude deps/meck # gazelle:exclude deps/observer_cli # gazelle:exclude deps/osiris diff --git a/MODULE.bazel b/MODULE.bazel index ba4f6f06f9d7..34cb6a19d229 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -267,6 +267,13 @@ erlang_package.git_package( repository = "michaelklishin/erlang-jose", ) +erlang_package.hex_package( + name = "json", + build_file = "@rabbitmq-server//bazel:BUILD.json", + sha256 = "9abf218dbe4ea4fcb875e087d5f904ef263d012ee5ed21d46e9dbca63f053d16", + version = "1.4.1", +) + erlang_package.hex_package( name = "thoas", build_file = "@rabbitmq-server//bazel:BUILD.thoas", @@ -361,6 +368,7 @@ use_repo( "getopt", "gun", "jose", + "json", "observer_cli", "prometheus", "ranch", diff --git a/Makefile b/Makefile index e334d6aaad3b..292b822429bd 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,8 @@ XREF_EXTRA_APP_DIRS = $(filter-out deps/rabbitmq_cli/_build/dev/lib/rabbit_commo # protocols directly. XREF_IGNORE = [ \ {'Elixir.CSV.Encode',impl_for,1}, \ + {'Elixir.JSON.Decoder',impl_for,1}, \ + {'Elixir.JSON.Encoder',impl_for,1}, \ {'Elixir.RabbitMQ.CLI.Core.DataCoercion',impl_for,1}] # Include Elixir libraries in the Xref checks. diff --git a/deps/rabbitmq_cli/BUILD.bazel b/deps/rabbitmq_cli/BUILD.bazel index d4c0f504ab8a..35931ebe5f54 100644 --- a/deps/rabbitmq_cli/BUILD.bazel +++ b/deps/rabbitmq_cli/BUILD.bazel @@ -17,6 +17,13 @@ mix_archive_build( archives = ["@hex//:archive"], ) +mix_archive_build( + name = "json_ez", + srcs = ["@json//:sources"], + out = "json.ez", + archives = ["@hex//:archive"], +) + # Note: All the various rabbitmq-* scripts are just copies of rabbitmqctl rabbitmqctl( name = "rabbitmqctl", @@ -32,6 +39,7 @@ rabbitmqctl( license_files = glob(["LICENSE*"]), source_deps = { "@csv//:sources": "csv", + "@json//:sources": "json", }, visibility = ["//visibility:public"], deps = [ @@ -101,6 +109,7 @@ plt( ], ez_deps = [ ":csv_ez", + ":json_ez", ], ignore_warnings = True, libs = [":elixir"], @@ -142,6 +151,7 @@ rabbitmqctl_test( source_deps = { "@amqp//:sources": "amqp", "@csv//:sources": "csv", + "@json//:sources": "json", "@temp//:sources": "temp", "@x509//:sources": "x509", }, diff --git a/deps/rabbitmq_cli/Makefile b/deps/rabbitmq_cli/Makefile index 8352583bb38f..a4c62349f25f 100644 --- a/deps/rabbitmq_cli/Makefile +++ b/deps/rabbitmq_cli/Makefile @@ -1,11 +1,12 @@ PROJECT = rabbitmq_cli BUILD_DEPS = rabbit_common -DEPS = csv observer_cli stdout_formatter +DEPS = csv json observer_cli stdout_formatter TEST_DEPS = amqp amqp_client temp x509 rabbit dep_amqp = hex 3.3.0 dep_csv = hex 3.2.0 +dep_json = hex 1.4.1 dep_temp = hex 0.4.7 dep_x509 = hex 0.8.8 diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/export_definitions_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/export_definitions_command.ex index a16f42fde4d9..c009c79d187e 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/export_definitions_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/export_definitions_command.ex @@ -159,7 +159,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ExportDefinitionsCommand do end) end) - {:ok, json} = :rabbit_json.try_encode(map) + {:ok, json} = JSON.encode(map) json end diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/import_definitions_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/import_definitions_command.ex index 233c8660be8d..665b821fcc01 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/import_definitions_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/import_definitions_command.ex @@ -166,7 +166,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ImportDefinitionsCommand do # defp deserialise(bin, "json") do - :rabbit_json.try_decode(bin) + JSON.decode(bin) end defp deserialise(bin, "erlang") do diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/list_user_limits_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/list_user_limits_command.ex index 97241303c784..1e01a13f644b 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/list_user_limits_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/list_user_limits_command.ex @@ -36,7 +36,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListUserLimitsCommand do val -> Enum.map(val, fn {user, val} -> - {:ok, val_encoded} = :rabbit_json.try_encode(Map.new(val)) + {:ok, val_encoded} = JSON.encode(Map.new(val)) [user: user, limits: val_encoded] end) end @@ -56,7 +56,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListUserLimitsCommand do {:badrpc, node} val when is_list(val) or is_map(val) -> - {:ok, val_encoded} = :rabbit_json.try_encode(Map.new(val)) + {:ok, val_encoded} = JSON.encode(Map.new(val)) val_encoded end end diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/list_vhost_limits_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/list_vhost_limits_command.ex index 6f5e4063f3d4..973452816bac 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/list_vhost_limits_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/list_vhost_limits_command.ex @@ -36,7 +36,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListVhostLimitsCommand do val -> Enum.map(val, fn {vhost, val} -> - {:ok, val_encoded} = :rabbit_json.try_encode(Map.new(val)) + {:ok, val_encoded} = JSON.encode(Map.new(val)) [vhost: vhost, limits: val_encoded] end) end @@ -54,7 +54,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListVhostLimitsCommand do {:badrpc, node} val when is_list(val) or is_map(val) -> - :rabbit_json.try_encode(Map.new(val)) + JSON.encode(Map.new(val)) end end diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/json.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/json.ex index 246140ead00c..ad46b1be9bf3 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/json.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/json.ex @@ -18,7 +18,7 @@ defmodule RabbitMQ.CLI.Formatters.Json do end def format_output(output, _opts) do - {:ok, json} = :rabbit_json.try_encode(keys_to_atoms(output)) + {:ok, json} = JSON.encode(keys_to_atoms(output)) json end diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/json_stream.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/json_stream.ex index 23d7be95ecf4..7f29998a8631 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/json_stream.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/json_stream.ex @@ -31,7 +31,7 @@ defmodule RabbitMQ.CLI.Formatters.JsonStream do end def format_output(output, _opts) do - {:ok, json} = :rabbit_json.try_encode(output) + {:ok, json} = JSON.encode(keys_to_atoms(output)) json end diff --git a/deps/rabbitmq_cli/lib/rabbitmqctl.ex b/deps/rabbitmq_cli/lib/rabbitmqctl.ex index a25a65585ccf..fc9fd2321f39 100644 --- a/deps/rabbitmq_cli/lib/rabbitmqctl.ex +++ b/deps/rabbitmq_cli/lib/rabbitmqctl.ex @@ -558,7 +558,7 @@ defmodule RabbitMQCtl do end defp format_error({:error, :check_failed, err}, %{formatter: "json"}, _) when is_map(err) do - {:ok, res} = :rabbit_json.try_encode(err) + {:ok, res} = JSON.encode(err) {:error, ExitCodes.exit_unavailable(), res} end @@ -578,12 +578,12 @@ defmodule RabbitMQCtl do # Catch all clauses defp format_error({:error, err}, %{formatter: "json"}, _) when is_map(err) do - {:ok, res} = :rabbit_json.try_encode(err) + {:ok, res} = JSON.encode(err) {:error, ExitCodes.exit_unavailable(), res} end defp format_error({:error, exit_code, err}, %{formatter: "json"}, _) when is_map(err) do - {:ok, res} = :rabbit_json.try_encode(err) + {:ok, res} = JSON.encode(err) {:error, exit_code, res} end diff --git a/deps/rabbitmq_cli/mix.exs b/deps/rabbitmq_cli/mix.exs index 2e32e32c92c2..409aa5fcab33 100644 --- a/deps/rabbitmq_cli/mix.exs +++ b/deps/rabbitmq_cli/mix.exs @@ -22,6 +22,7 @@ defmodule RabbitMQCtl.MixfileBase do exclude: [ CSV, CSV.Encode, + JSON, :mnesia, :msacc, :observer_cli, @@ -140,6 +141,10 @@ defmodule RabbitMQCtl.MixfileBase do is_bazel = System.get_env("IS_BAZEL") != nil [ + { + :json, + path: Path.join(deps_dir, "json") + }, { :csv, path: Path.join(deps_dir, "csv") diff --git a/deps/rabbitmq_cli/test/ctl/export_definitions_command_test.exs b/deps/rabbitmq_cli/test/ctl/export_definitions_command_test.exs index a429e43b9e15..d1be4f6897ad 100644 --- a/deps/rabbitmq_cli/test/ctl/export_definitions_command_test.exs +++ b/deps/rabbitmq_cli/test/ctl/export_definitions_command_test.exs @@ -111,7 +111,7 @@ defmodule ExportDefinitionsCommandTest do {:ok, nil} = @command.run([valid_file_path()], context[:opts]) {:ok, bin} = File.read(valid_file_path()) - {:ok, map} = :rabbit_json.try_decode(bin) + {:ok, map} = JSON.decode(bin) assert Map.has_key?(map, "rabbitmq_version") end @@ -128,7 +128,7 @@ defmodule ExportDefinitionsCommandTest do clear_parameter("/", "federation-upstream", "up-1") {:ok, bin} = File.read(valid_file_path()) - {:ok, map} = :rabbit_json.try_decode(bin) + {:ok, map} = JSON.decode(bin) assert Map.has_key?(map, "rabbitmq_version") params = map["parameters"] assert is_map(hd(params)["value"]) diff --git a/deps/rabbitmq_cli/test/ctl/set_user_limits_command_test.exs b/deps/rabbitmq_cli/test/ctl/set_user_limits_command_test.exs index b57a649923c9..bb9da3588dc4 100644 --- a/deps/rabbitmq_cli/test/ctl/set_user_limits_command_test.exs +++ b/deps/rabbitmq_cli/test/ctl/set_user_limits_command_test.exs @@ -131,6 +131,6 @@ defmodule SetUserLimitsCommandTest do defp assert_limits(context, definition) do limits = get_user_limits(context[:user]) - assert {:ok, limits} == :rabbit_json.try_decode(definition) + assert {:ok, limits} == JSON.decode(definition) end end diff --git a/deps/rabbitmq_cli/test/ctl/set_vhost_limits_command_test.exs b/deps/rabbitmq_cli/test/ctl/set_vhost_limits_command_test.exs index f591b1443b32..6a1bec75aac7 100644 --- a/deps/rabbitmq_cli/test/ctl/set_vhost_limits_command_test.exs +++ b/deps/rabbitmq_cli/test/ctl/set_vhost_limits_command_test.exs @@ -138,6 +138,6 @@ defmodule SetVhostLimitsCommandTest do defp assert_limits(context) do limits = get_vhost_limits(context[:vhost]) - assert {:ok, limits} == :rabbit_json.try_decode(context[:definition]) + assert {:ok, limits} == JSON.decode(context[:definition]) end end diff --git a/deps/rabbitmq_cli/test/json_formatting.exs b/deps/rabbitmq_cli/test/json_formatting.exs index c27826b59e59..70cb6a5a04b9 100644 --- a/deps/rabbitmq_cli/test/json_formatting.exs +++ b/deps/rabbitmq_cli/test/json_formatting.exs @@ -29,7 +29,7 @@ defmodule JSONFormattingTest do error_check(command, exit_ok()) end) - {:ok, doc} = :rabbit_json.try_decode(output) + {:ok, doc} = JSON.decode(output) assert Map.has_key?(doc, "memory") assert Map.has_key?(doc, "file_descriptors") @@ -53,7 +53,7 @@ defmodule JSONFormattingTest do error_check(command, exit_ok()) end) - {:ok, doc} = :rabbit_json.try_decode(output) + {:ok, doc} = JSON.decode(output) assert Enum.member?(doc["disk_nodes"], node) assert Map.has_key?(doc["listeners"], node) diff --git a/deps/rabbitmq_cli/test/test_helper.exs b/deps/rabbitmq_cli/test/test_helper.exs index 9c7a544bc1aa..d36e70f654bc 100644 --- a/deps/rabbitmq_cli/test/test_helper.exs +++ b/deps/rabbitmq_cli/test/test_helper.exs @@ -19,6 +19,7 @@ true = Code.append_path(Path.join([System.get_env("DEPS_DIR"), "rabbit_common", true = Code.append_path(Path.join([System.get_env("DEPS_DIR"), "rabbit", "ebin"])) true = Code.append_path(Path.join(["_build", Atom.to_string(Mix.env()), "lib", "amqp", "ebin"])) +true = Code.append_path(Path.join(["_build", Atom.to_string(Mix.env()), "lib", "json", "ebin"])) true = Code.append_path(Path.join(["_build", Atom.to_string(Mix.env()), "lib", "x509", "ebin"])) if function_exported?(Mix, :ensure_application!, 1) do diff --git a/dist.bzl b/dist.bzl index dfb36f009f06..bcd03269a653 100644 --- a/dist.bzl +++ b/dist.bzl @@ -335,6 +335,15 @@ def source_archive( prefix = "deps", ) + pkg_files( + name = "json-files", + srcs = [ + "@json//:sources", + ], + strip_prefix = "", + prefix = "deps/json", + ) + pkg_files( name = "csv-files", srcs = [ @@ -349,6 +358,7 @@ def source_archive( extension = extension, srcs = [ ":deps-files", + ":json-files", ":csv-files", Label("@rabbitmq-server//:root-licenses"), ],