condo 1.0.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.textile +19 -32
  3. data/lib/condo.rb +124 -127
  4. data/lib/condo/configuration.rb +41 -76
  5. data/lib/condo/engine.rb +32 -39
  6. data/lib/condo/errors.rb +6 -8
  7. data/lib/condo/strata/amazon_s3.rb +246 -294
  8. data/lib/condo/strata/google_cloud_storage.rb +238 -272
  9. data/lib/condo/strata/open_stack_swift.rb +251 -0
  10. data/lib/condo/version.rb +1 -1
  11. metadata +31 -96
  12. data/app/assets/javascripts/condo.js +0 -9
  13. data/app/assets/javascripts/condo/amazon.js +0 -403
  14. data/app/assets/javascripts/condo/condo.js +0 -184
  15. data/app/assets/javascripts/condo/config.js +0 -69
  16. data/app/assets/javascripts/condo/google.js +0 -338
  17. data/app/assets/javascripts/condo/md5/hash.worker.emulator.js +0 -23
  18. data/app/assets/javascripts/condo/md5/hash.worker.js +0 -11
  19. data/app/assets/javascripts/condo/md5/hasher.js +0 -119
  20. data/app/assets/javascripts/condo/md5/spark-md5.js +0 -599
  21. data/app/assets/javascripts/condo/rackspace.js +0 -326
  22. data/app/assets/javascripts/condo/services/abstract-md5.js.erb +0 -86
  23. data/app/assets/javascripts/condo/services/base64.js +0 -184
  24. data/app/assets/javascripts/condo/services/broadcaster.js +0 -26
  25. data/app/assets/javascripts/condo/services/uploader.js +0 -302
  26. data/app/assets/javascripts/core/core.js +0 -4
  27. data/app/assets/javascripts/core/services/1-safe-apply.js +0 -17
  28. data/app/assets/javascripts/core/services/2-messaging.js +0 -171
  29. data/lib/condo/strata/rackspace_cloud_files.rb +0 -245
  30. data/test/condo_test.rb +0 -27
  31. data/test/dummy/README.rdoc +0 -261
  32. data/test/dummy/Rakefile +0 -7
  33. data/test/dummy/app/assets/javascripts/application.js +0 -15
  34. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  35. data/test/dummy/app/controllers/application_controller.rb +0 -3
  36. data/test/dummy/app/helpers/application_helper.rb +0 -2
  37. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  38. data/test/dummy/config.ru +0 -4
  39. data/test/dummy/config/application.rb +0 -59
  40. data/test/dummy/config/boot.rb +0 -10
  41. data/test/dummy/config/database.yml +0 -25
  42. data/test/dummy/config/environment.rb +0 -5
  43. data/test/dummy/config/environments/development.rb +0 -37
  44. data/test/dummy/config/environments/production.rb +0 -67
  45. data/test/dummy/config/environments/test.rb +0 -37
  46. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  47. data/test/dummy/config/initializers/inflections.rb +0 -15
  48. data/test/dummy/config/initializers/mime_types.rb +0 -5
  49. data/test/dummy/config/initializers/secret_token.rb +0 -7
  50. data/test/dummy/config/initializers/session_store.rb +0 -8
  51. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  52. data/test/dummy/config/locales/en.yml +0 -5
  53. data/test/dummy/config/routes.rb +0 -58
  54. data/test/dummy/public/404.html +0 -26
  55. data/test/dummy/public/422.html +0 -26
  56. data/test/dummy/public/500.html +0 -25
  57. data/test/dummy/public/favicon.ico +0 -0
  58. data/test/dummy/script/rails +0 -6
  59. data/test/integration/navigation_test.rb +0 -10
  60. data/test/test_helper.rb +0 -15
