5 Puppet::Type.type(:rabbitmq_binding).provide(:rabbitmqadmin) do
6 has_command(:rabbitmqctl, 'rabbitmqctl') do
7 environment HOME: '/tmp'
9 has_command(:rabbitmqadmin, '/usr/local/bin/rabbitmqadmin') do
10 environment HOME: '/tmp'
13 confine feature: :posix
15 # Without this, the composite namevar stuff doesn't work properly.
22 @should_vhost = resource[:vhost]
28 rabbitmqctl('list_vhosts', '-q').split(%r{\n}).map do |vhost|
34 def self.all_bindings(vhost)
35 rabbitmqctl('list_bindings', '-q', '-p', vhost, 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments').split(%r{\n})
40 all_vhosts.each do |vhost|
41 all_bindings(vhost).map do |line|
42 source_name, destination_name, destination_type, routing_key, arguments = line.split(%r{\t})
43 # Convert output of arguments from the rabbitmqctl command to a json string.
45 arguments = arguments.gsub(%r{^\[(.*)\]$}, '').gsub(%r{\{("(?:.|\\")*?"),}, '{\1:').gsub(%r{\},\{}, ',')
46 arguments = '{}' if arguments == ''
50 hashed_name = Digest::SHA256.hexdigest format('%s@%s@%s@%s', source_name, destination_name, vhost, routing_key)
51 next if source_name.empty?
54 destination: destination_name,
56 destination_type: destination_type,
57 routing_key: routing_key,
58 arguments: JSON.parse(arguments),
62 resources << new(binding) if binding[:name]
69 # https://github.com/puppetlabs/puppetlabs-netapp/blob/d0a655665463c69c932f835ba8756be32417a4e9/lib/puppet/provider/netapp_qtree/sevenmode.rb#L66-L73
70 def self.prefetch(resources)
72 resources.each do |name, res|
73 if (provider = bindings.find { |binding| binding.source == res[:source] && binding.destination == res[:destination] && binding.vhost == res[:vhost] && binding.routing_key == res[:routing_key] })
74 resources[name].provider = provider
80 @property_hash[:ensure] == :present
84 vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : ''
85 arguments = resource[:arguments]
86 arguments = {} if arguments.nil?
87 rabbitmqadmin('declare',
90 "--user=#{resource[:user]}",
91 "--password=#{resource[:password]}",
93 '/etc/rabbitmq/rabbitmqadmin.conf',
94 "source=#{resource[:source]}",
95 "destination=#{resource[:destination]}",
96 "arguments=#{arguments.to_json}",
97 "routing_key=#{resource[:routing_key]}",
98 "destination_type=#{resource[:destination_type]}")
99 @property_hash[:ensure] = :present
103 vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : ''
104 rabbitmqadmin('delete', 'binding', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf', "source=#{resource[:source]}", "destination_type=#{resource[:destination_type]}", "destination=#{resource[:destination]}", "properties_key=#{resource[:routing_key]}")
105 @property_hash[:ensure] = :absent