simply_stored 0.1.5 → 0.1.8
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.
- data/lib/simply_stored/couch.rb +1 -1
- data/lib/simply_stored/storage.rb +10 -4
- data/test/simply_stored_couch_test.rb +38 -4
- metadata +2 -2
data/lib/simply_stored/couch.rb
CHANGED
@@ -69,7 +69,7 @@ module SimplyStored
|
|
69
69
|
raise SimplyStored::Error, "Can't load record without an id" if what.nil?
|
70
70
|
document = CouchPotato.database.load_document(what)
|
71
71
|
if document.nil? or !document.is_a?(self) or (document.deleted? && !with_deleted)
|
72
|
-
raise(SimplyStored::RecordNotFound)
|
72
|
+
raise(SimplyStored::RecordNotFound, "#{self.name} could not be found with #{what.inspect}")
|
73
73
|
end
|
74
74
|
document
|
75
75
|
end
|
@@ -6,13 +6,14 @@ module SimplyStored
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def s3_connection(name)
|
9
|
-
@_s3_connection ||= RightAws::S3.new(_s3_options[name][:access_key], _s3_options[name][:secret_access_key], :multi_thread => true)
|
9
|
+
@_s3_connection ||= RightAws::S3.new(_s3_options[name][:access_key], _s3_options[name][:secret_access_key], :multi_thread => true, :ca_file => _s3_options[name][:ca_file])
|
10
10
|
end
|
11
11
|
|
12
12
|
def s3_bucket(name)
|
13
13
|
if !@_s3_bucket
|
14
14
|
@_s3_bucket = s3_connection(name).bucket(_s3_options[name][:bucket])
|
15
|
-
|
15
|
+
location = (_s3_options[name][:location] == :eu) ? :eu : nil
|
16
|
+
@_s3_bucket = s3_connection(name).bucket(_s3_options[name][:bucket], true, _s3_options[name][:permissions], :location => location) if @_s3_bucket.nil?
|
16
17
|
end
|
17
18
|
@_s3_bucket
|
18
19
|
rescue Exception => e
|
@@ -55,7 +56,12 @@ module SimplyStored
|
|
55
56
|
|
56
57
|
name = name.to_sym
|
57
58
|
raise ArgumentError, "No bucket name specified for attachment #{name}" if options[:bucket].blank?
|
58
|
-
options
|
59
|
+
options = {
|
60
|
+
:permissions => 'private',
|
61
|
+
:ssl => true,
|
62
|
+
:location => :us, # use :eu for European buckets
|
63
|
+
:ca_file => nil # point to CA file for SSL certificate verification
|
64
|
+
}.update(options)
|
59
65
|
self._s3_options ||= {}
|
60
66
|
self._s3_options[name] = options
|
61
67
|
|
@@ -82,7 +88,7 @@ module SimplyStored
|
|
82
88
|
|
83
89
|
define_method("#{name}_url") do
|
84
90
|
if _s3_options[name][:permissions] == 'private'
|
85
|
-
RightAws::S3Generator.new(_s3_options[name][:access_key], _s3_options[name][:secret_access_key], :multi_thread => true).bucket(_s3_options[name][:bucket]).get(s3_attachment_key(name), 5.minutes)
|
91
|
+
RightAws::S3Generator.new(_s3_options[name][:access_key], _s3_options[name][:secret_access_key], :multi_thread => true, :ca_file => _s3_options[name][:ca_file]).bucket(_s3_options[name][:bucket]).get(s3_attachment_key(name), 5.minutes)
|
86
92
|
else
|
87
93
|
"http://#{_s3_options[name][:bucket].to_s}.s3.amazonaws.com/#{s3_attachment_key(name)}"
|
88
94
|
end
|
@@ -165,6 +165,16 @@ class CouchTest < Test::Unit::TestCase
|
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
|
+
should 'tell you which class failed to load something' do
|
169
|
+
exception = nil
|
170
|
+
begin
|
171
|
+
User.find('abc')
|
172
|
+
rescue SimplyStored::RecordNotFound => e
|
173
|
+
exception = e
|
174
|
+
end
|
175
|
+
assert_equal "User could not be found with \"abc\"", exception.message
|
176
|
+
end
|
177
|
+
|
168
178
|
should 'raise an error when nil was specified' do
|
169
179
|
assert_raises(SimplyStored::Error) do
|
170
180
|
User.find(nil)
|
@@ -1070,6 +1080,7 @@ class CouchTest < Test::Unit::TestCase
|
|
1070
1080
|
context "with s3 interaction" do
|
1071
1081
|
setup do
|
1072
1082
|
CouchLogItem.instance_variable_set(:@_s3_connection, nil)
|
1083
|
+
CouchLogItem._s3_options[:log_data][:ca_file] = nil
|
1073
1084
|
|
1074
1085
|
bucket = stub(:bckt) do
|
1075
1086
|
stubs(:put).returns(true)
|
@@ -1089,7 +1100,7 @@ class CouchTest < Test::Unit::TestCase
|
|
1089
1100
|
context "when saving the attachment" do
|
1090
1101
|
should "fetch the collection" do
|
1091
1102
|
@log_item.log_data = "Yay! It logged!"
|
1092
|
-
RightAws::S3.expects(:new).with('abcdef', 'secret!', :multi_thread => true).returns(@s3)
|
1103
|
+
RightAws::S3.expects(:new).with('abcdef', 'secret!', :multi_thread => true, :ca_file => nil).returns(@s3)
|
1093
1104
|
@log_item.save
|
1094
1105
|
end
|
1095
1106
|
|
@@ -1111,16 +1122,27 @@ class CouchTest < Test::Unit::TestCase
|
|
1111
1122
|
CouchLogItem._s3_options[:log_data][:bucket] = 'mybucket'
|
1112
1123
|
|
1113
1124
|
@s3.expects(:bucket).with('mybucket').returns(nil)
|
1114
|
-
@s3.expects(:bucket).with('mybucket', true, 'private').returns(@bucket)
|
1125
|
+
@s3.expects(:bucket).with('mybucket', true, 'private', :location => nil).returns(@bucket)
|
1126
|
+
@log_item.save
|
1127
|
+
end
|
1128
|
+
|
1129
|
+
should "accept :us location option but not set it in RightAWS::S3" do
|
1130
|
+
@log_item.log_data = "Yay! log me"
|
1131
|
+
CouchLogItem._s3_options[:log_data][:bucket] = 'mybucket'
|
1132
|
+
CouchLogItem._s3_options[:log_data][:location] = :us
|
1133
|
+
|
1134
|
+
@s3.expects(:bucket).with('mybucket').returns(nil)
|
1135
|
+
@s3.expects(:bucket).with('mybucket', true, 'private', :location => nil).returns(@bucket)
|
1115
1136
|
@log_item.save
|
1116
1137
|
end
|
1117
1138
|
|
1118
1139
|
should "raise an error if the bucket is not ours" do
|
1119
1140
|
@log_item.log_data = "Yay! log me too"
|
1120
1141
|
CouchLogItem._s3_options[:log_data][:bucket] = 'mybucket'
|
1142
|
+
CouchLogItem._s3_options[:log_data][:location] = :eu
|
1121
1143
|
|
1122
1144
|
@s3.expects(:bucket).with('mybucket').returns(nil)
|
1123
|
-
@s3.expects(:bucket).with('mybucket', true, 'private').raises(RightAws::AwsError, 'BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again')
|
1145
|
+
@s3.expects(:bucket).with('mybucket', true, 'private', :location => :eu).raises(RightAws::AwsError, 'BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again')
|
1124
1146
|
|
1125
1147
|
assert_raise(ArgumentError) do
|
1126
1148
|
@log_item.save
|
@@ -1193,9 +1215,11 @@ class CouchTest < Test::Unit::TestCase
|
|
1193
1215
|
end
|
1194
1216
|
|
1195
1217
|
should "add a short-lived access key for private attachments" do
|
1218
|
+
@log_item._s3_options[:log_data][:bucket] = 'bucket-for-monsieur'
|
1219
|
+
@log_item._s3_options[:log_data][:location] = :us
|
1196
1220
|
@log_item._s3_options[:log_data][:permissions] = 'private'
|
1197
1221
|
@log_item.save
|
1198
|
-
assert @log_item.log_data_url.include?("https://bucket-for-monsieur.s3.amazonaws.com:443/#{@log_item.s3_attachment_key(:log_data)}")
|
1222
|
+
assert @log_item.log_data_url.include?("https://bucket-for-monsieur.s3.amazonaws.com:443/#{@log_item.s3_attachment_key(:log_data)}"), @log_item.log_data_url
|
1199
1223
|
assert @log_item.log_data_url.include?("Signature=")
|
1200
1224
|
assert @log_item.log_data_url.include?("Expires=")
|
1201
1225
|
end
|
@@ -1208,6 +1232,16 @@ class CouchTest < Test::Unit::TestCase
|
|
1208
1232
|
end
|
1209
1233
|
|
1210
1234
|
context "when fetching the data" do
|
1235
|
+
should "create a configured S3 connection" do
|
1236
|
+
CouchLogItem._s3_options[:log_data][:bucket] = 'mybucket'
|
1237
|
+
CouchLogItem._s3_options[:log_data][:location] = :eu
|
1238
|
+
CouchLogItem._s3_options[:log_data][:ca_file] = '/etc/ssl/ca.crt'
|
1239
|
+
|
1240
|
+
RightAws::S3.expects(:new).with('abcdef', 'secret!', :multi_thread => true, :ca_file => '/etc/ssl/ca.crt').returns(@s3)
|
1241
|
+
|
1242
|
+
@log_item.log_data
|
1243
|
+
end
|
1244
|
+
|
1211
1245
|
should "fetch the data from s3 and set the attachment attribute" do
|
1212
1246
|
@log_item.instance_variable_set(:@_s3_attachments, {})
|
1213
1247
|
@bucket.expects(:get).with("couch_log_items/log_data/#{@log_item.id}").returns("Yay!")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simply_stored
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Meyer, Jonathan Weiss
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-06 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|