fog-aliyun 0.3.10 → 0.3.16

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
  SHA256:
3
- metadata.gz: 5da51b9b9b9dba901f7d457ca4dc24ac63a2dc271691920b648f47041102d913
4
- data.tar.gz: f76b4c63734441c9fc4d1d7089f70f9d37d9d91b433e23d8400bd84e009eb14c
3
+ metadata.gz: 91aa2154dd185e6481eff2429ffc9c04e8651764dd8d6cf196c2b689a38c461b
4
+ data.tar.gz: a7aff361e70ead42b81f2d07aff5cbb92c5dcf6624f6dbfd0e0e1e80cc888a1e
5
5
  SHA512:
6
- metadata.gz: a87085ec484fcdf4a1140cd3f0ae390fe5cdc444791024e3263facb2977318ee5a6a1c2e76ff0d3b47deda665abe61405f3956e421dc36be43ba071e0ca5e5f4
7
- data.tar.gz: a3382c51257b146bf3e3d7803042cc36b241965330d72a345816dcedb8d92799aed0e84c6b8fbf57a53659fa9dab9fb2f9be9e6e7337fc9c5288e64a43c68acc
6
+ metadata.gz: bdc525d0d99894eb5e0dd63a6e0f4eff5fc9ebddce5c2eecbed0559010bfe25db134076d1f8a6bacc5f72d3efe4772efd02925e27481e8f3a413a6c5eb13ed01
7
+ data.tar.gz: f4726017f3fd50a33d4015adf8c1f5870645f2401acb79ab43b88fd845cef67fc838fb7a0044eed53c7007aa4ee2705819ecbe04e3f7eca3b12c78d90d6fbed8
data/.gitignore CHANGED
@@ -23,3 +23,5 @@ tmp
23
23
  *.a
24
24
  mkmf.log
