aws3upload 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/aws3upload +26 -7
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8693e820060909b497dedde0e823882e9098ed0b
4
- data.tar.gz: 66fa2810cdd0b11dda672a99691144bc661eed8a
3
+ metadata.gz: a6169f8f558b4aff0381f5a26e74cf68fec0bcfb
4
+ data.tar.gz: d60dac73ada01c1291505906dc1341e229405e11
5
5
  SHA512:
6
- metadata.gz: 78ca2d5a6321377931ce8740ce116ddb6d2eb1758faab4e3b309d32b0b86093313f9b172443a681267ce3aede24981bfab3d2835292001de05d26391d764be47
7
- data.tar.gz: f352dd43a23ffb3b360560bafedd825c7c7e3fa7c2beecc426be9f4693b1fb0725e08c0f2cf75a81ef0659064aaf3248acbb6b9060ffd39f7af56fd8f172db72
6
+ metadata.gz: a2ca097c97a7d95f0d284b748de022474be5e3e6a33da2b9da6df6f0c50e6a1a6433bffb2d8b4558d0105c0d63abceb4d82bd3d6371206a3bbe12ef313647bb4
7
+ data.tar.gz: 59d310f7033179fc80da36c748c476aad25de7671398a0375d3896330127369cf61ba794ef32540a5484ce1ba7943fb2c00c3ad383a6294417f565220d428d1f
data/bin/aws3upload CHANGED
@@ -1,13 +1,32 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'aws-sdk'
3
+ require 'optparse'
3
4
 
4
- bucket = ENV['AWS_S3_BUCKET']
5
- source = File.absolute_path(ARGV[0])
6
- target = ARGV[1]
5
+ options = {}
6
+ OptionParser.new do |opts|
7
+ opts.banner = "Usage: aws3upload [OPTIONS] SOURCE DEST"
8
+ opts.on('-t', '--tags KEY=VALUE,...', Array, 'Add s3 tags for object') do |tags|
9
+ options[:tags] = tags.map { |i|
10
+ i.split('=')
11
+ }.to_h.map { |k,v| {key: k, value: v} }
12
+ end
13
+ end.parse!
14
+
15
+ bucket = ENV['AWS_S3_BUCKET']
16
+ source = ARGV.shift
17
+ target = ARGV.shift
18
+
19
+ raise "Missing AWS_S3_BUCKET env variable" unless bucket
20
+ raise "Missing DEST argument" unless target
21
+ raise "Missing SOURCE argument" unless source
7
22
 
8
23
  puts "Copy #{source} to #{bucket}:::#{target}"
9
24
 
10
- s3 = Aws::S3::Resource.new
11
- name = File.basename(source)
12
- obj = s3.bucket(bucket).object(target)
13
- obj.upload_file(source)
25
+ s3 = Aws::S3::Client.new
26
+ File.open(source,'rb') do |file|
27
+ s3.put_object(bucket: bucket, key: target, body: file)
28
+ end
29
+
30
+ if options[:tags]
31
+ s3.put_object_tagging({bucket: bucket, key: target, tagging:{ tag_set: options[:tags] } })
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws3upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Shmelev