fog-dtdream 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/fog-dtdream.gemspec +32 -0
- data/lib/fog/dtdream/core.rb +48 -0
- data/lib/fog/dtdream/models/storage/directories.rb +45 -0
- data/lib/fog/dtdream/models/storage/directory.rb +71 -0
- data/lib/fog/dtdream/models/storage/file.rb +174 -0
- data/lib/fog/dtdream/models/storage/files.rb +145 -0
- data/lib/fog/dtdream/requests/storage/copy_object.rb +32 -0
- data/lib/fog/dtdream/requests/storage/delete_bucket.rb +26 -0
- data/lib/fog/dtdream/requests/storage/delete_container.rb +32 -0
- data/lib/fog/dtdream/requests/storage/delete_object.rb +50 -0
- data/lib/fog/dtdream/requests/storage/get_bucket.rb +140 -0
- data/lib/fog/dtdream/requests/storage/get_container.rb +67 -0
- data/lib/fog/dtdream/requests/storage/get_containers.rb +72 -0
- data/lib/fog/dtdream/requests/storage/get_object.rb +42 -0
- data/lib/fog/dtdream/requests/storage/get_object_http_url.rb +39 -0
- data/lib/fog/dtdream/requests/storage/get_object_https_url.rb +97 -0
- data/lib/fog/dtdream/requests/storage/head_object.rb +31 -0
- data/lib/fog/dtdream/requests/storage/list_buckets.rb +46 -0
- data/lib/fog/dtdream/requests/storage/list_objects.rb +105 -0
- data/lib/fog/dtdream/requests/storage/put_bucket.rb +19 -0
- data/lib/fog/dtdream/requests/storage/put_container.rb +30 -0
- data/lib/fog/dtdream/requests/storage/put_object.rb +196 -0
- data/lib/fog/dtdream/storage.rb +206 -0
- data/lib/fog/dtdream/version.rb +5 -0
- data/lib/fog/dtdream.rb +9 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cc5888cc2436ef0e17480046ad2d4a60a74182db
|
4
|
+
data.tar.gz: 065780c8718a48ad4a9a7562b63c23a4c8d280e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: db2726ff1276ecd5562a41e2ad28a67cc4ae85e45eaabcc77556fc6c721236bcf18c3a89af2aa42b366605572f45eae5bd3eb432abf551cd55e484c07996f746
|
7
|
+
data.tar.gz: 0d5f0cb08ef09dc3f0691455de385e11affd4da2a121108067d2dd39c4cf17d452483e8620aa254194c9bb47b9f58c06e2debebde8dab1273e4bfddcaa07c1f1
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Fog::Dtdream
|
2
|
+
|
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
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'fog-dtdream'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fog-dtdream
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fog-dtdream.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fog/dtdream"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/fog-dtdream.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fog/dtdream/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fog-dtdream"
|
8
|
+
spec.version = Fog::Dtdream::VERSION
|
9
|
+
spec.authors = ["dengqinsi"]
|
10
|
+
spec.email = ["dengqs@dtdream.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Module for the 'fog' gem to support Aliyun Web Services.}
|
13
|
+
spec.description = %q{This library can be used as a module for `fog` or as standalone provider to use the Aliyun Web Services in applications..}
|
14
|
+
spec.homepage = "https://github.com/denques/fog-aliyun.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'fog/core'
|
2
|
+
require 'fog/json'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Dtdream
|
6
|
+
extend Fog::Provider
|
7
|
+
|
8
|
+
module Errors
|
9
|
+
class ServiceError < Fog::Errors::Error
|
10
|
+
attr_reader :response_data
|
11
|
+
|
12
|
+
def self.slurp(error)
|
13
|
+
if error.response.body.empty?
|
14
|
+
data = nil
|
15
|
+
message = nil
|
16
|
+
else
|
17
|
+
data = Fog::JSON.decode(error.response.body)
|
18
|
+
message = data['message']
|
19
|
+
if message.nil? and !data.values.first.nil?
|
20
|
+
message = data.values.first['message']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
new_error = super(error, message)
|
25
|
+
new_error.instance_variable_set(:@response_data, data)
|
26
|
+
new_error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class ServiceUnavailable < ServiceError; end
|
31
|
+
|
32
|
+
class BadRequest < ServiceError
|
33
|
+
attr_reader :validation_errors
|
34
|
+
|
35
|
+
def self.slurp(error)
|
36
|
+
new_error = super(error)
|
37
|
+
unless new_error.response_data.nil? or new_error.response_data['badRequest'].nil?
|
38
|
+
new_error.instance_variable_set(:@validation_errors, new_error.response_data['badRequest']['validationErrors'])
|
39
|
+
end
|
40
|
+
new_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
service(:storage , 'Storage')
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/dtdream/models/storage/directory'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Storage
|
6
|
+
class Dtdream
|
7
|
+
class Directories < Fog::Collection
|
8
|
+
model Fog::Storage::Dtdream::Directory
|
9
|
+
|
10
|
+
def all
|
11
|
+
containers = service.get_containers()
|
12
|
+
data = Array.new
|
13
|
+
i = 0
|
14
|
+
containers.each do |entry|
|
15
|
+
key = entry["Prefix"][0]
|
16
|
+
key[-1] = ''
|
17
|
+
data[i] = {:key=>key}
|
18
|
+
i = i + 1
|
19
|
+
end
|
20
|
+
|
21
|
+
load(data)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(key, options = {})
|
25
|
+
if key != nil && key != "" && key != '.'
|
26
|
+
dir = key+'/'
|
27
|
+
ret = service.head_object(dir, options)
|
28
|
+
if ret.data[:status] == 200
|
29
|
+
new(:key => key)
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
else
|
34
|
+
ret = service.get_container("")
|
35
|
+
if ret
|
36
|
+
new(:key => "")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
rescue Fog::Storage::Dtdream::NotFound
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
require 'fog/dtdream/models/storage/files'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Storage
|
6
|
+
class Dtdream
|
7
|
+
class Directory < Fog::Model
|
8
|
+
identity :key, :aliases => 'name'
|
9
|
+
|
10
|
+
attribute :bytes, :aliases => 'X-Container-Bytes-Used'
|
11
|
+
attribute :count, :aliases => 'X-Container-Object-Count'
|
12
|
+
|
13
|
+
attr_writer :public
|
14
|
+
|
15
|
+
def destroy
|
16
|
+
#��ȫ��飬���Ŀ¼�ǿղ�����ɾ��
|
17
|
+
requires :key
|
18
|
+
prefix = key+'/'
|
19
|
+
ret = service.list_objects(:prefix=>prefix)["Contents"]
|
20
|
+
if ret.size == 1
|
21
|
+
service.delete_container(key)
|
22
|
+
true
|
23
|
+
else
|
24
|
+
if ret.size == 0
|
25
|
+
raise Fog::Storage::Dtdream::NotFound, " Not found: Direction not exist!"
|
26
|
+
elsif ret.size > 1
|
27
|
+
raise Fog::Storage::Dtdream::NotFound, " Forbidden: Direction not empty!"
|
28
|
+
end
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def files
|
34
|
+
# requires :key
|
35
|
+
# if key != "" && key != "." && key != nil
|
36
|
+
# prefix = key+"/"
|
37
|
+
# end
|
38
|
+
# files = service.list_objects({:prefix => prefix})["Contents"]
|
39
|
+
# data = Array.new
|
40
|
+
# i = 0
|
41
|
+
# files.each do |file|
|
42
|
+
# if file["Key"][0][-1] != "/"
|
43
|
+
# key = file["Key"][0]
|
44
|
+
# data[i] = {:key=>key}
|
45
|
+
# i = i + 1
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# #load(data)
|
50
|
+
# data
|
51
|
+
@files ||= begin
|
52
|
+
Fog::Storage::Dtdream::Files.new(
|
53
|
+
:directory => self,
|
54
|
+
:service => service
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def public_url
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def save
|
64
|
+
requires :key
|
65
|
+
service.put_container(key)
|
66
|
+
true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Storage
|
5
|
+
class Dtdream
|
6
|
+
class File < Fog::Model
|
7
|
+
identity :key, :aliases => 'name'
|
8
|
+
|
9
|
+
attribute :access_control_allow_origin, :aliases => ['Access-Control-Allow-Origin']
|
10
|
+
attribute :content_length, :aliases => ['bytes', 'Content-Length'], :type => :integer
|
11
|
+
attribute :content_type, :aliases => ['content_type', 'Content-Type']
|
12
|
+
attribute :content_disposition, :aliases => ['content_disposition', 'Content-Disposition']
|
13
|
+
attribute :etag, :aliases => ['hash', 'Etag']
|
14
|
+
attribute :last_modified, :aliases => ['last_modified', 'Last-Modified'], :type => :time
|
15
|
+
attribute :metadata
|
16
|
+
attribute :origin, :aliases => ['Origin']
|
17
|
+
|
18
|
+
def body
|
19
|
+
attributes[:body] ||= if last_modified
|
20
|
+
collection.get(identity).body
|
21
|
+
else
|
22
|
+
''
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def body=(new_body)
|
27
|
+
attributes[:body] = new_body
|
28
|
+
end
|
29
|
+
|
30
|
+
def directory
|
31
|
+
@directory
|
32
|
+
end
|
33
|
+
|
34
|
+
def copy(target_directory_key, target_file_key, options={})
|
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)
|
40
|
+
target_directory = service.directories.new(:key => target_directory_key)
|
41
|
+
target_directory.files.get(target_file_key)
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
requires :directory, :key
|
46
|
+
service.delete_object(directory.key, key)
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
def metadata
|
51
|
+
attributes[:metadata] ||= headers_to_metadata
|
52
|
+
end
|
53
|
+
|
54
|
+
def owner=(new_owner)
|
55
|
+
if new_owner
|
56
|
+
attributes[:owner] = {
|
57
|
+
:display_name => new_owner['DisplayName'],
|
58
|
+
:id => new_owner['ID']
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def public=(new_public)
|
64
|
+
new_public
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get a url for file.
|
68
|
+
#
|
69
|
+
# required attributes: key
|
70
|
+
#
|
71
|
+
# @param expires [String] number of seconds (since 1970-01-01 00:00) before url expires
|
72
|
+
# @param options [Hash]
|
73
|
+
# @return [String] url
|
74
|
+
#
|
75
|
+
def url(expires, options = {})
|
76
|
+
requires :directory, :key
|
77
|
+
self.service.create_temp_url(directory.key, key, expires, "GET", options)
|
78
|
+
end
|
79
|
+
|
80
|
+
def public_url
|
81
|
+
requires :key
|
82
|
+
self.collection.get_url(self.key)
|
83
|
+
end
|
84
|
+
|
85
|
+
def save(options = {})
|
86
|
+
requires :body, :directory, :key
|
87
|
+
options['Content-Type'] = content_type if content_type
|
88
|
+
options['Content-Disposition'] = content_disposition if content_disposition
|
89
|
+
options['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin
|
90
|
+
options['Origin'] = origin if origin
|
91
|
+
options.merge!(metadata_to_headers)
|
92
|
+
|
93
|
+
if directory.key == ""
|
94
|
+
object = key
|
95
|
+
else
|
96
|
+
object = directory.key+"/"+key
|
97
|
+
end
|
98
|
+
data = service.put_object_with_body(object, body, options)
|
99
|
+
update_attributes_from(data)
|
100
|
+
refresh_metadata
|
101
|
+
|
102
|
+
self.content_length = Fog::Storage.get_body_size(body)
|
103
|
+
self.content_type ||= Fog::Storage.get_content_type(body)
|
104
|
+
true
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def directory=(new_directory)
|
110
|
+
@directory = new_directory
|
111
|
+
end
|
112
|
+
|
113
|
+
def refresh_metadata
|
114
|
+
metadata.reject! {|k, v| v.nil? }
|
115
|
+
end
|
116
|
+
|
117
|
+
def headers_to_metadata
|
118
|
+
key_map = key_mapping
|
119
|
+
Hash[metadata_attributes.map {|k, v| [key_map[k], v] }]
|
120
|
+
end
|
121
|
+
|
122
|
+
def key_mapping
|
123
|
+
key_map = metadata_attributes
|
124
|
+
key_map.each_pair {|k, v| key_map[k] = header_to_key(k)}
|
125
|
+
end
|
126
|
+
|
127
|
+
def header_to_key(opt)
|
128
|
+
opt.gsub(metadata_prefix, '').split('-').map {|k| k[0, 1].downcase + k[1..-1]}.join('_').to_sym
|
129
|
+
end
|
130
|
+
|
131
|
+
def metadata_to_headers
|
132
|
+
header_map = header_mapping
|
133
|
+
Hash[metadata.map {|k, v| [header_map[k], v] }]
|
134
|
+
end
|
135
|
+
|
136
|
+
def header_mapping
|
137
|
+
header_map = metadata.dup
|
138
|
+
header_map.each_pair {|k, v| header_map[k] = key_to_header(k)}
|
139
|
+
end
|
140
|
+
|
141
|
+
def key_to_header(key)
|
142
|
+
metadata_prefix + key.to_s.split(/[-_]/).map(&:capitalize).join('-')
|
143
|
+
end
|
144
|
+
|
145
|
+
def metadata_attributes
|
146
|
+
if last_modified
|
147
|
+
if directory.key == ""
|
148
|
+
object = key
|
149
|
+
else
|
150
|
+
object = directory.key+"/"+key
|
151
|
+
end
|
152
|
+
|
153
|
+
headers = service.head_object(object).data[:headers]
|
154
|
+
headers.reject! {|k, v| !metadata_attribute?(k)}
|
155
|
+
else
|
156
|
+
{}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def metadata_attribute?(key)
|
161
|
+
key.to_s =~ /^#{metadata_prefix}/
|
162
|
+
end
|
163
|
+
|
164
|
+
def metadata_prefix
|
165
|
+
"X-Object-Meta-"
|
166
|
+
end
|
167
|
+
|
168
|
+
def update_attributes_from(data)
|
169
|
+
merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/dtdream/models/storage/file'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Storage
|
6
|
+
class Dtdream
|
7
|
+
class Files < Fog::Collection
|
8
|
+
attribute :directory
|
9
|
+
attribute :limit
|
10
|
+
attribute :marker
|
11
|
+
attribute :path
|
12
|
+
attribute :prefix
|
13
|
+
|
14
|
+
model Fog::Storage::Dtdream::File
|
15
|
+
|
16
|
+
def all(options = {})
|
17
|
+
requires :directory
|
18
|
+
if directory.key != "" && directory.key != "." && directory.key != nil
|
19
|
+
prefix = directory.key+"/"
|
20
|
+
end
|
21
|
+
files = service.list_objects({:prefix => prefix})["Contents"]
|
22
|
+
data = Array.new
|
23
|
+
i = 0
|
24
|
+
files.each do |file|
|
25
|
+
if file["Key"][0][-1] != "/"
|
26
|
+
key = file["Key"][0]
|
27
|
+
data[i] = {:key=>key}
|
28
|
+
i = i + 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#load(data)
|
33
|
+
data
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
alias_method :each_file_this_page, :each
|
38
|
+
def each
|
39
|
+
if !block_given?
|
40
|
+
self
|
41
|
+
else
|
42
|
+
subset = dup.all
|
43
|
+
|
44
|
+
subset.each_file_this_page {|f| yield f}
|
45
|
+
while subset.length == (subset.limit || 10000)
|
46
|
+
subset = subset.all(:marker => subset.last.key)
|
47
|
+
subset.each_file_this_page {|f| yield f}
|
48
|
+
end
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get(key, &block)
|
55
|
+
requires :directory
|
56
|
+
if directory.key == ""
|
57
|
+
object = key
|
58
|
+
else
|
59
|
+
object = directory.key+"/"+key
|
60
|
+
end
|
61
|
+
|
62
|
+
data = service.head_object(object).data
|
63
|
+
contentLen = data[:headers]["Content-Length"].to_i
|
64
|
+
if data[:status] != 200 || contentLen <= 0
|
65
|
+
return nil
|
66
|
+
end
|
67
|
+
|
68
|
+
file_data = {
|
69
|
+
:content_length => contentLen,
|
70
|
+
:key => key,
|
71
|
+
:last_modified => data[:headers]["Last-Modified"]
|
72
|
+
}
|
73
|
+
|
74
|
+
if block_given?
|
75
|
+
pagesNum = (contentLen + Excon::CHUNK_SIZE - 1)/Excon::CHUNK_SIZE
|
76
|
+
|
77
|
+
for i in 1..pagesNum
|
78
|
+
_start = (i-1)*(Excon::CHUNK_SIZE)
|
79
|
+
_end = i*(Excon::CHUNK_SIZE) - 1
|
80
|
+
range = "#{_start}-#{_end}"
|
81
|
+
chunk = service.get_object(object, range) && yield(chunk)
|
82
|
+
end
|
83
|
+
new(file_data)
|
84
|
+
else
|
85
|
+
data = service.get_object(object)
|
86
|
+
file_data.merge!(:body => data[:body])
|
87
|
+
new(file_data)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_url(key)
|
93
|
+
requires :directory
|
94
|
+
if directory.key == ""
|
95
|
+
object = key
|
96
|
+
else
|
97
|
+
object = directory.key+"/"+key
|
98
|
+
end
|
99
|
+
service.get_object_http_url_public(object, 3600)
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_http_url(key, expires, options = {})
|
103
|
+
requires :directory
|
104
|
+
if directory.key == ""
|
105
|
+
object = key
|
106
|
+
else
|
107
|
+
object = directory.key+"/"+key
|
108
|
+
end
|
109
|
+
service.get_object_http_url_public(object, expires, options)
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_https_url(key, expires, options = {})
|
113
|
+
requires :directory
|
114
|
+
if directory.key == ""
|
115
|
+
object = key
|
116
|
+
else
|
117
|
+
object = directory.key+"/"+key
|
118
|
+
end
|
119
|
+
service.get_object_https_url_public(object, expires, options)
|
120
|
+
end
|
121
|
+
|
122
|
+
def head(key, options = {})
|
123
|
+
requires :directory
|
124
|
+
if directory.key == ""
|
125
|
+
object = key
|
126
|
+
else
|
127
|
+
object = directory.key+"/"+key
|
128
|
+
end
|
129
|
+
data = service.head_object(object).data
|
130
|
+
file_data = data[:headers].merge({
|
131
|
+
:key => key
|
132
|
+
})
|
133
|
+
new(file_data)
|
134
|
+
rescue Fog::Storage::Dtdream::NotFound
|
135
|
+
nil
|
136
|
+
end
|
137
|
+
|
138
|
+
def new(attributes = {})
|
139
|
+
requires :directory
|
140
|
+
super({ :directory => directory }.merge!(attributes))
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class Dtdream
|
4
|
+
class Real
|
5
|
+
# Copy object
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * source_container_name<~String> - Name of source bucket
|
9
|
+
# * source_object_name<~String> - Name of source object
|
10
|
+
# * target_container_name<~String> - Name of bucket to create copy in
|
11
|
+
# * target_object_name<~String> - Name for new copy of object
|
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)
|
15
|
+
headers = { 'x-oss-copy-source' => "/#{source_bucket}/#{source_object}" }
|
16
|
+
location = get_bucket_location(target_bucket)
|
17
|
+
endpoint = "http://"+location+".aliyuncs.com"
|
18
|
+
resource = target_bucket+'/'+target_object
|
19
|
+
request({
|
20
|
+
:expects => [200, 203],
|
21
|
+
:headers => headers,
|
22
|
+
:method => 'PUT',
|
23
|
+
:path => target_object,
|
24
|
+
:bucket => target_bucket,
|
25
|
+
:resource => resource,
|
26
|
+
:endpoint => endpoint
|
27
|
+
})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|