Class: HolePunch::Definition
- Inherits:
-
Object
- Object
- HolePunch::Definition
- Defined in:
- lib/holepunch/definition.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
Class Method Summary collapse
Instance Method Summary collapse
- #add_group(group) ⇒ Object
-
#initialize(env = nil) ⇒ Definition
constructor
A new instance of Definition.
- #validate! ⇒ Object
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
#env ⇒ Object (readonly)
Returns the value of attribute env.
60 61 62 |
# File 'lib/holepunch/definition.rb', line 60 def env @env end |
#groups ⇒ Object (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). unless filename.file? raise SecurityGroupsFileNotFoundError, "#{filename} not found" end DSL.evaluate(file, env) end |
Instance Method Details
#add_group(group) ⇒ Object
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 |