@@ -0,0 +1,251 @@
1
+ # encoding: utf-8
2
+
3
+ module Condo; end
4
+ module Condo::Strata; end
5
+
6
+ #
7
+ # NOTE:: Set Account Metadata Key for Public Access before this will work - X-Account-Meta-Temp-Url-Key: <your key>
8
+ #
9
+
10
+ class Condo::Strata::OpenStackSwift
11
+
12
+ MIN_CHUNK_SIZE = 2097152
13
+
14
+ def initialize(options)
15
+ @options = {
16
+ :name => :OpenStackSwift,
17
+ :location => :dfw, # dallas or chicago - this is set at bucket creation time
18
+ :fog => {
19
+ :provider => 'Rackspace',
20
+ :rackspace_username => options[:username],
21
+ :rackspace_api_key => options[:secret_key],
22
+ :rackspace_cdn_url => options[:rackspace_cdn_url],
23
+ :rackspace_temp_url_key => options[:temp_url_key],
24
+ :rackspace_auth_url => options[:auth_url] || 'https://identity.api.rackspacecloud.com/v2.0' # is US and UK is 'lon.auth.api.rackspacecloud.com'
25
+ }
26
+ }.merge!(options)
27
+
28
+ case @options[:location]
29
+ when :dfw, :dallas, :DFW
30
+ @options[:location] = 'storage101.dfw1.clouddrive.com'
31
+ @options[:fog][:rackspace_region] = :dfw
32
+ when :ord, :chicago, :ORD
33
+ @options[:location] = 'storage101.ord1.clouddrive.com'
34
+ @options[:fog][:rackspace_region] = :ord
35
+ else @options[:location]
36
+ end
37
+
38
+
39
+ #raise ArgumentError, 'Rackspace Username missing' if @options[:username].nil?
40
+ #raise ArgumentError, 'Rackspace Secret Key missing' if @options[:secret_key].nil?
41
+
42
+ raise ArgumentError, 'Swift Storage URL missing' if @options[:storage_url].nil?
43
+ raise ArgumentError, 'Swift Temp URL Key missing' if @options[:temp_url_key].nil?
44
+
45
+
46
+ @options[:location] = @options[:location].to_sym
47
+ end
48
+
49
+
50
+ def name
51
+ @options[:name]
52
+ end
53
+
54
+
55
+ def location
56
+ @options[:location]
57
+ end
58
+
59
+
60
+ # Here for convenience
61
+ def set_metadata_key(key)
62
+ fog_connection.request(
63
+ :expects => [201, 202, 204],
64
+ :method => 'POST',
65
+ :headers => {'X-Account-Meta-Temp-Url-Key' => key}
66
+ )
67
+ end
68
+
69
+
70
+ def allow_cors(domains = 'http://localhost:3000', options_age = 10, headers = 'etag, x-object-manifest, content-type, accept, origin, x-requested-with')
71
+ fog_connection.request(
72
+ :expects => [201, 202, 204],
73
+ :method => 'POST',
74
+ :headers => {
75
+ 'X-Container-Meta-Access-Control-Allow-Origin' => domains,
76
+ 'X-Container-Meta-Access-Control-Max-Age' => options_age,
77
+ 'X-Container-Meta-Access-Control-Allow-Headers' => headers
78
+ }
79
+ )
80
+ end
81
+
82
+
83
+ # Create a signed URL for accessing a private file
84
+ def get_object(options)
85
+ options = {}.merge!(options) # Need to deep copy here
86
+ options[:object_options] = {
87
+ :expires => 5.minutes.from_now,
88
+ :verb => :get,
89
+ :headers => {},
90
+ :parameters => {}
91
+ }.merge!(options[:object_options] || {})
92
+ options.merge!(@options)
93
+
94
+ # provide the signed request
95
+ sign_request(options)[:url]
96
+ end
97
+
98
+
99
+ # Creates a new upload request (either single shot or multi-part)
100
+ # => Passed: bucket_name, object_key, object_options, file_size
101
+ def new_upload(options)
102
+ options = {}.merge!(options) # Need to deep copy here
103
+ options[:object_options] = {
104
+ :expires => 5.minutes.from_now,
105
+ :verb => :put,
106
+ :headers => {},
107
+ :parameters => {}
108
+ }.merge!(options[:object_options])
109
+ options.merge!(@options)
110
+
111
+ options[:object_options][:headers]['ETag'] = options[:file_id] if options[:file_id].present? && options[:object_options][:headers]['ETag'].nil?
112
+ options[:object_options][:headers]['Content-Type'] = 'binary/octet-stream' if options[:object_options][:headers]['Content-Type'].nil?
113
+
114
+
115
+ # Decide what type of request is being sent
116
+ request = {}
117
+ # 2 mb (minimum chunk size)
118
+ if options[:file_size] > MIN_CHUNK_SIZE
119
+
120
+ options[:object_key] = options[:object_key] + gen_part_ext(options[:file_size], 1) # Append the part number
121
+ request[:type] = :chunked_upload
122
+ else
123
+
124
+ request[:type] = :direct_upload
125
+ end
126
+
127
+ # provide the signed request
128
+ request[:signature] = sign_request(options)
129
+ request
130
+ end
131
+
132
+
133
+ # Returns the part we are up to
134
+ def get_parts(options)
135
+ {
136
+ :type => :parts,
137
+ # NOTE:: This is legacy V1 - before parallel uploads
138
+ :current_part => options[:resumable_id]
139
+ }
140
+ end
141
+
142
+
143
+ # Returns the requests for uploading parts and completing a resumable upload
144
+ def set_part(options)
145
+ options[:object_options] = {
146
+ :expires => 5.minutes.from_now,
147
+ :headers => {},
148
+ :parameters => {},
149
+ :verb => :put
150
+ }.merge!(options[:object_options])
151
+ options.merge!(@options)
152
+
153
+
154
+ request = {}
155
+ if options[:part] == 'finish'
156
+ =begin
157
+ Dynamic large object now have to be created on the server...
158
+ This is how that was done. We now use Static Large Objects that can be created client side
159
+
160
+ key = CGI::escape options[:object_key]
161
+
162
+ # Send the commitment request
163
+ fog_connection.request(
164
+ :expects => [200, 201],
165
+ :method => 'PUT',
166
+ :headers => {
167
+ 'X-Object-Manifest' => "#{CGI::escape options[:bucket_name]}/#{key}/p"
168
+ },
169
+ path: "#{CGI::escape options[:bucket_name]}/#{key}"
170
+ )
171
+
172
+ return {}
173
+ =end
174
+
175
+ options[:object_options][:headers]['ETag'] = options[:file_id] if options[:file_id].present?
176
+ options[:object_options][:headers]['Content-Type'] = 'application/json'
177
+ options[:object_key] = CGI::escape(options[:object_key])
178
+ request[:signature] = sign_request(options, '&multipart-manifest=put')
179
+ else
180
+ # Send the part upload request
181
+ options[:object_options][:headers]['ETag'] = options[:file_id] if options[:file_id].present? && options[:object_options][:headers]['ETag'].nil?
182
+ options[:object_options][:headers]['Content-Type'] = 'binary/octet-stream'
183
+ object_key = CGI::escape(options[:object_key]) + gen_part_ext(options[:file_size], options[:part])
184
+ options[:object_key] = object_key
185
+ request[:type] = :part_upload
186
+
187
+ # Required for static large objects
188
+ request[:path] = "#{CGI::escape options[:bucket_name]}/#{object_key}"
189
+ request[:signature] = sign_request(options)
190
+ end
191
+
192
+ # provide the signed request
193
+ request
194
+ end
195
+
196
+
197
+ def fog_connection
198
+ @fog = @fog || Fog::Storage.new(@options[:fog])
199
+ return @fog
200
+ end
201
+
202
+
203
+ def destroy(upload)
204
+ connection = fog_connection
205
+ directory = connection.directories.get(upload.bucket_name) # it is assumed this exists - if not then the upload wouldn't have taken place
206
+
207
+ if upload.resumable
208
+ directory.files.all({'prefix' => upload.object_key}).each do |file|
209
+ return false unless file.destroy
210
+ end
211
+ end
212
+
213
+ file = directory.files.get(upload.object_key) # this is the manifest when resumable
214
+
215
+ return true if file.nil?
216
+ return file.destroy
217
+ end
218
+
219
+
220
+
221
+ protected
222
+
223
+
224
+
225
+ def sign_request(options, param = nil)
226
+ # Build base URL
227
+ options[:object_options][:expires] = options[:object_options][:expires].utc.to_i
228
+ url = "/v1/#{options[:storage_url]}/#{CGI::escape options[:bucket_name]}/#{options[:object_key]}"
229
+
230
+ # Build a request signature
231
+ signature = "#{options[:object_options][:verb].to_s.upcase}\n#{options[:object_options][:expires]}\n#{url}"
232
+
233
+ # Encode the request signature
234
+ signature = OpenSSL::HMAC.hexdigest('sha1', @options[:temp_url_key], signature)
235
+
236
+ # Finish building the request
237
+ return {
238
+ :verb => options[:object_options][:verb].to_s.upcase,
239
+ :url => "#{options[:http_only] ? 'http' : 'https'}://#{@options[:location]}#{url}?temp_url_sig=#{signature}&temp_url_expires=#{options[:object_options][:expires]}#{param}",
240
+ :headers => options[:object_options][:headers]
241
+ }
242
+ end
243
+
244
+
245
+ def gen_part_ext(fileSize, partNumber)
246
+ rval = (fileSize.to_f / MIN_CHUNK_SIZE).ceil.to_s.length
247
+ partPad = partNumber.to_s.rjust(rval, '0')
248
+ "/p#{partPad}"
249
+ end
250
+ end
251
+
@@ -1,3 +1,3 @@
1
1
  module Condo
