Class: Verifica::AclBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/verifica/acl_builder.rb

Overview

Builder that holds mutable list of Access Control Entries and methods to add new entries

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(initial_aces = EMPTY_ARRAY) ⇒ AclBuilder

Note:

Use Verifica::Acl.build or Verifica::Acl#build instead of this constructor directly

Returns a new instance of AclBuilder.



13
14
15
16
# File 'lib/verifica/acl_builder.rb', line 13

def initialize(initial_aces = EMPTY_ARRAY)
  @aces = initial_aces.dup
  freeze
end

Instance Method Details

#allow(sid, actions) ⇒ self

Add Access Control Entries that allow particular actions for the given Security Identifier

Examples:

builder = AclBuilder.new
  .allow("anonymous", [:read])
  .allow("root", [:read, :write, :delete])
acl = builder.build

Parameters:

  • sid (String)

    Security Identifier

  • actions (Enumerable<Symbol>, Enumerable<String>)

    list of actions allowed for the given SID

Returns:

  • (self)


32
33
34
35
# File 'lib/verifica/acl_builder.rb', line 32

def allow(sid, actions)
  @aces.concat(actions.map { |action| Ace.new(sid, action, true) })
  self
end

#buildAcl

Returns a new, immutable Access Control List.

Returns:

  • (Acl)

    a new, immutable Access Control List



59
60
61
# File 'lib/verifica/acl_builder.rb', line 59

def build
  Acl.new(@aces)
end

#deny(sid, actions) ⇒ self

Add Access Control Entries that deny particular actions for the given Security Identifier

Examples:

builder = Verifica::AclBuilder.new
  .deny("country:US", [:read, :comment])
  .deny("country:CA", [:read, :comment])
acl = builder.build

Parameters:

  • sid (String)

    Security Identifier

  • actions (Enumerable<Symbol>, Enumerable<String>)

    list of actions denied for the given SID

Returns:

  • (self)


51
52
53
54
# File 'lib/verifica/acl_builder.rb', line 51

def deny(sid, actions)
  @aces.concat(actions.map { |action| Ace.new(sid, action, false) })
  self
end