rabbitmq / rabbitmq-cli

Command line tools for RabbitMQ
Other
105 stars 34 forks source link

CLI definition export incorrectly serialises federation upstreams #435

Closed michaelklishin closed 4 years ago

michaelklishin commented 4 years ago

"Incorrectly" here means it uses keyword lists instead of maps:

Importing definitions in JSON from a file at "/path/to/defs.plugins.cli.json" ...
Error:
Validation failed

Unrecognised terms [[<<"ack-mode">>,<<"on-confirm">>],
                    [<<"trust-user-id">>,false],
                    [<<"uri">>,<<"amqp://127.0.0.1:5672">>]] in up-1
Key "uri" not found in up-1
 (//federation-upstream/up-1)

This issue is not present with a file produced by the HTTP API.

Discovered while working on https://github.com/rabbitmq/rabbitmq-server/issues/2384.

Apparently it was introduced by this change https://github.com/rabbitmq/rabbitmq-server/commit/460a432 that makes exported parameter values to be proplists and not maps.

michaelklishin commented 4 years ago

This is how parameters in the problematic case are deserialised:

"parameters" => [
     %{
       "component" => "federation-upstream",
       "name" => "up-1",
       "value" => [
         ["ack-mode", "on-confirm"],
         ["trust-user-id", false],
         ["uri", "amqp://127.0.0.1:5672"]
       ],
       "vhost" => "/"
     },
     %{
       "component" => "shovel",
       "name" => "shovel-60",
       "value" => [
         ["ack-mode", "on-confirm"],
         ["dest-add-forward-headers", false],
         ["dest-protocol", "amqp091"],
         ["dest-queue", "shovel-60-dst"],
         ["dest-uri", "amqp://localhost:5672"],
         ["src-delete-after", "never"],
         ["src-protocol", "amqp091"],
         ["src-queue", "shovel-60-src"],
         ["src-uri", "amqp://localhost:5672"]
       ],
       "vhost" => "/"
     }
   ]
michaelklishin commented 4 years ago

JSON file difference makes it clear it's an export_definitions issue:

"parameters": [
        {
            "component": "federation-upstream",
            "name": "up-1",
            "value": [
                [
                    "ack-mode",
                    "on-confirm"
                ],
                [
                    "trust-user-id",
                    false
                ],
                [
                    "uri",
                    "amqp://127.0.0.1:5672"
                ]
            ],
            "vhost": "/"
        },
        {
            "component": "shovel",
            "name": "shovel-60",
            "value": [
                [
                    "ack-mode",
                    "on-confirm"
                ],
                [
                    "dest-add-forward-headers",
                    false
                ],
                [
                    "dest-protocol",
                    "amqp091"
                ],
                [
                    "dest-queue",
                    "shovel-60-dst"
                ],
                [
                    "dest-uri",
                    "amqp://localhost:5672"
                ],
                [
                    "src-delete-after",
                    "never"
                ],
                [
                    "src-protocol",
                    "amqp091"
                ],
                [
                    "src-queue",
                    "shovel-60-src"
                ],
                [
                    "src-uri",
                    "amqp://localhost:5672"
                ]
            ],
            "vhost": "/"
        }
    ],

vs. HTTP API-produced one:

    "parameters": [
        {
            "value": {
                "ack-mode": "on-confirm",
                "trust-user-id": false,
                "uri": "amqp://127.0.0.1:5672"
            },
            "vhost": "/",
            "component": "federation-upstream",
            "name": "up-1"
        },
        {
            "value": {
                "ack-mode": "on-confirm",
                "dest-add-forward-headers": false,
                "dest-protocol": "amqp091",
                "dest-queue": "shovel-60-dst",
                "dest-uri": "amqp://localhost:5672",
                "src-delete-after": "never",
                "src-protocol": "amqp091",
                "src-queue": "shovel-60-src",
                "src-uri": "amqp://localhost:5672"
            },
            "vhost": "/",
            "component": "shovel",
            "name": "shovel-60"
        }
    ],