2
- VERSION = "1.0.6"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: condo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-20 00:00:00.000000000 Z
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.0
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fog
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
41
55
  description: Provides signed upload signatures to your users browsers so they can
42
56
  upload directly to cloud storage providers
43
57
  email:
@@ -46,66 +60,18 @@ executables: []
46
60
  extensions: []
47
61
  extra_rdoc_files: []
48
62
  files:
49
- - app/assets/javascripts/condo/amazon.js
50
- - app/assets/javascripts/condo/condo.js
51
- - app/assets/javascripts/condo/config.js
52
- - app/assets/javascripts/condo/google.js
53
- - app/assets/javascripts/condo/md5/hash.worker.emulator.js
54
- - app/assets/javascripts/condo/md5/hash.worker.js
55
- - app/assets/javascripts/condo/md5/hasher.js
56
- - app/assets/javascripts/condo/md5/spark-md5.js
57
- - app/assets/javascripts/condo/rackspace.js
58
- - app/assets/javascripts/condo/services/abstract-md5.js.erb
59
- - app/assets/javascripts/condo/services/base64.js
60
- - app/assets/javascripts/condo/services/broadcaster.js
61
- - app/assets/javascripts/condo/services/uploader.js
62
- - app/assets/javascripts/condo.js
63
- - app/assets/javascripts/core/core.js
64
- - app/assets/javascripts/core/services/1-safe-apply.js
65
- - app/assets/javascripts/core/services/2-messaging.js
63
+ - LGPL3-LICENSE
64
+ - README.textile
65
+ - Rakefile
66
+ - lib/condo.rb
66
67
  - lib/condo/configuration.rb
