Class: ConsulBridge::DownloadMasters

Inherits:
Base
  • Object
show all
Defined in:
lib/consul_bridge/download_masters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

call

Constructor Details

#initialize(bucket:) ⇒ DownloadMasters

Returns a new instance of DownloadMasters.



8
9
10
# File 'lib/consul_bridge/download_masters.rb', line 8

def initialize(bucket:)
  self.bucket = bucket
end

Instance Attribute Details

#bucketObject

Returns the value of attribute bucket.



6
7
8
# File 'lib/consul_bridge/download_masters.rb', line 6

def bucket
  @bucket
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/consul_bridge/download_masters.rb', line 12

def call
  puts "Downloading master ips from bucket #{self.bucket}"

  master_ips = []

  storage = Fog::Storage.new provider: 'AWS', use_iam_profile: true
  bucket = storage.directories.get(self.bucket)
  bucket.files.each do |file|
    master_ips << [file.last_modified, file.key]
  end
  master_ips = master_ips.sort.reverse.collect { |file| file[1] }

  OpenStruct.new(
    master_ips: master_ips
  )
end