Class: Awspec::Type::SecurityGroup
- Defined in:
- lib/awspec/type/security_group.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#inbound ⇒ Object
readonly
Returns the value of attribute inbound.
-
#sg ⇒ Object
readonly
Returns the value of attribute sg.
Attributes inherited from Base
Instance Method Summary collapse
- #inbound_opened?(port = nil, protocol = nil, cidr = nil) ⇒ Boolean
-
#initialize(id) ⇒ SecurityGroup
constructor
A new instance of SecurityGroup.
- #method_missing(name) ⇒ Object
- #opened?(port = nil, protocol = nil, cidr = nil) ⇒ Boolean
- #outbound ⇒ Object
- #outbound_opened?(port = nil, protocol = nil, cidr = nil) ⇒ Boolean
Methods inherited from Base
#find_network_acl, #find_route_table, #find_security_group, #find_vpc
Constructor Details
#initialize(id) ⇒ SecurityGroup
Returns a new instance of SecurityGroup.
5 6 7 8 9 10 11 |
# File 'lib/awspec/type/security_group.rb', line 5 def initialize(id) super @client = @ec2_client @inbound = true @sg = find_security_group(id) @id = @sg[:group_id] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/awspec/type/security_group.rb', line 13 def method_missing(name) describe = name.to_s if @sg.key?(describe) @sg[describe] else super end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/awspec/type/security_group.rb', line 3 def client @client end |
#inbound ⇒ Object (readonly)
Returns the value of attribute inbound.
3 4 5 |
# File 'lib/awspec/type/security_group.rb', line 3 def inbound @inbound end |
#sg ⇒ Object (readonly)
Returns the value of attribute sg.
3 4 5 |
# File 'lib/awspec/type/security_group.rb', line 3 def sg @sg end |
Instance Method Details
#inbound_opened?(port = nil, protocol = nil, cidr = nil) ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/awspec/type/security_group.rb', line 30 def inbound_opened?(port = nil, protocol = nil, cidr = nil) @sg[:ip_permissions].find do || next true unless port next true unless [:from_port] next true unless [:to_port] next false unless port.between?([:from_port], [:to_port]) next false if protocol && [:ip_protocol] != protocol next true unless cidr ret = [:ip_ranges].select do |ip_range| ip_range[:cidr_ip] == cidr end next true if ret.count > 0 ret = [:user_id_group_pairs].select do |sg| next true if sg[:group_id] == cidr sg2 = find_security_group(sg[:group_id]) next true if sg2[:group_name] == cidr sg2[:tags].find do |tag| tag[:key] == 'Name' && tag[:value] == cidr end end next true if ret.count > 0 end end |
#opened?(port = nil, protocol = nil, cidr = nil) ⇒ Boolean
22 23 24 25 26 27 28 |
# File 'lib/awspec/type/security_group.rb', line 22 def opened?(port = nil, protocol = nil, cidr = nil) if @inbound return inbound_opened?(port, protocol, cidr) else return outbound_opened?(port, protocol, cidr) end end |
#outbound ⇒ Object
83 84 85 86 |
# File 'lib/awspec/type/security_group.rb', line 83 def outbound @inbound = false self end |
#outbound_opened?(port = nil, protocol = nil, cidr = nil) ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/awspec/type/security_group.rb', line 54 def outbound_opened?(port = nil, protocol = nil, cidr = nil) @sg[:ip_permissions_egress].find do || next true unless port next true unless [:from_port] next true unless [:to_port] next false unless port.between?([:from_port], [:to_port]) next false if protocol && [:ip_protocol] != protocol next true unless cidr ret = [:ip_ranges].select do |ip_range| ip_range[:cidr_ip] == cidr end next true if ret.count > 0 ret = [:user_id_group_pairs].select do |sg| next true if sg[:group_id] == cidr sg2 = find_security_group(sg[:group_id]) next true if sg2[:group_name] == cidr sg2[:tags].find do |tag| tag[:key] == 'Name' && tag[:value] == cidr end end next true if ret.count > 0 end end |