Class: Akashi::Vpc::SecurityGroup::Base

Inherits:
Base show all
Defined in:
lib/akashi/vpc/security_group/base.rb

Direct Known Subclasses

Elb, Gateway, Rds, Web

Class Method Summary collapse

Methods inherited from Ec2::Base

#name, #name=, service_class

Methods inherited from Base

base_class, collection, find, find_by, #initialize, where

Constructor Details

This class inherits a constructor from Akashi::Base

Class Method Details

.allObject



8
9
10
# File 'lib/akashi/vpc/security_group/base.rb', line 8

def all
  super.select { |security_group| security_group.name.end_with?("-#{role}") }
end

.create(vpc:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/akashi/vpc/security_group/base.rb', line 12

def create(vpc:)
  response = Akashi::Aws.ec2.client.create_security_group(
    vpc_id:      vpc.id,
    group_name:  name,
    description: name,
  )

  new(response[:group_id]).tap do |instance|
    ingress_ip_permissions.each do |ip_permission|
      instance.authorize_ingress(
        ip_permission[:protocol],
        ip_permission[:port],
        *ip_permission[:sources],
      )
    end
    instance.name = name
    puts "Created a SecurityGroup (#{instance.id}) whose role is \"#{role}\"."
  end
end

.nameObject



32
33
34
# File 'lib/akashi/vpc/security_group/base.rb', line 32

def name
  "#{Akashi.name}-#{role}"
end

.object_classObject



40
41
42
# File 'lib/akashi/vpc/security_group/base.rb', line 40

def object_class
  @object_class ||= "SecurityGroup"
end

.roleObject



36
37
38
# File 'lib/akashi/vpc/security_group/base.rb', line 36

def role
  self.to_s.demodulize.underscore.dasherize
end