Skip to content

Commit

Permalink
Merge pull request #7 from ochorocho/task/move-config
Browse files Browse the repository at this point in the history
[TASK] Move files to rabbitmq
  • Loading branch information
ochorocho authored Oct 28, 2023
2 parents 8901189 + 9bfdb0b commit a12ee7e
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 130 deletions.
12 changes: 6 additions & 6 deletions commands/rabbitmq/rabbitmq
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 // ""' -)

Expand All @@ -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 // "/"' -)
Expand All @@ -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 // ""' -)
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down
26 changes: 0 additions & 26 deletions config.rabbitmq.yaml

This file was deleted.

9 changes: 5 additions & 4 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
93 changes: 0 additions & 93 deletions rabbitmq-schema.json

This file was deleted.

25 changes: 25 additions & 0 deletions rabbitmq/config.yaml
Original file line number Diff line number Diff line change
@@ -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
87 changes: 87 additions & 0 deletions rabbitmq/schema.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
}
2 changes: 1 addition & 1 deletion tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a12ee7e

Please sign in to comment.