miasma 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d96b86dbb247d22f846177758907886638e4eec
4
- data.tar.gz: 5c052aae2f76878d06868e1c60daa01b38921fd2
3
+ metadata.gz: d32bced5ab7a65f5cec7aae1a717904e71dc8a94
4
+ data.tar.gz: 53581473453536b82a3afd67a9bd754f1ee43446
5
5
  SHA512:
6
- metadata.gz: 13d34cdd67c7bfea1470f25ffcd0a37a225a9900c59d1c49fa69a61e302e5dfa733f51c4d85ddd04e402b43e261f847bd2ba83c8b0899302a6cae25b933df57e
7
- data.tar.gz: e7e9a45b0ea4380ba9474b2ba6cdf26f3265bdcff1ce2ebe68a4a193bf4f931b83f347668a8e8ddd6f6d02660d7c04ba3a6813bc8f4579df5b32405c6279c854
6
+ metadata.gz: 4b02c183a44ba32b24e20f72260f6a89ed84c88efab319955326fc0fef4a0543fea459262ceec9ac32da60a05a52dbd7f508270bb557dda8e59ebb0e33f77651
7
+ data.tar.gz: 6b72a033e7ef5293dd764c92da47abe2faaaf1024359d88b1781d2682e541de304015d7c62948f621195c82c90f24f8f6e265b6db6295cc152920520bfc5d288
@@ -1,3 +1,9 @@
1
+ # v0.2.4
2
+ * Make `Storage::File#body` setup provider responsibility
3
+ * Fix module usage within RS to properly squash existing methods
4
+ * Allow RS identity to be shared where applicable
5
+ * Fix creation time attribute population of stacks within OpenStack provider
6
+
1
7
  # v0.2.2
2
8
  * Add support for pre-signed AWS URLs
3
9
  * Add `#url` method to `Storage::File` model
@@ -52,7 +52,7 @@ module Miasma
52
52
  'KeepRoot' => true
53
53
  )
54
54
  req_args[:headers] = Smash.new(
55
- 'Content-Length' => req_args[:body].length.to_s
55
+ 'Content-Length' => req_args[:body].size.to_s
56
56
  )
57
57
  end
58
58
  request(req_args)
@@ -167,11 +167,11 @@ module Miasma
167
167
  end
168
168
  end.compact
169
169
  ]
