Class: AmiSpec::AwsSecurityGroup

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ami_spec/aws_security_group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ec2: Aws::EC2::Resource.new, group_name_prefix: "ami-spec-", connection_port: 22, subnet_id:, allow_any_ip: false, logger: Logger.new(STDOUT)) ⇒ AwsSecurityGroup

Returns a new instance of AwsSecurityGroup.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ami_spec/aws_security_group.rb', line 13

def initialize(ec2: Aws::EC2::Resource.new,
               group_name_prefix: "ami-spec-",
               connection_port: 22,
               subnet_id:,
               allow_any_ip: false,
               logger: Logger.new(STDOUT))
  @ec2 = ec2
  @group_name = "#{group_name_prefix}#{SecureRandom.uuid}"
  @connection_port = connection_port
  @subnet_id = subnet_id
  @allow_any_ip = allow_any_ip
  @logger = logger
end

Instance Attribute Details

#group_nameObject (readonly)

Returns the value of attribute group_name.



28
29
30
# File 'lib/ami_spec/aws_security_group.rb', line 28

def group_name
  @group_name
end

Class Method Details

.create(**args) ⇒ Object



9
10
11
# File 'lib/ami_spec/aws_security_group.rb', line 9

def self.create(**args)
  new(**args).tap(&:create)
end

Instance Method Details

#createObject



30
31
32
33
34
# File 'lib/ami_spec/aws_security_group.rb', line 30

def create
  @logger.info "Creating temporary AWS security group: #{@group_name}"
  create_security_group
  allow_ingress_via_connection_port
end

#deleteObject



36
37
38
39
# File 'lib/ami_spec/aws_security_group.rb', line 36

def delete
  @logger.info "Deleting temporary AWS security group: #{@group_name}"
  @security_group.delete
end