fog-dtdream 0.0.6 → 0.0.7

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: 6398420d365c49d09affecd30f8cfd33b24cb332
4
- data.tar.gz: 6afaf704a2a6f74e7d8e5aa923e6eb52def8f8ab
3
+ metadata.gz: f8c5290adef3beff7f2be88066e5adc31b613f73
4
+ data.tar.gz: 815decd956a9bb646000c7fb148395b3a43ddca4
5
5
  SHA512:
6
- metadata.gz: fd17846c872247acb8d5229e73ddbcc6a396f77a3e02ca349b0e0e1e987f1dae4610aeef1a16056e1f67326ae85f06f21e9b0871eff47bf528a6931670d78c83
7
- data.tar.gz: 8081c3e90cab87be249b1ce6c5764cb29b484b3a89ce2a4cb87d3f85eba838c75a9e1f24c94b7d1fedbd9c4e878cc352ae9903b0c56b0fc78bc035181164532d
6
+ metadata.gz: e41c00d5e2d7866a14a10845cf5d7de046728eee5cfc247b9556bbd3c131de390dd3ec1f6f32e1e1f8472e4417df1a1c59750b0de39cc0491017ad8777e93b87
7
+ data.tar.gz: 61c636ed394e684a92212a7530251f9202fe8da2863ed88b807d8528431f37f63d1aaae09d57f132e817b4b460d9d4e17c112812e7560db177e3b978e9b0de08
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *~
data/.rspec CHANGED
File without changes
data/.travis.yml CHANGED
File without changes
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 TODO: Write your name
3
+ Copyright (c) 2015 dengqinsi
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,14 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fog/dtdream`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
@@ -13,27 +11,321 @@ gem 'fog-dtdream'
13
11
  ```
14
12
 
15
13
  And then execute:
16
-
14
+ ```shell
17
15
  $ bundle
16
+ ```
18
17
 
19
18
  Or install it yourself as:
20
19
 
20
+ ```shell
21
21
  $ gem install fog-dtdream
22
+ ```
22
23
 
23
24
  ## Usage
25
+ Before you can use fog-dtdream, you must require it in your application:
24
26
 
25
- TODO: Write usage instructions here
27
+ ```ruby
28
+ require 'fog/dtdream'
29
+ ```
26
30
 
