lobber 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +74 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +17 -0
- data/bin/lob +9 -0
- data/lib/lobber/cli.rb +31 -0
- data/lib/lobber/uploader.rb +96 -0
- data/lib/lobber/version.rb +3 -0
- data/lib/lobber.rb +10 -0
- data/lobber.gemspec +28 -0
- data/spec/lib/lobber/cli_spec.rb +72 -0
- data/spec/lib/lobber/uploader_spec.rb +171 -0
- data/spec/lib/lobber_spec.rb +31 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/matchers/exit_with_code.rb +21 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77cc787f9506dd4633bcbf40c6d788e31ebf02af
|
4
|
+
data.tar.gz: 4a9aec85ada3eb3751646750cc894a7bfda870ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ab9db1bae1c139f6abead67171a2aaf8e3c74f09f32f86e4173985600018eeb30369b1923b1a57a118c671c5f07525e72c031efa4c066bea94568d7e40cbe12a
|
7
|
+
data.tar.gz: b379a4c3dcb4507b61acd812dc5bbc28b848b42894f0cde1ce2c5c1cb582087037b97cdb253383ad989b0acde5ecb59b5808896dd8eeeafec79a3b97f1fcdbdc
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
lob
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lobber (0.0.2)
|
5
|
+
fog
|
6
|
+
thor
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
builder (3.2.2)
|
12
|
+
coderay (1.0.9)
|
13
|
+
diff-lcs (1.2.4)
|
14
|
+
excon (0.25.3)
|
15
|
+
ffi (1.9.0-java)
|
16
|
+
fog (1.15.0)
|
17
|
+
builder
|
18
|
+
excon (~> 0.25.0)
|
19
|
+
formatador (~> 0.2.0)
|
20
|
+
mime-types
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
net-scp (~> 1.1)
|
23
|
+
net-ssh (>= 2.1.3)
|
24
|
+
nokogiri (~> 1.5)
|
25
|
+
ruby-hmac
|
26
|
+
formatador (0.2.4)
|
27
|
+
method_source (0.8.2)
|
28
|
+
mime-types (1.25)
|
29
|
+
mini_portile (0.5.1)
|
30
|
+
multi_json (1.7.9)
|
31
|
+
net-scp (1.1.2)
|
32
|
+
net-ssh (>= 2.6.5)
|
33
|
+
net-ssh (2.6.8)
|
34
|
+
nokogiri (1.6.0)
|
35
|
+
mini_portile (~> 0.5.0)
|
36
|
+
pry (0.9.12.2)
|
37
|
+
coderay (~> 1.0.5)
|
38
|
+
method_source (~> 0.8)
|
39
|
+
slop (~> 3.4)
|
40
|
+
pry (0.9.12.2-java)
|
41
|
+
coderay (~> 1.0.5)
|
42
|
+
method_source (~> 0.8)
|
43
|
+
slop (~> 3.4)
|
44
|
+
spoon (~> 0.0)
|
45
|
+
rake (10.1.0)
|
46
|
+
rspec (2.14.1)
|
47
|
+
rspec-core (~> 2.14.0)
|
48
|
+
rspec-expectations (~> 2.14.0)
|
49
|
+
rspec-mocks (~> 2.14.0)
|
50
|
+
rspec-core (2.14.5)
|
51
|
+
rspec-expectations (2.14.2)
|
52
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
53
|
+
rspec-mocks (2.14.3)
|
54
|
+
ruby-hmac (0.4.0)
|
55
|
+
simplecov (0.7.1)
|
56
|
+
multi_json (~> 1.0)
|
57
|
+
simplecov-html (~> 0.7.1)
|
58
|
+
simplecov-html (0.7.1)
|
59
|
+
slop (3.4.6)
|
60
|
+
spoon (0.0.4)
|
61
|
+
ffi
|
62
|
+
thor (0.18.1)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
java
|
66
|
+
ruby
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
bundler (~> 1.3)
|
70
|
+
lobber!
|
71
|
+
pry
|
72
|
+
rake
|
73
|
+
rspec
|
74
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mike Ball
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/mdb/lobber.png?branch=master)](https://travis-ci.org/mdb/lobber)
|
2
|
+
|
3
|
+
# Lobber
|
4
|
+
|
5
|
+
Quickly toss a directory to Amazon S3 from the command line.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
git clone https://github.com/mdb/lobber
|
10
|
+
cd lobber
|
11
|
+
rake install
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
lob some_directory
|
16
|
+
|
17
|
+
Or pass in a bucket name to substitute your $FOG_DIRECTORY env variable:
|
18
|
+
|
19
|
+
lob some_directory --bucket some_aws_bucket
|
20
|
+
|
21
|
+
## Required Environment Variables
|
22
|
+
|
23
|
+
* AWS_ACCESS_KEY=your_aws_access_key
|
24
|
+
* AWS_SECRET_KEY=your_aws_secret_key
|
25
|
+
* FOG_DIRECTORY=some_aws_bucket
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
Rake::RDocTask.new do |rdoc|
|
11
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
12
|
+
|
13
|
+
rdoc.rdoc_dir = 'rdoc'
|
14
|
+
rdoc.title = "lobber #{version}"
|
15
|
+
rdoc.rdoc_files.include('README*')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
data/bin/lob
ADDED
data/lib/lobber/cli.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Lobber
|
4
|
+
class CLI < Thor
|
5
|
+
default_task :lob
|
6
|
+
|
7
|
+
desc "DIRECTORY", "Upload a directory to Amazon S3"
|
8
|
+
option :bucket
|
9
|
+
def lob(directory = nil)
|
10
|
+
return usage unless directory
|
11
|
+
|
12
|
+
unless File.directory? directory
|
13
|
+
error "#{directory} is not a valid directory"
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
Lobber.upload(directory, options[:bucket])
|
18
|
+
|
19
|
+
say "Successfully uploaded #{directory}", "\033[32m"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "usage", "Display usage banner", hide: true
|
23
|
+
def usage
|
24
|
+
say "Lobber #{Lobber::VERSION}"
|
25
|
+
say "https://github.com/mdb/lob"
|
26
|
+
say "\n"
|
27
|
+
|
28
|
+
help
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'fog'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
module Lobber
|
5
|
+
class Uploader
|
6
|
+
attr_reader :directory, :bucket_name
|
7
|
+
|
8
|
+
def initialize(directory, bucket_name = nil)
|
9
|
+
@bucket_name = bucket_name
|
10
|
+
@directory = sanitize(directory)
|
11
|
+
end
|
12
|
+
|
13
|
+
def upload
|
14
|
+
verify_env_variables
|
15
|
+
directory_content.each do |file, value|
|
16
|
+
create_file_or_directory(file, value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def directory_content
|
21
|
+
hash = {}
|
22
|
+
|
23
|
+
Rake::FileList["#{directory}/**/*"].each do |path|
|
24
|
+
if File.directory?(path)
|
25
|
+
hash["#{path}/"] = :directory
|
26
|
+
else
|
27
|
+
hash[path] = File.read(path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
hash
|
32
|
+
end
|
33
|
+
|
34
|
+
def bucket
|
35
|
+
@bucket ||= s3.directories.create(key: fog_directory, public: true)
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_file_or_directory(file_or_directory, directory_flag)
|
39
|
+
if directory_flag == :directory
|
40
|
+
create_directory file_or_directory
|
41
|
+
else
|
42
|
+
create_file file_or_directory
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_directory directory
|
47
|
+
bucket.files.create(key: directory, public: true)
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_file file
|
51
|
+
bucket.files.create(key: file, public: true, body: File.open(file))
|
52
|
+
end
|
53
|
+
|
54
|
+
def s3
|
55
|
+
@s3 ||= Fog::Storage.new(
|
56
|
+
provider: :aws,
|
57
|
+
aws_access_key_id: aws_access_key,
|
58
|
+
aws_secret_access_key: aws_secret_key
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def verify_env_variables
|
63
|
+
missing = []
|
64
|
+
|
65
|
+
missing << 'AWS_ACCESS_KEY' unless aws_access_key
|
66
|
+
missing << 'AWS_SECRET_KEY' unless aws_secret_key
|
67
|
+
missing << 'FOG_DIRECTORY' unless fog_directory
|
68
|
+
|
69
|
+
return true if missing.empty?
|
70
|
+
|
71
|
+
raise "Required environment variables missing: #{missing.inspect}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def aws_access_key
|
75
|
+
ENV['AWS_ACCESS_KEY']
|
76
|
+
end
|
77
|
+
|
78
|
+
def aws_secret_key
|
79
|
+
ENV['AWS_SECRET_KEY']
|
80
|
+
end
|
81
|
+
|
82
|
+
def fog_directory
|
83
|
+
@bucket_name || ENV['FOG_DIRECTORY']
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def sanitize(directory_path)
|
89
|
+
if directory_path.match(/\/$/)
|
90
|
+
directory_path.chop
|
91
|
+
else
|
92
|
+
directory_path
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/lobber.rb
ADDED
data/lobber.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lobber/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lobber"
|
8
|
+
spec.version = Lobber::VERSION
|
9
|
+
spec.authors = ["Mike Ball"]
|
10
|
+
spec.email = ["mikedball@gmail.com"]
|
11
|
+
spec.description = %q{A commandline tool to quickly push a directory to AWS S3}
|
12
|
+
spec.summary = %q{Toss a directory to AWS S3}
|
13
|
+
spec.homepage = "http://github.com/mdb/lob"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "fog"
|
22
|
+
spec.add_dependency "thor"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "simplecov"
|
28
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
describe Lobber::CLI do
|
7
|
+
subject { cli }
|
8
|
+
let(:cli) { described_class.new }
|
9
|
+
|
10
|
+
let(:tmpdir) { Dir.mktmpdir }
|
11
|
+
let(:input_filename) { File.join(tmpdir, "README.md") }
|
12
|
+
let(:some_file) { File.read("README.md") }
|
13
|
+
|
14
|
+
before do
|
15
|
+
Fog.mock!
|
16
|
+
File.open(input_filename, 'w') {|file| file.write some_file }
|
17
|
+
cli.stub :say
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
Fog.unmock!
|
22
|
+
FileUtils.rm_rf tmpdir
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#lob" do
|
26
|
+
context "it's not passed any arguments" do
|
27
|
+
it "returns usage details" do
|
28
|
+
cli.should_receive(:usage).exactly(1).times
|
29
|
+
cli.lob
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "it's passed a directory that does not exist" do
|
34
|
+
it "reports that it was passed an invalid directory and exits with an exit code of 1" do
|
35
|
+
Kernel.stub(:exit).and_return true
|
36
|
+
File.stub(:directory?).and_return false
|
37
|
+
cli.should_receive(:error).with("foo is not a valid directory")
|
38
|
+
lambda { cli.lob 'foo' }.should exit_with_code(1)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when it's passed a valid directory" do
|
43
|
+
before :each do
|
44
|
+
ENV.stub(:[]).and_return true
|
45
|
+
File.stub(:directory?).and_return true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "uploads" do
|
49
|
+
Lobber.should_receive(:upload).with("foo", nil)
|
50
|
+
cli.lob "foo"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "reports that the directory has been successfully uploaded" do
|
54
|
+
cli.should_receive(:say).with("Successfully uploaded foo", "\e[32m")
|
55
|
+
cli.lob "foo"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#usage" do
|
61
|
+
subject(:usage) { cli.usage }
|
62
|
+
|
63
|
+
it "displays version info, GitHub info, and help" do
|
64
|
+
cli.should_receive(:say).with('Lobber 0.0.1')
|
65
|
+
cli.should_receive(:say).with('https://github.com/mdb/lob')
|
66
|
+
cli.should_receive(:say).with("\n")
|
67
|
+
cli.should_receive(:help)
|
68
|
+
|
69
|
+
usage
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lobber::Uploader do
|
4
|
+
let(:directory_name) { 'spec' }
|
5
|
+
let(:uploader) { Lobber::Uploader.new(directory_name) }
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
Fog.mock!
|
9
|
+
uploader.stub(:aws_access_key).and_return 'fake key'
|
10
|
+
uploader.stub(:aws_secret_key).and_return 'fake key'
|
11
|
+
uploader.stub(:fog_directory).and_return directory_name
|
12
|
+
end
|
13
|
+
|
14
|
+
after :each do
|
15
|
+
Fog.unmock!
|
16
|
+
end
|
17
|
+
|
18
|
+
it "exists as a class within the Lob module" do
|
19
|
+
Lobber::Uploader.class.should eq Class
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#upload" do
|
23
|
+
before :each do
|
24
|
+
uploader.stub(:verify_env_variables).and_return(true)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "verifies necessary environment variables" do
|
28
|
+
uploader.should_receive :verify_env_variables
|
29
|
+
uploader.upload
|
30
|
+
end
|
31
|
+
|
32
|
+
it "calls #create_file_or_directory with each file or directory in the directory" do
|
33
|
+
uploader.stub(:directory_content).and_return 'foo' => 'bar', 'baz' => 'bim'
|
34
|
+
uploader.should_receive(:create_file_or_directory).with('foo', 'bar')
|
35
|
+
uploader.should_receive(:create_file_or_directory).with('baz', 'bim')
|
36
|
+
uploader.upload
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#directory_content" do
|
41
|
+
it "returns the content for the directory it's passed" do
|
42
|
+
File.stub(:read).and_return 'content'
|
43
|
+
uploader.directory_content.should eq(
|
44
|
+
"spec/lib/" => :directory,
|
45
|
+
"spec/lib/lobber/" => :directory,
|
46
|
+
"spec/lib/lobber/uploader_spec.rb" => "content",
|
47
|
+
"spec/lib/lobber/cli_spec.rb" => "content",
|
48
|
+
"spec/lib/lobber_spec.rb" => "content",
|
49
|
+
"spec/spec_helper.rb" => "content",
|
50
|
+
"spec/support/" => :directory,
|
51
|
+
"spec/support/matchers/" => :directory,
|
52
|
+
"spec/support/matchers/exit_with_code.rb" => "content"
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#bucket" do
|
58
|
+
it "creates a bucket of the same name" do
|
59
|
+
uploader.bucket.class.should eq Fog::Storage::AWS::Directory
|
60
|
+
uploader.bucket.key.should eq 'spec'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#create_file_or_directory" do
|
65
|
+
context "when it is called with the directory flag" do
|
66
|
+
it "calls #create_directory" do
|
67
|
+
uploader.should_receive(:create_directory).with 'foo'
|
68
|
+
uploader.create_file_or_directory 'foo', :directory
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when it is called without the directory flag" do
|
73
|
+
it "calls #create_directory" do
|
74
|
+
uploader.should_receive(:create_file).with 'foo'
|
75
|
+
uploader.create_file_or_directory 'foo', 'some_content'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#create_directory" do
|
81
|
+
it "creates an s3 directory" do
|
82
|
+
uploader.bucket.files.should_receive(:create).with(key: 'foo', public: true)
|
83
|
+
uploader.create_directory "foo"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#create_file" do
|
88
|
+
it "creates an s3 file" do
|
89
|
+
File.stub(:open).and_return 'content'
|
90
|
+
uploader.bucket.files.should_receive(:create).with(key: 'foo', public: true, body: 'content')
|
91
|
+
uploader.create_file "foo"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#s3" do
|
96
|
+
before :each do
|
97
|
+
uploader.stub(:aws_access_key).and_return('aws_access_key')
|
98
|
+
uploader.stub(:aws_secret_key).and_return('aws_secret_key')
|
99
|
+
end
|
100
|
+
|
101
|
+
it "it instantiates a new Fog::Storage class with the proper arguments" do
|
102
|
+
Fog::Storage.should_receive(:new).with(
|
103
|
+
provider: :aws,
|
104
|
+
aws_access_key_id: 'aws_access_key',
|
105
|
+
aws_secret_access_key: 'aws_secret_key'
|
106
|
+
)
|
107
|
+
uploader.s3
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#verify_env_variables" do
|
112
|
+
context "when one of the required environment variables is absent" do
|
113
|
+
it "raises an error reporting that the missing environment variable is required" do
|
114
|
+
uploader.stub(:aws_access_key).and_return nil
|
115
|
+
expect { uploader.verify_env_variables }.to raise_error(RuntimeError, 'Required environment variables missing: ["AWS_ACCESS_KEY"]')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when all of the required environment variables are defined" do
|
120
|
+
before :each do
|
121
|
+
uploader.stub(:aws_access_key).and_return true
|
122
|
+
uploader.stub(:aws_secret_key).and_return true
|
123
|
+
uploader.stub(:fog_directory).and_return true
|
124
|
+
end
|
125
|
+
|
126
|
+
it "it does not raise an error" do
|
127
|
+
expect { uploader.verify_env_variables }.not_to raise_error
|
128
|
+
end
|
129
|
+
|
130
|
+
it "returns true" do
|
131
|
+
uploader.verify_env_variables.should eq true
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#aws_access_key" do
|
137
|
+
it "returns the value of the AWS_ACCESS_KEY environment variable" do
|
138
|
+
some_uploader = Lobber::Uploader.new 'foo'
|
139
|
+
ENV.stub(:[])
|
140
|
+
ENV.should_receive(:[]).with 'AWS_ACCESS_KEY'
|
141
|
+
some_uploader.aws_access_key
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#aws_secret_key" do
|
146
|
+
it "returns the value of the AWS_ACCESS_KEY environment variable" do
|
147
|
+
some_uploader = Lobber::Uploader.new 'foo'
|
148
|
+
ENV.stub(:[])
|
149
|
+
ENV.should_receive(:[]).with 'AWS_SECRET_KEY'
|
150
|
+
some_uploader.aws_secret_key
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "#fog_directory" do
|
155
|
+
context "the uploader is not instantiated with a bucket name parameter" do
|
156
|
+
it "returns the value of the FOG_DIRECTORY environment variable" do
|
157
|
+
some_uploader = Lobber::Uploader.new 'foo'
|
158
|
+
ENV.stub(:[])
|
159
|
+
ENV.should_receive(:[]).with 'FOG_DIRECTORY'
|
160
|
+
some_uploader.fog_directory
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "the uploader is instantiated with a bucket name parameter" do
|
165
|
+
it "returns the value of the bucket name it was passed on instantiation" do
|
166
|
+
some_uploader = Lobber::Uploader.new 'foo', 'bar'
|
167
|
+
some_uploader.fog_directory.should eq 'bar'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lobber do
|
4
|
+
it "exists as a module" do
|
5
|
+
Lobber.class.should eq Module
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".upload" do
|
9
|
+
before :each do
|
10
|
+
@uploader_double = double(Lobber::Uploader)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "it is only passed a directory name, and not an S3 bucket name" do
|
14
|
+
it "verifies environment variables and uploads the directory and its contents to S3" do
|
15
|
+
Lobber::Uploader.should_receive(:new).with('foo', nil).and_return(@uploader_double)
|
16
|
+
@uploader_double.should_receive(:upload)
|
17
|
+
|
18
|
+
Lobber.upload 'foo'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "it is passed a directory name and an S3 bucket name" do
|
23
|
+
it "verifies environment variables and uploads the directory and its contents to the specified S3 bucket" do
|
24
|
+
Lobber::Uploader.should_receive(:new).with('foo', 'bar').and_return(@uploader_double)
|
25
|
+
@uploader_double.should_receive(:upload)
|
26
|
+
|
27
|
+
Lobber.upload 'foo', 'bar'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.require(:development)
|
3
|
+
|
4
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
5
|
+
|
6
|
+
SimpleCov.start
|
7
|
+
|
8
|
+
require 'lobber'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
#some (optional) config here
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
RSpec::Matchers.define :exit_with_code do |exp_code|
|
2
|
+
actual = nil
|
3
|
+
match do |block|
|
4
|
+
begin
|
5
|
+
block.call
|
6
|
+
rescue SystemExit => e
|
7
|
+
actual = e.status
|
8
|
+
end
|
9
|
+
actual and actual == exp_code
|
10
|
+
end
|
11
|
+
failure_message_for_should do |block|
|
12
|
+
"expected block to call exit(#{exp_code}) but exit" +
|
13
|
+
(actual.nil? ? " not called" : "(#{actual}) was called")
|
14
|
+
end
|
15
|
+
failure_message_for_should_not do |block|
|
16
|
+
"expected block not to call exit(#{exp_code})"
|
17
|
+
end
|
18
|
+
description do
|
19
|
+
"expect block to call exit(#{exp_code})"
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lobber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Ball
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fog
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A commandline tool to quickly push a directory to AWS S3
|
98
|
+
email:
|
99
|
+
- mikedball@gmail.com
|
100
|
+
executables:
|
101
|
+
- lob
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- .ruby-gemset
|
107
|
+
- .ruby-version
|
108
|
+
- .travis.yml
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/lob
|
115
|
+
- lib/lobber.rb
|
116
|
+
- lib/lobber/cli.rb
|
117
|
+
- lib/lobber/uploader.rb
|
118
|
+
- lib/lobber/version.rb
|
119
|
+
- lobber.gemspec
|
120
|
+
- spec/lib/lobber/cli_spec.rb
|
121
|
+
- spec/lib/lobber/uploader_spec.rb
|
122
|
+
- spec/lib/lobber_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
- spec/support/matchers/exit_with_code.rb
|
125
|
+
homepage: http://github.com/mdb/lob
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.0.3
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Toss a directory to AWS S3
|
149
|
+
test_files:
|
150
|
+
- spec/lib/lobber/cli_spec.rb
|
151
|
+
- spec/lib/lobber/uploader_spec.rb
|
152
|
+
- spec/lib/lobber_spec.rb
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
- spec/support/matchers/exit_with_code.rb
|