---

apiVersion: v1
kind: ConfigMap
metadata:
  name: rabbitmq-config
data:
  config: |
    ## RabbitMQ configuration

    ## Networking
    listeners.tcp.default = 5672
    listeners.ssl = none

    tcp_listen_options.backlog = 1024
    tcp_listen_options.nodelay = true
    tcp_listen_options.keepalive = true

    ## Credentials
    loopback_users = none
    default_user = {{ .Values.config.default_user }}
    default_pass = {{ .Values.config.default_pass }}

    vm_memory_high_watermark.relative = {{ .Values.config.vm_memory_high_watermark_relative }}
    hipe_compile = false

    ## Management
    management.listener.port = 15672
    management.listener.ip = 0.0.0.0
    management.listener.ssl = false
    management.load_definitions = /etc/rabbitmq/definitions.json

    ## Clustering
    cluster_formation.node_cleanup.interval = 30
    cluster_formation.node_cleanup.only_log_warning = true
    cluster_partition_handling = autoheal
    cluster_keepalive_interval = 30000
    cluster_formation.peer_discovery_backend = rabbit_peer_discovery_etcd
    cluster_formation.etcd.port = {{ .Values.config.etcd.port }}
    cluster_formation.etcd.host = {{ .Values.config.etcd.host }}
    cluster_formation.etcd.scheme = {{ .Values.config.etcd.scheme }}
    {{- if .Values.config.etcd.key_prefix }}
    cluster_formation.etcd.key_prefix = {{ .Values.config.etcd.key_prefix }}
    {{- end }}

    ## Logging
    {{- if .Values.config.logging.logdir }}
    log.dir = {{ .Values.config.logging.logdir }}
    {{- end }}
    log.file = {{ .Values.config.logging.logfile }}
    log.file.level = {{ .Values.config.logging.loglevel }}
    log.console = {{ .Values.config.logging.logconsole }}
    log.console.level = {{ .Values.config.logging.logconsolelevel }}
    {{- if .Values.config.logging.logfederationfile }}
    log.federation.file = {{ .Values.config.logging.logfederationfile }}
    {{- end }}

    ## Network partition
    cluster_partition_handling = autoheal

  definitions: |
    {
      "rabbit_version": "3.7.8",
      "users": [
        {
          "name": "guest",
          "password_hash": "fd0GyzAf6C6hmgCJ5VU+TSyzUNlzypPlGb7VDKkqUvJqVxyd",
          "hashing_algorithm": "rabbit_password_hashing_sha256",
          "tags": "administrator"
        },
        {
          "name": "admin",
          "password_hash": "5l4+gjNoHj1ucDL5qM2r0+HIdIMvRbgzU2426xzHQ335mHrx",
          "hashing_algorithm": "rabbit_password_hashing_sha256",
          "tags": "administrator"
        },
        {
          "name": "synthesis-development",
          "password_hash": "/G9CmJHs7OFhDMiY6RP1qjKHVAx1xEUg9rr90psrbedNHAKe",
          "hashing_algorithm": "rabbit_password_hashing_sha256",
          "tags": "administrator"
        },
        {
          "name": "synthesis-testing",
          "password_hash": "glQsYczNxcTOCSvgWH9XHEXBBfJx2vc/NdqXidNtuamFdKkv",
          "hashing_algorithm": "rabbit_password_hashing_sha256",
          "tags": "administrator"
        },
        {
          "name": "synthesis-staging",
          "password_hash": "P8wIKKsmdjWB32NJxA4RPsekZ/iXPw4Otc5bHtSETVpsuZUF",
          "hashing_algorithm": "rabbit_password_hashing_sha256",
          "tags": "administrator"
        },
        {
          "name": "synthesis-production",
          "password_hash": "GIaPyB9yxZbV26gGB+Q1yF38m2IBkUsCYANdcbm74Hbt+D95",
          "hashing_algorithm": "rabbit_password_hashing_sha256",
          "tags": "administrator"
        }
      ],
      "vhosts": [
        {
          "name": "/"
        },
        {
          "name": "synthesis-development"
        },
        {
          "name": "synthesis-production"
        },
        {
          "name": "synthesis-staging"
        },
        {
          "name": "synthesis-testing"
        }
      ],
      "permissions":[
        {
          "user": "guest",
          "vhost": "/",
          "configure": ".*",
          "write": ".*",
          "read": ".*"
        },
        {
          "user": "admin",
          "vhost": "/",
          "configure": ".*",
          "write": ".*",
          "read": ".*"
        },
        {
          "user": "admin",
          "vhost": "synthesis-development",
          "configure": ".*",
          "write": ".*",
          "read": ".*"
        },
        {
          "user": "admin",
          "vhost": "synthesis-production",
          "configure": ".*",
          "write": ".*",
          "read": ".*"
        },
        {
          "user": "admin",
          "vhost": "synthesis-staging",
          "configure": ".*",
          "write": ".*",
          "read": ".*"
        },
        {
          "user": "admin",
          "vhost": "synthesis-testing",
          "configure": ".*",
          "write": ".*",
          "read": ".*"
        },
        {
          "user": "synthesis-development",
          "vhost": "synthesis-development",
          "configure": ".*",
          "write": ".*",
          "read": ".*"
        },
        {
          "user": "synthesis-production",
          "vhost": "synthesis-production",
          "configure": ".*",
          "write": ".*",
          "read": ".*"
        },
        {
          "user": "synthesis-staging",
          "vhost": "synthesis-staging",
          "configure": ".*",
          "write": ".*",
          "read": ".*"
        },
        {
          "user": "synthesis-testing",
          "vhost": "synthesis-testing",
          "configure": ".*",
          "write": ".*",
          "read": ".*"
        }
      ],
      "topic_permissions": [],
      "parameters":[],
      "global_parameters": [
        {
            "name": "cluster_name",
            {{- if .Values.location }}
            "value": "rabbitmq-cluster-{{ .Values.location }}"
            {{- else }}
            "value": "{{ .Values.definitions.cluster_name | default "rabbitmq-cluster-local" }}"
            {{- end }}
        }
      ],
      "policies": [],
      "queues":[
        {
          "name": "freeswitch",
          "vhost": "/",
          "durable": true,
          "auto_delete": false,
          "arguments": {}
        },
        {
          "name": "freeswitch",
          "vhost": "synthesis-development",
          "durable": true,
          "auto_delete": false,
          "arguments": {}
        },
        {
          "name": "freeswitch",
          "vhost": "synthesis-production",
          "durable": true,
          "auto_delete": false,
          "arguments": {}
        },
        {
          "name": "freeswitch",
          "vhost": "synthesis-staging",
          "durable": true,
          "auto_delete": false,
          "arguments": {}
        },
        {
          "name": "freeswitch",
          "vhost": "synthesis-testing",
          "durable": true,
          "auto_delete": false,
          "arguments": {}
        },
        {
          "name": "rtpengine",
          "vhost": "/",
          "durable": true,
          "auto_delete": false,
          "arguments": {}
        },
        {
          "name": "rtpengine",
          "vhost": "synthesis-development",
          "durable": true,
          "auto_delete": false,
          "arguments": {}
        },
        {
          "name": "rtpengine",
          "vhost": "synthesis-production",
          "durable": true,
          "auto_delete": false,
          "arguments": {}
        },
        {
          "name": "rtpengine",
          "vhost": "synthesis-staging",
          "durable": true,
          "auto_delete": false,
          "arguments": {}
        },
        {
          "name": "rtpengine",
          "vhost": "synthesis-testing",
          "durable": true,
          "auto_delete": false,
          "arguments": {}
        }
      ],
      "exchanges":[
        {
          "name": "FS.kube",
          "vhost": "/",
          "type": "topic",
          "durable": true,
          "auto_delete": false,
          "internal": false,
          "arguments": {}
        },
        {
          "name": "FS.kube",
          "vhost": "synthesis-development",
          "type": "topic",
          "durable": true,
          "auto_delete": false,
          "internal": false,
          "arguments": {}
        },
        {
          "name": "FS.kube",
          "vhost": "synthesis-production",
          "type": "topic",
          "durable": true,
          "auto_delete": false,
          "internal": false,
          "arguments": {}
        },
        {
          "name": "FS.kube",
          "vhost": "synthesis-staging",
          "type": "topic",
          "durable": true,
          "auto_delete": false,
          "internal": false,
          "arguments": {}
        },
        {
          "name": "FS.kube",
          "vhost": "synthesis-testing",
          "type": "topic",
          "durable": true,
          "auto_delete": false,
          "internal": false,
          "arguments": {}
        },
        {
          "name": "eventRtpengine",
          "vhost": "/",
          "type": "topic",
          "durable": true,
          "auto_delete": false,
          "internal": false,
          "arguments": {}
        },
        {
          "name": "eventRtpengine",
          "vhost": "synthesis-development",
          "type": "topic",
          "durable": true,
          "auto_delete": false,
          "internal": false,
          "arguments": {}
        },
        {
          "name": "eventRtpengine",
          "vhost": "synthesis-production",
          "type": "topic",
          "durable": true,
          "auto_delete": false,
          "internal": false,
          "arguments": {}
        },
        {
          "name": "eventRtpengine",
          "vhost": "synthesis-staging",
          "type": "topic",
          "durable": true,
          "auto_delete": false,
          "internal": false,
          "arguments": {}
        },
        {
          "name": "eventRtpengine",
          "vhost": "synthesis-testing",
          "type": "topic",
          "durable": true,
          "auto_delete": false,
          "internal": false,
          "arguments": {}
        }
      ],
      "bindings":[
        {
          "source": "FS.kube",
          "vhost": "/",
          "destination": "freeswitch",
          "destination_type": "queue",
          "routing_key": "freeswitch",
          "arguments": {}
        },
        {
          "source": "FS.kube",
          "vhost": "synthesis-development",
          "destination": "freeswitch",
          "destination_type": "queue",
          "routing_key": "freeswitch",
          "arguments": {}
        },
        {
          "source": "FS.kube",
          "vhost": "synthesis-production",
          "destination": "freeswitch",
          "destination_type": "queue",
          "routing_key": "freeswitch",
          "arguments": {}
        },
        {
          "source": "FS.kube",
          "vhost": "synthesis-staging",
          "destination": "freeswitch",
          "destination_type": "queue",
          "routing_key": "freeswitch",
          "arguments": {}
        },
        {
          "source": "FS.kube",
          "vhost": "synthesis-testing",
          "destination": "freeswitch",
          "destination_type": "queue",
          "routing_key": "freeswitch",
          "arguments": {}
        },
        {
          "source": "eventRtpengine",
          "vhost": "/",
          "destination": "rtpengine",
          "destination_type": "queue",
          "routing_key": "rtpengine",
          "arguments": {}
        },
        {
          "source": "eventRtpengine",
          "vhost": "synthesis-development",
          "destination": "rtpengine",
          "destination_type": "queue",
          "routing_key": "rtpengine",
          "arguments": {}
        },
        {
          "source": "eventRtpengine",
          "vhost": "synthesis-production",
          "destination": "rtpengine",
          "destination_type": "queue",
          "routing_key": "rtpengine",
          "arguments": {}
        },
        {
          "source": "eventRtpengine",
          "vhost": "synthesis-staging",
          "destination": "rtpengine",
          "destination_type": "queue",
          "routing_key": "rtpengine",
          "arguments": {}
        },
        {
          "source": "eventRtpengine",
          "vhost": "synthesis-testing",
          "destination": "rtpengine",
          "destination_type": "queue",
          "routing_key": "rtpengine",
          "arguments": {}
        }
      ]
    }