27
- ## Development
31
+ Since it's a bad practice to have your credentials in source code, you should load them from default fog configuration file: ```~/.fog```. This file could look like this:
28
32
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+ ```
34
+ default:
35
+ :aliyun_accesskey_id: <YOUR_ACCESS_KEY_ID>,
36
+ :aliyun_accesskey_secret: <YOUR_SECRET_ACCESS_KEY>,
37
+ :aliyun_oss_endpoint: <YOUR_OSS_ENDPOINT>,
38
+ :aliyun_oss_location: <YOUR_OSS_LOACTION>,
39
+ :aliyun_oss_bucket: <YOUR_OSS_BUCKET>
40
+ ```
30
41
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+ ### Connecting to OSS
43
+ ```ruby
44
+ conn = Fog::Storage[:dtdream]
45
+ ```
46
+
47
+ If you haven't modified your default fog configuration file or you don't want to use it, you can load your credentials by this way:
48
+ ```ruby
49
+ opt = {
50
+ :provider => 'dtdream',
51
+ :aliyun_accesskey_id => <YOUR_ACCESS_KEY_ID>,
52
+ :aliyun_accesskey_secret => <YOUR_SECRET_ACCESS_KEY>,
53
+ :aliyun_oss_endpoint => <YOUR_OSS_ENDPOINT>,
54
+ :aliyun_oss_location => <YOUR_OSS_LOACTION>,
55
+ :aliyun_oss_bucket => <YOUR_OSS_BUCKET>,
56
+ }
57
+ conn = Fog::Storage.new(opt)
58
+ ```
59
+
60
+ ## Fog::Dtdream Abstractions
61
+
62
+ Fog::Dtdream provides both a **model** and **request** abstraction. The request abstraction provides the most efficient interface and the model abstraction wraps the request abstraction to provide a convenient `ActiveModel` like interface.
63
+
64
+ ### Request Layer
65
+ The Fog::Storage object supports a number of methods that wrap individual HTTP requests to the OSS API.
66
+
67
+ To see a list of requests supported by the storage service:
68
+
69
+ conn.requests
70
+
71
+ This returns:
72
+ ```
73
+ [[nil, :copy_object], [nil, :delete_bucket], [nil, :delete_object], [nil, :get_bucket], [nil, :get_object], [nil, :get_object_http_url], [nil, :get_object_https_url], [nil, :head_object], [nil, :put_bucket], [nil, :put_object], [nil, :list_buckets], [nil, :list_objects], [nil, :get_containers], [nil, :get_container], [nil, :delete_container], [nil, :put_container]]
74
+ ```
75
+
76
+ #### Example Requests(list_buckets)
77
+ To request all of buckets:
78
+
79
+ ```ruby
80
+ conn.list_buckets
81
+ ```
82
+
83
+ And this returns like the flowing;
84
+ ```
85
+ [{"Location"=>"oss-cn-beijing", "Name"=>"dt1", "CreationDate"=>"2015-07-30T08:38:02.000Z"}, {"Location"=>"oss-cn-shenzhen", "Name"=>"ruby1", "CreationDate"=>"2015-07-30T02:22:34.000Z"}, {"Location"=>"oss-cn-qingdao", "Name"=>"yuanhang123", "CreationDate"=>"2015-05-18T03:06:31.000Z"}]
86
+ ```
87
+
88
+ You can also request in this way;
89
+ ```ruby
90
+ conn.list_buckets(:prefix=>"pre")
91
+ ```
92
+
93
+ Here is a summary of the optional parameters:
94
+ <table>
95
+ <tr>
96
+ <th>Parameters</th>
97
+ <th>Description</th>
98
+ </tr>
99
+ <tr>
100
+ <td>:prefix</td>
101
+ <td>
102
+ The bucket name of the results must start with 'prefix'.It won't filter prefix information if not set<br>
103
+ Data Types: String<br>
104
+ Defaults:none
105
+ </td>
106
+ </tr>
107
+ <tr>
108
+ <td>:marker</td>
109
+ <td>
110
+ The result will start from the marker alphabetically.It wil start from the first if not set.<br>
111
+ Data Types: String<br>
112
+ Defaults: none
113
+ </tr>
114
+ <tr>
115
+ <td>:maxKeys</td>
116
+ <td>
117
+ Set the max number of the results. It will set to 100 if not set. The max value of maxKeys is 1000.<br>
118
+ Data Types: String<br>
119
+ Defaults: 100
120
+ </td>
121
+ </tr>
122
+ </table>
123
+
124
+ To learn more about `Fog::Dtdream` request methods, you can refer to our source code. To learn more about OSS API, refer to [AliYun OSS API](https://docs.aliyun.com/?spm=5176.383663.9.2.jpghde#/pub/oss/api-reference/abstract).
125
+
126
+ ### Model Layer
127
+ Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors.
128
+
129
+ Here is a summary of common model methods:
130
+
131
+ <table>
132
+ <tr>
133
+ <th>Method</th>
134
+ <th>Description</th>
135
+ </tr>
136
+ <tr>
137
+ <td>create</td>
138
+ <td>
139
+ Accepts hash of attributes and creates object.<br>
140
+ Note: creation is a non-blocking call and you will be required to wait for a valid state before using resulting object.
141
+ </td>
142
+ </tr>
143
+ <tr>
144
+ <td>save</td>
145
+ <td>Saves object.<br>
146
+ Note: not all objects support updating object.</td>
147
+ </tr>
148
+ <tr>
149
+ <td>destroy</td>
150
+ <td>
151
+ Destroys object.<br>
152
+ Note: this is a non-blocking call and object deletion might not be instantaneous.
153
+ </td>
154
+ <tr>
155
+ <td>reload</td>
156
+ <td>Updates object with latest state from service.</td>
157
+ <tr>
158
+ <td>attributes</td>
159
+ <td>Returns a hash containing the list of model attributes and values.</td>
160
+ </tr>
161
+ <td>identity</td>
162
+ <td>
163
+ Returns the identity of the object.<br>
164
+ Note: This might not always be equal to object.id.
165
+ </td>
166
+ </tr>
167
+ </table>
168
+
169
+ The remainder of this document details the model abstraction.
170
+
171
+ **Note:** Fog sometimes refers to OSS containers as directories.
172
+
173
+ ## List Directories
174
+
175
+ To retrieve a list of directories:
176
+
177
+ ```ruby
178
+ conn.directories
179
+ ```
180
+
181
+ This returns a collection of `Fog::Storage::Dtdream::Directory` models:
182
+
183
+ ## Get Directory
184
+
185
+ To retrieve a specific directory:
186
+
187
+ ```ruby
188
+ conn.directories.get "dir"
189
+ ```
190
+
191
+ This returns a `Fog::Storage::Dtdream::Directory` instance:
192
+
193
+ ## Create Directory
194
+
195
+ To create a directory:
196
+
197
+ ```ruby
198
+ conn.directories.create :key => 'backups'
199
+ ```
200
+
201
+ ## Delete Directory
202
+
203
+ To delete a directory:
204
+
205
+ ```ruby
206
+ directory.destroy
207
+ ```
208
+
209
+ **Note**: Directory must be empty before it can be deleted.
210
+
211
+
212
+ ## Directory URL
213
+
214
+ To get a directory's URL:
215
+
216
+ ```ruby
217
+ directory.public_url
218
+ ```
219
+
220
+ ## List Files
221
+
222
+ To list files in a directory:
223
+
224
+ ```ruby
225
+ directory.files
226
+ ```
227
+
228
+ **Note**: File contents is not downloaded until `body` attribute is called.
229
+
230
+ ## Upload Files
32
231
 
33
- ## Contributing
232
+ To upload a file into a directory:
233
+
234
+ ```ruby
235
+ file = directory.files.create :key => 'space.jpg', :body => File.open "space.jpg"
236
+ ```
237
+
238
+ **Note**: For files larger than 5 GB please refer to the [Upload Large Files](#upload_large_files) section.
239
+
240
+ ### Additional Parameters
241
+
242
+ The `create` method also supports the following key values:
243
+
244
+ <table>
245
+ <tr>
246
+ <th>Key</th>
247
+ <th>Description</th>
248
+ </tr>
249
+ <tr>
250
+ <td>:content_type</td>
251
+ <td>The content type of the object. Cloud Files will attempt to auto detect this value if omitted.</td>
252
+ </tr>
253
+ <tr>
254
+ <td>:origin</td>
255
+ <td>The origin is the URI of the object's host.</td>
256
+ </tr>
257
+ <tr>
258
+ <td>:etag</td>
259
+ <td>The MD5 checksum of your object's data. If specified, Cloud Files will validate the integrity of the uploaded object.</td>
260
+ </tr>
261
+ </table>
262
+
263
+ ## Upload Large Files
264
+
265
+ OSS requires files larger than 5 GB (the OSS default limit) to be uploaded into segments along with an accompanying manifest file. All of the segments must be uploaded to the same container.
266
+
267
+ Segmented files are downloaded like ordinary files. See [Download Files](#download-files) section for more information.
268
+
269
+ ## Download Files
270
+
271
+ The most efficient way to download files from a private or public directory is as follows:
272
+
273
+ ```ruby
274
+ File.open('downloaded-file.jpg', 'w') do | f |
275
+ directory.files.get("my_big_file.jpg") do | data, remaining, content_length |
276
+ f.syswrite data
277
+ end
278
+ end
279
+ ```
34
280
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fog-dtdream. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
281
+ This will download and save the file.
36
282
 
283
+ **Note**: The `body` attribute of file will be empty if a file has been downloaded using this method.
284
+
285
+ If a file object has already been loaded into memory, you can save it as follows:
286
+
287
+ ```ruby
288
+ File.open('germany.jpg', 'w') {|f| f.write(file_object.body) }
289
+ ```
290
+
291
+ **Note**: This method is more memory intensive as the entire object is loaded into memory before saving the file as in the example above.
292
+
293
+
294
+ ## File URL
295
+
296
+ To get a file's URL:
297
+
298
+ ```ruby
299
+ file.public_url
300
+ ```
301
+
302
+ ## Copy File
303
+
304
+ Cloud Files supports copying files. To copy files into a container named "trip" with a name of "europe.jpg" do the following:
305
+
306
+ ```ruby
307
+ file.copy("trip", "europe.jpg")
308
+ ```
309
+
310
+ To move or rename a file, perform a copy operation and then delete the old file:
311
+
312
+ ```ruby
313
+ file.copy("trip", "germany.jpg")
314
+ file.destroy
315
+ ```
316
+
317
+ ## Delete File
318
+
319
+ To delete a file:
320
+
321
+ ```ruby
322
+ file.destroy
323
+ ```
324
+ ## Development
325
+
326
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
327
+
328
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
329
 
38
330
  ## License
39
331
 
data/fog-dtdream.gemspec CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["dengqinsi"]
10
10
  spec.email = ["dengqs@dtdream.com"]
11
11
 
12
- spec.summary = %q{Module use 'fog' gem to support Aliyun Web Services.}
13
- spec.description = %q{Support aliyun OSS in version 0.0.3. It will support more aliyun services later.}
14
- spec.homepage = "https://github.com/denques/fog-aliyun.git"
12
+ spec.summary = %q{Use 'fog' gem to support Aliyun Web Services.}
13
+ spec.description = %q{As a FOG provider, fog-dtdream support aliyun OSS. Maybe it will support more aliyun services later.}
14
+ spec.homepage = "https://git.oschina.net/dengqinsi/fog-dtdream.git"
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency 'fog-json', '~> 1.0'
28
28
  spec.add_dependency 'fog-xml', '~> 0.1'
29
29
  spec.add_dependency 'ipaddress', '~> 0.8'
30
- spec.add_dependency 'activesupport', '~> 4.2'
30
+ spec.add_dependency 'xml-simple', '~> 1.1'
31
31
  end
@@ -0,0 +1,29 @@
1
+ class Dtdream < Fog::Bin
2
+ class << self
3
+ def class_for(key)
4
+ case key
5
+ when :storage
6
+ Fog::Storage::Dtdream
7
+ else
8
+ raise ArgumentError, "Unrecognized service: #{key}"
9
+ end
10
+ end
11
+
12
+ def [](service)
13
+ @@connections ||= Hash.new do |hash, key|
14
+ hash[key] = case key
15
+ when :storage
16
+ Fog::Logger.warning("Dtdream[:storage] is not recommended, use Storage[:openstack] for portability")
17
+ Fog::Storage.new(:provider => 'dtdream')
18
+ else
19
+ raise ArgumentError, "Unrecognized service: #{key.inspect}"
20
+ end
21
+ end
22
+ @@connections[service]
23
+ end
24
+
25
+ def services
26
+ Fog::Dtdream.services
27
+ end
28
+ end
29
+ end
@@ -9,10 +9,13 @@ module Fog
9
9
 
10
10
  def all
11
11
  containers = service.get_containers()
12
+ if nil == containers
13
+ return nil
14
+ end
12
15
  data = Array.new
13
16
  i = 0
14
17
  containers.each do |entry|
15
- key = entry["Prefix"]
18
+ key = entry["Prefix"][0]
16
19
  key[-1] = ''
17
20
  data[i] = {:key=>key}
18
21
  i = i + 1
@@ -12,37 +12,20 @@ module Fog
12
12
  requires :key
13
13
  prefix = key+'/'
14
14
  ret = service.list_objects(:prefix=>prefix)["Contents"]
15
- if ret.size == 1
15
+
16
+ if ret.nil?
17
+ puts " Not found: Direction not exist!"
18
+ false
19
+ elsif ret.size == 1
16
20
  service.delete_container(key)
17
21
  true
18
22
  else
19
- if ret.size == 0
20
- raise Fog::Storage::Dtdream::NotFound, " Not found: Direction not exist!"
21
- elsif ret.size > 1
22
- raise Fog::Storage::Dtdream::NotFound, " Forbidden: Direction not empty!"
23
- end
23
+ raise Fog::Storage::Dtdream::Error, " Forbidden: Direction not empty!"
24
24
  false
25
25
  end
26
26
  end
27
27
 
28
28
  def files
29
- # requires :key
30
- # if key != "" && key != "." && key != nil
31
- # prefix = key+"/"
32
- # end
33
- # files = service.list_objects({:prefix => prefix})["Contents"]
34
- # data = Array.new
35
- # i = 0
36
- # files.each do |file|
37
- # if file["Key"][0][-1] != "/"
38
- # key = file["Key"][0]
39
- # data[i] = {:key=>key}
40
- # i = i + 1
41
- # end
42
- # end
43
- #
44
- # #load(data)
45
- # data
46
29
  @files ||= begin
47
30
  Fog::Storage::Dtdream::Files.new(
48
31
  :directory => self,
@@ -33,10 +33,17 @@ module Fog
33
33
 
34
34
  def copy(target_directory_key, target_file_key, options={})
35
35
  requires :directory, :key
36
- options['Content-Type'] ||= content_type if content_type
37
- options['Access-Control-Allow-Origin'] ||= access_control_allow_origin if access_control_allow_origin
38
- options['Origin'] ||= origin if origin
39
- service.copy_object(directory.key, key, target_directory_key, target_file_key, options)
36
+ if directory.key == ""
37
+ source_object = key
38
+ else
39
+ source_object = directory.key+"/"+key
40
+ end
41
+ if target_directory_key == ""
42
+ target_object = target_file_key
43
+ else
44
+ target_object = target_directory_key+"/"+target_file_key
45
+ end
46
+ service.copy_object(nil, source_object, nil, target_object, options)
40
47
  target_directory = service.directories.new(:key => target_directory_key)
41
48
  target_directory.files.get(target_file_key)
42
49
  end
@@ -105,7 +112,13 @@ module Fog
105
112
  else
106
113
  object = directory.key+"/"+key
107
114
  end
108
- data = service.put_object_with_body(object, body, options)
115
+ if body.is_a?(::File)
116
+ data = service.put_object(object, body, options).data
117
+ elsif body.is_a?(String)
118
+ data = service.put_object_with_body(object, body, options).data
119
+ else
120
+ raise Fog::Storage::Dtdream::Error, " Forbidden: Invalid body type: #{body.class}!"
121
+ end
109
122
  update_attributes_from(data)
110
123
  refresh_metadata
111
124
 
@@ -176,7 +189,7 @@ module Fog
176
189
  end
177
190
 
178
191
  def update_attributes_from(data)
179
- merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
192
+ merge_attributes(data[:headers].reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
180
193
  end
181
194
  end
182
195
  end
@@ -18,22 +18,23 @@ module Fog
18
18
  if directory.key != "" && directory.key != "." && directory.key != nil
19
19
  prefix = directory.key+"/"
20
20
  end
21
- files = service.list_objects({:prefix => prefix})["ListBucketResult"]["Contents"]
21
+ files = service.list_objects({:prefix => prefix})["Contents"]
22
22
  data = Array.new
23
23
  i = 0
24
24
  files.each do |file|
25
- if file["Key"][-1] != "/"
26
- content_length = file["Size"].to_i
27
- key = file["Key"]
28
- lastModified = file["LastModified"]
29
- if lastModified != nil && lastModified != ""
30
- last_modified = (Time.parse(lastModified)).localtime
31
- else
32
- last_modified = nil
33
- end
34
- data[i] = {:content_length=>content_length,
35
- :key=>key,
36
- :last_modified=>last_modified}
25
+ if file["Key"][0][-1] != "/"
26
+ content_length = file["Size"][0].to_i
27
+ key = file["Key"][0]
28
+ lastModified = file["LastModified"][0]
29
+ if lastModified != nil && lastModified != ""
30
+ last_modified = (Time.parse(lastModified)).localtime
31
+ else
32
+ last_modified = nil
33
+ end
34
+ data[i] = {:content_length => content_length,
35
+ :key => key,
36
+ :last_modified => last_modified,
37
+ :etag => file["ETag"][0]}
37
38
  i = i + 1
38
39
  end
39
40
  end
@@ -69,7 +70,7 @@ module Fog
69
70
 
70
71
  data = service.head_object(object).data
71
72
  contentLen = data[:headers]["Content-Length"].to_i
72
- if data[:status] != 200 || contentLen <= 0
73
+ if data[:status] != 200
73
74
  return nil
74
75
  end
75
76
  lastModified = data[:headers]["Last-Modified"]
@@ -83,7 +84,9 @@ module Fog
83
84
  file_data = {
84
85
  :content_length => contentLen,
85
86
  :key => key,
86
- :last_modified => last_modified
87
+ :last_modified => last_modified,
88
+ :content_type => data[:headers]["Content-Type"],
89
+ :etag => data[:headers]["ETag"]
87
90
  }
88
91
 
89
92
  if block_given?
@@ -153,7 +156,9 @@ module Fog
153
156
  file_data = {
154
157
  :content_length => data[:headers]["Content-Length"].to_i,
155
158
  :key => key,
156
- :last_modified => last_modified
159
+ :last_modified => last_modified,
160
+ :content_type => data[:headers]["Content-Type"],
161
+ :etag => data[:headers]["ETag"]
157
162
  }
158
163
  new(file_data)
159
164
  rescue Fog::Storage::Dtdream::NotFound
@@ -10,8 +10,12 @@ module Fog
10
10
  # * target_container_name<~String> - Name of bucket to create copy in
11
11
  # * target_object_name<~String> - Name for new copy of object
12
12
  # * options<~Hash> - Additional headers options={}
13
- def copy_object(source_bucket, source_object, target_bucket, target_object)
14
- #headers = { 'X-Copy-From' => "/#{source_container_name}/#{source_object_name}" }.merge(options)
13
+ def copy_object(source_bucket, source_object, target_bucket, target_object, options = {})
14
+ options = options.reject {|key, value| value.nil?}
15
+ bucket = options[:bucket]
16
+ bucket ||= @aliyun_oss_bucket
17
+ source_bucket ||= bucket
18
+ target_bucket ||= bucket
15
19
  headers = { 'x-oss-copy-source' => "/#{source_bucket}/#{source_object}" }
16
20
  location = get_bucket_location(target_bucket)
17
21
  endpoint = "http://"+location+".aliyuncs.com"
@@ -14,7 +14,7 @@ module Fog
14
14
  :endpoint => endpoint
15
15
  )
16
16
  xml = ret.data[:body]
17
- result = Hash.from_xml(xml)
17
+ result = XmlSimple.xml_in(xml)
18
18
  end
19
19
 
20
20
  def get_bucket_location(bucket)
@@ -27,7 +27,7 @@ module Fog
27
27
  :bucket => bucket,
28
28
  :resource => resource
29
29
  )
30
- location = Hash.from_xml(ret.data[:body])["LocationConstraint"]
30
+ location = XmlSimple.xml_in(ret.data[:body])
31
31
  end
32
32
 
33
33
  def get_bucket_acl(bucket)
@@ -43,7 +43,7 @@ module Fog
43
43
  :resource => resource,
44
44
  :endpoint => endpoint
45
45
  )
46
- acl = Hash.from_xml(ret.data[:body])["AccessControlPolicy"]["AccessControlList"]["Grant"]
46
+ acl = XmlSimple.xml_in(ret.data[:body])["AccessControlList"][0]["Grant"][0]
47
47
  end
48
48
 
49
49
  #{"AllowedOrigin"=>["1"], "AllowedMethod"=>["DELETE"], "AllowedHeader"=>["1"], "ExposeHeader"=>["1"], "MaxAgeSeconds"=>["1"]}
@@ -53,14 +53,18 @@ module Fog
53
53
  attribute = '?cors'
54
54
  resource = bucket+'/'+attribute
55
55
  ret = request(
56
- :expects => [200, 203],
56
+ :expects => [200, 203, 404],
57
57
  :method => 'GET',
58
58
  :path => attribute,
59
59
  :bucket => bucket,
60
60
  :resource => resource,
61
61
  :endpoint => endpoint
62
62
  )
63
- cors = Hash.from_xml(ret.data[:body])["CORSConfiguration"]["CORSRule"]
63
+ if 404 != ret.data[:status]
64
+ cors = XmlSimple.xml_in(ret.data[:body])["CORSRule"][0]
65
+ else
66
+ nil
67
+ end
64
68
  end
65
69
 
66
70
  #{"ID"=>["651a67ed-5b4f-4d9b-87ae-49dbaaa4b0ad"], "Prefix"=>["1"], "Status"=>["Enabled"], "Expiration"=>[{"Days"=>["30"]}]}
@@ -70,14 +74,18 @@ module Fog
70
74
  attribute = '?lifecycle'
71
75
  resource = bucket+'/'+attribute
72
76
  ret = request(
73
- :expects => [200, 203],
77
+ :expects => [200, 203, 404],
74
78
  :method => 'GET',
75
79
  :path => attribute,
76
80
  :bucket => bucket,
77
81
  :resource => resource,
78
82
  :endpoint => endpoint
79
83
  )
80
- lifecycle = Hash.from_xml(ret.data[:body])["LifecycleConfiguration"]["Rule"]
84
+ if 404 != ret.data[:status]
85
+ lifecycle = XmlSimple.xml_in(ret.data[:body])["Rule"][0]
86
+ else
87
+ nil
88
+ end
81
89
  end
82
90
 
83
91
  #返回log的prefix,如果没有设置log开关,返回nil
@@ -94,7 +102,7 @@ module Fog
94
102
  :resource => resource,
95
103
  :endpoint => endpoint
96
104
  )
97
- logging = Hash.from_xml(ret.data[:body])["BucketLoggingStatus"]["LoggingEnabled"]
105
+ logging = XmlSimple.xml_in(ret.data[:body])["LoggingEnabled"][0]["TargetPrefix"]
98
106
  end
99
107
 
100
108
  #{"AllowEmptyReferer"=>["true"], "RefererList"=>[{}]}
@@ -111,7 +119,7 @@ module Fog
111
119
  :resource => resource,
112
120
  :endpoint => endpoint
113
121
  )
