Update rabbitmq module
[mirror/dsa-puppet.git] / 3rdparty / modules / rabbitmq / lib / puppet / provider / rabbitmq_plugin / rabbitmqplugins.rb
1 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmqctl'))
2 Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmqplugins, parent: Puppet::Provider::Rabbitmqctl) do
3   # Prefer rabbitmq-plugins if it's in $PATH, but fall back to /usr/lib/rabbitmq/bin
4   if Puppet::Util.which('rabbitmq-plugins')
5     has_command(:rabbitmqplugins, 'rabbitmq-plugins') do
6       environment HOME: '/tmp'
7     end
8   else
9     has_command(:rabbitmqplugins, '/usr/lib/rabbitmq/bin/rabbitmq-plugins') do
10       environment HOME: '/tmp'
11     end
12   end
13
14   confine feature: :posix
15
16   def self.instances
17     plugin_list = run_with_retries do
18       rabbitmqplugins('list', '-E', '-m')
19     end
20
21     plugin_list.split(%r{\n}).map do |line|
22       raise Puppet::Error, "Cannot parse invalid plugins line: #{line}" unless line =~ %r{^(\S+)$}
23       new(name: Regexp.last_match(1))
24     end
25   end
26
27   def create
28     if resource[:umask].nil?
29       rabbitmqplugins('enable', resource[:name])
30     else
31       Puppet::Util.withumask(resource[:umask]) { rabbitmqplugins('enable', resource[:name]) }
32     end
33   end
34
35   def destroy
36     rabbitmqplugins('disable', resource[:name])
37   end
38
39   def exists?
40     self.class.run_with_retries { rabbitmqplugins('list', '-E', '-m') }.split(%r{\n}).include? resource[:name]
41   end
42 end