Revert "Update 3rdparty rabbitmq module"
[mirror/dsa-puppet.git] / 3rdparty / modules / rabbitmq / lib / puppet / type / rabbitmq_user.rb
index 9fda2c2..baf4795 100644 (file)
@@ -1,24 +1,5 @@
 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
+  desc 'Native type for managing rabbitmq users'
 
   ensurable do
     defaultto(:present)
@@ -32,25 +13,27 @@ DESC
 
   autorequire(:service) { 'rabbitmq-server' }
 
-  newparam(:name, namevar: true) do
+  newparam(:name, :namevar => true) do
     desc 'Name of user'
-    newvalues(%r{^\S+$})
+    newvalues(/^\S+$/)
   end
 
   newproperty(:password) do
     desc 'User password to be set *on creation* and validated each run'
-    def insync?(_is)
-      provider.check_password(should)
+    def insync?(is)
+      provider.check_password
     end
-
-    def change_to_s(_current, _desired)
-      'password has been changed'
+    def set(value)
+      provider.change_password
+    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})
+    newvalues(/true|false/)
     munge do |value|
       # converting to_s in case its a boolean
       value.to_s.to_sym
@@ -58,25 +41,45 @@ DESC
     defaultto :false
   end
 
-  newproperty(:tags, array_matching: :all) do
+  newproperty(:tags, :array_matching => :all) do
     desc 'additional tags for the user'
     validate do |value|
-      unless value =~ %r{^\S+$}
+      unless value =~ /^\S+$/
         raise ArgumentError, "Invalid tag: #{value.inspect}"
       end
 
-      if value == 'administrator'
-        raise ArgumentError, 'must use admin property instead of administrator tag'
+      if value == "administrator"
+        raise ArgumentError, "must use admin property instead of administrator tag"
       end
     end
     defaultto []
 
     def insync?(is)
-      is.sort == should.sort
+      self.is_to_s(is) == self.should_to_s
     end
 
-    def should_to_s(value)
-      Array(value)
+    def is_to_s(currentvalue = @is)
+      if currentvalue
+        "[#{currentvalue.sort.join(', ')}]"
+      else
+        '[]'
+      end
     end
+
+    def should_to_s(newvalue = @should)
+      if newvalue
+        "[#{newvalue.sort.join(', ')}]"
+      else
+        '[]'
+      end
+    end
+
   end
+
+  validate do
+    if self[:ensure] == :present and ! self[:password]
+      raise ArgumentError, 'must set password when creating user' unless self[:password]
+    end
+  end
+
 end