aliyun-oss-sdk 0.0.3 → 0.1.0
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 +4 -4
- data/.rubocop.yml +17 -0
- data/Gemfile +1 -0
- data/README.md +12 -10
- data/Rakefile +10 -0
- data/aliyun-oss.gemspec +2 -2
- data/lib/aliyun/oss.rb +4 -11
- data/lib/aliyun/oss/authorization.rb +59 -27
- data/lib/aliyun/oss/client.rb +137 -62
- data/lib/aliyun/oss/client/bucket_multiparts.rb +43 -0
- data/lib/aliyun/oss/client/bucket_objects.rb +111 -0
- data/lib/aliyun/oss/client/buckets.rb +50 -0
- data/lib/aliyun/oss/client/clients.rb +54 -0
- data/lib/aliyun/oss/error.rb +43 -0
- data/lib/aliyun/oss/http.rb +65 -23
- data/lib/aliyun/oss/struct.rb +26 -0
- data/lib/aliyun/oss/struct/bucket.rb +252 -0
- data/lib/aliyun/oss/struct/cors.rb +65 -0
- data/lib/aliyun/oss/struct/lifecycle.rb +73 -0
- data/lib/aliyun/oss/struct/logging.rb +33 -0
- data/lib/aliyun/oss/struct/multipart.rb +101 -0
- data/lib/aliyun/oss/struct/object.rb +71 -0
- data/lib/aliyun/oss/struct/part.rb +48 -0
- data/lib/aliyun/oss/struct/referer.rb +21 -0
- data/lib/aliyun/oss/struct/website.rb +13 -0
- data/lib/aliyun/oss/utils.rb +41 -1
- data/lib/aliyun/oss/version.rb +1 -1
- data/lib/aliyun/oss/xml_generator.rb +174 -0
- data/todo.md +5 -0
- data/wiki/bucket.md +20 -20
- data/wiki/cors.md +59 -0
- data/wiki/error.md +42 -31
- data/wiki/get_start.md +24 -7
- data/wiki/installation.md +2 -2
- data/wiki/lifecycle.md +75 -0
- data/wiki/multipart.md +7 -5
- data/wiki/object.md +16 -12
- metadata +48 -6
- data/lib/aliyun/oss/multipart/part.rb +0 -32
- data/lib/aliyun/oss/rule/cors.rb +0 -63
- data/lib/aliyun/oss/rule/lifecycle.rb +0 -61
@@ -0,0 +1,252 @@
|
|
1
|
+
module Aliyun
|
2
|
+
module Oss
|
3
|
+
module Struct
|
4
|
+
class Bucket < Base
|
5
|
+
# Bucket Name
|
6
|
+
attr_accessor :name
|
7
|
+
|
8
|
+
# Bucket Location
|
9
|
+
attr_accessor :location
|
10
|
+
|
11
|
+
# Createion date of Bucket
|
12
|
+
attr_accessor :creation_date
|
13
|
+
|
14
|
+
# reference to client
|
15
|
+
attr_accessor :client
|
16
|
+
|
17
|
+
# Get the location
|
18
|
+
#
|
19
|
+
# @return [String]
|
20
|
+
#
|
21
|
+
# @see Client#bucket_get_location
|
22
|
+
def location!
|
23
|
+
result = client.bucket_get_location.parsed_response
|
24
|
+
Utils.dig_value(result, 'LocationConstraint', '__content__')
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get Logging configration for bucket
|
28
|
+
#
|
29
|
+
# return [true]
|
30
|
+
#
|
31
|
+
# @see Client#bucket_get_logging
|
32
|
+
def logging!
|
33
|
+
result = client.bucket_get_logging.parsed_response
|
34
|
+
Struct::Logging.new(Utils.dig_value(result, 'BucketLoggingStatus'))
|
35
|
+
end
|
36
|
+
|
37
|
+
# Used to enable access logging.
|
38
|
+
#
|
39
|
+
# @param (see #bucket_enable_logging)
|
40
|
+
#
|
41
|
+
# @return [true]
|
42
|
+
#
|
43
|
+
# @see Client#bucket_enable_logging
|
44
|
+
def enable_logging(*args)
|
45
|
+
!!client.bucket_enable_logging(*args)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Used to disable access logging.
|
49
|
+
#
|
50
|
+
# @param (see #bucket_disable_logging)
|
51
|
+
#
|
52
|
+
# @return [true]
|
53
|
+
#
|
54
|
+
# @see Client#bucket_disable_logging
|
55
|
+
def disable_logging
|
56
|
+
!!client.bucket_disable_logging
|
57
|
+
end
|
58
|
+
|
59
|
+
# Get the acl
|
60
|
+
#
|
61
|
+
# @return [String]
|
62
|
+
#
|
63
|
+
# @see Client#bucket_get_acl
|
64
|
+
def acl!
|
65
|
+
result = client.bucket_get_acl.parsed_response
|
66
|
+
acl_keys = %w(AccessControlPolicy AccessControlList Grant)
|
67
|
+
Utils.dig_value(result, *acl_keys)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Set ACL for bucket
|
71
|
+
#
|
72
|
+
# @param (see #bucket_set_acl)
|
73
|
+
#
|
74
|
+
# @raise (see #bucket_set_acl)
|
75
|
+
#
|
76
|
+
# @return [true]
|
77
|
+
#
|
78
|
+
# @see Client#bucket_set_acl
|
79
|
+
def set_acl(*args)
|
80
|
+
!!client.bucket_set_acl(*args)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Get the CORS
|
84
|
+
#
|
85
|
+
# @return [Array<Aliyun::Oss::Struct::Cors>]
|
86
|
+
#
|
87
|
+
# @see Client#bucket_get_cors
|
88
|
+
def cors!
|
89
|
+
result = client.bucket_get_cors.parsed_response
|
90
|
+
cors_keys = %w(CORSConfiguration CORSRule)
|
91
|
+
Utils.wrap(Utils.dig_value(result, *cors_keys)).map do |cors|
|
92
|
+
Struct::Cors.new(cors)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Set CORS for bucket
|
97
|
+
#
|
98
|
+
# @see (see #bucket_enable_cors)
|
99
|
+
#
|
100
|
+
# @param (see #bucket_enable_cors)
|
101
|
+
#
|
102
|
+
# @raise (see #bucket_enable_cors)
|
103
|
+
#
|
104
|
+
# @return [true]
|
105
|
+
#
|
106
|
+
# @see Client#bucket_enable_cors
|
107
|
+
def enable_cors(*args)
|
108
|
+
!!client.bucket_enable_cors(*args)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Disable CORS for bucket
|
112
|
+
#
|
113
|
+
# @see (see #bucket_disable_cors)
|
114
|
+
#
|
115
|
+
# @raise (see #bucket_disable_cors)
|
116
|
+
#
|
117
|
+
# @return [true]
|
118
|
+
#
|
119
|
+
# @see Client#bucket_disable_cors
|
120
|
+
def disable_cors
|
121
|
+
!!client.bucket_disable_cors
|
122
|
+
end
|
123
|
+
|
124
|
+
# Get the website configuration
|
125
|
+
#
|
126
|
+
# @return [Aliyun::Oss::Rule::Website]
|
127
|
+
#
|
128
|
+
# @see Client#bucket_get_website
|
129
|
+
def website!
|
130
|
+
result = client.bucket_get_website.parsed_response
|
131
|
+
suffix_keys = %w(WebsiteConfiguration IndexDocument Suffix)
|
132
|
+
error_keys = %w(WebsiteConfiguration ErrorDocument Key)
|
133
|
+
Aliyun::Oss::Struct::Website.new(
|
134
|
+
suffix: Utils.dig_value(result, *suffix_keys),
|
135
|
+
error_key: Utils.dig_value(result, *error_keys)
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Used to enable static website hosted mode.
|
140
|
+
#
|
141
|
+
# @see (see #bucket_enable_website)
|
142
|
+
#
|
143
|
+
# @param (see #bucket_enable_website)
|
144
|
+
#
|
145
|
+
# @raise (see #bucket_enable_website)
|
146
|
+
#
|
147
|
+
# @return [true]
|
148
|
+
#
|
149
|
+
# @see Client#bucket_enable_website
|
150
|
+
def enable_website(*args)
|
151
|
+
!!client.bucket_enable_website(*args)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Used to disable website hostted mode.
|
155
|
+
#
|
156
|
+
# @see (see #bucket_disable_website)
|
157
|
+
#
|
158
|
+
# @raise (see #bucket_disable_website)
|
159
|
+
#
|
160
|
+
# @return [Response]
|
161
|
+
#
|
162
|
+
# @see Client#bucket_disable_website
|
163
|
+
def disable_website
|
164
|
+
!!client.bucket_disable_website
|
165
|
+
end
|
166
|
+
|
167
|
+
# Get the referer configuration
|
168
|
+
#
|
169
|
+
# @return [Aliyun::Oss::Struct::Referer]
|
170
|
+
#
|
171
|
+
# @see Client#bucket_get_referer
|
172
|
+
def referer!
|
173
|
+
result = client.bucket_get_referer.parsed_response
|
174
|
+
allow_empty = %w(RefererConfiguration AllowEmptyReferer)
|
175
|
+
referers = %w(RefererConfiguration RefererList Referer)
|
176
|
+
Aliyun::Oss::Struct::Referer.new(
|
177
|
+
allow_empty: Utils.dig_value(result, *allow_empty),
|
178
|
+
referers: Utils.dig_value(result, *referers)
|
179
|
+
)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Used to set referer for bucket.
|
183
|
+
#
|
184
|
+
# @see (see #bucket_set_referer)
|
185
|
+
#
|
186
|
+
# @param (see #bucket_set_referer)
|
187
|
+
#
|
188
|
+
# @raise (see #bucket_set_referer)
|
189
|
+
#
|
190
|
+
# @return [true]
|
191
|
+
#
|
192
|
+
# @see Client#set_referer
|
193
|
+
def set_referer(*args)
|
194
|
+
!!client.bucket_set_referer(*args)
|
195
|
+
end
|
196
|
+
|
197
|
+
# Get the lifecycle configuration
|
198
|
+
#
|
199
|
+
# @return [Array<Aliyun::Oss::Struct::Lifecycle?]
|
200
|
+
#
|
201
|
+
# @see Client#bucket_get_lifecycle
|
202
|
+
def lifecycle!
|
203
|
+
result = client.bucket_get_lifecycle.parsed_response
|
204
|
+
lifecycle_keys = %w(LifecycleConfiguration Rule)
|
205
|
+
Utils.wrap(Utils.dig_value(result, *lifecycle_keys)).map do |lifecycle|
|
206
|
+
Struct::LifeCycle.new(lifecycle)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# Used to enable and set lifecycle for bucket
|
211
|
+
#
|
212
|
+
# @param (see #bucket_enable_lifecycle)
|
213
|
+
#
|
214
|
+
# @raise (see #bucket_enable_lifecycle)
|
215
|
+
#
|
216
|
+
# @return [true]
|
217
|
+
#
|
218
|
+
# @see Client#bucket_enable_lifecycle
|
219
|
+
def enable_lifecycle(*args)
|
220
|
+
!!client.bucket_enable_lifecycle(*args)
|
221
|
+
end
|
222
|
+
|
223
|
+
# Used to disable lifecycle for bucket
|
224
|
+
#
|
225
|
+
# @raise (see #bucket_disable_lifecycle)
|
226
|
+
#
|
227
|
+
# @return [true]
|
228
|
+
#
|
229
|
+
# @see Client#bucket_disable_lifecycle
|
230
|
+
def disable_lifecycle
|
231
|
+
!!client.bucket_disable_lifecycle
|
232
|
+
end
|
233
|
+
|
234
|
+
# OPTIONS Object
|
235
|
+
#
|
236
|
+
# @see (see #bucket_preflight)
|
237
|
+
#
|
238
|
+
# @param (see #bucket_preflight)
|
239
|
+
#
|
240
|
+
# @raise (see #bucket_preflight)
|
241
|
+
#
|
242
|
+
# @return [true]
|
243
|
+
#
|
244
|
+
# @see Client#bucket_preflight
|
245
|
+
def preflight(*args)
|
246
|
+
!!client.bucket_preflight(*args)
|
247
|
+
end
|
248
|
+
alias_method :options, :preflight
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Aliyun
|
2
|
+
module Oss
|
3
|
+
module Struct
|
4
|
+
class Cors < Base
|
5
|
+
ACCESSPTED_METHODS = %w(GET PUT DELETE POST HEAD)
|
6
|
+
|
7
|
+
# Set allowed origins. [Array]
|
8
|
+
attr_accessor :allowed_origin
|
9
|
+
|
10
|
+
# Set allowed methods. [Array]
|
11
|
+
attr_accessor :allowed_method
|
12
|
+
|
13
|
+
# Set allowed headers used in preflight (see #bucket_preflight). [Array]
|
14
|
+
attr_accessor :allowed_header
|
15
|
+
|
16
|
+
# Set allowed used response headers for user. [Array]
|
17
|
+
attr_accessor :expose_header
|
18
|
+
|
19
|
+
# Specifies cache time the browser to pre-fetch a particular resource request in seconds. [Integer]
|
20
|
+
attr_accessor :max_age_seconds
|
21
|
+
|
22
|
+
def allowed_origin=(allowed_origin)
|
23
|
+
@allowed_origin = Utils.wrap(allowed_origin)
|
24
|
+
end
|
25
|
+
|
26
|
+
def allowed_method=(allowed_method)
|
27
|
+
@allowed_method = Utils.wrap(allowed_method)
|
28
|
+
.map(&:upcase)
|
29
|
+
.select { |method| ACCESSPTED_METHODS.include?(method.to_s) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def allowed_header=(allowed_header)
|
33
|
+
@allowed_header = Utils.wrap(allowed_header)
|
34
|
+
end
|
35
|
+
|
36
|
+
def expose_header=(expose_header)
|
37
|
+
@expose_header = Utils.wrap(expose_header)
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_hash
|
41
|
+
return {} unless valid?
|
42
|
+
|
43
|
+
attrs = {
|
44
|
+
'AllowedOrigin' => allowed_origin,
|
45
|
+
'AllowedMethod' => allowed_method
|
46
|
+
}
|
47
|
+
attrs.merge!('AllowedHeader' => allowed_header) if value_present?(allowed_header)
|
48
|
+
attrs.merge!('EsposeHeader' => expose_header) if value_present?(expose_header)
|
49
|
+
attrs.merge!('MaxAgeSeconds' => max_age_seconds) if max_age_seconds
|
50
|
+
attrs
|
51
|
+
end
|
52
|
+
|
53
|
+
def valid?
|
54
|
+
value_present?(allowed_origin) && value_present?(allowed_method)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def value_present?(value)
|
60
|
+
value && !value.empty?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Aliyun
|
2
|
+
module Oss
|
3
|
+
module Struct
|
4
|
+
class LifeCycle < Base
|
5
|
+
# Rule ID, auto set when not set. [String]
|
6
|
+
attr_accessor :id
|
7
|
+
|
8
|
+
# Used for filter objects. [String]
|
9
|
+
attr_accessor :prefix
|
10
|
+
|
11
|
+
# Used for set rule status. [Boolean]
|
12
|
+
attr_accessor :enabled
|
13
|
+
|
14
|
+
# Set auto delete objects after days since last modified, at least exist one with date [Integer]
|
15
|
+
attr_accessor :days
|
16
|
+
|
17
|
+
# Set auto auto delete object at given time, at least exist one with days, [Time]
|
18
|
+
attr_accessor :date
|
19
|
+
|
20
|
+
def status=(status)
|
21
|
+
@enabled = (status == 'Enabled')
|
22
|
+
end
|
23
|
+
|
24
|
+
def date=(date)
|
25
|
+
@date = date.is_a?(String) ? Time.parse(date) : date
|
26
|
+
end
|
27
|
+
|
28
|
+
def days=(days)
|
29
|
+
@days = days.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_hash
|
33
|
+
return {} unless valid?
|
34
|
+
|
35
|
+
{
|
36
|
+
'ID' => id || '',
|
37
|
+
'Prefix' => prefix,
|
38
|
+
'Status' => status,
|
39
|
+
'Expiration' => expiration
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def expiration=(expiration)
|
44
|
+
return unless expiration.is_a?(Hash)
|
45
|
+
|
46
|
+
if expiration.key?('Days')
|
47
|
+
self.days = expiration['Days']
|
48
|
+
elsif expiration.key?('Date')
|
49
|
+
self.date = expiration['Date']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def valid?
|
54
|
+
prefix && (days || date)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def status
|
60
|
+
enabled ? 'Enabled' : 'Disabled'
|
61
|
+
end
|
62
|
+
|
63
|
+
def expiration
|
64
|
+
if date && date.is_a?(Time)
|
65
|
+
{ 'Date' => date.utc.strftime('%Y-%m-%dT00:00:00.000Z') }
|
66
|
+
elsif days && days.is_a?(Integer)
|
67
|
+
{ 'Days' => days.to_i }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Aliyun
|
2
|
+
module Oss
|
3
|
+
module Struct
|
4
|
+
class Logging < Base
|
5
|
+
# Container for logging information. This element and its children are present when logging is enabled; otherwise, this element and its children are absent.
|
6
|
+
attr_accessor :logging_enabled
|
7
|
+
|
8
|
+
# This element specifies the bucket where server access logs will be delivered.
|
9
|
+
attr_accessor :target_bucket
|
10
|
+
|
11
|
+
# Specifies the prefix for the keys that the log files are being stored for.
|
12
|
+
attr_accessor :target_prefix
|
13
|
+
|
14
|
+
def initialize(attributes = {})
|
15
|
+
@logging_enabled = false
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def logging_enabled=(logging_enabled)
|
20
|
+
return @logging_enabled = false unless logging_enabled.is_a?(Hash)
|
21
|
+
|
22
|
+
if logging_enabled.key?('TargetBucket')
|
23
|
+
@target_bucket = logging_enabled['TargetBucket']
|
24
|
+
end
|
25
|
+
if logging_enabled.key?('TargetPrefix')
|
26
|
+
@target_prefix = logging_enabled['TargetPrefix']
|
27
|
+
end
|
28
|
+
@logging_enabled = true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Aliyun
|
2
|
+
module Oss
|
3
|
+
module Struct
|
4
|
+
class Multipart < Base
|
5
|
+
# UUID for the Multipart Upload Event
|
6
|
+
attr_accessor :upload_id
|
7
|
+
|
8
|
+
# Object name of the Multipart Upload Event
|
9
|
+
attr_accessor :key
|
10
|
+
|
11
|
+
# Bucket name of the Multipart Upload Event
|
12
|
+
attr_accessor :bucket
|
13
|
+
|
14
|
+
# Initiation time of the Multipart Upload Event
|
15
|
+
attr_accessor :initiated
|
16
|
+
|
17
|
+
# reference to client
|
18
|
+
attr_accessor :client
|
19
|
+
|
20
|
+
def initiated=(initiated)
|
21
|
+
@initiated = Time.parse(initiated)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Upload part to Multipart Upload Event
|
25
|
+
#
|
26
|
+
# @param number [Integer] the part number, Range in 1~10000.
|
27
|
+
# @param file [File, bin data] the upload data
|
28
|
+
#
|
29
|
+
# @raise (see #bucket_multipart_upload)
|
30
|
+
#
|
31
|
+
# @return [true]
|
32
|
+
def upload(*args)
|
33
|
+
!!client.bucket_multipart_upload(*args.unshift(upload_id, key))
|
34
|
+
end
|
35
|
+
|
36
|
+
# Copy exsting object to Multipart Upload Event
|
37
|
+
#
|
38
|
+
# @param number [Integer] the part number, Range in 1~10000.
|
39
|
+
# @param options [Hash] options
|
40
|
+
# @option (see #bucket_multipart_copy_upload)
|
41
|
+
#
|
42
|
+
# @raise (see #bucket_multipart_copy_upload)
|
43
|
+
#
|
44
|
+
# @return [true]
|
45
|
+
#
|
46
|
+
# @see Client#bucket_list_parts
|
47
|
+
def copy(*args)
|
48
|
+
!!client.bucket_multipart_copy_upload(*args.unshift(upload_id, key))
|
49
|
+
end
|
50
|
+
|
51
|
+
# List uploaded parts for the Multipart Upload Event
|
52
|
+
#
|
53
|
+
# @param options [Hash] options
|
54
|
+
# @option (see #bucket_list_parts)
|
55
|
+
#
|
56
|
+
# @raise (see #bucket_list_parts)
|
57
|
+
#
|
58
|
+
# @return [Array<Aliyun::Oss::Struct::Part>]
|
59
|
+
#
|
60
|
+
# @see Client#bucket_list_parts
|
61
|
+
def list_parts(options = {})
|
62
|
+
result = client.bucket_list_parts(upload_id, key, options)
|
63
|
+
.parsed_response
|
64
|
+
|
65
|
+
parts_keys = %w(ListPartsResult Part)
|
66
|
+
Utils.wrap(Utils.dig_value(result, *parts_keys)).map do |part|
|
67
|
+
Struct::Part.new(part)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Complete Multipart Upload Event
|
72
|
+
#
|
73
|
+
# @param parts [Array<Multipart:Part>] parts
|
74
|
+
#
|
75
|
+
# @raise (see #bucket_complete_multipart)
|
76
|
+
#
|
77
|
+
# @return [Struct::Object]
|
78
|
+
#
|
79
|
+
# @see Client#bucket_complete_multipart
|
80
|
+
def complete(parts = [])
|
81
|
+
resp = client.bucket_complete_multipart(upload_id, key, parts)
|
82
|
+
keys = %w(CompleteMultipartUploadResult)
|
83
|
+
Struct::Object.new(
|
84
|
+
Utils.dig_value(resp.parsed_response, *keys).merge(client: client)
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Abort Multipart Upload Event
|
89
|
+
#
|
90
|
+
# @raise (see #bucket_abort_multipart)
|
91
|
+
#
|
92
|
+
# @return [true]
|
93
|
+
#
|
94
|
+
# @see Client#bucket_abort_multipart
|
95
|
+
def abort
|
96
|
+
!!client.bucket_abort_multipart(upload_id, key)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|