class Chef::Knife::S3Upload

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/s3_upload.rb, line 38
def run
  $stdout.sync = true

  validate!

  public = false

  if config[:bucket].nil?
    puts "No bucket specified"
    exit 1
  end

  if config[:localfile].nil?
    puts "No file specified"
    exit 1
  end

  if !File.exists?(config[:localfile])
    puts "file '" + config[:localfile] + "' does not exist"
    exit 1
  end

  if config[:pathname].nil?
    puts "No remote path specified. Uploading as " + config[:localfile]
    config[:pathname] = config[:localfile]
  end

  if !config[:is_public].nil?
    public = true
  end

  begin
    remote_file = connection.directories.get(config[:bucket]).files.create(
        :key  => config[:pathname],
        :body => File.open(config[:localfile]),
        :public => public
    )
  end

end