10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/commands/s3up.rb', line 10
def execute
opt_hash = {}
v_opts = OptionParser.new do |opts|
opts.banner = 'Usage: vagrant s3up BOX S3_BUCKET. Example: vagrant s3up testing.box livefyre-vagrant-boxes'
end
argv = parse_options(v_opts)
unless argv && argv.size == 2
@env.ui.error "Need BOX and/or S3_BUCKET argument. See -h for details"
return 1
end
box_file = argv[0]
bucket_name = argv[1]
begin
aws_creds = YAML.load_file("#{ENV['HOME']}/.s3_keys")
rescue Exception => e
@env.ui.error "You need a valid .s3_keys yaml file in your HOME dir, currently using: #{ENV['HOME']} as HOME path See README for details"
return 1
end
unless File.extname(box_file) == '.box'
@env.ui.error "Only box extension files allowed for upload. See -h for details"
return 1
end
AWS::S3::Base.establish_connection!(aws_creds)
s3_boxes = AWS::S3::Bucket.find(bucket_name)
AWS::S3::S3Object.store(box_file, open(box_file), bucket_name)
@env.ui.info "File: #{box_file} uploaded to Bucket: #{s3_boxes.name}"
end
|