114
- referer = Hash.from_xml(ret.data[:body])["RefererConfiguration"]
122
+ referer = XmlSimple.xml_in(ret.data[:body])
115
123
  end
116
124
 
117
125
  #{"IndexDocument"=>[{"Suffix"=>["abc.html"]}], "ErrorDocument"=>[{"Key"=>["error.html"]}]}
@@ -121,14 +129,18 @@ module Fog
121
129
  attribute = '?website'
122
130
  resource = bucket+'/'+attribute
123
131
  ret = request(
124
- :expects => [200, 203],
132
+ :expects => [200, 203, 404],
125
133
  :method => 'GET',
126
134
  :path => attribute,
127
135
  :bucket => bucket,
128
136
  :resource => resource,
129
137
  :endpoint => endpoint
130
138
  )
131
- website = Hash.from_xml(ret.data[:body])["WebsiteConfiguration"]
139
+ if 404 != ret.data[:status]
140
+ website = XmlSimple.xml_in(ret.data[:body])
141
+ else
142
+ nil
143
+ end
132
144
  end
133
145
 
134
146
  end
@@ -26,7 +26,7 @@ module Fog
26
26
  path+="&marker="+marker
27
27
  end
28
28
  if maxKeys
29
- path+="&maxKeys="+maxKeys
29
+ path+="&max-keys="+maxKeys
30
30
  end
31
31
  if delimiter
32
32
  path+="&delimiter="+delimiter
@@ -34,13 +34,13 @@ module Fog
34
34
  elsif marker
35
35
  path+="?marker="+marker
36
36
  if maxKeys
37
- path+="&maxKeys="+maxKeys
37
+ path+="&max-keys="+maxKeys
38
38
  end
39
39
  if delimiter
40
40
  path+="&delimiter="+delimiter
41
41
  end
42
42
  elsif maxKeys
43
- path+="?maxKeys="+maxKeys
43
+ path+="?max-keys="+maxKeys
44
44
  if delimiter
45
45
  path+="&delimiter="+delimiter
46
46
  end
@@ -59,7 +59,7 @@ module Fog
59
59
  :bucket => bucket
60
60
  )
61
61
  xml = ret.data[:body]
62
- result = Hash.from_xml(xml)["ListBucketResult"]["CommonPrefixes"]
62
+ result = XmlSimple.xml_in(xml)["CommonPrefixes"]
63
63
  end
64
64
  end
65
65
 
@@ -29,7 +29,7 @@ module Fog
29
29
  path+="&marker="+marker
30
30
  end
31
31
  if maxKeys
32
- path+="&maxKeys="+maxKeys
32
+ path+="&max-keys="+maxKeys
33
33
  end
34
34
  if delimiter
35
35
  path+="&delimiter="+delimiter
@@ -38,14 +38,14 @@ module Fog
38
38
  elsif marker
39
39
  path+="?marker="+marker
40
40
  if maxKeys
41
- path+="&maxKeys="+maxKeys
41
+ path+="&max-keys="+maxKeys
42
42
  end
43
43
  if delimiter
44
44
  path+="&delimiter="+delimiter
45
45
  end
46
46
 
47
47
  elsif maxKeys
48
- path+="?maxKeys="+maxKeys
48
+ path+="?max-keys="+maxKeys
49
49
  if delimiter
50
50
  path+="&delimiter="+delimiter
51
51
  end
@@ -64,7 +64,7 @@ module Fog
64
64
  :bucket => bucket
65
65
  )
66
66
  xml = ret.data[:body]
67
- result = Hash.from_xml(xml)["ListBucketResult"]["CommonPrefixes"]
67
+ result = XmlSimple.xml_in(xml)["CommonPrefixes"]
68
68
  end
69
69
  end
70
70
 
@@ -19,7 +19,7 @@ module Fog
19
19
  end
20
20
  resource = bucket+'/'+object
21
21
  para = {
22
- :expects => [200, 206],
22
+ :expects => [200, 206, 404],
23
23
  :method => 'GET',
24
24
  :path => object,
25
25
  :bucket => bucket,
@@ -32,65 +32,6 @@ module Fog
32
32
  url = "acl is wrong with value:"+acl
33
33
  end
34
34
  end
35
- # creates a temporary url
36
- #
37
- # ==== Parameters
38
- # * container<~String> - Name of container containing object
39
- # * object<~String> - Name of object to get expiring url for
40
- # * expires<~Time> - An expiry time for this url
41
- # * method<~String> - The method to use for accessing the object (GET, PUT, HEAD)
42
- # * options<~Hash> - An optional options hash
43
- # * 'scheme'<~String> - The scheme to use (http, https)
44
- # * 'host'<~String> - The host to use
45
- # * 'port'<~Integer> - The port to use
46
- #
47
- # ==== Returns
48
- # * response<~Excon::Response>:
49
- # * body<~String> - url for object
50
- #
51
- # ==== See Also
52
- # http://docs.rackspace.com/files/api/v1/cf-devguide/content/Create_TempURL-d1a444.html
53
- def create_temp_url(container, object, expires, method, options = {})
54
- raise ArgumentError, "Insufficient parameters specified." unless (container && object && expires && method)
55
- raise ArgumentError, "Storage must be instantiated with the :openstack_temp_url_key option" if @openstack_temp_url_key.nil?
56
-
57
- scheme = options[:scheme] || @scheme
58
- host = options[:host] || @host
59
- port = options[:port] || @port
60
-
61
- # POST not allowed
62
- allowed_methods = %w{GET PUT HEAD}
63
- unless allowed_methods.include?(method)
64
- raise ArgumentError.new("Invalid method '#{method}' specified. Valid methods are: #{allowed_methods.join(', ')}")
65
- end
66
-
67
- expires = expires.to_i
68
- object_path_escaped = "#{@path}/#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object,"/")}"
69
- object_path_unescaped = "#{@path}/#{Fog::OpenStack.escape(container)}/#{object}"
70
- string_to_sign = "#{method}\n#{expires}\n#{object_path_unescaped}"
71
-
72
- hmac = Fog::HMAC.new('sha1', @openstack_temp_url_key)
73
- sig = sig_to_hex(hmac.sign(string_to_sign))
74
-
75
- temp_url_options = {
76
- :scheme => scheme,
77
- :host => host,
78
- :port => port,
79
- :path => object_path_escaped,
80
- :query => "temp_url_sig=#{sig}&temp_url_expires=#{expires}"
81
- }
82
- URI::Generic.build(temp_url_options).to_s
83
- end
84
-
85
- private
86
-
87
- def sig_to_hex(str)
88
- str.unpack("C*").map { |c|
89
- c.to_s(16)
90
- }.map { |h|
91
- h.size == 1 ? "0#{h}" : h
92
- }.join
93
- end
94
35
  end
95
36
 
96
37
  class Mock
@@ -15,17 +15,17 @@ module Fog
15
15
  path+="&marker="+marker
16
16
  end
17
17
  if maxKeys
18
- path+="&maxKeys="+maxKeys
18
+ path+="&max-keys="+maxKeys
19
19
  end
20
20
 
21
21
  elsif marker
22
22
  path+="?marker="+marker
23
23
  if maxKeys
24
- path+="&maxKeys="+maxKeys
24
+ path+="&max-keys="+maxKeys
25
25
  end
26
26
 
27
27
  elsif maxKeys
28
- path+="?maxKeys="+maxKeys
28
+ path+="?max-keys="+maxKeys
29
29
  end
30
30
 
31
31
  ret = request(
@@ -34,7 +34,7 @@ module Fog
34
34
  :path => path
35
35
  )
36
36
  xml = ret.data[:body]
37
- result = Hash.from_xml(xml)["ListAllMyBucketsResult"]["Buckets"]["Bucket"]
37
+ result = XmlSimple.xml_in(xml)["Buckets"][0]
38
38
  end
39
39
 
40
40
  end
@@ -18,7 +18,7 @@ module Fog
18
18
  path+="&marker="+marker
19
19
  end
20
20
  if maxKeys
21
- path+="&maxKeys="+maxKeys
21
+ path+="&max-keys="+maxKeys
22
22
  end
23
23
  if delimiter
24
24
  path+="&delimiter="+delimiter
@@ -27,14 +27,14 @@ module Fog
27
27
  elsif marker
28
28
  path+="?marker="+marker
29
29
  if maxKeys
30
- path+="&maxKeys="+maxKeys
30
+ path+="&max-keys="+maxKeys
31
31
  end
32
32
  if delimiter
33
33
  path+="&delimiter="+delimiter
34
34
  end
35
35
 
36
36
  elsif maxKeys
37
- path+="?maxKeys="+maxKeys
37
+ path+="?max-keys="+maxKeys
38
38
  if delimiter
39
39
  path+="&delimiter="+delimiter
40
40
  end
@@ -53,7 +53,7 @@ module Fog
53
53
  :bucket => bucket
54
54
  )
55
55
  xml = ret.data[:body]
56
- result = Hash.from_xml(xml)
56
+ result = XmlSimple.xml_in(xml)
57
57
  end
58
58
 
59
59
  def list_multipart_uploads(bucket, endpoint, options = {})
@@ -72,7 +72,7 @@ module Fog
72
72
  :resource => resource,
73
73
  :endpoint => endpoint
74
74
  )
75
- result = Hash.from_xml(ret.data[:body])["ListMultipartUploadsResult"]["Upload"]
75
+ uploadid = XmlSimple.xml_in(ret.data[:body])["Upload"]
76
76
 
77
77
  end
78
78
 
@@ -92,7 +92,7 @@ module Fog
92
92
  :resource => resource,
93
93
  :endpoint => endpoint
94
94
  )
95
- result = Hash.from_xml(ret.data[:body])["ListPartsResult"]["Part"]
95
+ parts = XmlSimple.xml_in(ret.data[:body])["Part"]
96
96
  end
97
97
 
98
98
  end
@@ -19,9 +19,8 @@ module Fog
19
19
  end
20
20
 
21
21
  #object size ����100M���߷�Ƭ�ϴ���֧�ֶϵ�����
22
- if file.size >100 * 1024 * 1024
23
- put_multipart_object(bucket, object, file)
24
- return
22
+ if file.size >104857600
23
+ return put_multipart_object(bucket, object, file)
25
24
  end
26
25
 
27
26
  body = file.read
@@ -47,7 +46,7 @@ module Fog
47
46
  endpoint = "http://"+location+".aliyuncs.com"
48
47
 
49
48
  #object size ����100M���߷�Ƭ�ϴ���֧�ֶϵ�����
50
- # if body.size >100 * 1024 * 1024
49
+ # if body.size >104857600
51
50
  # put_multipart_object_with_body(bucket, object, body)
52
51
  # return
53
52
  # end
@@ -89,7 +88,11 @@ module Fog
89
88
 
90
89
  #����bucket��uploads�¼����ҵ���Ӧupload������������򴴽�upload�¼�
91
90
  uploads = list_multipart_uploads(bucket, endpoint)
92
- upload = uploads.find do |tmpupload| tmpupload["Key"][0] == object end
91
+ if nil != uploads
92
+ upload = uploads.find do |tmpupload| tmpupload["Key"][0] == object end
93
+ else
94
+ upload = nil
95
+ end
93
96
 
94
97
  parts = nil
95
98
  uploadedSize = 0
@@ -143,7 +146,7 @@ module Fog
143
146
  :resource => resource,
144
147
  :endpoint => endpoint
145
148
  )
146
- uploadid = Hash.from_xml(ret.data[:body])["InitiateMultipartUploadResult"]["UploadId"]
149
+ uploadid = XmlSimple.xml_in(ret.data[:body])["UploadId"][0]
147
150
  end
148
151
 
149
152
  def upload_part(bucket, object, endpoint, partNumber, uploadId, body)
@@ -178,7 +181,8 @@ module Fog
178
181
  part = parts[i]
179
182
  request_part[i] = {"PartNumber"=>part["PartNumber"], "ETag"=>part["ETag"]}
180
183
  end
181
- body = request_part.to_xml({root:"CompleteMultipartUpload", children:"Part", skip_instruct:true, skip_types:true})
184
+ body = XmlSimple.xml_out({"Part"=>request_part},'RootName'=>'CompleteMultipartUpload')
185
+
182
186
  path = object+"?uploadId="+uploadId
183
187
  resource = bucket+'/'+path
184
188
  ret = request(
@@ -1,6 +1,5 @@
1
1
  require 'fog/dtdream/core'
2
- require "active_support/core_ext/hash"
3
- require "active_support/core_ext/hash/conversions"
2
+ require 'xmlsimple'
4
3
 
5
4
  module Fog
6
5
  module Storage
@@ -108,7 +107,7 @@ module Fog
108
107
  if params[:headers]
109
108
  params[:headers].each do |k,v|
110
109
  if k != "Range"
111
- headers += "#{k}: #{v}\n"
110
+ headers += "#{k}:#{v}\n"
112
111
  end
113
112
  end
114
113
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Dtdream
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
data/lib/fog/dtdream.rb CHANGED
@@ -2,6 +2,7 @@ require "fog/dtdream/core"
2
2
  require "fog/dtdream/storage"
3
3
  require "fog/dtdream/version"
4
4
 
5
+
5
6
  module Fog
6
7
  module Dtdream
7
8
  # Your code goes here...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-dtdream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - dengqinsi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-19 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,21 +109,21 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.8'
111
111
  - !ruby/object:Gem::Dependency
112
- name: activesupport
112
+ name: xml-simple
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '4.2'
117
+ version: '1.1'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '4.2'
125
- description: Support aliyun OSS in version 0.0.3. It will support more aliyun services
126
- later.
124
+ version: '1.1'
125
+ description: As a FOG provider, fog-dtdream support aliyun OSS. Maybe it will support
126
+ more aliyun services later.
127
127
  email:
128
128
  - dengqs@dtdream.com
129
129
  executables: []
@@ -135,12 +135,13 @@ files:
135
135
  - ".travis.yml"
136
136
  - CODE_OF_CONDUCT.md
137
137
  - Gemfile
138
- - LICENSE.txt
138
+ - LICENSE
139
139
  - README.md
140
140
  - Rakefile
141
141
  - bin/console
142
142
  - bin/setup
143
143
  - fog-dtdream.gemspec
144
+ - lib/fog/bin/dtdream.rb
144
145
  - lib/fog/dtdream.rb
145
146
  - lib/fog/dtdream/core.rb
146
147
  - lib/fog/dtdream/models/storage/directories.rb
@@ -165,7 +166,7 @@ files:
165
166
  - lib/fog/dtdream/requests/storage/put_object.rb
166
167
  - lib/fog/dtdream/storage.rb
167
168
  - lib/fog/dtdream/version.rb
168
- homepage: https://github.com/denques/fog-aliyun.git
169
+ homepage: https://git.oschina.net/dengqinsi/fog-dtdream.git
169
170
  licenses:
170
171
  - MIT
171
172
  metadata: {}
@@ -188,6 +189,6 @@ rubyforge_project:
188
189
  rubygems_version: 2.4.8
189
190
  signing_key:
190
191
  specification_version: 4
191
- summary: Module use 'fog' gem to support Aliyun Web Services.
192
+ summary: Use 'fog' gem to support Aliyun Web Services.
192
193
  test_files: []
193
194
  has_rdoc: