fog-aliyun 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -5
- data/lib/fog/aliyun/models/storage/files.rb +12 -3
- data/lib/fog/aliyun/storage.rb +38 -14
- data/lib/fog/aliyun/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cffd78ea3a1c223ae9e0b45b3ec996c3e8baa55d
|
4
|
+
data.tar.gz: 54de6ae02cece427a30c90aeb3fc98b055a59cbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca783c81990b44dbd811460e10a72bdc749e0bb5c862fc29ab1a84e6c1403e4e9c34f8f33ec23d3c5cac1e044016cacdaa388ff51092f2566a5fcf383d26521c
|
7
|
+
data.tar.gz: b6a0937a7e9bb735638645e2b040c0ddb6b660d81b8703eab3288e442ffdb39e8cbed73e582ac8bee5a08af1c337d38ef937a4103e160cc42f746e7fcee92f25
|
data/README.md
CHANGED
@@ -32,9 +32,7 @@ Since it's a bad practice to have your credentials in source code, you should lo
|
|
32
32
|
default:
|
33
33
|
:aliyun_accesskey_id: <YOUR_ACCESS_KEY_ID>,
|
34
34
|
:aliyun_accesskey_secret: <YOUR_SECRET_ACCESS_KEY>,
|
35
|
-
:
|
36
|
-
:aliyun_oss_location: <YOUR_OSS_LOACTION>,
|
37
|
-
:aliyun_oss_bucket: <YOUR_OSS_BUCKET>
|
35
|
+
:aliyun_region_id: <YOUR_TARGET_REGION>
|
38
36
|
```
|
39
37
|
|
40
38
|
### Connecting to OSS
|
@@ -48,12 +46,17 @@ opt = {
|
|
48
46
|
:provider => 'aliyun',
|
49
47
|
:aliyun_accesskey_id => <YOUR_ACCESS_KEY_ID>,
|
50
48
|
:aliyun_accesskey_secret => <YOUR_SECRET_ACCESS_KEY>,
|
51
|
-
:aliyun_oss_endpoint => <YOUR_OSS_ENDPOINT>,
|
52
|
-
:aliyun_oss_location => <YOUR_OSS_LOACTION>,
|
53
49
|
:aliyun_oss_bucket => <YOUR_OSS_BUCKET>,
|
50
|
+
:aliyun_region_id => <YOUR_TARGET_REGION>,
|
51
|
+
:aliyun_oss_endpoint => <YOUR_OSS_ENDPOINT>,
|
54
52
|
}
|
55
53
|
conn = Fog::Storage.new(opt)
|
56
54
|
```
|
55
|
+
**-> Note:** `:aliyun_region_id` is optional and default to "cn-hangzhou".
|
56
|
+
**-> Note:** `:aliyun_oss_endpoint` is optional. If it is not specified, it will be generated automatically by `:aliyun_region_id`.
|
57
|
+
Its basic format is "oss-<region-id>.aliyuncs.com" and with default schema "http" and default port "80".
|
58
|
+
If you want to use https or 443 port, you can use a format "<schema>://oss-<region-id>.aliyuncs.com:<port>".
|
59
|
+
|
57
60
|
|
58
61
|
## Fog::Aliyun Abstractions
|
59
62
|
|
@@ -66,6 +66,18 @@ module Fog
|
|
66
66
|
else
|
67
67
|
directory.key + '/' + key
|
68
68
|
end
|
69
|
+
begin
|
70
|
+
data = service.get_object(object)
|
71
|
+
rescue => error
|
72
|
+
case error.response.body
|
73
|
+
when /<Code>NoSuchKey<\/Code>/
|
74
|
+
nil
|
75
|
+
else
|
76
|
+
raise(error)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
contentLen = data[:headers]['Content-Length'].to_i
|
69
81
|
|
70
82
|
if block_given?
|
71
83
|
pagesNum = (contentLen + Excon::CHUNK_SIZE - 1) / Excon::CHUNK_SIZE
|
@@ -80,12 +92,9 @@ module Fog
|
|
80
92
|
body = nil
|
81
93
|
end
|
82
94
|
else
|
83
|
-
data = service.get_object(object)
|
84
95
|
body = data[:body]
|
85
96
|
end
|
86
97
|
|
87
|
-
contentLen = data[:headers]['Content-Length'].to_i
|
88
|
-
return nil if data[:status] != 200
|
89
98
|
lastModified = data[:headers]['Last-Modified']
|
90
99
|
last_modified = if !lastModified.nil? && lastModified != ''
|
91
100
|
Time.parse(lastModified).localtime
|
data/lib/fog/aliyun/storage.rb
CHANGED
@@ -3,11 +3,21 @@ require 'xmlsimple'
|
|
3
3
|
module Fog
|
4
4
|
module Storage
|
5
5
|
class Aliyun < Fog::Service
|
6
|
+
|
7
|
+
DEFAULT_REGION = 'cn-hangzhou'
|
8
|
+
|
9
|
+
DEFAULT_SCHEME = 'http'
|
10
|
+
DEFAULT_SCHEME_PORT = {
|
11
|
+
'http' => 80,
|
12
|
+
'https' => 443
|
13
|
+
}
|
14
|
+
|
6
15
|
recognizes :aliyun_oss_endpoint,
|
7
16
|
:aliyun_oss_location,
|
8
|
-
:
|
17
|
+
:aliyun_region_id
|
9
18
|
requires :aliyun_accesskey_id,
|
10
|
-
:aliyun_accesskey_secret
|
19
|
+
:aliyun_accesskey_secret,
|
20
|
+
:aliyun_oss_bucket
|
11
21
|
|
12
22
|
model_path 'fog/aliyun/models/storage'
|
13
23
|
model :directory
|
@@ -37,9 +47,9 @@ module Fog
|
|
37
47
|
# Initialize connection to OSS
|
38
48
|
#
|
39
49
|
# ==== Notes
|
40
|
-
# options parameter must include values for :
|
41
|
-
# :
|
42
|
-
# if
|
50
|
+
# options parameter must include values for :aliyun_accesskey_id, :aliyun_secret_access_key and :aliyun_oss_bucket in order to create a connection.
|
51
|
+
# :aliyun_oss_location will be replaced by :aliyun_region_id, and it has a default value cn-hangzhou
|
52
|
+
# if :aliyun_oss_endpoint is not specified, it will be generated by method region_to_endpoint
|
43
53
|
#
|
44
54
|
# ==== Examples
|
45
55
|
# sdb = Fog::Storage.new(:provider=>'aliyun',
|
@@ -55,32 +65,37 @@ module Fog
|
|
55
65
|
attr_reader :aliyun_accesskey_id
|
56
66
|
attr_reader :aliyun_accesskey_secret
|
57
67
|
attr_reader :aliyun_oss_endpoint
|
58
|
-
attr_reader :
|
68
|
+
attr_reader :aliyun_region_id
|
59
69
|
attr_reader :aliyun_oss_bucket
|
60
70
|
|
61
71
|
def initialize(options = {})
|
62
72
|
# initialize the parameters
|
63
|
-
@
|
64
|
-
@
|
73
|
+
@aliyun_region_id = options[:aliyun_region_id] || options[:aliyun_oss_location] || DEFAULT_REGION
|
74
|
+
@aliyun_oss_endpoint = options[:aliyun_oss_endpoint] || region_to_endpoint(@aliyun_region_id)
|
65
75
|
@aliyun_accesskey_id = options[:aliyun_accesskey_id]
|
66
76
|
@aliyun_accesskey_secret = options[:aliyun_accesskey_secret]
|
67
77
|
@aliyun_oss_bucket = options[:aliyun_oss_bucket]
|
68
78
|
|
69
79
|
# check for the parameters
|
70
80
|
missing_credentials = []
|
71
|
-
missing_credentials << :
|
72
|
-
missing_credentials << :aliyun_oss_location unless @aliyun_oss_location
|
81
|
+
missing_credentials << :aliyun_oss_bucket unless @aliyun_oss_bucket
|
73
82
|
missing_credentials << :aliyun_accesskey_id unless @aliyun_accesskey_id
|
74
83
|
missing_credentials << :aliyun_accesskey_secret unless @aliyun_accesskey_secret
|
75
84
|
raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
|
76
85
|
|
77
86
|
@connection_options = options[:connection_options] || {}
|
78
87
|
|
88
|
+
endpoint = @aliyun_oss_endpoint
|
89
|
+
|
90
|
+
if !endpoint.start_with?(DEFAULT_SCHEME)
|
91
|
+
@aliyun_oss_endpoint = "#{DEFAULT_SCHEME}://#{endpoint}"
|
92
|
+
end
|
93
|
+
|
79
94
|
uri = URI.parse(@aliyun_oss_endpoint)
|
80
95
|
@host = uri.host
|
81
96
|
@path = uri.path
|
82
|
-
@
|
83
|
-
@
|
97
|
+
@scheme = uri.scheme || DEFAULT_SCHEME
|
98
|
+
@port = uri.port || DEFAULT_SCHEME_PORT[@scheme]
|
84
99
|
|
85
100
|
@persistent = options[:persistent] || false
|
86
101
|
end
|
@@ -89,6 +104,15 @@ module Fog
|
|
89
104
|
@connection.reset
|
90
105
|
end
|
91
106
|
|
107
|
+
def region_to_endpoint(region=nil)
|
108
|
+
case region.to_s
|
109
|
+
when ''
|
110
|
+
"oss-#{DEFAULT_REGION}.aliyuncs.com"
|
111
|
+
else
|
112
|
+
"oss-#{region}.aliyuncs.com"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
92
116
|
def request(params)
|
93
117
|
method = params[:method]
|
94
118
|
time = Time.new.utc
|
@@ -181,14 +205,14 @@ module Fog
|
|
181
205
|
class Mock
|
182
206
|
def initialize(options = {})
|
183
207
|
@aliyun_oss_endpoint = options[:aliyun_oss_endpoint]
|
184
|
-
@
|
208
|
+
@aliyun_region_id = options[:aliyun_region_id]
|
185
209
|
@aliyun_accesskey_id = options[:aliyun_accesskey_id]
|
186
210
|
@aliyun_accesskey_secret = options[:aliyun_accesskey_secret]
|
187
211
|
@aliyun_oss_bucket = options[:aliyun_oss_bucket]
|
188
212
|
|
189
213
|
# missing_credentials = Array.new
|
190
214
|
# missing_credentials << :aliyun_oss_endpoint unless @aliyun_oss_endpoint
|
191
|
-
# missing_credentials << :
|
215
|
+
# missing_credentials << :aliyun_region_id unless @aliyun_region_id
|
192
216
|
# missing_credentials << :aliyun_accesskey_id unless @aliyun_accesskey_id
|
193
217
|
# missing_credentials << :aliyun_accesskey_secret unless @aliyun_accesskey_secret
|
194
218
|
# raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
|
data/lib/fog/aliyun/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-aliyun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Qinsi Deng, Jianxun Li, Jane Han
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -304,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
304
304
|
version: '0'
|
305
305
|
requirements: []
|
306
306
|
rubyforge_project:
|
307
|
-
rubygems_version: 2.
|
307
|
+
rubygems_version: 2.5.2.1
|
308
308
|
signing_key:
|
309
309
|
specification_version: 4
|
310
310
|
summary: Fog provider for Aliyun Web Services.
|