25
25
  gemfiles/*.lock
26
+ morethan100m
27
+ *.log
@@ -0,0 +1,55 @@
1
+ ## 0.3.17 (Unreleased)
2
+ ## 0.3.16 (June 18, 2020)
3
+
4
+ IMPROVEMENTS:
5
+ - [Enhance tests][Files & Directory scenarios] Test get nested directories and files in nested directory [GH-98](https://github.com/fog/fog-aliyun/pull/98)
6
+ - remove get_bucket_location and use ruby sdk to improve performance when uploading object [GH-97](https://github.com/fog/fog-aliyun/pull/97)
7
+ - using bucket_exist to checking bucket [GH-95](https://github.com/fog/fog-aliyun/pull/95)
8
+ - add change log [GH-94](https://github.com/fog/fog-aliyun/pull/94)
9
+
10
+ BUG FIXES:
11
+ - fix delete all of files bug when specifying a prefix [GH-102](https://github.com/fog/fog-aliyun/pull/102)
12
+
13
+ ## 0.3.15 (June 05, 2020)
14
+
15
+ BUG FIXES:
16
+ - change dependence ruby sdk to gems [GH-92](https://github.com/fog/fog-aliyun/pull/92)
17
+
18
+ ## 0.3.13 (June 02, 2020)
19
+
20
+ IMPROVEMENTS:
21
+ - using ruby sdk to delete object [GH-90](https://github.com/fog/fog-aliyun/pull/90)
22
+
23
+ ## 0.3.12 (May 28, 2020 )
24
+
25
+ BUG FIXES:
26
+ - add missing dependence [GH-88](https://github.com/fog/fog-aliyun/pull/88)
27
+
28
+ ## 0.3.11 (May 25, 2020)
29
+
30
+ IMPROVEMENTS:
31
+ - using oss ruby sdk to improve downloading object performance [GH-86](https://github.com/fog/fog-aliyun/pull/86)
32
+ - Add performance tests [GH-85](https://github.com/fog/fog-aliyun/pull/85)
33
+ - [Enhance tests][Entity operations]Add tests for each type of entity that validates the CURD operations [GH-84](https://github.com/fog/fog-aliyun/pull/84)
34
+ - [Enhance tests][Auth & Connectivity scenarios] Test region is selected according to provider configuration [GH-83](https://github.com/fog/fog-aliyun/pull/83)
35
+ - [Enhance tests][Files & Directory scenarios] test file listing using parameters such as prefix, marker, delimeter and maxKeys [GH-82](https://github.com/fog/fog-aliyun/pull/82)
36
+ - [Enhance tests][Files & Directory scenarios]test directory listing using parameters such as prefix, marker, delimeter and maxKeys [GH-81](https://github.com/fog/fog-aliyun/pull/81)
37
+ - [Enhance tests][Files & Directory scenarios]Test that it is possible to upload (write) large file (multi part upload) [GH-79](https://github.com/fog/fog-aliyun/pull/79)
38
+ - upgrade deprecated code [GH-78](https://github.com/fog/fog-aliyun/pull/78)
39
+ - improve fog/integration_spec [GH-77](https://github.com/fog/fog-aliyun/pull/77)
40
+ - [Enhance tests][Files & Directory scenarios]Test that it is possible to upload (write) a file [GH-76](https://github.com/fog/fog-aliyun/pull/76)
41
+ - upgrade deprecated code [GH-74](https://github.com/fog/fog-aliyun/pull/74)
42
+ - support https scheme [GH-71](https://github.com/fog/fog-aliyun/pull/71)
43
+ - [Enhance tests][Files & Directory scenarios]Test that it is possible to destroy a file/directory [GH-69](https://github.com/fog/fog-aliyun/pull/69)
44
+ - improve fog/integration_spec [GH-68](https://github.com/fog/fog-aliyun/pull/68)
45
+ - Implement basic integration tests [GH-66](https://github.com/fog/fog-aliyun/pull/66)
46
+
47
+ ## 0.3.10 (May 07, 2020)
48
+
49
+ IMPROVEMENTS:
50
+ - Set max limitation to 1000 when get objects [GH-64](https://github.com/fog/fog-aliyun/pull/64)
51
+
52
+ ## 0.3.9 (May 07, 2020)
53
+
54
+ BUG FIXES:
55
+ - diectories.get supports options to filter the specified objects [GH-62](https://github.com/fog/fog-aliyun/pull/62)
data/README.md CHANGED
@@ -30,9 +30,9 @@ Since it's a bad practice to have your credentials in source code, you should lo
30
30
 
31
31
  ```
32
32
  default:
33
- :aliyun_accesskey_id: <YOUR_ACCESS_KEY_ID>,
34
- :aliyun_accesskey_secret: <YOUR_SECRET_ACCESS_KEY>,
35
- :aliyun_region_id: <YOUR_TARGET_REGION>
33
+ aliyun_accesskey_id: "<YOUR_ACCESS_KEY_ID>"
34
+ aliyun_accesskey_secret: "<YOUR_SECRET_ACCESS_KEY>"
35
+ aliyun_region_id: "<YOUR_TARGET_REGION>"
36
36
  ```
37
37
 
38
38
  ### Connecting to OSS
@@ -307,6 +307,64 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
307
307
 
308
308
  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).
309
309
 
310
+ ## Testing
311
+
312
+
313
+
314
+ To run test suite use the following command:
315
+
316
+ ```
317
+ rake spec
318
+ ```
319
+
320
+ ### Code coverage
321
+
322
+ To run test suite with code coverage:
323
+
324
+ ```
325
+ export COVERAGE=true
326
+ rake spec
327
+ ```
328
+
329
+ The result will be generated in `coverage` folder.
330
+
331
+ ### Integration tests
332
+
333
+ To run integration tests please prepare a set of AliCloud credentials to be used by integration tests.
334
+
335
+ Define the credentials and bucket in `~/.fog` file in using following format:
336
+
337
+ ```
338
+ default:
339
+ aliyun_accesskey_id: "...access key..." # You can create a set of credentials
340
+ aliyun_accesskey_secret: "...secret..." # using Alicloud console portal
341
+ aliyun_region_id: "...region name..." # Example: cn-shanghai
342
+ aliyun_oss_bucket: "...name of the bucket..." # Example: fog-integration-test-bucket
343
+ ```
344
+
345
+ WARNING: Do NOT use any productive account credentials and buckets for the testing, it may be harmful to your data!
346
+
347
+ The tests are using [https://github.com/aliyun/aliyun-cli#installation](Aliyun CLI) to setup integration bucket and content for tests,
348
+ please install it locally before running integration tests.
349
+
350
+ Aliyun CLI will be configured automatically as part of test execution using the credentials provided for fog connection.
351
+
352
+ Then run the test suite with `INTEGRATION` environment variable to activate integration tests:
353
+
354
+ ```
355
+ export INTEGRATION=true
356
+ rake spec
357
+ ```
358
+
359
+ ### Performance test
360
+
361
+ Performance tests are providing memory consumption report for download/upload operations.
362
+
363
+ ```
364
+ export PERFORMANCE=true
365
+ rake spec
366
+ ```
367
+
310
368
  ## License
311
369
 
312
370
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -26,7 +26,11 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'rake'
27
27
  spec.add_development_dependency 'rspec'
28
28
  spec.add_development_dependency 'rubocop'
29
+ spec.add_development_dependency 'simplecov'
30
+ spec.add_development_dependency 'memory_profiler'
31
+ spec.add_development_dependency 'aliyun-sdk', '~> 0.7.2'
29
32
 
33
+ spec.add_dependency 'aliyun-sdk', '~> 0.7.2'
30
34
  spec.add_dependency 'fog-core'
31
35
  spec.add_dependency 'fog-json'
32
36
  spec.add_dependency 'ipaddress', '~> 0.8'
@@ -2,19 +2,16 @@
2
2
 
3
3
  require 'fog/core'
4
4
  require 'fog/json'
5
- require 'fog/aliyun/version'
5
+ require File.expand_path('../aliyun/version', __FILE__)
6
6
 
7
7
  module Fog
8
- module Compute
9
- autoload :Aliyun, 'fog/aliyun/compute'
10
- end
11
-
12
- module Storage
13
- autoload :Aliyun, 'fog/aliyun/storage'
14
- end
15
-
16
8
  module Aliyun
17
9
  extend Fog::Provider
10
+
11
+ # Services
12
+ autoload :Compute, File.expand_path('../aliyun/compute', __FILE__)
13
+ autoload :Storage, File.expand_path('../aliyun/storage', __FILE__)
14
+
18
15
  service(:compute, 'Compute')
19
16
  service(:storage, 'Storage')
20
17
  end
@@ -4,10 +4,10 @@ require 'fog/core/collection'
4
4
  require 'fog/aliyun/models/storage/directory'
5
5
 
6
6
  module Fog
7
- module Storage
8
- class Aliyun
7
+ module Aliyun
8
+ class Storage
9
9
  class Directories < Fog::Collection
10
- model Fog::Storage::Aliyun::Directory
10
+ model Fog::Aliyun::Storage::Directory
11
11
 
12
12
  def all
13
13
  containers = service.get_containers
@@ -72,7 +72,7 @@ module Fog
72
72
  else
73
73
  new(key: '')
74
74
  end
75
- rescue Fog::Storage::Aliyun::NotFound
75
+ rescue Fog::Aliyun::Storage::NotFound
76
76
  nil
77
77
  end
78
78
  end
@@ -4,8 +4,8 @@ require 'fog/core/model'
4
4
  require 'fog/aliyun/models/storage/files'
5
5
 
6
6
  module Fog
7
- module Storage
8
- class Aliyun
7
+ module Aliyun
8
+ class Storage
9
9
  class Directory < Fog::Model
10
10
  identity :key, :aliases => ['Key', 'Name', 'name']
11
11
 
@@ -20,14 +20,14 @@ module Fog
20
20
  service.delete_container(key)
21
21
  true
22
22
  else
23
- raise Fog::Storage::Aliyun::Error, ' Forbidden: Direction not empty!'
23
+ raise Fog::Aliyun::Storage::Error, ' Forbidden: Direction not empty!'
24
24
  false
25
25
  end
26
26
  end
27
27
 
28
28
  def files
29
29
  @files ||= begin
30
- Fog::Storage::Aliyun::Files.new(
30
+ Fog::Aliyun::Storage::Files.new(
31
31
  directory: self,
32
32
  service: service
33
33
  )
@@ -3,8 +3,8 @@
3
3
  require 'fog/core/model'
4
4
 
5
5
  module Fog
6
- module Storage
7
- class Aliyun
6
+ module Aliyun
7
+ class Storage
8
8
  class File < Fog::Model
9
9
  identity :key, aliases: ['Key', 'Name', 'name']
10
10
  attribute :date, aliases: 'Date'
@@ -120,11 +120,12 @@ module Fog
120
120
  directory_key + '/' + key
121
121
  end
122
122
  if body.is_a?(::File)
123
- data = service.put_object(object, body, options.merge(bucket: bucket_name)).data
123
+ service.put_object(object, body, options.merge(bucket: bucket_name))
124
+ data = service.head_object(object, bucket: bucket_name)
124
125
  elsif body.is_a?(String)
125
126
  data = service.put_object_with_body(object, body, options.merge(bucket: bucket_name)).data
126
127
  else
127
- raise Fog::Storage::Aliyun::Error, " Forbidden: Invalid body type: #{body.class}!"
128
+ raise Fog::Aliyun::Storage::Error, " Forbidden: Invalid body type: #{body.class}!"
128
129
  end
129
130
  update_attributes_from(data)
130
131
  refresh_metadata
@@ -2,10 +2,11 @@
2
2
 
3
3
  require 'fog/core/collection'
4
4
  require 'fog/aliyun/models/storage/file'
5
+ require 'aliyun/oss'
5
6
 
6
7
  module Fog
7
- module Storage
8
- class Aliyun
8
+ module Aliyun
9
+ class Storage
9
10
  class Files < Fog::Collection
10
11
  attribute :directory
11
12
  attribute :limit
@@ -17,7 +18,7 @@ module Fog
17
18
  attribute :marker, :aliases => 'Marker'
18
19
  attribute :max_keys, :aliases => ['MaxKeys', 'max-keys']
19
20
 
20
- model Fog::Storage::Aliyun::File
21
+ model Fog::Aliyun::Storage::File
21
22
 
22
23
  # check_directory_key have two functions:
23
24
  # 1. trim the directory_key suffix '/'
@@ -35,44 +36,36 @@ module Fog
35
36
  # The bucket name can not contain '/', so if directory_key, return directory.
36
37
  if directory_key.include? '/'
37
38
  directory_key
39
+ elsif service.bucket_exists?(directory_key)
40
+ bucket_name = directory_key
41
+ directory_key = ''
38
42
  else
39
- data = service.get_bucket(directory_key)
40
- if data.class == Hash && data.key?('Code') && !data['Code'].nil? && !data['Code'].empty?
41
- directory_key
42
- else
43
- bucket_name = directory_key
44
- directory_key = ''
45
- end
43
+ directory_key
46
44
  end
47
45
  end
48
46
  return bucket_name, directory_key
49
47
  end
50
48
 
51
- def all(_options = {})
49
+ def all(options = {})
52
50
  requires :directory
53
- bucket_name, directory_key = check_directory_key(directory.key)
54
- prefix_value = prefix
55
- prefix_value = directory_key + '/' + prefix if directory_key != '' && directory_key != '.' && !directory_key.nil?
56
- files = service.list_objects(prefix: prefix_value, bucket: bucket_name)['Contents']
57
- return if files.nil?
58
- data = []
59
- i = 0
60
- files.each do |file|
61
- next unless file['Key'][0][-1] != '/'
62
- content_length = file['Size'][0].to_i
63
- key = file['Key'][0]
64
- lastModified = file['LastModified'][0]
65
- last_modified = (Time.parse(lastModified).localtime if !lastModified.nil? && lastModified != '')
66
- type = file['Type'][0]
67
- data[i] = { content_length: content_length,
68
- key: key,
69
- last_modified: last_modified,
70
- etag: file['ETag'][0],
71
- object_type: type }
72
- i += 1
51
+ options = {
52
+ 'delimiter' => delimiter,
53
+ 'marker' => marker,
54
+ 'max-keys' => max_keys.to_i,
55
+ 'prefix' => prefix
56
+ }.merge!(options)
57
+ options = options.reject {|key,value| value.nil? || value.to_s.empty?}
58
+ merge_attributes(options)
59
+ parent = directory.collection.get(
60
+ directory.key,
61
+ options
62
+ )
63
+ if parent
64
+ merge_attributes(parent.files.attributes)
65
+ load(parent.files.map {|file| file.attributes})
66
+ else
67
+ nil
73
68
  end
74
-
75
- load(data)
76
69
  end
77
70
 
78
71
  alias each_file_this_page each
@@ -102,63 +95,34 @@ module Fog
102
95
  end
103
96
  begin
104
97
  data = service.get_object(object, nil, bucket: bucket_name)
105
- rescue StandardError => error
106
- case error.response.body
107
- when %r{<Code>NoSuchKey</Code>},%r{<Code>SymlinkTargetNotExist</Code>}
98
+ lastModified = data['headers'][:last_modified]
99
+ last_modified = (Time.parse(lastModified).localtime if !lastModified.nil? && lastModified != '')
100
+
101
+ date = data['headers'][:date]
102
+ date = (Time.parse(date).localtime if !date.nil? && date != '')
103
+ file_data = {
104
+ body: data[:body],
105
+ content_length: data['headers'][:content_length].to_i,
106
+ key: key,
107
+ last_modified: last_modified,
108
+ content_type: data['headers'][:content_type],
109
+ etag: data['headers'][:etag],
110
+ date: date,
111
+ connection: data['headers'][:connection],
112
+ accept_ranges: data['headers'][:accept_ranges],
113
+ server: data['headers'][:server],
114
+ object_type: data['headers'][:x_oss_object_type]
115
+ }
116
+
117
+ new(file_data)
118
+ rescue AliyunOssSdk::ServerError => error
119
+ case error.error_code
120
+ when %r{NoSuchKey},%r{SymlinkTargetNotExist}
108
121
  nil
109
122
  else
110
123
  raise(error)
111
124
  end
112
125
  end
113
-
114
- contentLen = data[:headers]['Content-Length'].to_i
115
-
116
- if block_given?
117
- pagesNum = (contentLen + Excon::CHUNK_SIZE - 1) / Excon::CHUNK_SIZE
118
-
119
- for i in 1..pagesNum
120
- _start = (i - 1) * Excon::CHUNK_SIZE
121
- _end = i * Excon::CHUNK_SIZE - 1
122
- range = "#{_start}-#{_end}"
123
- begin
124
- data = service.get_object(object, range, bucket: bucket_name)
125
- chunk = data[:body]
126
- rescue StandardError => error
127
- case error.response.body
128
- when %r{<Code>NoSuchKey</Code>},%r{<Code>SymlinkTargetNotExist</Code>}
129
- chunk = ''
130
- else
131
- raise(error)
132
- end
133
- end
134
- yield(chunk)
135
- body = nil
136
- end
137
- else
138
- body = data[:body]
139
- end
140
-
141
- lastModified = data[:headers]['Last-Modified']
142
- last_modified = (Time.parse(lastModified).localtime if !lastModified.nil? && lastModified != '')
143
-
144
- date = data[:headers]['Date']
145
- date = (Time.parse(date).localtime if !date.nil? && date != '')
146
- file_data = {
147
- body: body,
148
- content_length: contentLen,
149
- key: key,
150
- last_modified: last_modified,
151
- content_type: data[:headers]['Content-Type'],
152
- etag: data[:headers]['ETag'],
153
- date: date,
154
- connection: data[:headers]['Connection'],
155
- accept_ranges: data[:headers]['Accept-Ranges'],
156
- server: data[:headers]['Server'],
157
- object_type: data[:headers]['x-oss-object-type'],
158
- content_disposition: data[:headers]['Content-Disposition']
159
- }
160
-
161
- new(file_data)
162
126
  end
163
127
 
164
128
  def get_url(key)
@@ -225,7 +189,7 @@ module Fog
225
189
  object_type: data[:headers]['x-oss-object-type']
226
190
  }
227
191
  new(file_data)
228
- rescue Fog::Storage::Aliyun::NotFound
192
+ rescue Fog::Aliyun::Storage::NotFound
229
193
  nil
230
194
  end
231
195