diff --git a/commands/rabbitmq/rabbitmq b/commands/rabbitmq/rabbitmq index 3fc2d35..062e5b7 100755 --- a/commands/rabbitmq/rabbitmq +++ b/commands/rabbitmq/rabbitmq @@ -13,7 +13,7 @@ CMD=$1 # Subcommands allowed to watch ALLOWED_DISPLAY_ARGUMENTS=("overview" "connections" "channels" "consumers" "exchanges" "queues" "bindings" "users" "vhosts" "permissions" "nodes" "parameters" "policies" "operator_policies" "vhost_limits" ) -YAML_FILE=/mnt/ddev_config/config.rabbitmq.yaml +YAML_FILE=/mnt/ddev_config/rabbitmq/config.yaml function watcher() { subcommand=$1 @@ -41,7 +41,7 @@ function watcher() { function add_vhosts() { vhosts_json=$(rabbitmqctl list_vhosts --formatter json) readarray vhosts_existing < <(echo "$vhosts_json" | yq -o=y -I=0 '.[].name' -) - readarray vhosts < <(yq -o=j -I=0 '.rabbitmq.vhost[]' $YAML_FILE ) + readarray vhosts < <(yq -o=j -I=0 '.vhost[]' $YAML_FILE ) for vhost in "${vhosts[@]}"; do name=$(echo "$vhost" | yq '.name // ""' -) @@ -64,7 +64,7 @@ function add_vhosts() { } function add_queues() { - readarray queues < <(yq -o=j -I=0 '.rabbitmq.queue[]' $YAML_FILE ) + readarray queues < <(yq -o=j -I=0 '.queue[]' $YAML_FILE ) for queue in "${queues[@]}"; do name=$(echo "$queue" | yq '.name' -) vhost=$(echo "$queue" | yq '.vhost // "/"' -) @@ -84,7 +84,7 @@ function add_queues() { function add_users() { users_json=$(rabbitmqctl list_users --silent --formatter json) readarray users_existing < <(echo "$users_json" | yq -o=y -I=0 '.[].user' -) - readarray users < <(yq -o=j -I=0 '.rabbitmq.user[]' $YAML_FILE ) + readarray users < <(yq -o=j -I=0 '.user[]' $YAML_FILE ) for user in "${users[@]}"; do name=$(echo "$user" | yq '.name // ""' -) @@ -121,7 +121,7 @@ case $CMD in apply) echo "Apply config $YAML_FILE" - plugins_array=$(yq eval '.rabbitmq.plugins[]' "$YAML_FILE") + plugins_array=$(yq eval '.plugins[]' "$YAML_FILE") plugins=$(echo "${plugins_array[*]}" | tr '\n' ' ' | xargs) rabbitmq-plugins enable "$plugins" @@ -166,7 +166,7 @@ case $CMD in echo "——————————————" echo -e "\033[1mApply\033[0m" echo "—————" - echo "Create queues, users and add 'plugins' according to configuration (see .ddev/config.rabbitmq.yaml)" + echo "Create queues, users and add 'plugins' according to configuration (see .ddev/rabbitmq/config.yaml)" echo "👉 ddev rabbitmq apply" echo "" echo -e "\033[1mWipe\033[0m" diff --git a/config.rabbitmq.yaml b/config.rabbitmq.yaml deleted file mode 100644 index e0cd606..0000000 --- a/config.rabbitmq.yaml +++ /dev/null @@ -1,26 +0,0 @@ -#ddev-generated -rabbitmq: - vhost: - - name: ddev-vhost - default-queue-type: classic - queue: - - name: ddev-queue - vhost: ddev-vhost - durable: true - - name: ddev-additional - vhost: ddev-vhost - durable: true - user: - - name: ddev-admin - password: password - tags: - - administrator - - management - permissions: - - vhost: ddev-vhost - conf: .* - write: .* - read: .* - plugins: - # Required! - - rabbitmq_management diff --git a/install.yaml b/install.yaml index 581cd2c..fcb5ebf 100644 --- a/install.yaml +++ b/install.yaml @@ -6,9 +6,10 @@ project_files: - commands/rabbitmq/rabbitmq - commands/rabbitmq/rabbitmqadmin - commands/rabbitmq/rabbitmqctl - - config.rabbitmq.yaml - - rabbitmq-schema.json + - rabbitmq/config.yaml + - rabbitmq/schema.json -# Shell actions that can be done during removal of the add-on removal_actions: - - rm -f "${DDEV_APPROOT}/.ddev/rabbitmq-schema.json" + # JSON can not contain "ddev-generated" comment and this file is not intended + # to be modified therefore it is removed manually on removal + - rm -f "${DDEV_APPROOT}/.ddev/rabbitmq/schema.json" diff --git a/rabbitmq-schema.json b/rabbitmq-schema.json deleted file mode 100644 index 88a7764..0000000 --- a/rabbitmq-schema.json +++ /dev/null @@ -1,93 +0,0 @@ -{ - "$schema": "./config.rabbitmq.yaml", - "type": "object", - "properties": { - "rabbitmq": { - "type": "object", - "properties": { - "user": { - "type": "array", - "items": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "password": { - "type": "string" - }, - "tags": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "management", - "policymaker", - "monitoring", - "administrator" - ] - } - } - }, - "required": ["name", "password", "tags"] - } - }, - "queue": { - "type": "array", - "items": { - "type": "object", - "properties": { - "vhost": { - "type": "string", - "pattern": "^([a-zA-Z_\-\/]*)$" - }, - "name": { - "type": "string", - "pattern": "^([a-zA-Z_-]*)$" - }, - "durable": { - "type": "boolean" - } - }, - "required": ["name"] - } - }, - "plugins": { - "type": "array", - "items": { - "type": "string" - } - }, - "vhost": { - "type": "array", - "items": { - "type": "object", - "properties": { - "name": { - "type": "string", - "pattern": "^([a-zA-Z_\-0-9]*)$" - }, - "default-queue-type": { - "type": "string", - "enum": [ - "classic", - "quorum", - "stream" - ] - }, - "tags": { - "type": "array", - "items": { - "type": "string", - "pattern": "^([a-zA-Z_\-0-9]*)$" - } - } - }, - "required": ["name", "default-queue-type"] - } - } - } - } - }, - "required": ["rabbitmq"] -} diff --git a/rabbitmq/config.yaml b/rabbitmq/config.yaml new file mode 100644 index 0000000..4744999 --- /dev/null +++ b/rabbitmq/config.yaml @@ -0,0 +1,25 @@ +#ddev-generated +vhost: + - name: ddev-vhost + default-queue-type: classic +queue: + - name: ddev-queue + vhost: ddev-vhost + durable: true + - name: ddev-additional + vhost: ddev-vhost + durable: true +user: + - name: ddev-admin + password: password + tags: + - administrator + - management + permissions: + - vhost: ddev-vhost + conf: .* + write: .* + read: .* +plugins: + # Required! + - rabbitmq_management diff --git a/rabbitmq/schema.json b/rabbitmq/schema.json new file mode 100644 index 0000000..15ec632 --- /dev/null +++ b/rabbitmq/schema.json @@ -0,0 +1,87 @@ +{ + "$schema": "./config.yaml", + "type": "object", + "properties": { + "user": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "password": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "management", + "policymaker", + "monitoring", + "administrator" + ] + } + } + }, + "required": ["name", "password", "tags"] + } + }, + "queue": { + "type": "array", + "items": { + "type": "object", + "properties": { + "vhost": { + "type": "string", + "pattern": "^([a-zA-Z_\-\/]*)$" + }, + "name": { + "type": "string", + "pattern": "^([a-zA-Z_-]*)$" + }, + "durable": { + "type": "boolean" + } + }, + "required": ["name"] + } + }, + "plugins": { + "type": "array", + "items": { + "type": "string" + } + }, + "vhost": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "pattern": "^([a-zA-Z_\-0-9]*)$" + }, + "default-queue-type": { + "type": "string", + "enum": [ + "classic", + "quorum", + "stream" + ] + }, + "tags": { + "type": "array", + "items": { + "type": "string", + "pattern": "^([a-zA-Z_\-0-9]*)$" + } + } + }, + "required": ["name", "default-queue-type"] + } + } + } +} diff --git a/tests/test.bats b/tests/test.bats index 1855c6d..cd2a891 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -62,7 +62,7 @@ setup() { @test "Remove addon - see files removed" { ddev get --remove rabbitmq - expected_files_not_to_exist=(docker-compose.rabbitmq.yaml commands/rabbitmq/rabbitmq commands/rabbitmq/rabbitmqadmin commands/rabbitmq/rabbitmqctl config.rabbitmq.yaml rabbitmq-schema.json) + expected_files_not_to_exist=(docker-compose.rabbitmq.yaml commands/rabbitmq/rabbitmq commands/rabbitmq/rabbitmqadmin commands/rabbitmq/rabbitmqctl rabbitmq/config.yaml rabbitmq/schema.json) for file in "${expected_files_not_to_exist[@]}"; do [ ! -f "$TESTDIR/.ddev/$file" ] done