rain_forest 0.1.2
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/.document +5 -0
- data/.travis.yml +3 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +108 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +74 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/rain_forest.rb +1 -0
- data/lib/rain_forest/s3.rb +90 -0
- data/rain_forest.gemspec +70 -0
- data/spec/rain_forest/s3_spec.rb +120 -0
- data/spec/spec_helper.rb +38 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad4afd2ceafc100732a1021fbe2150695f5c7db7
|
4
|
+
data.tar.gz: 803185da5d7bdf8e4c19e29f3920504ddc4bd4f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5fd03581a6387ff88de7a78f8803e172be4a2fc36aed85668a7e363d7fab51e6fc3317bbcf75b065b0212009688375e3edca438763963ab1308f08dcdc4a8ef3
|
7
|
+
data.tar.gz: 3b5c078ba82c3ab8c32c8ed260e1241c009b151b0e2c62d24b90c68ba51b88e4c31cfe3dd7a14f9eb261487ccf84505e0e423692c6f184e17e59e0efbd1441ca
|
data/.document
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
ruby '2.0.0'
|
4
|
+
|
5
|
+
# Add dependencies required to use your gem here.
|
6
|
+
# Example:
|
7
|
+
# gem "activesupport", ">= 2.3.5"
|
8
|
+
gem 'aws-sdk', '2.1.14', require: true
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem "rspec", "2.14.0"
|
14
|
+
gem 'coveralls', require: false
|
15
|
+
gem "rdoc", "~> 3.12"
|
16
|
+
gem "bundler", "~> 1.0"
|
17
|
+
gem "jeweler", "~> 2.0.1"
|
18
|
+
gem "simplecov", ">= 0"
|
19
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.8)
|
5
|
+
aws-sdk (2.1.14)
|
6
|
+
aws-sdk-resources (= 2.1.14)
|
7
|
+
aws-sdk-core (2.1.14)
|
8
|
+
jmespath (~> 1.0)
|
9
|
+
aws-sdk-resources (2.1.14)
|
10
|
+
aws-sdk-core (= 2.1.14)
|
11
|
+
builder (3.2.2)
|
12
|
+
coveralls (0.8.3)
|
13
|
+
json (~> 1.8)
|
14
|
+
rest-client (>= 1.6.8, < 2)
|
15
|
+
simplecov (~> 0.10.0)
|
16
|
+
term-ansicolor (~> 1.3)
|
17
|
+
thor (~> 0.19.1)
|
18
|
+
descendants_tracker (0.0.4)
|
19
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
20
|
+
diff-lcs (1.2.5)
|
21
|
+
docile (1.1.5)
|
22
|
+
domain_name (0.5.25)
|
23
|
+
unf (>= 0.0.5, < 1.0.0)
|
24
|
+
faraday (0.9.2)
|
25
|
+
multipart-post (>= 1.2, < 3)
|
26
|
+
git (1.2.9.1)
|
27
|
+
github_api (0.12.4)
|
28
|
+
addressable (~> 2.3)
|
29
|
+
descendants_tracker (~> 0.0.4)
|
30
|
+
faraday (~> 0.8, < 0.10)
|
31
|
+
hashie (>= 3.4)
|
32
|
+
multi_json (>= 1.7.5, < 2.0)
|
33
|
+
nokogiri (~> 1.6.6)
|
34
|
+
oauth2
|
35
|
+
hashie (3.4.2)
|
36
|
+
highline (1.7.7)
|
37
|
+
http-cookie (1.0.2)
|
38
|
+
domain_name (~> 0.5)
|
39
|
+
jeweler (2.0.1)
|
40
|
+
builder
|
41
|
+
bundler (>= 1.0)
|
42
|
+
git (>= 1.2.5)
|
43
|
+
github_api
|
44
|
+
highline (>= 1.6.15)
|
45
|
+
nokogiri (>= 1.5.10)
|
46
|
+
rake
|
47
|
+
rdoc
|
48
|
+
jmespath (1.1.3)
|
49
|
+
json (1.8.3)
|
50
|
+
jwt (1.5.1)
|
51
|
+
mime-types (2.6.2)
|
52
|
+
mini_portile (0.6.2)
|
53
|
+
multi_json (1.11.2)
|
54
|
+
multi_xml (0.5.5)
|
55
|
+
multipart-post (2.0.0)
|
56
|
+
netrc (0.10.3)
|
57
|
+
nokogiri (1.6.6.2)
|
58
|
+
mini_portile (~> 0.6.0)
|
59
|
+
oauth2 (1.0.0)
|
60
|
+
faraday (>= 0.8, < 0.10)
|
61
|
+
jwt (~> 1.0)
|
62
|
+
multi_json (~> 1.3)
|
63
|
+
multi_xml (~> 0.5)
|
64
|
+
rack (~> 1.2)
|
65
|
+
rack (1.6.4)
|
66
|
+
rake (10.4.2)
|
67
|
+
rdoc (3.12.2)
|
68
|
+
json (~> 1.4)
|
69
|
+
rest-client (1.8.0)
|
70
|
+
http-cookie (>= 1.0.2, < 2.0)
|
71
|
+
mime-types (>= 1.16, < 3.0)
|
72
|
+
netrc (~> 0.7)
|
73
|
+
rspec (2.14.0)
|
74
|
+
rspec-core (~> 2.14.0)
|
75
|
+
rspec-expectations (~> 2.14.0)
|
76
|
+
rspec-mocks (~> 2.14.0)
|
77
|
+
rspec-core (2.14.8)
|
78
|
+
rspec-expectations (2.14.5)
|
79
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
80
|
+
rspec-mocks (2.14.6)
|
81
|
+
simplecov (0.10.0)
|
82
|
+
docile (~> 1.1.0)
|
83
|
+
json (~> 1.8)
|
84
|
+
simplecov-html (~> 0.10.0)
|
85
|
+
simplecov-html (0.10.0)
|
86
|
+
term-ansicolor (1.3.2)
|
87
|
+
tins (~> 1.0)
|
88
|
+
thor (0.19.1)
|
89
|
+
thread_safe (0.3.5)
|
90
|
+
tins (1.6.0)
|
91
|
+
unf (0.1.4)
|
92
|
+
unf_ext
|
93
|
+
unf_ext (0.0.7.1)
|
94
|
+
|
95
|
+
PLATFORMS
|
96
|
+
ruby
|
97
|
+
|
98
|
+
DEPENDENCIES
|
99
|
+
aws-sdk (= 2.1.14)
|
100
|
+
bundler (~> 1.0)
|
101
|
+
coveralls
|
102
|
+
jeweler (~> 2.0.1)
|
103
|
+
rdoc (~> 3.12)
|
104
|
+
rspec (= 2.14.0)
|
105
|
+
simplecov
|
106
|
+
|
107
|
+
BUNDLED WITH
|
108
|
+
1.10.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Lukas Beaton
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Rain Forest: an Amazon ecosystem
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/rain_forest)
|
4
|
+
[](https://travis-ci.org/LukasBeaton/rain_forest)
|
5
|
+
[](https://coveralls.io/github/LukasBeaton/rain_forest?branch=master)
|
6
|
+
|
7
|
+
Rain Forest is a collection of simplified adaptors for Amazon Web Services and relies on the [aws-sdk Gem](https://rubygems.org/gems/aws-sdk). The intention is for Rain Forest to one day support many of Amazon's web services. However, at the moment there is only support for S3.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Use Ruby Gems to install rain_forest to get started:
|
12
|
+
|
13
|
+
$ gem install rain_forest
|
14
|
+
|
15
|
+
There are 4 ENVIRONMENT variables which are used to configure Rain Forest to your AWS account:
|
16
|
+
|
17
|
+
ENV["rain_forest_aws_akid"] = "YOUR_ACCESS_KEY_ID"
|
18
|
+
ENV["rain_forest_aws_secret"] = "YOUR_SECRET_ACCESS_KEY"
|
19
|
+
ENV["rain_forest_aws_region"] = "YOUR_BUCKET_REGION"
|
20
|
+
ENV["rain_forest_aws_bucket"] = "YOUR_BUCKET"
|
21
|
+
|
22
|
+
In a typical Rails environment you could use a YML file and an initializer to configure Rain Forest as follows:
|
23
|
+
|
24
|
+
config/rain_forest.yml
|
25
|
+
|
26
|
+
rain_forest:
|
27
|
+
development:
|
28
|
+
aws_akid: "YOUR_ACCESS_KEY_ID"
|
29
|
+
aws_secret: "YOUR_SECRET_ACCESS_KEY"
|
30
|
+
aws_region: "YOUR_BUCKET_REGION"
|
31
|
+
aws_bucket: "YOUR_BUCKET"
|
32
|
+
test:
|
33
|
+
aws_akid: "YOUR_ACCESS_KEY_ID"
|
34
|
+
aws_secret: "YOUR_SECRET_ACCESS_KEY"
|
35
|
+
aws_region: "YOUR_BUCKET_REGION"
|
36
|
+
aws_bucket: "YOUR_BUCKET"
|
37
|
+
production:
|
38
|
+
aws_akid: "YOUR_ACCESS_KEY_ID"
|
39
|
+
aws_secret: "YOUR_SECRET_ACCESS_KEY"
|
40
|
+
aws_region: "YOUR_BUCKET_REGION"
|
41
|
+
aws_bucket: "YOUR_BUCKET"
|
42
|
+
|
43
|
+
config/initializers/rain_forest.rb
|
44
|
+
|
45
|
+
config = YAML.load_file("#{Rails.root}/config/rain_forest.yml")
|
46
|
+
environment = Rails.env || "development"
|
47
|
+
|
48
|
+
options = config['rain_forest'][environment]
|
49
|
+
options.each do |k,v|
|
50
|
+
ENV["rain_forest_#{k}"] = v
|
51
|
+
end
|
52
|
+
|
53
|
+
## Available Methods
|
54
|
+
RainForest::S3.write(storage_key, data, permission='public-read')
|
55
|
+
RainForest::S3.read(storage_key)
|
56
|
+
RainForest::S3.move(source_key, dest_key)
|
57
|
+
RainForest::S3.content_length(storage_key)
|
58
|
+
RainForest::S3.delete_objects(prefix)
|
59
|
+
|
60
|
+
|
61
|
+
## Contributing to Rain Forest
|
62
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
63
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
64
|
+
* Fork the project.
|
65
|
+
* Start a feature/bugfix branch.
|
66
|
+
* Commit and push until you are happy with your contribution.
|
67
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
68
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
69
|
+
|
70
|
+
## Copyright
|
71
|
+
|
72
|
+
Copyright (c) 2015 Lukas Beaton. See LICENSE.txt for
|
73
|
+
further details.
|
74
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "rain_forest"
|
18
|
+
gem.homepage = "http://github.com/LukasBeaton/rain_forest"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A simplified adaptor for Amazon Web Services}
|
21
|
+
gem.description = %Q{A simplified adaptor for Amazon Web Services. Only S3 is supported at the moment.}
|
22
|
+
gem.email = "lukas.beaton@gmail.com"
|
23
|
+
gem.authors = ["Lukas Beaton"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Code coverage detail"
|
35
|
+
task :simplecov do
|
36
|
+
ENV['COVERAGE'] = "true"
|
37
|
+
Rake::Task['spec'].execute
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rdoc/task'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "rain_forest #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/lib/rain_forest.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "rain_forest", "s3")
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module RainForest
|
4
|
+
class S3
|
5
|
+
attr_accessor :bucket, :client
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
region = ENV['rain_forest_aws_region']
|
9
|
+
credentials = ::Aws::Credentials.new(ENV['rain_forest_aws_akid'], ENV['rain_forest_aws_secret'])
|
10
|
+
@bucket = ENV['rain_forest_aws_bucket']
|
11
|
+
@client = ::Aws::S3::Client.new(region: region, credentials: credentials)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.write(storage_key, data, permission='public-read')
|
15
|
+
self.new.write(storage_key, data, permission)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.read(storage_key)
|
19
|
+
self.new.read(storage_key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.move(source_key, dest_key)
|
23
|
+
self.new.move(source_key, dest_key)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.content_length(storage_key)
|
27
|
+
self.new.content_length(storage_key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.delete_objects(prefix)
|
31
|
+
self.new.delete_objects(prefix)
|
32
|
+
end
|
33
|
+
|
34
|
+
def write(storage_key, data, permission='public-read')
|
35
|
+
begin
|
36
|
+
@client.put_object(bucket: @bucket, key: storage_key, body: data, acl: permission)
|
37
|
+
rescue Exception => e
|
38
|
+
return false, e.message
|
39
|
+
end
|
40
|
+
|
41
|
+
return true, nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def read(storage_key)
|
45
|
+
begin
|
46
|
+
resp = @client.get_object(bucket: @bucket, key: storage_key)
|
47
|
+
return true, resp.body.read
|
48
|
+
rescue Exception => e
|
49
|
+
return false, e.message
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def move(source_key, dest_key)
|
54
|
+
begin
|
55
|
+
@client.copy_object(bucket: @bucket, copy_source: "#{@bucket}/#{source_key}", key: dest_key)
|
56
|
+
@client.delete_object(bucket: @bucket, key: source_key)
|
57
|
+
rescue Exception => e
|
58
|
+
return false, e.message
|
59
|
+
end
|
60
|
+
|
61
|
+
return true, nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def content_length(storage_key)
|
65
|
+
begin
|
66
|
+
resp = @client.head_object(bucket: @bucket, key: storage_key)
|
67
|
+
return resp.content_length
|
68
|
+
rescue Exception
|
69
|
+
return -1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete_objects(prefix)
|
74
|
+
begin
|
75
|
+
objects_deleted = 0
|
76
|
+
resp = @client.list_objects(bucket: @bucket, prefix: prefix)
|
77
|
+
|
78
|
+
if resp.contents.length > 0
|
79
|
+
objects = resp.contents.map{|f| {key: f.key}}
|
80
|
+
resp = @client.delete_objects(bucket: @bucket, delete: {objects: objects})
|
81
|
+
objects_deleted += resp.deleted.length
|
82
|
+
end
|
83
|
+
|
84
|
+
return objects_deleted
|
85
|
+
rescue Exception
|
86
|
+
return -1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/rain_forest.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "rain_forest"
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Lukas Beaton"]
|
12
|
+
s.date = "2015-10-14"
|
13
|
+
s.description = "A simplified adaptor for Amazon Web Services. Only S3 is supported at the moment."
|
14
|
+
s.email = "lukas.beaton@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".travis.yml",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.markdown",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/rain_forest.rb",
|
29
|
+
"lib/rain_forest/s3.rb",
|
30
|
+
"rain_forest.gemspec",
|
31
|
+
"spec/rain_forest/s3_spec.rb",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = "http://github.com/LukasBeaton/rain_forest"
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = "2.0.14"
|
38
|
+
s.summary = "A simplified adaptor for Amazon Web Services"
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 4
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<aws-sdk>, ["= 2.1.14"])
|
45
|
+
s.add_development_dependency(%q<rspec>, ["= 2.14.0"])
|
46
|
+
s.add_development_dependency(%q<coveralls>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
50
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<aws-sdk>, ["= 2.1.14"])
|
53
|
+
s.add_dependency(%q<rspec>, ["= 2.14.0"])
|
54
|
+
s.add_dependency(%q<coveralls>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
58
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<aws-sdk>, ["= 2.1.14"])
|
62
|
+
s.add_dependency(%q<rspec>, ["= 2.14.0"])
|
63
|
+
s.add_dependency(%q<coveralls>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
67
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RainForest::S3 do
|
4
|
+
let(:credentials){ double("AWS Crendetials") }
|
5
|
+
let(:client){ double("AWS Client") }
|
6
|
+
|
7
|
+
before do
|
8
|
+
expect(::Aws::Credentials).to receive(:new).with(ENV["rain_forest_aws_akid"], ENV["rain_forest_aws_secret"]).and_return(credentials).at_least(:once)
|
9
|
+
expect(::Aws::S3::Client).to receive(:new).with(region: ENV["rain_forest_aws_region"], credentials: credentials).and_return(client).at_least(:once)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#write" do
|
13
|
+
it "works with default public-read permissions" do
|
14
|
+
expect(client).to receive(:put_object).with(bucket: ENV["rain_forest_aws_bucket"], key: "STORAGE-KEY", body: "Some test data...", acl: "public-read").and_return(true)
|
15
|
+
|
16
|
+
success, message = RainForest::S3.write("STORAGE-KEY", "Some test data...")
|
17
|
+
|
18
|
+
expect(success).to eq(true)
|
19
|
+
expect(message).to eq(nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "handles errors" do
|
23
|
+
expect(client).to receive(:put_object).with(bucket: ENV["rain_forest_aws_bucket"], key: "STORAGE-KEY", body: "Some test data...", acl: "public-read").and_raise(Exception.new("KABOOM!"))
|
24
|
+
|
25
|
+
success, message = RainForest::S3.write("STORAGE-KEY", "Some test data...")
|
26
|
+
|
27
|
+
expect(success).to eq(false)
|
28
|
+
expect(message).to eq("KABOOM!")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#read" do
|
33
|
+
let(:response_body){ double("Response Body", read: "Some test data...") }
|
34
|
+
let(:response_object){ double("Response Object", body: response_body) }
|
35
|
+
|
36
|
+
it "works" do
|
37
|
+
expect(client).to receive(:get_object).with(bucket: ENV["rain_forest_aws_bucket"], key: "STORAGE-KEY").and_return(response_object)
|
38
|
+
|
39
|
+
success, data = RainForest::S3.read("STORAGE-KEY")
|
40
|
+
|
41
|
+
expect(success).to eq(true)
|
42
|
+
expect(data).to eq("Some test data...")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "handles errors" do
|
46
|
+
expect(client).to receive(:get_object).with(bucket: ENV["rain_forest_aws_bucket"], key: "STORAGE-KEY").and_raise(Exception.new("KABOOM!"))
|
47
|
+
|
48
|
+
success, data = RainForest::S3.read("STORAGE-KEY")
|
49
|
+
|
50
|
+
expect(success).to eq(false)
|
51
|
+
expect(data).to eq("KABOOM!")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#content_length" do
|
56
|
+
let(:response_metadata){ double("Response Metadata", content_length: 12345) }
|
57
|
+
|
58
|
+
it "works" do
|
59
|
+
expect(client).to receive(:head_object).with(bucket: ENV["rain_forest_aws_bucket"], key: "STORAGE-KEY").and_return(response_metadata)
|
60
|
+
|
61
|
+
response = RainForest::S3.content_length("STORAGE-KEY")
|
62
|
+
|
63
|
+
expect(response).to eq(12345)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns -1 for errors" do
|
67
|
+
expect(client).to receive(:head_object).with(bucket: ENV["rain_forest_aws_bucket"], key: "STORAGE-KEY").and_raise(Exception.new("KABOOM!"))
|
68
|
+
|
69
|
+
response = RainForest::S3.content_length("STORAGE-KEY")
|
70
|
+
|
71
|
+
expect(response).to eq(-1)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#delete_objects" do
|
76
|
+
let(:content_1){ OpenStruct.new(key: "abc") }
|
77
|
+
let(:content_2){ OpenStruct.new(key: "123") }
|
78
|
+
let(:contents){ [content_1, content_2] }
|
79
|
+
let(:objects_response){ double("Objects", contents: contents) }
|
80
|
+
let(:deleted_response){ double("Deleted Objects", deleted: contents) }
|
81
|
+
|
82
|
+
it "works and returns the number of delete objects" do
|
83
|
+
expect(client).to receive(:list_objects).with(bucket: ENV["rain_forest_aws_bucket"], prefix: "SOME-PREFIX").and_return(objects_response)
|
84
|
+
expect(client).to receive(:delete_objects).with(bucket: ENV["rain_forest_aws_bucket"], delete: {objects: [{key: "abc"}, {key: "123"}]}).and_return(deleted_response)
|
85
|
+
|
86
|
+
result = RainForest::S3.delete_objects("SOME-PREFIX")
|
87
|
+
|
88
|
+
expect(result).to eq(2)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns -1 for errors" do
|
92
|
+
expect(client).to receive(:list_objects).with(bucket: ENV["rain_forest_aws_bucket"], prefix: "SOME-PREFIX").and_raise(Exception.new("KABOOM!"))
|
93
|
+
|
94
|
+
result = RainForest::S3.delete_objects("SOME-PREFIX")
|
95
|
+
|
96
|
+
expect(result).to eq(-1)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#move" do
|
101
|
+
it "works" do
|
102
|
+
expect(client).to receive(:copy_object).with(bucket: ENV["rain_forest_aws_bucket"], copy_source: "#{ENV["rain_forest_aws_bucket"]}/SOURCE-KEY", key: "DEST-KEY")
|
103
|
+
expect(client).to receive(:delete_object).with(bucket: ENV["rain_forest_aws_bucket"], key: "SOURCE-KEY")
|
104
|
+
|
105
|
+
success, message = RainForest::S3.move("SOURCE-KEY", "DEST-KEY")
|
106
|
+
|
107
|
+
expect(success).to eq(true)
|
108
|
+
expect(message).to eq(nil)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "handles errors" do
|
112
|
+
expect(client).to receive(:copy_object).and_raise(Exception.new("KABOOM!"))
|
113
|
+
|
114
|
+
success, message = RainForest::S3.move("SOURCE-KEY", "DEST-KEY")
|
115
|
+
|
116
|
+
expect(success).to eq(false)
|
117
|
+
expect(message).to eq("KABOOM!")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.require(:development)
|
4
|
+
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
|
8
|
+
require 'rain_forest'
|
9
|
+
|
10
|
+
module SimpleCov::Configuration
|
11
|
+
def clean_filters
|
12
|
+
@filters = []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
SimpleCov.configure do
|
17
|
+
clean_filters
|
18
|
+
load_adapter 'test_frameworks'
|
19
|
+
end
|
20
|
+
|
21
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
22
|
+
add_filter "/.rvm/"
|
23
|
+
end
|
24
|
+
|
25
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
26
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
27
|
+
|
28
|
+
# Requires supporting files with custom matchers and macros, etc,
|
29
|
+
# in ./support/ and its subdirectories.
|
30
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
31
|
+
|
32
|
+
ENV["rain_forest_aws_akid"] = "DUMMY_rain_forest_aws_akid"
|
33
|
+
ENV["rain_forest_aws_secret"] = "DUMMY_rain_forest_aws_secret"
|
34
|
+
ENV["rain_forest_aws_region"] = "DUMMY_rain_forest_aws_region"
|
35
|
+
ENV["rain_forest_aws_bucket"] = "DUMMY_rain_forest_aws_bucket"
|
36
|
+
|
37
|
+
RSpec.configure do |config|
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rain_forest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lukas Beaton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-14 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.1.14
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.14
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.14.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.14.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coveralls
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jeweler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.0.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.0.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A simplified adaptor for Amazon Web Services. Only S3 is supported at
|
112
|
+
the moment.
|
113
|
+
email: lukas.beaton@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files:
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.markdown
|
119
|
+
files:
|
120
|
+
- .document
|
121
|
+
- .travis.yml
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.markdown
|
126
|
+
- Rakefile
|
127
|
+
- VERSION
|
128
|
+
- lib/rain_forest.rb
|
129
|
+
- lib/rain_forest/s3.rb
|
130
|
+
- rain_forest.gemspec
|
131
|
+
- spec/rain_forest/s3_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: http://github.com/LukasBeaton/rain_forest
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.0.14
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: A simplified adaptor for Amazon Web Services
|
157
|
+
test_files: []
|