Revert "Update 3rdparty rabbitmq module"
[mirror/dsa-puppet.git] / 3rdparty / modules / rabbitmq / lib / puppet / type / rabbitmq_binding.rb
index 1165fd9..1309480 100644 (file)
@@ -1,42 +1,5 @@
 Puppet::Type.newtype(:rabbitmq_binding) do
-  desc <<-DESC
-Native type for managing rabbitmq bindings
-
-@example Create a rabbitmq_binding
- rabbitmq_binding { 'myexchange@myqueue@myvhost':
-   user             => 'dan',
-   password         => 'bar',
-   destination_type => 'queue',
-   routing_key      => '#',
-   arguments        => {},
-   ensure           => present,
- }
-
-@example Create bindings with same source / destination / vhost but different routing key using individual parameters
-rabbitmq_binding { 'binding 1':
-  ensure           => present,
-  source           => 'myexchange',
-  destination      => 'myqueue',
-  vhost            => 'myvhost',
-  user             => 'dan',
-  password         => 'bar',
-  destination_type => 'queue',
-  routing_key      => 'key1',
-  arguments        => {},
-}
-
-rabbitmq_binding { 'binding 2':
-  ensure           => present,
-  source           => 'myexchange',
-  destination      => 'myqueue',
-  vhost            => 'myvhost',
-  user             => 'dan',
-  password         => 'bar',
-  destination_type => 'queue',
-  routing_key      => 'key2',
-  arguments        => {},
-}
-DESC
+  desc 'Native type for managing rabbitmq bindings'
 
   ensurable do
     defaultto(:present)
@@ -48,70 +11,23 @@ DESC
     end
   end
 
-  # Match patterns without '@' as arbitrary names; match patterns with
-  # src@destination@vhost to their named params for backwards compatibility.
-  def self.title_patterns
-    [
-      [
-        %r{(^([^@]*)$)}m,
-        [
-          [:name]
-        ]
-      ],
-      [
-        %r{^((\S+)@(\S+)@(\S+))$}m,
-        [
-          [:name],
-          [:source],
-          [:destination],
-          [:vhost]
-        ]
-      ]
-    ]
-  end
-
-  newparam(:name) do
-    desc 'resource name, either source@destination@vhost or arbitrary name with params'
-
-    isnamevar
-  end
-
-  newproperty(:source) do
-    desc 'source of binding'
-
-    newvalues(%r{^\S+$})
-    isnamevar
-  end
-
-  newproperty(:destination) do
-    desc 'destination of binding'
-
-    newvalues(%r{^\S+$})
-    isnamevar
+  newparam(:name, :namevar => true) do
+    desc 'source and destination of bind'
+    newvalues(/^\S*@\S+@\S+$/)
   end
 
-  newproperty(:vhost) do
-    desc 'vhost'
-
-    newvalues(%r{^\S+$})
-    defaultto('/')
-    isnamevar
-  end
-
-  newproperty(:routing_key) do
-    desc 'binding routing_key'
-
-    newvalues(%r{^\S*$})
-    isnamevar
-  end
-
-  newproperty(:destination_type) do
+  newparam(:destination_type) do
     desc 'binding destination_type'
-    newvalues(%r{queue|exchange})
+    newvalues(/queue|exchange/)
     defaultto('queue')
   end
+  
+  newparam(:routing_key) do
+    desc 'binding routing_key'
+    newvalues(/^\S*$/)
+  end
 
-  newproperty(:arguments) do
+  newparam(:arguments) do
     desc 'binding arguments'
     defaultto {}
     validate do |value|
@@ -122,19 +38,19 @@ DESC
   newparam(:user) do
     desc 'The user to use to connect to rabbitmq'
     defaultto('guest')
-    newvalues(%r{^\S+$})
+    newvalues(/^\S+$/)
   end
 
   newparam(:password) do
     desc 'The password to use to connect to rabbitmq'
     defaultto('guest')
-    newvalues(%r{\S+})
+    newvalues(/\S+/)
   end
 
   autorequire(:rabbitmq_vhost) do
-    setup_autorequire('vhost')
+    [self[:name].split('@')[2]]
   end
-
+  
   autorequire(:rabbitmq_exchange) do
     setup_autorequire('exchange')
   end
@@ -149,41 +65,32 @@ DESC
 
   autorequire(:rabbitmq_user_permissions) do
     [
-      "#{self[:user]}@#{self[:source]}",
-      "#{self[:user]}@#{self[:destination]}"
+      "#{self[:user]}@#{self[:name].split('@')[1]}",
+      "#{self[:user]}@#{self[:name].split('@')[0]}"
     ]
   end
 
   def setup_autorequire(type)
     destination_type = value(:destination_type)
     if type == 'exchange'
-      rval = ["#{self[:source]}@#{self[:vhost]}"]
+      rval = ["#{self[:name].split('@')[0]}@#{self[:name].split('@')[2]}"]
       if destination_type == type
-        rval.push("#{self[:destination]}@#{self[:vhost]}")
+        rval.push("#{self[:name].split('@')[1]}@#{self[:name].split('@')[2]}")
       end
     else
-      rval = if destination_type == type
-               ["#{self[:destination]}@#{self[:vhost]}"]
-             else
-               []
-             end
+      if destination_type == type
+        rval = ["#{self[:name].split('@')[1]}@#{self[:name].split('@')[2]}"]
+      else
+        rval = []
+      end
     end
     rval
   end
 
   def validate_argument(argument)
-    raise ArgumentError, 'Invalid argument' unless [Hash].include?(argument.class)
-  end
-
-  # Validate that we have both source and destination now that these are not
-  # necessarily only coming from the resource title.
-  validate do
-    if !self[:source] && !defined? provider.source
-      raise ArgumentError, '`source` must be defined'
-    end
-
-    if !self[:destination] && !defined? provider.destination
-      raise ArgumentError, '`destination` must be defined'
+    unless [Hash].include?(argument.class)
+      raise ArgumentError, "Invalid argument"
     end
   end
+
 end