Class: Fog::Bouncer::Group
- Inherits:
-
Object
- Object
- Fog::Bouncer::Group
- Defined in:
- lib/fog/bouncer/group.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#local ⇒ Object
Returns the value of attribute local.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#remote ⇒ Object
Returns the value of attribute remote.
-
#security ⇒ Object
readonly
Returns the value of attribute security.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_source(source, &block) ⇒ Object
- #create_missing_remote ⇒ Object
- #destroy ⇒ Object
-
#exceeded? ⇒ Boolean
Public: Check if it has exceeded the 100 rules limit per group on AWS, docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using-network-security.html.
- #extra_remote_sources ⇒ Object
-
#initialize(name, description, security, &block) ⇒ Group
constructor
A new instance of Group.
- #inspect ⇒ Object
- #local? ⇒ Boolean
- #log(data, &block) ⇒ Object
- #missing_remote_sources ⇒ Object
- #remote? ⇒ Boolean
- #revoke ⇒ Object
- #sources ⇒ Object
- #sync ⇒ Object
- #use(name) ⇒ Object
Constructor Details
#initialize(name, description, security, &block) ⇒ Group
Returns a new instance of Group.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/bouncer/group.rb', line 15 def initialize(name, description, security, &block) @name = name @description = description @security = security @using = [] if block_given? @local = true instance_eval(&block) apply_definitions end end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/fog/bouncer/group.rb', line 4 def description @description end |
#local ⇒ Object
Returns the value of attribute local.
5 6 7 |
# File 'lib/fog/bouncer/group.rb', line 5 def local @local end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/fog/bouncer/group.rb', line 4 def name @name end |
#remote ⇒ Object
Returns the value of attribute remote.
5 6 7 |
# File 'lib/fog/bouncer/group.rb', line 5 def remote @remote end |
#security ⇒ Object (readonly)
Returns the value of attribute security.
4 5 6 |
# File 'lib/fog/bouncer/group.rb', line 4 def security @security end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
122 123 124 125 |
# File 'lib/fog/bouncer/group.rb', line 122 def ==(other) name == other.name && description == other.description end |
#add_source(source, &block) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/fog/bouncer/group.rb', line 27 def add_source(source, &block) if existing = sources.find { |s| s.match(source) } existing.instance_eval(&block) else sources << Sources.for(source, self, &block) end end |
#create_missing_remote ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fog/bouncer/group.rb', line 35 def create_missing_remote unless remote? log(create_missing_remote: true) do unless Fog::Bouncer.pretending? @remote = Fog::Bouncer.fog.security_groups.create(:name => name, :description => description) @remote.reload end end end end |
#destroy ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fog/bouncer/group.rb', line 46 def destroy revoke if remote? if name != "default" log(destroy: true) do unless Fog::Bouncer.pretending? remote.destroy @remote = nil end end else log(destroy: false) end end end |
#exceeded? ⇒ Boolean
Public: Check if it has exceeded the 100 rules limit per group on AWS,
http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using-network-security.html.
Examples
exceeded?
# => false
Returns a Boolean
71 72 73 |
# File 'lib/fog/bouncer/group.rb', line 71 def exceeded? .size > 100 end |
#extra_remote_sources ⇒ Object
75 76 77 |
# File 'lib/fog/bouncer/group.rb', line 75 def extra_remote_sources sources.select { |source| !source.local? && source.remote? } end |
#inspect ⇒ Object
127 128 129 |
# File 'lib/fog/bouncer/group.rb', line 127 def inspect "<#{self.class.name} @name=#{name.inspect} @description=#{description.inspect} @local=#{local} @remote=#{remote} @sources=#{sources.inspect}>" end |
#local? ⇒ Boolean
79 80 81 |
# File 'lib/fog/bouncer/group.rb', line 79 def local? !!local end |
#log(data, &block) ⇒ Object
11 12 13 |
# File 'lib/fog/bouncer/group.rb', line 11 def log(data, &block) self.class.log({ name: name }.merge(data), &block) end |
#missing_remote_sources ⇒ Object
83 84 85 |
# File 'lib/fog/bouncer/group.rb', line 83 def missing_remote_sources sources.select { |source| source.local? && !source.remote? } end |
#remote? ⇒ Boolean
87 88 89 |
# File 'lib/fog/bouncer/group.rb', line 87 def remote? !remote.nil? end |
#revoke ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fog/bouncer/group.rb', line 91 def revoke = sources.map do |source| source.protocols.select { |p| p.remote? } end.flatten.compact if remote? && .any? log(revoke: true) do remote.connection.revoke_security_group_ingress(name, "IpPermissions" => IPPermissions.from()) unless Fog::Bouncer.pretending? .each do |protocol| log({revoked: true}.merge(protocol.to_log)) protocol.source.protocols.delete_if { |p| p == protocol } unless Fog::Bouncer.pretending? end end end end |
#sources ⇒ Object
107 108 109 |
# File 'lib/fog/bouncer/group.rb', line 107 def sources @sources ||= [] end |
#sync ⇒ Object
111 112 113 114 115 116 |
# File 'lib/fog/bouncer/group.rb', line 111 def sync log(sync: true) do create_missing_remote synchronize_sources end end |
#use(name) ⇒ Object
118 119 120 |
# File 'lib/fog/bouncer/group.rb', line 118 def use(name) @using << security.definitions(name) end |