Class: HolePunch::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/holepunch/definition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Definition

Returns a new instance of Definition.



74
75
76
77
# File 'lib/holepunch/definition.rb', line 74

def initialize(env = nil)
  @env = env
  @groups = {}
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



60
61
62
# File 'lib/holepunch/definition.rb', line 60

def env
  @env
end

#groupsObject (readonly)

Returns the value of attribute groups.



61
62
63
# File 'lib/holepunch/definition.rb', line 61

def groups
  @groups
end

Class Method Details

.build(file, env) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/holepunch/definition.rb', line 64

def build(file, env)
  filename = Pathname.new(file).expand_path
  unless filename.file?
    raise SecurityGroupsFileNotFoundError, "#{filename} not found"
  end

  DSL.evaluate(file, env)
end

Instance Method Details

#add_group(group) ⇒ Object

Raises:

  • (DuplicateGroupError)


79
80
81
82
# File 'lib/holepunch/definition.rb', line 79

def add_group(group)
  raise DuplicateGroupError, "another group already exists with id #{id}" if groups.include?(group.id)
  groups[group.id] = group
end

#validate!Object



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/holepunch/definition.rb', line 84

def validate!
  # verify group references are defined
  groups.each do |id, group|
    group.ingresses.each do |ingress|
      ingress.sources.each do |source|
        next if HolePunch.cidr?(source)
        unless groups.include?(source)
          raise GroupError, "group '#{source}' referenced by group '#{id}' does not exist"
        end
      end
    end
  end
end