67
68
  - lib/condo/engine.rb
68
69
  - lib/condo/errors.rb
69
70
  - lib/condo/strata/amazon_s3.rb
70
71
  - lib/condo/strata/google_cloud_storage.rb
71
- - lib/condo/strata/rackspace_cloud_files.rb
72
+ - lib/condo/strata/open_stack_swift.rb
72
73
  - lib/condo/version.rb
73
- - lib/condo.rb
74
74
  - lib/tasks/condo_tasks.rake
75
- - LGPL3-LICENSE
76
- - Rakefile
77
- - README.textile
78
- - test/condo_test.rb
79
- - test/dummy/app/assets/javascripts/application.js
80
- - test/dummy/app/assets/stylesheets/application.css
81
- - test/dummy/app/controllers/application_controller.rb
82
- - test/dummy/app/helpers/application_helper.rb
83
- - test/dummy/app/views/layouts/application.html.erb
84
- - test/dummy/config/application.rb
85
- - test/dummy/config/boot.rb
86
- - test/dummy/config/database.yml
87
- - test/dummy/config/environment.rb
88
- - test/dummy/config/environments/development.rb
89
- - test/dummy/config/environments/production.rb
90
- - test/dummy/config/environments/test.rb
91
- - test/dummy/config/initializers/backtrace_silencers.rb
92
- - test/dummy/config/initializers/inflections.rb
93
- - test/dummy/config/initializers/mime_types.rb
94
- - test/dummy/config/initializers/secret_token.rb
95
- - test/dummy/config/initializers/session_store.rb
96
- - test/dummy/config/initializers/wrap_parameters.rb
97
- - test/dummy/config/locales/en.yml
98
- - test/dummy/config/routes.rb
99
- - test/dummy/config.ru
100
- - test/dummy/public/404.html
101
- - test/dummy/public/422.html
102
- - test/dummy/public/500.html
103
- - test/dummy/public/favicon.ico
104
- - test/dummy/Rakefile
105
- - test/dummy/README.rdoc
106
- - test/dummy/script/rails
107
- - test/integration/navigation_test.rb
108
- - test/test_helper.rb
109
75
  homepage: http://cotag.me/
