Class: Awshark::Ec2::SecurityRule
- Inherits:
-
Object
- Object
- Awshark::Ec2::SecurityRule
- Defined in:
- lib/awshark/ec2/security_rule.rb
Instance Attribute Summary collapse
-
#from_port ⇒ Object
readonly
Returns the value of attribute from_port.
-
#ip_protocol ⇒ Object
readonly
Returns the value of attribute ip_protocol.
-
#ip_ranges ⇒ Object
readonly
Returns the value of attribute ip_ranges.
-
#to_port ⇒ Object
readonly
Returns the value of attribute to_port.
Instance Method Summary collapse
- #cidr_ip ⇒ Object
- #description ⇒ Object
-
#initialize(args) ⇒ SecurityRule
constructor
A new instance of SecurityRule.
- #to_hash ⇒ Object
Constructor Details
#initialize(args) ⇒ SecurityRule
Returns a new instance of SecurityRule.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/awshark/ec2/security_rule.rb', line 8 def initialize(args) if args.is_a?(Aws::EC2::Types::IpPermission) @ip_protocol = args.ip_protocol @ip_ranges = args.ip_ranges @from_port = args.from_port @to_port = args.to_port else ip = args.fetch(:ip) description = args.fetch(:description) @ip_protocol = args.fetch(:ip_protocol, 'tcp') @ip_ranges = [OpenStruct.new({ cidr_ip: "#{ip}/32", description: description })] @from_port = args.fetch(:from_port) @to_port = args.fetch(:to_port) end end |
Instance Attribute Details
#from_port ⇒ Object (readonly)
Returns the value of attribute from_port.
6 7 8 |
# File 'lib/awshark/ec2/security_rule.rb', line 6 def from_port @from_port end |
#ip_protocol ⇒ Object (readonly)
Returns the value of attribute ip_protocol.
6 7 8 |
# File 'lib/awshark/ec2/security_rule.rb', line 6 def ip_protocol @ip_protocol end |
#ip_ranges ⇒ Object (readonly)
Returns the value of attribute ip_ranges.
6 7 8 |
# File 'lib/awshark/ec2/security_rule.rb', line 6 def ip_ranges @ip_ranges end |
#to_port ⇒ Object (readonly)
Returns the value of attribute to_port.
6 7 8 |
# File 'lib/awshark/ec2/security_rule.rb', line 6 def to_port @to_port end |
Instance Method Details
#cidr_ip ⇒ Object
24 25 26 |
# File 'lib/awshark/ec2/security_rule.rb', line 24 def cidr_ip ip_ranges[0].cidr_ip end |
#description ⇒ Object
28 29 30 |
# File 'lib/awshark/ec2/security_rule.rb', line 28 def description ip_ranges[0].description end |
#to_hash ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/awshark/ec2/security_rule.rb', line 32 def to_hash { ip_protocol: ip_protocol, from_port: from_port, to_port: to_port, ip_ranges: ip_ranges.map(&:to_h) } end |