Class: Serverspec::Type::AWS::EC2::SecurityGroup
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::AWS::EC2::SecurityGroup
- Defined in:
- lib/resources/ec2/security_group.rb
Overview
The SecurityGroup class exposes the EC2::SecurityGroup resources
Instance Method Summary collapse
-
#accessible_from?(cidr_s) ⇒ Boolean
Do the security group rules permit connections from the given CIDR range? Returns true iff there is an ingress rule with a source that contains the given CIDR range.
-
#description ⇒ String
A description of the security group.
-
#egress_permissions ⇒ Array(Hash)
- EC2-VPC
-
One or more outbound rules associated with the security group.
-
#group_name ⇒ String
The name of the security group.
-
#ingress_permissions ⇒ Array(Hash)
One or more inbound rules associated with the security group.
-
#initialize(sg_id, instance = nil) ⇒ SecurityGroup
constructor
AWS SDK for Ruby v2 Aws::EC2::Client wrapper for initializing a SecurityGroup resource.
-
#owner_id ⇒ String
The AWS account ID of the owner of the security group.
-
#tags ⇒ Array(Hash)
Any tags assigned to the security group.
-
#to_s ⇒ String
Returns the string representation of EC2::SecurityGroup.
-
#vpc_id ⇒ String
- EC2-VPC
-
The ID of the VPC for the security group.
Constructor Details
#initialize(sg_id, instance = nil) ⇒ SecurityGroup
AWS SDK for Ruby v2 Aws::EC2::Client wrapper for initializing a SecurityGroup resource
17 18 19 20 21 22 |
# File 'lib/resources/ec2/security_group.rb', line 17 def initialize(sg_id, instance = nil) check_init_arg 'sg_id', 'EC2::SecurityGroup', sg_id @sg_id = sg_id @aws = instance.nil? ? Aws::EC2::Client.new : instance get_security_group sg_id end |
Instance Method Details
#accessible_from?(cidr_s) ⇒ Boolean
Do the security group rules permit connections from the given CIDR range? Returns true iff there is an ingress rule with a source that contains the given CIDR range.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/resources/ec2/security_group.rb', line 79 def accessible_from?(cidr_s) return false if .empty? cidr = NetAddr::CIDR.create(cidr_s) allowed_cidrs = .map(&:ip_ranges) .flatten.map(&:cidr_ip) matching_rules = allowed_cidrs.map do |source_cidr| cidr == source_cidr || cidr.is_contained?(source_cidr) end matching_rules.include? true end |
#description ⇒ String
A description of the security group
44 45 46 |
# File 'lib/resources/ec2/security_group.rb', line 44 def description @sg.description end |
#egress_permissions ⇒ Array(Hash)
- EC2-VPC
-
One or more outbound rules associated with the security
group
57 58 59 |
# File 'lib/resources/ec2/security_group.rb', line 57 def @sg. end |
#group_name ⇒ String
The name of the security group
38 39 40 |
# File 'lib/resources/ec2/security_group.rb', line 38 def group_name @sg.group_name end |
#ingress_permissions ⇒ Array(Hash)
One or more inbound rules associated with the security group
50 51 52 |
# File 'lib/resources/ec2/security_group.rb', line 50 def @sg. end |
#owner_id ⇒ String
The AWS account ID of the owner of the security group
32 33 34 |
# File 'lib/resources/ec2/security_group.rb', line 32 def owner_id @sg.owner_id end |
#tags ⇒ Array(Hash)
Any tags assigned to the security group
69 70 71 |
# File 'lib/resources/ec2/security_group.rb', line 69 def @sg. end |
#to_s ⇒ String
Returns the string representation of EC2::SecurityGroup
26 27 28 |
# File 'lib/resources/ec2/security_group.rb', line 26 def to_s "EC2 SecurityGroup: #{@sg_id}" end |
#vpc_id ⇒ String
- EC2-VPC
-
The ID of the VPC for the security group
63 64 65 |
# File 'lib/resources/ec2/security_group.rb', line 63 def vpc_id @sg.vpc_id end |