Class: Chef::Knife::S3Download
- Inherits:
-
S3Base
- Object
- Chef::Knife
- S3Base
- Chef::Knife::S3Download
- Defined in:
- lib/chef/knife/s3_download.rb
Instance Method Summary collapse
Methods inherited from S3Base
#connection, included, #locate_config_value, #msg_pair, #validate!
Instance Method Details
#run ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/chef/knife/s3_download.rb', line 38 def run $stdout.sync = true validate! if config[:bucket].nil? puts "No bucket specified" exit 1 end if config[:pathname].nil? puts "No path specified" exit 1 end if config[:localfile].nil? config[:localfile] = config[:pathname] #TODO: should strip "directory" elements from the path? end if File.exists?(config[:localfile]) and config[:overwrite].nil? print config[:localfile] + " exists. Overwrite (y/n)? " ans=$stdin.gets if !ans.match(/^y/i) puts "Not overwriting, exiting" exit 0 end end begin remote_file = connection.directories.get(config[:bucket]).files.get(config[:pathname]) local_file = File.open(config[:localfile],'w') local_file.write(remote_file.body) end end |