Class: Dizby::Access::ControlList

Inherits:
Object
  • Object
show all
Defined in:
lib/dizby/access/control_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(order = :deny_allow) ⇒ ControlList

:allow_deny if denied, deny else if allowed, allow else, deny


20
21
22
23
24
# File 'lib/dizby/access/control_list.rb', line 20

def initialize(order = :deny_allow)
  @order = order
  @deny = List.new
  @allow = List.new
end

Instance Method Details

#allow_addr?(addr) ⇒ Boolean

Returns:

  • (Boolean)

30
31
32
33
34
35
36
37
38
39
# File 'lib/dizby/access/control_list.rb', line 30

def allow_addr?(addr)
  case @order
  when :deny_allow
    deny_allow?(addr)
  when :allow_deny
    allow_deny?(addr)
  else
    false
  end
end

#allow_deny?(addr) ⇒ Boolean (private)

Returns:

  • (Boolean)

63
64
65
66
67
# File 'lib/dizby/access/control_list.rb', line 63

def allow_deny?(addr)
  return false if @deny.matches?(addr)
  return true if @allow.matches?(addr)
  false
end

#allow_socket?(soc) ⇒ Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/dizby/access/control_list.rb', line 26

def allow_socket?(soc)
  allow_addr?(soc.peeraddr)
end

#deny_allow?(addr) ⇒ Boolean (private)

Returns:

  • (Boolean)

57
58
59
60
61
# File 'lib/dizby/access/control_list.rb', line 57

def deny_allow?(addr)
  return true if @allow.matches?(addr)
  return false if @deny.matches?(addr)
  true
end

#install_list(list)


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dizby/access/control_list.rb', line 41

def install_list(list)
  Hash[*list].each do |permission, domain|
    domain = Entry.new(domain)
    case permission.downcase
    when 'allow'
      @allow.push(domain)
    when 'deny'
      @deny.push(domain)
    else
      fail ArgumentError, "Invalid ACL entry #{list}"
    end
  end
end