blobstore_client 0.5.0 → 1.5.0.pre.1113

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,17 @@
1
1
  # Copyright (c) 2009-2012 VMware, Inc.
2
2
 
3
- require "base64"
4
- require "fog"
5
- require "multi_json"
6
- require "uri"
7
- require "uuidtools"
3
+ require 'base64'
4
+ require 'fog'
5
+ require 'multi_json'
6
+ require 'uri'
7
+ require 'httpclient'
8
8
 
9
9
  module Bosh
10
10
  module Blobstore
11
11
 
12
12
  class SwiftBlobstoreClient < BaseClient
13
13
 
14
- # Blobstore client for Swift
14
+ # Blobstore client for OpenStack Swift
15
15
  # @param [Hash] options Swift BlobStore options
16
16
  # @option options [Symbol] container_name
17
17
  # @option options [Symbol] swift_provider
@@ -26,130 +26,121 @@ module Bosh
26
26
  validate_options(@options)
27
27
 
28
28
  swift_provider = @options[:swift_provider]
29
- swift_options = {:provider => swift_provider}
29
+ swift_options = { provider: swift_provider }
30
30
  swift_options.merge!(@options[swift_provider.to_sym])
31
+
32
+ if swift_options.has_key?(:openstack_auth_url)
33
+ unless swift_options[:openstack_auth_url].match(/\/tokens$/)
34
+ swift_options[:openstack_auth_url] = swift_options[:openstack_auth_url] + '/tokens'
35
+ end
36
+ end
37
+
31
38
  swift = Fog::Storage.new(swift_options)
32
39
 
33
40
  container_name = @options[:container_name]
34
41
  @container = swift.directories.get(container_name)
35
- if @container.nil?
36
- raise NotFound, "Swift container '#{container_name}' not found"
37
- end
42
+ raise NotFound, "Swift container '#{container_name}' not found" if @container.nil?
43
+
38
44
  @container
39
45
  end
40
46
 
41
- def create_file(file)
42
- object_id = generate_object_id
43
- object = container.files.create(:key => object_id,
44
- :body => file,
45
- :public => true)
46
- encode_object_id(object_id, object.public_url)
47
+ protected
48
+
49
+ def create_file(object_id, file)
50
+ object_id ||= generate_object_id
51
+ object = container.files.create(key: object_id, body: file)
52
+ begin
53
+ public_url = object.public_url
54
+ rescue NotImplementedError
55
+ public_url = nil
56
+ end
57
+ encode_object_id(object_id, public_url)
47
58
  rescue Exception => e
48
59
  raise BlobstoreError, "Failed to create object: #{e.message}"
49
60
  end
50
61
 
51
62
  def get_file(object_id, file)
52
63
  object_info = decode_object_id(object_id)
53
- if object_info["purl"]
54
- response = @http_client.get(object_info["purl"]) do |block|
64
+ if object_info['purl']
65
+ response = @http_client.get(object_info['purl']) do |block|
55
66
  file.write(block)
56
67
  end
57
68
  if response.status != 200
58
- raise BlobstoreError, "Could not fetch object, %s/%s" %
59
- [response.status, response.content]
69
+ raise BlobstoreError, "Could not fetch object, #{response.status} #{response.content}"
60
70
  end
61
71
  else
62
- object = container.files.get(object_info["oid"]) do |block|
72
+ object = container.files.get(object_info['oid']) do |block|
63
73
  file.write(block)
64
74
  end
65
- if object.nil?
66
- raise NotFound, "Swift object '#{object_id}' not found"
67
- end
75
+ raise NotFound, "Swift object '#{object_info['oid']}' not found" if object.nil?
68
76
  end
69
77
  rescue Exception => e
70
- raise BlobstoreError,
71
- "Failed to find object '#{object_id}': #{e.message}"
78
+ raise BlobstoreError, "Failed to find object '#{object_id}': #{e.message}"
72
79
  end
73
80
 
74
- def delete(object_id)
81
+ def delete_object(object_id)
75
82
  object_info = decode_object_id(object_id)
76
- object = container.files.get(object_info["oid"])
77
- if object.nil?
78
- raise NotFound, "Swift object '#{object_id}' not found"
79
- else
80
- object.destroy
81
- end
83
+ object = container.files.get(object_info['oid'])
84
+
85
+ raise NotFound, "Swift object '#{object_id}' not found" if object.nil?
86
+
87
+ object.destroy
82
88
  rescue Exception => e
83
- raise BlobstoreError,
84
- "Failed to delete object '#{object_id}': #{e.message}"
89
+ raise BlobstoreError, "Failed to delete object '#{object_id}': #{e.message}"
85
90
  end
86
91
 
87
- private
88
-
89
- def generate_object_id
90
- UUIDTools::UUID.random_create.to_s
92
+ def object_exists?(object_id)
93
+ object_info = decode_object_id(object_id)
94
+ object = container.files.head(object_info['oid'])
95
+ object.nil? ? false : true
96
+ rescue Exception => e
97
+ raise BlobstoreError, "Failed to find object '#{object_id}': #{e.message}"
91
98
  end
92
99
 
