blobstore_client 1.5.0.pre.1141 → 1.5.0.pre.1142

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,8 +43,9 @@ module Bosh
43
43
  # Get an object from the blobstore.
44
44
  # @param [String] id object id
45
45
  # @param [File] file where to store the fetched object
46
+ # @param [Hash] options for individual request configuration
46
47
  # @return [String] the object contents if the file parameter is nil
47
- def get(id, file = nil)
48
+ def get(id, file = nil, options = {})
48
49
  if file
49
50
  get_file(id, file)
50
51
  file.flush
@@ -1,18 +1,24 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  module Bosh
4
2
  module Blobstore
5
3
  class Client
6
4
  PROVIDER_NAMES = %w[dav simple s3 swift atmos local]
7
5
 
8
6
  def self.create(blobstore_provider, options = {})
9
- unless PROVIDER_NAMES.include? blobstore_provider
10
- raise BlobstoreError, "Invalid client provider, available providers are: #{PROVIDER_NAMES}"
7
+ unless PROVIDER_NAMES.include?(blobstore_provider)
8
+ raise BlobstoreError,
9
+ "Unknown client provider '#{blobstore_provider}', " +
10
+ "available providers are: #{PROVIDER_NAMES}"
11
11
  end
12
-
13
12
  blobstore_client_constantize(blobstore_provider).new(options)
14
13
  end
15
14
 
15
+ def self.safe_create(provider, options = {})
16
+ wrapped_client = create(provider, options)
17
+ sha1_client = Sha1VerifiableBlobstoreClient.new(wrapped_client)
18
+ retryable = Retryable.new(tries: 3, sleep: 0.5, on: [BlobstoreError])
19
+ RetryableBlobstoreClient.new(sha1_client, retryable)
20
+ end
21
+
16
22
  private
17
23
 
18
24
  def self.blobstore_client_constantize(base_string)
@@ -0,0 +1,29 @@
1
+ require 'forwardable'
2
+
3
+ module Bosh
4
+ module Blobstore
5
+ class RetryableBlobstoreClient < BaseClient
6
+ extend Forwardable
7
+
8
+ def initialize(client, retryable)
9
+ @client = client
10
+ @retryable = retryable
11
+ end
12
+
13
+ def get(id, file = nil, options = {})
14
+ # BoshRetryable#retryer interface does not allow nil
15
+ # as a successful return value; hence, we save off last result
16
+ last_result = nil
17
+
18
+ @retryable.retryer do
19
+ last_result = @client.get(id, file, options)
20
+ true
21
+ end
22
+
23
+ last_result
24
+ end
25
+
26
+ def_delegators :@client, :create, :delete, :exists?
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,43 @@
1
+ require 'digest/sha1'
2
+ require 'forwardable'
3
+
4
+ module Bosh
5
+ module Blobstore
6
+ class Sha1VerifiableBlobstoreClient < BaseClient
7
+ extend Forwardable
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ def get(id, file = nil, options = {})
14
+ if options.has_key?(:sha1)
15
+ expected_sha1 = options[:sha1]
16
+ raise ArgumentError, 'sha1 must not be nil' unless expected_sha1
17
+ end
18
+
19
+ result_file = @client.get(id, file, options)
20
+
21
+ if expected_sha1
22
+ # Blobstore clients either modify passed in file
23
+ # or return new temporary file
24
+ check_sha1(expected_sha1, file || result_file)
25
+ end
26
+
27
+ result_file
28
+ end
29
+
30
+ def_delegators :@client, :create, :delete, :exists?
31
+
32
+ private
33
+
34
+ def check_sha1(expected_sha1, file_to_check)
35
+ expected_sha1 = expected_sha1
36
+ actual_sha1 = Digest::SHA1.file(file_to_check.path).hexdigest
37
+ unless expected_sha1 == actual_sha1
38
+ raise BlobstoreError, "sha1 mismatch expected=#{expected_sha1} actual=#{actual_sha1}"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -3,7 +3,7 @@
3
3
  module Bosh
4
4
  module Blobstore
5
5
  class Client
6
- VERSION = '1.5.0.pre.1141'
6
+ VERSION = '1.5.0.pre.1142'
7
7
  end
8
8
  end
9
9
  end
@@ -1,14 +1,15 @@
1
- # Copyright (c) 2009-2012 VMware, Inc.
2
-
3
1
  require 'common/common'
4
2
  require 'blobstore_client/version'
5
3
  require 'blobstore_client/errors'
6
4
  require 'blobstore_client/client'
7
5
 
8
6
  Bosh::Blobstore.autoload(:BaseClient, 'blobstore_client/base')
7
+ require 'blobstore_client/retryable_blobstore_client'
8
+ require 'blobstore_client/sha1_verifiable_blobstore_client'
9
+
9
10
  Bosh::Blobstore.autoload(:S3BlobstoreClient, 'blobstore_client/s3_blobstore_client')
10
11
  Bosh::Blobstore.autoload(:SimpleBlobstoreClient, 'blobstore_client/simple_blobstore_client')
11
12
  Bosh::Blobstore.autoload(:SwiftBlobstoreClient, 'blobstore_client/swift_blobstore_client')
12
13
  Bosh::Blobstore.autoload(:AtmosBlobstoreClient, 'blobstore_client/atmos_blobstore_client')
13
14
  Bosh::Blobstore.autoload(:LocalClient, 'blobstore_client/local_client')
14
- Bosh::Blobstore.autoload(:DavBlobstoreClient, 'blobstore_client/dav_blobstore_client')
15
+ Bosh::Blobstore.autoload(:DavBlobstoreClient, 'blobstore_client/dav_blobstore_client')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blobstore_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.pre.1141
4
+ version: 1.5.0.pre.1142
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 1.5.0.pre.1141
101
+ version: 1.5.0.pre.1142
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,10 +106,42 @@ dependencies:
106
106
  requirements:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: 1.5.0.pre.1141
109
+ version: 1.5.0.pre.1142
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rspec-fire
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
110
142
  description: ! 'BOSH blobstore client
111
143
 
112
- 903d52'
144
+ 31eb14'
113
145
  email: support@cloudfoundry.com
114
146
  executables:
115
147
  - blobstore_client_console
@@ -125,7 +157,9 @@ files:
125
157
  - lib/blobstore_client/dav_blobstore_client.rb
126
158
  - lib/blobstore_client/errors.rb
127
159
  - lib/blobstore_client/local_client.rb
160
+ - lib/blobstore_client/retryable_blobstore_client.rb
128
161
  - lib/blobstore_client/s3_blobstore_client.rb
162
+ - lib/blobstore_client/sha1_verifiable_blobstore_client.rb
129
163
  - lib/blobstore_client/simple_blobstore_client.rb
130
164
  - lib/blobstore_client/swift_blobstore_client.rb
131
165
  - lib/blobstore_client/version.rb