3
# rabbitmq-common - common formula shell functions and config variables
5
# Copyright (C) 2011 Canonical Ltd.
6
# Author: Adam Gandelman <adam.gandelman@canonical.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
RABBIT_CTL='rabbitmqctl'
22
HOSTNAME=`hostname -f`
23
ERLANG_COOKIE="/var/lib/rabbitmq/.erlang.cookie"
25
function user_exists {
26
$RABBIT_CTL list_users | grep -wq "^$1"
29
function user_is_admin {
30
$RABBIT_CTL list_users | grep -w "^$1" | grep -q "administrator"
33
function vhost_exists {
34
$RABBIT_CTL list_vhosts | grep "^$VHOST\$" >/dev/null
37
function create_vhost {
38
$RABBIT_CTL add_vhost $VHOST
41
function user_create {
42
juju-log "rabbitmq: Creating user $1."
44
$RABBIT_CTL add_user $1 $PASSWORD || return 1
46
# grant the user all permissions on the default vhost /
47
# TODO: investigate sane permissions
48
juju-log "rabbitmq: Granting permission to $1 on vhost /"
49
$RABBIT_CTL set_permissions -p $VHOST $1 ".*" ".*" ".*"
51
if [[ $2 == 'admin' ]] ; then
52
user_is_admin $1 && return 0
53
juju-log "rabbitmq: Granting user $1 admin access"
54
$RABBIT_CTL set_user_tags "$1" administrator || return 1