Update 3rdparty rabbitmq module
[mirror/dsa-puppet.git] / 3rdparty / modules / rabbitmq / lib / puppet / provider / rabbitmq_plugin / rabbitmqplugins.rb
index 7ab5420..9437cf3 100644 (file)
@@ -1,40 +1,35 @@
 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl'))
-Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmqplugins, :parent => Puppet::Provider::Rabbitmqctl) do
-
-  if Puppet::PUPPETVERSION.to_f < 3
-    if Facter.value(:osfamily) == 'RedHat'
-      commands :rabbitmqplugins => '/usr/lib/rabbitmq/bin/rabbitmq-plugins'
-    else
-      commands :rabbitmqplugins => 'rabbitmq-plugins'
+Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmqplugins, parent: Puppet::Provider::Rabbitmqctl) do
+  # Prefer rabbitmq-plugins if it's in $PATH, but fall back to /usr/lib/rabbitmq/bin
+  if Puppet::Util.which('rabbitmq-plugins')
+    has_command(:rabbitmqplugins, 'rabbitmq-plugins') do
+      environment HOME: '/tmp'
     end
   else
-    if Facter.value(:osfamily) == 'RedHat'
-      has_command(:rabbitmqplugins, '/usr/lib/rabbitmq/bin/rabbitmq-plugins') do
-        environment :HOME => "/tmp"
-      end
-    else
-      has_command(:rabbitmqplugins, 'rabbitmq-plugins') do
-        environment :HOME => "/tmp"
-      end
+    has_command(:rabbitmqplugins, '/usr/lib/rabbitmq/bin/rabbitmq-plugins') do
+      environment HOME: '/tmp'
     end
   end
 
-  defaultfor :feature => :posix
+  confine feature: :posix
 
   def self.instances
-    self.run_with_retries {
+    plugin_list = run_with_retries do
       rabbitmqplugins('list', '-E', '-m')
-    }.split(/\n/).map do |line|
-      if line =~ /^(\S+)$/
-        new(:name => $1)
-      else
-        raise Puppet::Error, "Cannot parse invalid plugins line: #{line}"
-      end
+    end
+
+    plugin_list.split(%r{\n}).map do |line|
+      raise Puppet::Error, "Cannot parse invalid plugins line: #{line}" unless line =~ %r{^(\S+)$}
+      new(name: Regexp.last_match(1))
     end
   end
 
   def create
-    rabbitmqplugins('enable', resource[:name])
+    if resource[:umask].nil?
+      rabbitmqplugins('enable', resource[:name])
+    else
+      Puppet::Util.withumask(resource[:umask]) { rabbitmqplugins('enable', resource[:name]) }
+    end
   end
 
   def destroy
@@ -42,11 +37,6 @@ Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmqplugins, :parent => Puppet:
   end
 
   def exists?
-    self.class.run_with_retries {
-      rabbitmqplugins('list', '-E', '-m')
-    }.split(/\n/).detect do |line|
-      line.match(/^#{resource[:name]}$/)
-    end
+    self.class.run_with_retries { rabbitmqplugins('list', '-E', '-m') }.split(%r{\n}).include? resource[:name]
   end
-
 end