110
76
  licenses: []
111
77
  metadata: {}
@@ -115,50 +81,19 @@ require_paths:
115
81
  - lib
116
82
  required_ruby_version: !ruby/object:Gem::Requirement
117
83
  requirements:
118
- - - '>='
84
+ - - ">="
119
85
  - !ruby/object:Gem::Version
120
86
  version: '0'
121
87
  required_rubygems_version: !ruby/object:Gem::Requirement
122
88
  requirements:
123
- - - '>='
89
+ - - ">="
124
90
  - !ruby/object:Gem::Version
125
91
  version: '0'
126
92
  requirements: []
127
93
  rubyforge_project:
128
- rubygems_version: 2.0.14
94
+ rubygems_version: 2.4.6
129
95
  signing_key:
130
96
  specification_version: 4
131
97
  summary: Direct Cloud Storage Uploader
132
- test_files:
133
- - test/condo_test.rb
134
- - test/dummy/app/assets/javascripts/application.js
135
- - test/dummy/app/assets/stylesheets/application.css
136
- - test/dummy/app/controllers/application_controller.rb
137
- - test/dummy/app/helpers/application_helper.rb
138
- - test/dummy/app/views/layouts/application.html.erb
139
- - test/dummy/config/application.rb
140
- - test/dummy/config/boot.rb
141
- - test/dummy/config/database.yml
142
- - test/dummy/config/environment.rb
143
- - test/dummy/config/environments/development.rb
144
- - test/dummy/config/environments/production.rb
145
- - test/dummy/config/environments/test.rb
146
- - test/dummy/config/initializers/backtrace_silencers.rb
147
- - test/dummy/config/initializers/inflections.rb
148
- - test/dummy/config/initializers/mime_types.rb
149
- - test/dummy/config/initializers/secret_token.rb
150
- - test/dummy/config/initializers/session_store.rb
151
- - test/dummy/config/initializers/wrap_parameters.rb
152
- - test/dummy/config/locales/en.yml
153
- - test/dummy/config/routes.rb
154
- - test/dummy/config.ru
155
- - test/dummy/public/404.html
156
- - test/dummy/public/422.html
157
- - test/dummy/public/500.html
158
- - test/dummy/public/favicon.ico
159
- - test/dummy/Rakefile
160
- - test/dummy/README.rdoc
161
- - test/dummy/script/rails
162
- - test/integration/navigation_test.rb
163
- - test/test_helper.rb
98
+ test_files: []
164
99
  has_rdoc:
@@ -1,9 +0,0 @@
1
- //= require core/core
2
- //= require core/services/1-safe-apply
3
- //= require core/services/2-messaging
4
- //= require condo/condo
5
- //= require condo/services/base64
6
- //= require condo/services/broadcaster
7
- //= require condo/services/abstract-md5
8
- //= require condo/services/uploader
9
- //= require condo/config