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
|
Puppet::Type.newtype(:mongodb_user) do
@doc = 'Manage a MongoDB user. This includes management of users password as well as privileges.'
ensurable
def initialize(*args)
super
# Sort roles array before comparison.
self[:roles] = Array(self[:roles]).sort!
end
newparam(:name, :namevar=>true) do
desc "The name of the user."
end
newparam(:database) do
desc "The user's target database."
defaultto do
fail("Parameter 'database' must be set")
end
newvalues(/^\w+$/)
end
newparam(:tries) do
desc "The maximum amount of two second tries to wait MongoDB startup."
defaultto 10
newvalues(/^\d+$/)
munge do |value|
Integer(value)
end
end
newproperty(:roles, :array_matching => :all) do
desc "The user's roles."
defaultto ['dbAdmin']
newvalue(/^\w+$/)
# Pretty output for arrays.
def should_to_s(value)
value.inspect
end
def is_to_s(value)
value.inspect
end
end
newproperty(:password_hash) do
desc "The password hash of the user. Use mongodb_password() for creating hash."
defaultto do
fail("Property 'password_hash' must be set. Use mongodb_password() for creating hash.")
end
newvalue(/^\w+$/)
end
end
|