rain_forest 0.2.0 → 0.3.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 +4 -4
- data/README.markdown +6 -6
- data/VERSION +1 -1
- data/lib/rain_forest/s3.rb +14 -3
- data/rain_forest.gemspec +2 -2
- data/spec/rain_forest/s3_spec.rb +14 -14
- data/spec/spec_helper.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5276b08a7b706b69e684e0539ed058298181b7a3
|
4
|
+
data.tar.gz: 52c8fde23cf2d9559e383c7ed3c612b2cb7071b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccd1c72dc8cb90034fd48e883a5c874bf67965b82e4e0f93c6a248a9fd9bea9a5fda95092412401745ace292030dbbb4b7a19e35c3b93f6ace33ab6c42044995
|
7
|
+
data.tar.gz: d3d2dd20848cbeafec5c5e6a49a08f7908b25ccede58bb2aa0d9e346d11d5aa944392ed27d2cf1ff0c2304ba052fc48aa50ad4c224e3911c12894946096381d4
|
data/README.markdown
CHANGED
@@ -14,12 +14,12 @@ Use Ruby Gems to install rain_forest to get started:
|
|
14
14
|
|
15
15
|
There are 4 ENVIRONMENT variables which are used to configure Rain Forest to your AWS account:
|
16
16
|
|
17
|
-
ENV["
|
18
|
-
ENV["
|
19
|
-
ENV["
|
20
|
-
ENV["
|
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
21
|
|
22
|
-
In a typical Rails
|
22
|
+
In a typical Rails application you could use a YML file and an initializer to configure Rain Forest as follows:
|
23
23
|
|
24
24
|
config/rain_forest.yml
|
25
25
|
|
@@ -47,7 +47,7 @@ config/initializers/rain_forest.rb
|
|
47
47
|
|
48
48
|
options = config['rain_forest'][environment]
|
49
49
|
options.each do |k,v|
|
50
|
-
ENV["
|
50
|
+
ENV["RAIN_FOREST_#{k}".upcase] = v
|
51
51
|
end
|
52
52
|
|
53
53
|
## Available Methods
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/rain_forest/s3.rb
CHANGED
@@ -5,9 +5,20 @@ module RainForest
|
|
5
5
|
attr_accessor :bucket, :client
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
region =
|
9
|
-
|
10
|
-
|
8
|
+
region = ENV['RAIN_FOREST_AWS_REGION']
|
9
|
+
region = ENV['rain_forest_aws_region'] if region.nil?#fallback to older config
|
10
|
+
|
11
|
+
akid = ENV['RAIN_FOREST_AWS_AKID']
|
12
|
+
akid = ENV['rain_forest_aws_akid'] if akid.nil?#fallback to older config
|
13
|
+
|
14
|
+
secret = ENV['RAIN_FOREST_AWS_SECRET']
|
15
|
+
secret = ENV['rain_forest_aws_secret'] if secret.nil?#fallback to older config
|
16
|
+
|
17
|
+
bucket = ENV['RAIN_FOREST_AWS_BUCKET']
|
18
|
+
bucket = ENV['rain_forest_aws_bucket'] if bucket.nil?#fallback to older config
|
19
|
+
|
20
|
+
credentials = ::Aws::Credentials.new(akid, secret)
|
21
|
+
@bucket = ENV['RAIN_FOREST_AWS_BUCKET']
|
11
22
|
@client = ::Aws::S3::Client.new(region: region, credentials: credentials)
|
12
23
|
end
|
13
24
|
|
data/rain_forest.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rain_forest"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Lukas Beaton"]
|
12
|
-
s.date = "2016-
|
12
|
+
s.date = "2016-06-13"
|
13
13
|
s.description = "A simplified adaptor for Amazon Web Services. Only S3 is supported at the moment."
|
14
14
|
s.email = "lukas.beaton@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/rain_forest/s3_spec.rb
CHANGED
@@ -5,13 +5,13 @@ describe RainForest::S3 do
|
|
5
5
|
let(:client){ double("AWS Client") }
|
6
6
|
|
7
7
|
before do
|
8
|
-
expect(::Aws::Credentials).to receive(:new).with(ENV["
|
9
|
-
expect(::Aws::S3::Client).to receive(:new).with(region: ENV["
|
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
10
|
end
|
11
11
|
|
12
12
|
describe "#write" do
|
13
13
|
it "works with default public-read permissions" do
|
14
|
-
expect(client).to receive(:put_object).with(bucket: ENV["
|
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
15
|
|
16
16
|
success, message = RainForest::S3.write("STORAGE-KEY", "Some test data...")
|
17
17
|
|
@@ -20,7 +20,7 @@ describe RainForest::S3 do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "accepts other options" do
|
23
|
-
expect(client).to receive(:put_object).with(bucket: ENV["
|
23
|
+
expect(client).to receive(:put_object).with(bucket: ENV["RAIN_FOREST_AWS_BUCKET"], key: "STORAGE-KEY", body: "Some test data...", acl: "public-read", content_encoding: 'utf8').and_return(true)
|
24
24
|
|
25
25
|
success, message = RainForest::S3.write("STORAGE-KEY", "Some test data...", content_encoding: 'utf8')
|
26
26
|
|
@@ -29,7 +29,7 @@ describe RainForest::S3 do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "handles errors" do
|
32
|
-
expect(client).to receive(:put_object).with(bucket: ENV["
|
32
|
+
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!"))
|
33
33
|
|
34
34
|
success, message = RainForest::S3.write("STORAGE-KEY", "Some test data...")
|
35
35
|
|
@@ -43,7 +43,7 @@ describe RainForest::S3 do
|
|
43
43
|
let(:response_object){ double("Response Object", body: response_body) }
|
44
44
|
|
45
45
|
it "works" do
|
46
|
-
expect(client).to receive(:get_object).with(bucket: ENV["
|
46
|
+
expect(client).to receive(:get_object).with(bucket: ENV["RAIN_FOREST_AWS_BUCKET"], key: "STORAGE-KEY").and_return(response_object)
|
47
47
|
|
48
48
|
success, data = RainForest::S3.read("STORAGE-KEY")
|
49
49
|
|
@@ -52,7 +52,7 @@ describe RainForest::S3 do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it "handles errors" do
|
55
|
-
expect(client).to receive(:get_object).with(bucket: ENV["
|
55
|
+
expect(client).to receive(:get_object).with(bucket: ENV["RAIN_FOREST_AWS_BUCKET"], key: "STORAGE-KEY").and_raise(Exception.new("KABOOM!"))
|
56
56
|
|
57
57
|
success, data = RainForest::S3.read("STORAGE-KEY")
|
58
58
|
|
@@ -65,7 +65,7 @@ describe RainForest::S3 do
|
|
65
65
|
let(:response_metadata){ double("Response Metadata", content_length: 12345) }
|
66
66
|
|
67
67
|
it "works" do
|
68
|
-
expect(client).to receive(:head_object).with(bucket: ENV["
|
68
|
+
expect(client).to receive(:head_object).with(bucket: ENV["RAIN_FOREST_AWS_BUCKET"], key: "STORAGE-KEY").and_return(response_metadata)
|
69
69
|
|
70
70
|
response = RainForest::S3.content_length("STORAGE-KEY")
|
71
71
|
|
@@ -73,7 +73,7 @@ describe RainForest::S3 do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "returns -1 for errors" do
|
76
|
-
expect(client).to receive(:head_object).with(bucket: ENV["
|
76
|
+
expect(client).to receive(:head_object).with(bucket: ENV["RAIN_FOREST_AWS_BUCKET"], key: "STORAGE-KEY").and_raise(Exception.new("KABOOM!"))
|
77
77
|
|
78
78
|
response = RainForest::S3.content_length("STORAGE-KEY")
|
79
79
|
|
@@ -89,8 +89,8 @@ describe RainForest::S3 do
|
|
89
89
|
let(:deleted_response){ double("Deleted Objects", deleted: contents) }
|
90
90
|
|
91
91
|
it "works and returns the number of delete objects" do
|
92
|
-
expect(client).to receive(:list_objects).with(bucket: ENV["
|
93
|
-
expect(client).to receive(:delete_objects).with(bucket: ENV["
|
92
|
+
expect(client).to receive(:list_objects).with(bucket: ENV["RAIN_FOREST_AWS_BUCKET"], prefix: "SOME-PREFIX").and_return(objects_response)
|
93
|
+
expect(client).to receive(:delete_objects).with(bucket: ENV["RAIN_FOREST_AWS_BUCKET"], delete: {objects: [{key: "abc"}, {key: "123"}]}).and_return(deleted_response)
|
94
94
|
|
95
95
|
result = RainForest::S3.delete_objects("SOME-PREFIX")
|
96
96
|
|
@@ -98,7 +98,7 @@ describe RainForest::S3 do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it "returns -1 for errors" do
|
101
|
-
expect(client).to receive(:list_objects).with(bucket: ENV["
|
101
|
+
expect(client).to receive(:list_objects).with(bucket: ENV["RAIN_FOREST_AWS_BUCKET"], prefix: "SOME-PREFIX").and_raise(Exception.new("KABOOM!"))
|
102
102
|
|
103
103
|
result = RainForest::S3.delete_objects("SOME-PREFIX")
|
104
104
|
|
@@ -108,8 +108,8 @@ describe RainForest::S3 do
|
|
108
108
|
|
109
109
|
describe "#move" do
|
110
110
|
it "works" do
|
111
|
-
expect(client).to receive(:copy_object).with(bucket: ENV["
|
112
|
-
expect(client).to receive(:delete_object).with(bucket: ENV["
|
111
|
+
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")
|
112
|
+
expect(client).to receive(:delete_object).with(bucket: ENV["RAIN_FOREST_AWS_BUCKET"], key: "SOURCE-KEY")
|
113
113
|
|
114
114
|
success, message = RainForest::S3.move("SOURCE-KEY", "DEST-KEY")
|
115
115
|
|
data/spec/spec_helper.rb
CHANGED
@@ -29,10 +29,10 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
29
29
|
# in ./support/ and its subdirectories.
|
30
30
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
31
31
|
|
32
|
-
ENV["
|
33
|
-
ENV["
|
34
|
-
ENV["
|
35
|
-
ENV["
|
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
36
|
|
37
37
|
RSpec.configure do |config|
|
38
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rain_forest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Beaton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|