170
- if(file.attributes[:body].is_a?(IO) && file.body.length >= Storage::MAX_BODY_SIZE_FOR_STRINGIFY)
170
+ if(file.attributes[:body].is_a?(IO) && file.body.size >= Storage::MAX_BODY_SIZE_FOR_STRINGIFY)
171
171
  upload_id = request(
172
172
  args.merge(
173
173
  Smash.new(
174
- :path => uri_escape(file.name),
174
+ :path => file_path(file),
175
175
  :endpoint => bucket_endpoint(bucket),
176
176
  :params => {
177
177
  :uploads => true
@@ -187,7 +187,7 @@ module Miasma
187
187
  count,
188
188
  request(
189
189
  :method => :put,
190
- :path => uri_escape(file.name),
190
+ :path => file_path(file),
191
191
  :endpoint => bucket_endpoint(bucket),
192
192
  :headers => Smash.new(
193
193
  'Content-Length' => content.size,
@@ -215,7 +215,7 @@ module Miasma
215
215
  )
216
216
  result = request(
217
217
  :method => :post,
218
- :path => uri_escape(file.name),
218
+ :path => file_path(file),
219
219
  :endpoint => bucket_endpoint(file.bucket),
220
220
  :params => Smash.new(
221
221
  'UploadId' => upload_id
@@ -228,7 +228,7 @@ module Miasma
228
228
  file.etag = result.get(:body, 'CompleteMultipartUploadResult', 'ETag')
229
229
  else
230
230
  if(file.attributes[:body].is_a?(IO) || file.attributes[:body].is_a?(StringIO))
231
- args[:headers]['Content-Length'] = file.body.length.to_s
231
+ args[:headers]['Content-Length'] = file.body.size.to_s
232
232
  file.body.rewind
233
233
  args[:body] = file.body.read
234
234
  file.body.rewind
@@ -237,7 +237,7 @@ module Miasma
237
237
  args.merge(
238
238
  Smash.new(
239
239
  :method => :put,
240
- :path => uri_escape(file.name),
240
+ :path => file_path(file),
241
241
  :endpoint => bucket_endpoint(file.bucket)
242
242
  )
243
243
  )
@@ -258,7 +258,7 @@ module Miasma
258
258
  if(file.persisted?)
259
259
  request(
260
260
  :method => :delete,
261
- :path => file.name,
261
+ :path => file_path(file),
262
262
  :endpoint => bucket_endpoint(file.bucket),
263
263
  :expects => 204
264
264
  )
@@ -276,7 +276,7 @@ module Miasma
276
276
  if(file.persisted?)
277
277
  name = file.name
278
278
  result = request(
279
- :path => uri_escape(file.name),
279
+ :path => file_path(file),
280
280
  :endpoint => bucket_endpoint(file.bucket)
281
281
  )
282
282
  file.data.clear && file.dirty.clear
@@ -300,7 +300,7 @@ module Miasma
300
300
  def file_url(file, timeout_secs)
301
301
  if(file.persisted?)
302
302
  signer.generate_url(
303
- :get, ::File.join(uri_escape(file.bucket.name), uri_escape(file.name)),
303
+ :get, ::File.join(uri_escape(file.bucket.name), file_path(file)),
304
304
  :headers => Smash.new(
305
305
  'Host' => aws_host
306
306
  ),
@@ -322,11 +322,20 @@ module Miasma
322
322
  def file_body(file)
323
323
  if(file.persisted?)
324
324
  result = request(
325
- :path => uri_escape(file.name),
325
+ :path => file_path(file),
326
326
  :endpoint => bucket_endpoint(file.bucket)
327
327
  )
328
328
  content = result[:body]
329
- content.is_a?(String) ? StringIO.new(content) : content
329
+ begin
330
+ if(content.is_a?(String))
331
+ StringIO.new(content)
332
+ else
333
+ content.stream!
334
+ content
335
+ end
336
+ rescue HTTP::StateError
337
+ StringIO.new(content.to_s)
338
+ end
330
339
  else
331
340
  StringIO.new('')
332
341
  end
@@ -346,6 +355,13 @@ module Miasma
346
355
  true
347
356
  end
348
357
 
358
+ # @return [String] escaped file path
359
+ def file_path(file)
360
+ file.name.split('/').map do |part|
361
+ uri_escape(part)
362
+ end.join('/')
363
+ end
364
+
349
365
  end
350
366
  end
351
367
  end
@@ -220,7 +220,6 @@ module Miasma
220
220
  attribute :open_stack_tenant_name, String
221
221
  attribute :open_stack_domain, String
222
222
  attribute :open_stack_project, String
223
-
224
223
  end
225
224
  end
226
225
 
@@ -260,6 +259,8 @@ module Miasma
260
259
  'identity' => 'keystone'
261
260
  )
262
261
 
262
+ include Miasma::Utils::Memoization
263
+
263
264
  # @return [Miasma::Contrib::OpenStackApiCore::Authenticate]
264
265
  attr_reader :identity
265
266
 
@@ -269,10 +270,15 @@ module Miasma
269
270
  # @return [self]
270
271
  def initialize(creds)
271
272
  @credentials = creds
273
+ memo_key = "miasma_open_stack_identity_#{creds.checksum}"
272
274
  if(creds[:open_stack_identity_url].include?('v3'))
273
- @identity = identity_class('Authenticate::Version3').new(creds)
275
+ @identity = memoize(memo_key, :direct) do
276
+ identity_class('Authenticate::Version3').new(creds)
277
+ end
274
278
  elsif(creds[:open_stack_identity_url].include?('v2'))
275
- @identity = identity_class('Authenticate::Version2').new(creds)
279
+ @identity = memoize(memo_key, :direct) do
280
+ identity_class('Authenticate::Version2').new(creds)
281
+ end
276
282
  else
277
283
  # @todo allow attribute to override?
278
284
  raise ArgumentError.new('Failed to determine Identity service version')
@@ -160,7 +160,7 @@ module Miasma
160
160
  Stack.new(
161
161
  self,
162
162
  :id => s[:id],
163
- :creation_time => Time.parse(s[:creation_time]),
163
+ :created => Time.parse(s[:creation_time]),
164
164
  :description => s[:description],
165
165
  :name => s[:stack_name],
166
166
  :state => s[:stack_status].downcase.to_sym,
@@ -33,21 +33,29 @@ module Miasma
33
33
  # @param klass [Class]
34
34
  def self.included(klass)
35
35
  klass.attributes.clear
36
+
36
37
  klass.class_eval do
37
38
  attribute :rackspace_api_key, String, :required => true
38
39
  attribute :rackspace_username, String, :required => true
39
40
  attribute :rackspace_region, String, :required => true
40
- end
41
- end
42
41
 
43
- # @return [Miasma::Contrib::RackspaceApiCore]
44
- def open_stack_api
45
- key = "miasma_rackspace_api_#{attributes.checksum}".to_sym
46
- memoize(key, :direct) do
47
- Miasma::Contrib::RackspaceApiCore.new(attributes)
42
+ # @return [Miasma::Contrib::RackspaceApiCore]
43
+ def open_stack_api
44
+ key = "miasma_rackspace_api_#{attributes.checksum}".to_sym
45
+ memoize(key, :direct) do
46
+ Miasma::Contrib::RackspaceApiCore.new(attributes)
47
+ end
48
+ end
49
+
50
+ # @return [String]
51
+ def open_stack_region
52
+ rackspace_region
53
+ end
54
+
48
55
  end
49
56
  end
50
57
 
58
+
51
59
  end
52
60
 
53
61
  # @return [Smash] Authentication endpoints
@@ -5,6 +5,7 @@ module Miasma
5
5
  class AutoScale
6
6
  class Rackspace < AutoScale
7
7
 
8
+ include Contrib::OpenStackApiCore::ApiCommon
8
9
  include Contrib::RackspaceApiCore::ApiCommon
9
10
 
10
11
  # Save auto scale group
@@ -5,6 +5,7 @@ module Miasma
5
5
  class LoadBalancer
6
6
  class Rackspace < LoadBalancer
7
7
 
8
+ include Contrib::OpenStackApiCore::ApiCommon
8
9
  include Contrib::RackspaceApiCore::ApiCommon
9
10
 
10
11
  # Save load balancer
@@ -45,13 +45,7 @@ module Miasma
45
45
  # @note object returned will provide #readpartial
46
46
  def body
47
47
  unless(attributes[:body])
48
- begin
49
- _body = api.file_body(self)
50
- _body.stream!
51
- data[:body] = api.file_body(self)
52
- rescue HTTP::StateError
53
- data[:body] = StringIO.new(_body.to_s)
54
- end
48
+ data[:body] = api.file_body(self)
55
49
  end
56
50
  attributes[:body]
57
51
  end
@@ -222,7 +222,11 @@ module Miasma
222
222
  class << self
223
223
 
224
224
  def inherited(klass)
225
- klass.set_attributes(self.attributes)
225
+ klass.set_attributes(
226
+ MultiJson.load(
227
+ MultiJson.dump(self.attributes)
228
+ ).to_smash
229
+ )
226
230
  end
227
231
 
228
232
  end
@@ -1,4 +1,4 @@
1
1
  module Miasma
2
2
  # current library version
3
- VERSION = Gem::Version.new('0.2.2')
3
+ VERSION = Gem::Version.new('0.2.4')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miasma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-24 00:00:00.000000000 Z
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie