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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7c3f28cba2b2acb17e34f8f00a8ed5577bf6c1e
4
- data.tar.gz: 465522578a4c15f6a1c4b043ee48f89c62dd78bd
3
+ metadata.gz: cffd78ea3a1c223ae9e0b45b3ec996c3e8baa55d
4
+ data.tar.gz: 54de6ae02cece427a30c90aeb3fc98b055a59cbb
5
5
  SHA512:
6
- metadata.gz: fb70b9d6a7b355632beb07a470c782e2ce53dffd93a9668446648053d24b57b95cd88d5ec262d7dfe34b23be4ed335e08627d9ec9c90292c1dd37b9bd791d71a
7
- data.tar.gz: 3f2257c4ecbf8842c547e446d3841c048a7ad057c52c39dd1924c6a52f3f754a9edfe2cc373ca5b2ecdcbbe83d92948e932237c57c91aabd030888e6848e6685
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
- :aliyun_oss_endpoint: <YOUR_OSS_ENDPOINT>,
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
@@ -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
- :aliyun_oss_bucket
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 :aliyun_oss_endpoint, :aliyun_accesskey_id,
41
- # :aliyun_secret_access_key, :aliyun_oss_location and :aliyun_oss_bucket in order to create a connection.
42
- # if you haven't set these values in the configuration file.
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 :aliyun_oss_location
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
- @aliyun_oss_endpoint = options[:aliyun_oss_endpoint]
64
- @aliyun_oss_location = options[:aliyun_oss_location]
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 << :aliyun_oss_endpoint unless @aliyun_oss_endpoint
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
- @port = uri.port
83
- @scheme = uri.scheme
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
- @aliyun_oss_location = options[:aliyun_oss_location]
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 << :aliyun_oss_location unless @aliyun_oss_location
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?
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Aliyun
3
- VERSION = '0.2.1'.freeze
3
+ VERSION = '0.2.2'.freeze
4
4
  end
5
5
  end
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.1
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-04-13 00:00:00.000000000 Z
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.6.14
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.