lib/heirloom/artifact/artifact_downloader.rb in heirloom-0.1.3 vs lib/heirloom/artifact/artifact_downloader.rb in heirloom-0.1.4
- old
+ new
@@ -1,67 +1,49 @@
module Heirloom
class ArtifactDownloader
+ attr_accessor :config, :id, :name, :logger
+
def initialize(args)
- @config = args[:config]
- @logger = args[:logger]
+ self.config = args[:config]
+ self.name = args[:name]
+ self.id = args[:id]
+ self.logger = config.logger
end
def download(args)
- @id = args[:id]
- @name = args[:name]
- @output = args[:output]
- @region = args[:region]
+ region = args[:region]
- s3_downloader = Downloader::S3.new :config => @config,
- :logger => @logger,
- :region => @region
+ s3_downloader = Downloader::S3.new :config => config,
+ :logger => logger,
+ :region => region
- bucket = artifact_reader.get_bucket :region => @region,
- :name => @name,
- :id => @id
+ bucket = artifact_reader.get_bucket :region => region
+ key = artifact_reader.get_key :region => region
- key = artifact_reader.get_key :region => @region,
- :name => @name,
- :id => @id
+ logger.info "Downloading s3://#{bucket}/#{key} from #{region}."
- @logger.info "Downloading s3://#{bucket}/#{key} from #{@region}."
-
file = s3_downloader.download_file :bucket => bucket,
:key => key
- @logger.info "Writing file to #{@output}."
+ output = args[:output] ||= "./#{key.split('/').last}"
- File.open(@output, 'w') do |local_file|
+ logger.info "Writing file to #{output}."
+
+ File.open(output, 'w') do |local_file|
local_file.write file
end
+
+ logger.info "Download complete."
end
private
- def get_bucket
- artifact = artifact_reader.show :name => @name,
- :id => @id
-
- url = artifact["#{@region}-s3-url"].first
-
- bucket = url.gsub('s3://', '').split('/').first
- end
-
- def get_key
- artifact = artifact_reader.show :name => @name,
- :id => @id
-
- url = artifact["#{@region}-s3-url"].first
-
- bucket = url.gsub('s3://', '').gsub(get_bucket, '')
- bucket.slice!(0)
- bucket
- end
-
def artifact_reader
- @artifact_reader ||= ArtifactReader.new :config => @config
+ @artifact_reader ||= ArtifactReader.new :config => config,
+ :name => name,
+ :id => id
end
end
end