tori 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tori/backend/s3.rb +22 -17
- data/lib/tori/version.rb +1 -1
- data/test/test_tori_backend_s3.rb +17 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00e78b51cb71ee2dae463df6a3b2bc3518c9d4b1
|
4
|
+
data.tar.gz: a451f2d4fd7cdc7b4dcf15d4792a8ce36bbaabe7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e0474b601c7e5b5c9ecc9a53b8218eed8e39b8ae768527894f1eed5e28b2e10387dcebccf9a89d11e46fc8d5937495ba63997504648cbcb3d8456319595ea1e
|
7
|
+
data.tar.gz: 8f3dfe3d4309f8528129a341805c881fcfb3d23139ac9357cbaefbc41990ab892f3be9992730125e6ea2b057840b0ff3e58d3a2d4603bafb7b63c61dce3ed717
|
data/lib/tori/backend/s3.rb
CHANGED
@@ -6,15 +6,34 @@ module Tori
|
|
6
6
|
class S3
|
7
7
|
DEFAULT_CONTENT_TYPE = 'text/plain'.freeze
|
8
8
|
attr_accessor :bucket
|
9
|
+
attr_reader :client
|
10
|
+
|
9
11
|
# Must be set bucket name.
|
10
12
|
# And it use aws-sdk-core >= 2.0
|
11
|
-
# ENV
|
13
|
+
# ENV takes precedence over credentials file and instance profile
|
12
14
|
#
|
13
15
|
# example:
|
14
16
|
# Tori.config.backend = Tori::Backend::S3.new(bucket: 'tori_bucket')
|
15
|
-
def initialize(bucket:)
|
17
|
+
def initialize(bucket:, client: nil)
|
16
18
|
@bucket = bucket
|
17
|
-
|
19
|
+
if client
|
20
|
+
unless client.kind_of?(Aws::S3::Client)
|
21
|
+
raise TypeError, "client should be instance of Aws::S3::Client or nil"
|
22
|
+
end
|
23
|
+
@client = client
|
24
|
+
else
|
25
|
+
region = ENV['TORI_AWS_REGION'] || ENV['AWS_REGION'] || Aws.config[:region]
|
26
|
+
@client = if ENV['TORI_AWS_ACCESS_KEY_ID'] && ENV['TORI_AWS_SECRET_ACCESS_KEY']
|
27
|
+
Aws::S3::Client.new(
|
28
|
+
access_key_id: ENV['TORI_AWS_ACCESS_KEY_ID'],
|
29
|
+
secret_access_key: ENV['TORI_AWS_SECRET_ACCESS_KEY'],
|
30
|
+
region: region,
|
31
|
+
)
|
32
|
+
else
|
33
|
+
# Use instance profile or credentials file (~/.aws/credentials)
|
34
|
+
Aws::S3::Client.new(region: region)
|
35
|
+
end
|
36
|
+
end
|
18
37
|
end
|
19
38
|
|
20
39
|
def write(filename, resource, opts = nil)
|
@@ -90,20 +109,6 @@ module Tori
|
|
90
109
|
signer.presigned_url(method, bucket: @bucket, key: filename)
|
91
110
|
end
|
92
111
|
|
93
|
-
def client
|
94
|
-
@client ||= if ENV["TORI_AWS_ACCESS_KEY_ID"] && ENV["TORI_AWS_SECRET_ACCESS_KEY"]
|
95
|
-
Aws::S3::Client.new(
|
96
|
-
access_key_id: ENV["TORI_AWS_ACCESS_KEY_ID"],
|
97
|
-
secret_access_key: ENV["TORI_AWS_SECRET_ACCESS_KEY"],
|
98
|
-
region: ENV["TORI_AWS_REGION"] || ENV['AWS_REGION'] || Aws.config[:region],
|
99
|
-
)
|
100
|
-
else
|
101
|
-
Aws::S3::Client.new(
|
102
|
-
region: ENV["TORI_AWS_REGION"] || ENV['AWS_REGION'] || Aws.config[:region]
|
103
|
-
)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
112
|
def get_object(key:)
|
108
113
|
client.get_object bucket: @bucket, key: key
|
109
114
|
end
|
data/lib/tori/version.rb
CHANGED
@@ -30,7 +30,24 @@ class TestToriBackendS3 < Test::Unit::TestCase
|
|
30
30
|
|
31
31
|
test "#initialize" do
|
32
32
|
assert_instance_of Tori::Backend::S3, @backend
|
33
|
+
assert { ENV["TORI_AWS_ACCESS_KEY_ID"] == @backend.client.config.access_key_id }
|
34
|
+
assert { ENV["TORI_AWS_SECRET_ACCESS_KEY"] == @backend.client.config.secret_access_key }
|
35
|
+
|
36
|
+
custom_backend = Tori::Backend::S3.new(
|
37
|
+
bucket: ENV["TORI_TEST_BUCKET"],
|
38
|
+
client: Aws::S3::Client.new(access_key_id: 'aaa', secret_access_key: 'bbb'),
|
39
|
+
)
|
40
|
+
assert_instance_of Tori::Backend::S3, custom_backend
|
41
|
+
assert { 'aaa' == custom_backend.client.config.access_key_id }
|
42
|
+
assert { 'bbb' == custom_backend.client.config.secret_access_key }
|
43
|
+
|
33
44
|
assert_raise(ArgumentError){ Tori::Backend::S3.new }
|
45
|
+
assert_raise(TypeError) {
|
46
|
+
Tori::Backend::S3.new(
|
47
|
+
bucket: ENV["TORI_TEST_BUCKET"],
|
48
|
+
client: Object.new,
|
49
|
+
)
|
50
|
+
}
|
34
51
|
end
|
35
52
|
|
36
53
|
test "#respond_to_missing?" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.4.5
|
132
|
+
rubygems_version: 2.4.5.1
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: Simple file uploader
|