1 Puppet::Type.newtype(:rabbitmq_binding) do
3 Native type for managing rabbitmq bindings
5 @example Create a rabbitmq_binding
6 rabbitmq_binding { 'myexchange@myqueue@myvhost':
9 destination_type => 'queue',
15 @example Create bindings with same source / destination / vhost but different routing key using individual parameters
16 rabbitmq_binding { 'binding 1':
18 source => 'myexchange',
19 destination => 'myqueue',
23 destination_type => 'queue',
24 routing_key => 'key1',
28 rabbitmq_binding { 'binding 2':
30 source => 'myexchange',
31 destination => 'myqueue',
35 destination_type => 'queue',
36 routing_key => 'key2',
51 # Match patterns without '@' as arbitrary names; match patterns with
52 # src@destination@vhost to their named params for backwards compatibility.
53 def self.title_patterns
62 %r{^((\S+)@(\S+)@(\S+))$}m,
74 desc 'resource name, either source@destination@vhost or arbitrary name with params'
79 newproperty(:source) do
80 desc 'source of binding'
86 newproperty(:destination) do
87 desc 'destination of binding'
93 newproperty(:vhost) do
101 newproperty(:routing_key) do
102 desc 'binding routing_key'
108 newproperty(:destination_type) do
109 desc 'binding destination_type'
110 newvalues(%r{queue|exchange})
114 newproperty(:arguments) do
115 desc 'binding arguments'
118 resource.validate_argument(value)
123 desc 'The user to use to connect to rabbitmq'
128 newparam(:password) do
129 desc 'The password to use to connect to rabbitmq'
134 autorequire(:rabbitmq_vhost) do
135 setup_autorequire('vhost')
138 autorequire(:rabbitmq_exchange) do
139 setup_autorequire('exchange')
142 autorequire(:rabbitmq_queue) do
143 setup_autorequire('queue')
146 autorequire(:rabbitmq_user) do
150 autorequire(:rabbitmq_user_permissions) do
152 "#{self[:user]}@#{self[:source]}",
153 "#{self[:user]}@#{self[:destination]}"
157 def setup_autorequire(type)
158 destination_type = value(:destination_type)
159 if type == 'exchange'
160 rval = ["#{self[:source]}@#{self[:vhost]}"]
161 if destination_type == type
162 rval.push("#{self[:destination]}@#{self[:vhost]}")
165 rval = if destination_type == type
166 ["#{self[:destination]}@#{self[:vhost]}"]
174 def validate_argument(argument)
175 raise ArgumentError, 'Invalid argument' unless [Hash].include?(argument.class)
178 # Validate that we have both source and destination now that these are not
179 # necessarily only coming from the resource title.
181 if !self[:source] && !defined? provider.source
182 raise ArgumentError, '`source` must be defined'
185 if !self[:destination] && !defined? provider.destination
186 raise ArgumentError, '`destination` must be defined'