Class: Interferon::HostSources::AwsDynamo

Inherits:
Object
  • Object
show all
Defined in:
lib/interferon/host_sources/aws_dynamo.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AwsDynamo

Returns a new instance of AwsDynamo.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/interferon/host_sources/aws_dynamo.rb', line 5

def initialize(options)
  missing = %w(access_key_id secret_access_key).reject { |r| options.key?(r) }

  AWS.config(access_key_id: options['access_key_id'],
             secret_access_key: options['secret_access_key']) if missing.empty?

  # initialize a list of regions to check
  @regions = if options['regions'] && !options['regions'].empty?
               options['regions']
             else
               AWS.regions.map(&:name)
             end
end

Instance Method Details

#list_hostsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/interferon/host_sources/aws_dynamo.rb', line 19

def list_hosts
  hosts = []

  @regions.each do |region|
    client = AWS::DynamoDB.new(region: region)

    AWS.memoize do
      client.tables.each do |table|
        hosts << {
          source: 'aws_dynamo',
          region: region,
          table_name: table.name,

          read_capacity: table.read_capacity_units,
          write_capacity: table.write_capacity_units,

          # dynamodb does not support tagging
          owners: [],
          owner_groups: [],
        }
      end
    end
  end

  hosts
end