Sha256: 268441f4dbb20661cc7a7b908aa92d48788ce0e80d83e72b7288049f05a06989

Contents?: true

Size: 925 Bytes

Versions: 1

Compression:

Stored size: 925 Bytes

Contents

require 'metaractor'
require 'fog/aws'
require 'fog/local' if ENV['FOG_LOCAL']

module ConsulBridge
  class DownloadMasters
    include Metaractor

    required :bucket

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

      master_ips = []

      bucket = nil
      if ENV['FOG_LOCAL']
        puts 'Using fog local storage'
        storage = Fog::Storage.new provider: 'Local', local_root: '/fog'
        bucket = storage.directories.create(key: bucket_name)
      else
        storage = Fog::Storage.new provider: 'AWS', use_iam_profile: true
        bucket = storage.directories.get(bucket_name)
      end

      bucket.files.each do |file|
        master_ips << [file.last_modified, file.key]
      end
      master_ips = master_ips.sort.reverse.collect { |file| file[1] }

      context.master_ips = master_ips
    end

    private
    def bucket_name
      context.bucket
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
consul_bridge-0.1.5 lib/consul_bridge/download_masters.rb