1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
Puppet::Type.newtype(:rabbitmq_user) do
desc <<-DESC
Native type for managing rabbitmq users
@example query all current users
$ puppet resource rabbitmq_user
@example Configure a user, dan
rabbitmq_user { 'dan':
admin => true,
password => 'bar',
}
@example Optional parameter tags will set further rabbitmq tags like monitoring, policymaker, etc.
To set the administrator tag use admin-flag.
rabbitmq_user { 'dan':
admin => true,
password => 'bar',
tags => ['monitoring', 'tag1'],
}
DESC
ensurable do
defaultto(:present)
newvalue(:present) do
provider.create
end
newvalue(:absent) do
provider.destroy
end
end
autorequire(:service) { 'rabbitmq-server' }
newparam(:name, namevar: true) do
desc 'Name of user'
newvalues(%r{^\S+$})
end
newproperty(:password) do
desc 'User password to be set *on creation* and validated each run'
def insync?(_is)
provider.check_password(should)
end
def change_to_s(_current, _desired)
'password has been changed'
end
end
newproperty(:admin) do
desc 'whether or not user should be an admin'
newvalues(%r{true|false})
munge do |value|
# converting to_s in case its a boolean
value.to_s.to_sym
end
defaultto :false
end
newproperty(:tags, array_matching: :all) do
desc 'additional tags for the user'
validate do |value|
unless value =~ %r{^\S+$}
raise ArgumentError, "Invalid tag: #{value.inspect}"
end
if value == 'administrator'
raise ArgumentError, 'must use admin property instead of administrator tag'
end
end
defaultto []
def insync?(is)
is.sort == should.sort
end
def should_to_s(value)
Array(value)
end
end
end
|