f2s3 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/f2s3 +56 -0
- data/lib/f2s3.rb +6 -0
- data/lib/f2s3/uploader.rb +16 -0
- data/lib/f2s3/version.rb +3 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07bdd17d6d67e60d2c5bcea13971cfdee53737a4
|
4
|
+
data.tar.gz: 2e308719d51e5df6c1651107a38c2d343d764c6f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 000c5bce2ac86b9cca8c0b1872e3125608554a0bb23fe95da3e140ad60bccbb63a3c14cb069c72fcb4ea22e0b9f8df377f2a0fa917975ab098240e389026aa50
|
7
|
+
data.tar.gz: fed7c5c54b7c1ea26ce5c24e58686f9d870bdfce9e53154670ee07eed36e18a7359c88d5695442da0b1083f04bce7279c21c67accb4943fe72848b66cdeb7484
|
data/bin/f2s3
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'trollop'
|
4
|
+
require 'dotenv'
|
5
|
+
require_relative '../lib/f2s3'
|
6
|
+
|
7
|
+
class BucketPath
|
8
|
+
def self.build_from_opts(opts)
|
9
|
+
path_builder = new(opts)
|
10
|
+
path_builder.path
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(opts)
|
14
|
+
@s3_file_name = opts[:s3_file_name]
|
15
|
+
@bucket_path = opts[:bucket_path]
|
16
|
+
end
|
17
|
+
|
18
|
+
def path
|
19
|
+
ends_in_slash = @bucket_path[-1] == '/'
|
20
|
+
path = @bucket_path + (ends_in_slash ? '' : '/')
|
21
|
+
file = @s3_file_name.to_s
|
22
|
+
@path = path + file
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
opts = Trollop.options do
|
27
|
+
version "F2S3 version #{F2S3::VERSION}, (c) 2016 Cooper Lebrun"
|
28
|
+
banner <<-EOS
|
29
|
+
Upload a file to S3 in easy mode. If you need to upload multiple files,
|
30
|
+
let me know and I'll add it in. I don't use this for more than single file
|
31
|
+
upload so, until it's demonstrated that any other use case will touch this,
|
32
|
+
I'll just be a bit lazy.
|
33
|
+
EOS
|
34
|
+
# opt :flag, "description"
|
35
|
+
# TODO: make mnemonic short options
|
36
|
+
opt :products, 'JSON products path. required.', type: :string
|
37
|
+
opt :bucket_name, 'Name of the bucket. required.', type: :string
|
38
|
+
opt :bucket_path, 'Bucket path. required.', type: :string
|
39
|
+
opt :s3_file_name, 'the filename you want on S3', type: :string
|
40
|
+
opt :dotenv_file, 'location of your S3 credentials, in .env form',
|
41
|
+
type: :string, default: '.env'
|
42
|
+
end
|
43
|
+
|
44
|
+
Trollop.die :products, 'is required' unless opts[:products]
|
45
|
+
Trollop.die :products, 'must be a valid file' unless opts[:products_given] && File.exist?(opts[:products])
|
46
|
+
Trollop.die :bucket_name, 'is required' unless opts[:bucket_name_given]
|
47
|
+
Trollop.die :bucket_path, 'is required' unless opts[:bucket_path_given]
|
48
|
+
|
49
|
+
Dotenv.load(opts[:dotenv_file])
|
50
|
+
file_name = opts[:products]
|
51
|
+
|
52
|
+
bucket_path = BucketPath.build_from_opts(opts)
|
53
|
+
|
54
|
+
client = F2S3::Uploader.new(opts[:bucket_name])
|
55
|
+
client.upload_file(file_name, bucket_path)
|
56
|
+
|
data/lib/f2s3.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module F2S3
|
4
|
+
class Uploader
|
5
|
+
def initialize(bucket_name)
|
6
|
+
@s3 = Aws::S3::Resource.new
|
7
|
+
@bucket = @s3.bucket(bucket_name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def upload_file(file_name, bucket_path)
|
11
|
+
@bucket.object(bucket_path)
|
12
|
+
.upload_file(file_name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/lib/f2s3/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: f2s3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cooper LeBrun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
description: Simple file upload to an s3 bucket.
|
28
|
+
email:
|
29
|
+
- cooperlebrun@gmail.com
|
30
|
+
executables:
|
31
|
+
- f2s3
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- bin/f2s3
|
36
|
+
- lib/f2s3.rb
|
37
|
+
- lib/f2s3/uploader.rb
|
38
|
+
- lib/f2s3/version.rb
|
39
|
+
homepage: https://github.com/aokpower/f2s3
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.6.4
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Simple file upload to an s3 bucket.
|
63
|
+
test_files: []
|
64
|
+
has_rdoc:
|