20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/rabbitcage/filter.rb', line 20
def self.register permission, user, action, object, properties
available_actions = {:queue => ['Declare', 'Bind', 'Unbind', 'Delete', 'Purge'],
:connection => ['Start', 'StartOk', 'Open', 'Tune', 'TuneOk', 'Close', 'Redirect', 'Secure'],
:channel => ['Open', 'Flow', 'Alert', 'Close', 'CloseOk'],
:exchange => ['Declare', 'Delete'],
:access => ['Request'],
:basic => ['Qos', 'Consume', 'Cancel', 'Publish', 'Deliver', 'Get', 'Ack', 'Reject']
}
klass = []
if action.is_a? Array
klass = action.collect { |a| "AMQP::Protocol::#{object.camelize}::#{a.camelize}" }.join(',')
else
if action == :all && object != :all
klass = available_actions[object].collect { |x| "AMQP::Protocol::#{object.camelize}::#{x}" }
elsif action == :all && object == :all
klass = :any
elsif action != :all && object == :all
raise "This acl format is currently not supported"
exit
else
klass = "AMQP::Protocol::#{object.camelize}::#{action.camelize}"
end
end
klass = klass.join(', ') if klass.class == Array
@rules[klass] = [] unless @rules[klass].class == Array
name = properties.delete(:name)
properties[object] = name if name
cond = []
cond << ('@user =' << (user.is_a?(Regexp) ? "~ #{user.inspect}" : "= '#{user}'")) if user != :all
properties.each_pair do |p, value|
cond << ("frame.#{p} =" << (value.is_a?(Regexp) ? "~ #{value.inspect}" : "= '#{value}'"))
end
@rules[klass] << {:permission => permission, :user => user, :properties => cond.join(' and ') }
end
|