100
+ private
101
+
93
102
  def encode_object_id(object_id, public_url = nil)
94
- json = MultiJson.encode({:oid => object_id, :purl => public_url})
95
- URI::escape(Base64.encode64(json))
103
+ json = MultiJson.encode({ oid: object_id, purl: public_url })
104
+ URI.escape(Base64.encode64(json))
96
105
  end
97
106
 
98
107
  def decode_object_id(object_id)
99
108
  begin
100
- object_info = MultiJson.decode(Base64.decode64(URI::unescape(object_id)))
101
- rescue MultiJson::DecodeError => e
102
- raise BlobstoreError, "Failed to parse object_id: #{e.message}"
109
+ object_info = MultiJson.decode(Base64.decode64(URI.unescape(object_id)))
110
+ rescue MultiJson::DecodeError
111
+ object_info = {}
112
+ object_info['oid'] = object_id
103
113
  end
104
114
 
105
- if !object_info.kind_of?(Hash) || object_info["oid"].nil?
106
- raise BlobstoreError, "Invalid object_id: #{object_info.inspect}"
107
- end
115
+ raise BlobstoreError, "Invalid object_id: #{object_info.inspect}" if !object_info.kind_of?(Hash) || object_info['oid'].nil?
116
+
108
117
  object_info
109
118
  end
110
119
 
111
120
  def validate_options(options)
112
- unless options.is_a?(Hash)
113
- raise "Invalid options format, Hash expected, #{options.class} given"
114
- end
115
- unless options.has_key?(:container_name)
116
- raise "Swift container name is missing"
117
- end
118
- unless options.has_key?(:swift_provider)
119
- raise "Swift provider is missing"
120
- end
121
+ raise "Invalid options format, Hash expected, #{options.class} given" unless options.is_a?(Hash)
122
+ raise 'Swift container name is missing' unless options.has_key?(:container_name)
123
+ raise 'Swift provider is missing' unless options.has_key?(:swift_provider)
121
124
  case options[:swift_provider]
122
- when "hp"
123
- unless options.has_key?(:hp)
124
- raise "HP options are missing"
125
- end
126
- unless options[:hp].is_a?(Hash)
127
- raise "Invalid HP options, Hash expected,
128
- #{options[:hp].class} given"
129
- end
130
- unless options[:hp].has_key?(:hp_account_id)
131
- raise "HP account ID is missing"
132
- end
133
- unless options[:hp].has_key?(:hp_secret_key)
134
- raise "HP secret key is missing"
135
- end
136
- unless options[:hp].has_key?(:hp_tenant_id)
137
- raise "HP tenant ID is missing"
138
- end
139
- when "rackspace"
140
- unless options.has_key?(:rackspace)
141
- raise "Rackspace options are missing"
142
- end
143
- unless options[:rackspace].is_a?(Hash)
144
- raise "Invalid Rackspace options, Hash expected,
145
- #{options[:rackspace].class} given"
146
- end
147
- unless options[:rackspace].has_key?(:rackspace_username)
148
- raise "Rackspace username is missing"
149
- end
150
- unless options[:rackspace].has_key?(:rackspace_api_key)
151
- raise "Rackspace API key is missing"
152
- end
125
+ when 'hp'
126
+ raise 'HP options are missing' unless options.has_key?(:hp)
127
+ raise "Invalid HP options, Hash expected, #{options[:hp].class} given" unless options[:hp].is_a?(Hash)
128
+ raise 'HP access key is missing' unless options[:hp].has_key?(:hp_access_key)
129
+ raise 'HP secret key is missing' unless options[:hp].has_key?(:hp_secret_key)
130
+ raise 'HP tenant ID is missing' unless options[:hp].has_key?(:hp_tenant_id)
131
+ raise 'HP availability zone is missing' unless options[:hp].has_key?(:hp_avl_zone)
132
+ when 'openstack'
133
+ raise 'OpenStack options are missing' unless options.has_key?(:openstack)
134
+ raise "Invalid OpenStack options, Hash expected, #{options[:openstack].class} given" unless options[:openstack].is_a?(Hash)
135
+ raise 'OpenStack authorization URL is missing' unless options[:openstack].has_key?(:openstack_auth_url)
136
+ raise 'OpenStack user name is missing' unless options[:openstack].has_key?(:openstack_username)
137
+ raise 'OpenStack API key is missing' unless options[:openstack].has_key?(:openstack_api_key)
138
+ raise 'OpenStack tenant is missing' unless options[:openstack].has_key?(:openstack_tenant)
139
+ when 'rackspace'
140
+ raise 'Rackspace options are missing' unless options.has_key?(:rackspace)
141
+ raise "Invalid Rackspace options, Hash expected, #{options[:rackspace].class} given" unless options[:rackspace].is_a?(Hash)
142
+ raise 'Rackspace username is missing' unless options[:rackspace].has_key?(:rackspace_username)
143
+ raise 'Rackspace API key is missing' unless options[:rackspace].has_key?(:rackspace_api_key)
153
144
  else
154
145
  raise "Swift provider #{options[:swift_provider]} not supported"
155
146
  end
