Class: Banacle::AwsWrapper::Nacl

Inherits:
Object
  • Object
show all
Defined in:
lib/banacle/aws_wrapper/nacl.rb

Defined Under Namespace

Classes: EntryDuplicatedError, EntryNotFoundError, Result

Constant Summary collapse

DEFAULT_RULE_NUMBER =
100

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region, vpc_id, cidr_blocks) ⇒ Nacl

Returns a new instance of Nacl.



22
23
24
25
26
27
# File 'lib/banacle/aws_wrapper/nacl.rb', line 22

def initialize(region, vpc_id, cidr_blocks)
  @region = region
  @vpc_id = vpc_id
  @cidr_blocks = cidr_blocks
  @rule_numbers = ingress_rules.map(&:rule_number).sort
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



29
30
31
# File 'lib/banacle/aws_wrapper/nacl.rb', line 29

def action
  @action
end

#cidr_blocksObject (readonly)

Returns the value of attribute cidr_blocks.



29
30
31
# File 'lib/banacle/aws_wrapper/nacl.rb', line 29

def cidr_blocks
  @cidr_blocks
end

#regionObject (readonly)

Returns the value of attribute region.



29
30
31
# File 'lib/banacle/aws_wrapper/nacl.rb', line 29

def region
  @region
end

#rule_numbersObject

Returns the value of attribute rule_numbers.



30
31
32
# File 'lib/banacle/aws_wrapper/nacl.rb', line 30

def rule_numbers
  @rule_numbers
end

#vpc_idObject (readonly)

Returns the value of attribute vpc_id.



29
30
31
# File 'lib/banacle/aws_wrapper/nacl.rb', line 29

def vpc_id
  @vpc_id
end

Class Method Details

.create_network_acl_ingress_entries(region:, vpc_id:, cidr_blocks:) ⇒ Object



14
15
16
# File 'lib/banacle/aws_wrapper/nacl.rb', line 14

def self.create_network_acl_ingress_entries(region:, vpc_id:, cidr_blocks:)
  new(region, vpc_id, cidr_blocks).create_network_acl_ingress_entries
end

.delete_network_acl_entries(region:, vpc_id:, cidr_blocks:) ⇒ Object



18
19
20
# File 'lib/banacle/aws_wrapper/nacl.rb', line 18

def self.delete_network_acl_entries(region:, vpc_id:, cidr_blocks:)
  new(region, vpc_id, cidr_blocks).delete_network_acl_entries
end

Instance Method Details

#create_network_acl_ingress_entriesObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/banacle/aws_wrapper/nacl.rb', line 32

def create_network_acl_ingress_entries
  cidr_blocks.map do |cidr_block|
    begin
      rule_number = create_network_acl_ingress_entry(cidr_block)
      Result.new(cidr_block: cidr_block, status: true, rule_number: rule_number)
    rescue AwsWrapper::Error => e
      Result.new(cidr_block: cidr_block, status: false, error: e)
    end
  end
end

#delete_network_acl_entriesObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/banacle/aws_wrapper/nacl.rb', line 43

def delete_network_acl_entries
  cidr_blocks.map do |cidr_block|
    begin
      rule_number = delete_network_acl_entry(cidr_block)
      Result.new(cidr_block: cidr_block, status: true, rule_number: rule_number)
    rescue AwsWrapper::Error => e
      Result.new(cidr_block: cidr_block, status: false, error: e)
    end
  end
end