Class: Chef::Knife::S3Upload

Inherits:
S3Base show all
Defined in:
lib/chef/knife/s3_upload.rb

Instance Method Summary collapse

Methods inherited from S3Base

#connection, included, #locate_config_value, #msg_pair, #validate!

Instance Method Details

#runObject



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
73
74
75
76
77
# 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