@@ -3,7 +3,7 @@
3
3
  module Bosh
4
4
  module Blobstore
5
5
  class Client
6
- VERSION = "0.5.0"
6
+ VERSION = '1.5.0.pre.1113'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,32 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blobstore_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
5
- prerelease:
4
+ version: 1.5.0.pre.1113
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - VMware
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
12
+ date: 2013-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: aws-s3
15
+ name: aws-sdk
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.6.2
21
+ version: 1.8.5
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.6.2
29
+ version: 1.8.5
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: fog
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 1.6.0
37
+ version: 1.14.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,23 +42,23 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 1.6.0
45
+ version: 1.14.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: httpclient
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: '2.2'
53
+ version: 2.2.4
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: '2.2'
61
+ version: 2.2.4
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: multi_json
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 1.1.0
69
+ version: '1.1'
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 1.1.0
77
+ version: '1.1'
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: ruby-atmos-pure
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -91,22 +91,6 @@ dependencies:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
93
  version: 1.0.5
94
- - !ruby/object:Gem::Dependency
95
- name: uuidtools
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: 2.1.2
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: 2.1.2
110
94
  - !ruby/object:Gem::Dependency
111
95
  name: bosh_common
112
96
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +98,7 @@ dependencies:
114
98
  requirements:
115
99
  - - ~>
116
100
  - !ruby/object:Gem::Version
117
- version: '0.5'
101
+ version: 1.5.0.pre.1113
118
102
  type: :runtime
119
103
  prerelease: false
120
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,37 +106,33 @@ dependencies:
122
106
  requirements:
123
107
  - - ~>
124
108
  - !ruby/object:Gem::Version
125
- version: '0.5'
126
- description: BOSH blobstore client
127
- email: support@vmware.com
109
+ version: 1.5.0.pre.1113
110
+ description: ! 'BOSH blobstore client
111
+
112
+ cfd471'
113
+ email: support@cloudfoundry.com
128
114
  executables:
129
115
  - blobstore_client_console
130
116
  extensions: []
131
117
  extra_rdoc_files: []
132
118
  files:
133
119
  - bin/blobstore_client_console
120
+ - config/local.yml.example
134
121
  - lib/blobstore_client.rb
135
122
  - lib/blobstore_client/atmos_blobstore_client.rb
136
123
  - lib/blobstore_client/base.rb
137
124
  - lib/blobstore_client/client.rb
125
+ - lib/blobstore_client/dav_blobstore_client.rb
138
126
  - lib/blobstore_client/errors.rb
139
127
  - lib/blobstore_client/local_client.rb
140
128
  - lib/blobstore_client/s3_blobstore_client.rb
141
129
  - lib/blobstore_client/simple_blobstore_client.rb
142
130
  - lib/blobstore_client/swift_blobstore_client.rb
143
131
  - lib/blobstore_client/version.rb
144
- - README
145
- - Rakefile
146
- - spec/assets/file
147
- - spec/spec_helper.rb
148
- - spec/unit/atmos_blobstore_client_spec.rb
149
- - spec/unit/blobstore_client_spec.rb
150
- - spec/unit/local_client_spec.rb
151
- - spec/unit/s3_blobstore_client_spec.rb
152
- - spec/unit/simple_blobstore_client_spec.rb
153
- - spec/unit/swift_blobstore_client_spec.rb
154
- homepage: http://www.vmware.com
155
- licenses: []
132
+ - README.md
133
+ homepage: https://github.com/cloudfoundry/bosh
134
+ licenses:
135
+ - Apache 2.0
156
136
  post_install_message:
157
137
  rdoc_options: []
158
138
  require_paths:
@@ -162,31 +142,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
142
  requirements:
163
143
  - - ! '>='
164
144
  - !ruby/object:Gem::Version
165
- version: '0'
166
- segments:
167
- - 0
168
- hash: -2537561053731340493
145
+ version: 1.9.3
169
146
  required_rubygems_version: !ruby/object:Gem::Requirement
170
147
  none: false
171
148
  requirements:
172
- - - ! '>='
149
+ - - ! '>'
173
150
  - !ruby/object:Gem::Version
174
- version: '0'
175
- segments:
176
- - 0
177
- hash: -2537561053731340493
151
+ version: 1.3.1
178
152
  requirements: []
179
153
  rubyforge_project:
180
- rubygems_version: 1.8.24
154
+ rubygems_version: 1.8.23
181
155
  signing_key:
182
156
  specification_version: 3
183
157
  summary: BOSH blobstore client
184
- test_files:
185
- - spec/assets/file
186
- - spec/spec_helper.rb
187
- - spec/unit/atmos_blobstore_client_spec.rb
188
- - spec/unit/blobstore_client_spec.rb
189
- - spec/unit/local_client_spec.rb
190
- - spec/unit/s3_blobstore_client_spec.rb
191
- - spec/unit/simple_blobstore_client_spec.rb
192
- - spec/unit/swift_blobstore_client_spec.rb
158
+ test_files: []
data/README DELETED
@@ -1 +0,0 @@
1
- Blobstore client for VMware AppCloud Outer Shell.