aliyun-oss-sdk 0.1.1 → 0.1.2
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.
- data/README.md +137 -151
- data/aliyun-oss.gemspec +1 -2
- data/lib/aliyun/oss/api/bucket_multiparts.rb +184 -0
- data/lib/aliyun/oss/api/bucket_objects.rb +204 -0
- data/lib/aliyun/oss/api/bucket_property.rb +246 -0
- data/lib/aliyun/oss/api/buckets.rb +89 -0
- data/lib/aliyun/oss/authorization.rb +21 -32
- data/lib/aliyun/oss/client.rb +11 -683
- data/lib/aliyun/oss/client/bucket_objects.rb +5 -6
- data/lib/aliyun/oss/client/buckets.rb +11 -5
- data/lib/aliyun/oss/http.rb +1 -1
- data/lib/aliyun/oss/struct/bucket.rb +4 -0
- data/lib/aliyun/oss/struct/directory.rb +25 -0
- data/lib/aliyun/oss/struct/file.rb +8 -0
- data/lib/aliyun/oss/struct/multipart.rb +2 -2
- data/lib/aliyun/oss/struct/object.rb +22 -1
- data/lib/aliyun/oss/struct/part.rb +2 -8
- data/lib/aliyun/oss/utils.rb +6 -0
- data/lib/aliyun/oss/version.rb +1 -1
- data/todo.md +1 -0
- data/wiki/multipart.md +3 -3
- data/wiki/object_based/bucket.md +125 -0
- data/wiki/object_based/cors.md +71 -0
- data/wiki/object_based/error.md +70 -0
- data/wiki/object_based/get_start.md +93 -0
- data/wiki/object_based/installation.md +15 -0
- data/wiki/object_based/lifecycle.md +88 -0
- data/wiki/object_based/multipart.md +133 -0
- data/wiki/object_based/object.md +324 -0
- metadata +69 -43
- checksums.yaml +0 -7
@@ -0,0 +1,204 @@
|
|
1
|
+
module Aliyun
|
2
|
+
module Oss
|
3
|
+
module Api
|
4
|
+
module BucketObjects
|
5
|
+
# List objects in the bucket
|
6
|
+
#
|
7
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucket Get Bucket (List Object)
|
8
|
+
#
|
9
|
+
# @param options [Hash] options
|
10
|
+
# @option options [String] :prefix Filter objects with prefix
|
11
|
+
# @option options [String] :marker Result should after marker in alphabetical order
|
12
|
+
# @option options [Integer] :max-keys (100) Limit number of objects, the maxinum should <= 1000
|
13
|
+
# @option options [String] :delimiter Used to group objects with delimiter
|
14
|
+
# @option options [String] :encoding-type Encoding type used for unsupported character
|
15
|
+
#
|
16
|
+
# @return [Response]
|
17
|
+
def bucket_list_objects(options = {})
|
18
|
+
Utils.stringify_keys!(options)
|
19
|
+
accepted_keys = ['prefix', 'marker', 'max-keys', 'delimiter', 'encoding-type']
|
20
|
+
query = Utils.hash_slice(options, *accepted_keys)
|
21
|
+
http.get('/', query: query, bucket: bucket)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Upload file to bucket
|
25
|
+
#
|
26
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/object&PutObject Put Object
|
27
|
+
#
|
28
|
+
# @param key [String] Specify object name
|
29
|
+
# @param file [File, Bin data] Specify need upload resource
|
30
|
+
# @param [Hash] headers Specify other options
|
31
|
+
# @option headers [String] :Content-Type ('application/x-www-form-urlencoded') Specify Content-Type for the object
|
32
|
+
# @option headers [String] :Cache-Control Specify the caching behavior when download from browser, ref {https://www.ietf.org/rfc/rfc2616.txt?spm=5176.730001.3.128.Y5W4bu&file=rfc2616.txt RFC2616}
|
33
|
+
# @option headers [String] :Content-Disposition Specify the name when download, ref {https://www.ietf.org/rfc/rfc2616.txt?spm=5176.730001.3.128.Y5W4bu&file=rfc2616.txt RFC2616}
|
34
|
+
# @option headers [String] :Content-Encoding Specify the content encoding when download, ref {https://www.ietf.org/rfc/rfc2616.txt?spm=5176.730001.3.128.Y5W4bu&file=rfc2616.txt RFC2616}
|
35
|
+
# @option headers [String] :Content-MD5 RFC 1864 according to the agreement of the message Content (not including head) are calculated MD5 value 128 bits number, the number is base64 encoding for the Content of a message - MD5 value.The legality of the examination of the request headers can be used for information (a message content is consistent with send).Although the request header is optional, OSS recommend that users use the end-to-end check request header.
|
36
|
+
# @option headers [Integer] :Expires Specify the expiration time (milliseconds)
|
37
|
+
# @option headers [String] :x-oss-server-side-encryption Specify the oss server-side encryption algorithm when the object was created. supported value: 'AES256'
|
38
|
+
# @option headers [String] :x-oss-object-acl Specify the oss access when the object was created. supported value: public-read-write | public-read | private
|
39
|
+
# @option headers [Hash] other options will insert into headers when upload, such as user meta headers, eg: headers with prefix: x-oss-meta-
|
40
|
+
#
|
41
|
+
# @return [Response]
|
42
|
+
def bucket_create_object(key, file, headers = {})
|
43
|
+
Utils.stringify_keys!(headers)
|
44
|
+
http.put("/#{key}", headers: headers, body: Utils.to_data(file), bucket: bucket, key: key)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Copy an existing object in OSS into another object
|
48
|
+
#
|
49
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/object&CopyObject Copy Object
|
50
|
+
#
|
51
|
+
# @param key [String] the object name
|
52
|
+
# @param source_bucket [String] the source bucket name
|
53
|
+
# @param source_key [String] the source object name
|
54
|
+
# @param [Hash] headers
|
55
|
+
# @option options [String] :source_bucket the source bucket name
|
56
|
+
# @option options [String] :source_key the source object name
|
57
|
+
# @option options [String] :x-oss-copy-source-if-match If the specified ETag match the source object ETag, normal transfer and return 200; Otherwise return 412(precondition)
|
58
|
+
# @option options [String] :x-oss-copy-source-if-none-match If the specified ETag not match the source object ETag, normal transfer and return 200; Otherwise return 304(Not Modified)
|
59
|
+
# @option options [String] :x-oss-copy-source-if-unmodified-since If the specified time is equal to or later than the source object last modification time, normal transfer ans return 200; Otherwise returns 412(precondition)
|
60
|
+
# @option options [String] :x-oss-copy-source-if-modified-since If the specified time is earlier than the source object last modification time, normal transfer ans return 200; Otherwise returns 304(not modified)
|
61
|
+
# @option options [String] :x-oss-metadata-directive ('COPY') supported value: COPY, REPLACE;
|
62
|
+
# @option options [String] :x-oss-server-side-encryption supported value: AES256
|
63
|
+
# @option options [String] :x-oss-object-acl supported value: public-read, private, public-read-write
|
64
|
+
#
|
65
|
+
# @raise [RequestError]
|
66
|
+
#
|
67
|
+
# @return [Response]
|
68
|
+
def bucket_copy_object(key, source_bucket, source_key, headers = {})
|
69
|
+
fail('source_bucket must be not empty!') if source_bucket.nil? || source_bucket.empty?
|
70
|
+
fail('source_key must be not empty!') if source_key.nil? || source_key.empty?
|
71
|
+
|
72
|
+
Utils.stringify_keys!(headers)
|
73
|
+
headers.merge!('x-oss-copy-source' => "/#{source_bucket}/#{source_key}")
|
74
|
+
|
75
|
+
http.put("/#{key}", headers: headers, bucket: bucket, key: key)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Append data to a object, will create Appendable object
|
79
|
+
#
|
80
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/object&AppendObject Append Object
|
81
|
+
#
|
82
|
+
# @param key [String] object name
|
83
|
+
# @param file [file, bin data] the data to append
|
84
|
+
# @param position [Integer] append to position of object
|
85
|
+
# @option headers (see #bucket_create_object)
|
86
|
+
#
|
87
|
+
# @raise [RequestError]
|
88
|
+
#
|
89
|
+
# @return [Response]
|
90
|
+
def bucket_append_object(key, file, position = 0, headers = {})
|
91
|
+
Utils.stringify_keys!(headers)
|
92
|
+
|
93
|
+
query = { 'append' => true, 'position' => position }
|
94
|
+
body = Utils.to_data(file)
|
95
|
+
|
96
|
+
http.post("/#{key}", query: query, headers: headers, body: body, bucket: bucket, key: key)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Get the object
|
100
|
+
#
|
101
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/object&GetObject Get Object
|
102
|
+
#
|
103
|
+
# @param key [String] the object name
|
104
|
+
# @param query [Hash] query params
|
105
|
+
# @option query [String] :response-content-type Specify the header Content-Type in response
|
106
|
+
# @option query [String] :response-content-language Specify the header Content-Language in response
|
107
|
+
# @option query [String] :response-expires Specify the header Expires in response
|
108
|
+
# @option query [String] :response-cache-control Specify the header Cache-Control in response
|
109
|
+
# @option query [String] :response-content-disposition Specify the header Content-Disposition in response
|
110
|
+
# @option query [String] :response-content-encoding Specify the header Content-encoding in response
|
111
|
+
# @param headers [Hash] headers
|
112
|
+
# @option headers [String] :Range Specify the range of the file. Such as "bytes=0-9" means the 10 characters from 0 to 9.
|
113
|
+
# @option headers [String] :If-Modified-Since If the specified time is earlier than the file last modification time, return 200 OK; Otherwise returns 304(not modified)
|
114
|
+
# @option headers [String] :If-Unmodified-Since If the specified time is equal to or later than the file last modification time, normal transfer ans return 200; Otherwise returns 412(precondition)
|
115
|
+
# @option headers [String] :If-Match If the specified ETag match the object ETag, normal transfer and return 200; Otherwise return 412(precondition)
|
116
|
+
# @option headers [String] :If-None-Match If the specified ETag not match the object ETag, normal transfer and return 200; Otherwise return 304(Not Modified)
|
117
|
+
#
|
118
|
+
# @return [Response]
|
119
|
+
def bucket_get_object(key, query = {}, headers = {})
|
120
|
+
Utils.stringify_keys!(query)
|
121
|
+
Utils.stringify_keys!(headers)
|
122
|
+
|
123
|
+
http.get("/#{key}", query: query, headers: headers, bucket: bucket, key: key)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Delete object from bucket
|
127
|
+
#
|
128
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteObject Delete Object
|
129
|
+
#
|
130
|
+
# @param key [String] the object name
|
131
|
+
#
|
132
|
+
# @return [Response]
|
133
|
+
def bucket_delete_object(key)
|
134
|
+
http.delete("/#{key}", bucket: bucket, key: key)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Delete multiple objects, at max 1000 at once
|
138
|
+
#
|
139
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteMultipleObjects Delete Multiple Objects
|
140
|
+
#
|
141
|
+
# @param keys [Array<String>] the object names
|
142
|
+
# @param quiet [Boolean] Specify response mode: false(Quiet) return results for error objects, true(Verbose) return results of every objects
|
143
|
+
#
|
144
|
+
# @return [Response]
|
145
|
+
def bucket_delete_objects(keys, quiet = false)
|
146
|
+
query = { 'delete' => true }
|
147
|
+
|
148
|
+
body = XmlGenerator.generate_delete_objects_xml(keys, quiet)
|
149
|
+
|
150
|
+
http.post('/', query: query, body: body, bucket: bucket)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Get meta information of object
|
154
|
+
#
|
155
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/object&HeadObject Head Object
|
156
|
+
#
|
157
|
+
# @param key [String] object name
|
158
|
+
# @param headers [Hash] headers
|
159
|
+
# @option headers [String] :If-Modified-Since If the specified time is earlier than the file last modification time, return 200 OK; Otherwise returns 304(not modified)
|
160
|
+
# @option headers [String] :If-Unmodified-Since If the specified time is equal to or later than the file last modification time, normal transfer ans return 200; Otherwise returns 412(precondition)
|
161
|
+
# @option headers [String] :If-Match If the specified ETag match the object ETag, normal transfer and return 200; Otherwise return 412(precondition)
|
162
|
+
# @option headers [String] :If-None-Match If the specified ETag not match the object ETag, normal transfer and return 200; Otherwise return 304(Not Modified)
|
163
|
+
#
|
164
|
+
# @raise [RequestError]
|
165
|
+
#
|
166
|
+
# @return [Response]
|
167
|
+
def bucket_get_meta_object(key, headers = {})
|
168
|
+
Utils.stringify_keys!(headers)
|
169
|
+
http.head("/#{key}", headers: headers, bucket: bucket, key: key)
|
170
|
+
end
|
171
|
+
|
172
|
+
# Get access of object
|
173
|
+
#
|
174
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/object&GetObjectACL Get Object ACL
|
175
|
+
#
|
176
|
+
# @param key [String] object name
|
177
|
+
#
|
178
|
+
# @raise [RequestError]
|
179
|
+
#
|
180
|
+
# @return [Response]
|
181
|
+
def bucket_get_object_acl(key)
|
182
|
+
query = { 'acl' => true }
|
183
|
+
http.get("/#{key}", query: query, bucket: bucket, key: key)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Set access of object
|
187
|
+
#
|
188
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/object&PutObjectACL Put Object ACL
|
189
|
+
#
|
190
|
+
# @param key [String] object name
|
191
|
+
# @param acl [String] access value, supported value: private, public-read, public-read-write
|
192
|
+
#
|
193
|
+
# @raise [RequestError]
|
194
|
+
#
|
195
|
+
# @return [Response]
|
196
|
+
def bucket_set_object_acl(key, acl)
|
197
|
+
query = { 'acl' => true }
|
198
|
+
headers = { 'x-oss-object-acl' => acl }
|
199
|
+
http.put("/#{key}", query: query, headers: headers, bucket: bucket, key: key)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,246 @@
|
|
1
|
+
module Aliyun
|
2
|
+
module Oss
|
3
|
+
module Api
|
4
|
+
module BucketProperty
|
5
|
+
# Used to modify the bucket access.
|
6
|
+
#
|
7
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketACL Put Bucket Acl
|
8
|
+
#
|
9
|
+
# @param acl [String] supported value: public-read-write | public-read | private
|
10
|
+
# @raise [RequestError]
|
11
|
+
#
|
12
|
+
# @return [Response]
|
13
|
+
def bucket_set_acl(acl)
|
14
|
+
query = { 'acl' => true }
|
15
|
+
headers = { 'x-oss-acl' => acl }
|
16
|
+
http.put('/', query: query, headers: headers, bucket: bucket)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Used to enable access logging.
|
20
|
+
#
|
21
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketLogging Put Bucket Logging
|
22
|
+
#
|
23
|
+
# @param target_bucket [String] specifies the bucket where you want Aliyun OSS to store server access logs.
|
24
|
+
# @param target_prefix [String] this element lets you specify a prefix for the objects that the log files will be stored.
|
25
|
+
#
|
26
|
+
# @raise [RequestError]
|
27
|
+
#
|
28
|
+
# @return [Response]
|
29
|
+
def bucket_enable_logging(target_bucket, target_prefix = nil)
|
30
|
+
query = { 'logging' => true }
|
31
|
+
|
32
|
+
body = XmlGenerator.generate_enable_logging_xml(target_bucket,
|
33
|
+
target_prefix)
|
34
|
+
|
35
|
+
http.put('/', query: query, body: body, bucket: bucket)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Used to disable access logging.
|
39
|
+
#
|
40
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketLogging Delete Bucket Logging
|
41
|
+
#
|
42
|
+
# @raise [RequestError]
|
43
|
+
#
|
44
|
+
# @return [Response]
|
45
|
+
def bucket_disable_logging
|
46
|
+
query = { 'logging' => false }
|
47
|
+
http.delete('/', query: query, bucket: bucket)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Used to enable static website hosted mode.
|
51
|
+
#
|
52
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketWebsite Put Bucket Website
|
53
|
+
#
|
54
|
+
# @param suffix [String] A suffix that is appended to a request that is for a directory on the website endpoint (e.g. if the suffix is index.html and you make a request to samplebucket/images/ the data that is returned will be for the object with the key name images/index.html) The suffix must not be empty and must not include a slash character.
|
55
|
+
# @param key [String] The object key name to use when a 4XX class error occurs
|
56
|
+
#
|
57
|
+
# @raise [RequestError]
|
58
|
+
#
|
59
|
+
# @return [Response]
|
60
|
+
def bucket_enable_website(suffix, key = nil)
|
61
|
+
query = { 'website' => true }
|
62
|
+
|
63
|
+
body = XmlGenerator.generate_enable_website_xml(suffix, key)
|
64
|
+
|
65
|
+
http.put('/', query: query, body: body, bucket: bucket)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Used to disable website hostted mode.
|
69
|
+
#
|
70
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketWebsite Delete Bucket Website
|
71
|
+
#
|
72
|
+
# @raise [RequestError]
|
73
|
+
#
|
74
|
+
# @return [Response]
|
75
|
+
def bucket_disable_website
|
76
|
+
query = { 'website' => false }
|
77
|
+
http.delete('/', query: query, bucket: bucket)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Used to set referer for bucket.
|
81
|
+
#
|
82
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketReferer Put Bucket Referer
|
83
|
+
#
|
84
|
+
# @param referers [Array<String>] white list for allowed referer.
|
85
|
+
# @param allowed_empty [Boolean] whether allow empty refer.
|
86
|
+
#
|
87
|
+
# @raise [RequestError]
|
88
|
+
#
|
89
|
+
# @return [Response]
|
90
|
+
def bucket_set_referer(referers = [], allowed_empty = false)
|
91
|
+
query = { 'referer' => true }
|
92
|
+
|
93
|
+
body = XmlGenerator.generate_set_referer_xml(referers, allowed_empty)
|
94
|
+
|
95
|
+
http.put('/', query: query, body: body, bucket: bucket)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Used to enable and set lifecycle for bucket
|
99
|
+
#
|
100
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketLifecycle Put Bucket Lifecycle
|
101
|
+
#
|
102
|
+
# @param rules [Array<Aliyun::Oss::Struct::LifeCycle>] rules for lifecycle
|
103
|
+
#
|
104
|
+
# @raise [RequestError]
|
105
|
+
# @raise [Aliyun::Oss::InvalidLifeCycleRuleError]
|
106
|
+
# if rule invalid
|
107
|
+
#
|
108
|
+
# @return [Response]
|
109
|
+
def bucket_enable_lifecycle(rules = [])
|
110
|
+
query = { 'lifecycle' => true }
|
111
|
+
|
112
|
+
rules = Utils.wrap(rules)
|
113
|
+
|
114
|
+
rules.each do |rule|
|
115
|
+
unless rule.valid?
|
116
|
+
fail Aliyun::Oss::InvalidLifeCycleRuleError, rule.inspect
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
body = XmlGenerator.generate_lifecycle_rules(rules)
|
121
|
+
|
122
|
+
http.put('/', query: query, body: body, bucket: bucket)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Used to disable lifecycle for bucket.
|
126
|
+
#
|
127
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketLifecycle Delete Bucket Lifecycle
|
128
|
+
def bucket_disable_lifecycle
|
129
|
+
query = { 'lifecycle' => false }
|
130
|
+
http.delete('/', query: query, bucket: bucket)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Used to enable CORS and set rules for bucket
|
134
|
+
#
|
135
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/cors&PutBucketcors Put Bucket cors
|
136
|
+
#
|
137
|
+
# @param rules [Array<Aliyun::Oss::Struct::Cors>] array of rule
|
138
|
+
#
|
139
|
+
# @raise [RequestError]
|
140
|
+
# @raise [InvalidCorsRule]
|
141
|
+
# if rule invalid
|
142
|
+
#
|
143
|
+
# @return [Response]
|
144
|
+
def bucket_enable_cors(rules = [])
|
145
|
+
query = { 'cors' => true }
|
146
|
+
|
147
|
+
rules = Utils.wrap(rules)
|
148
|
+
|
149
|
+
rules.each do |rule|
|
150
|
+
unless rule.valid?
|
151
|
+
fail Aliyun::Oss::InvalidCorsRuleError, rule.inspect
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
body = XmlGenerator.generate_cors_rules(rules)
|
156
|
+
|
157
|
+
http.put('/', query: query, body: body, bucket: bucket)
|
158
|
+
end
|
159
|
+
|
160
|
+
# Used to disable cors and clear rules for bucket
|
161
|
+
#
|
162
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/cors&DeleteBucketcors Delete Bucket cors
|
163
|
+
#
|
164
|
+
# @raise [RequestError]
|
165
|
+
#
|
166
|
+
# @return [Response]
|
167
|
+
def bucket_disable_cors
|
168
|
+
query = { 'cors' => false }
|
169
|
+
http.delete('/', query: query, bucket: bucket)
|
170
|
+
end
|
171
|
+
|
172
|
+
# Get ACL for bucket
|
173
|
+
#
|
174
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketAcl Get Bucket ACL
|
175
|
+
#
|
176
|
+
# @return [Response]
|
177
|
+
def bucket_get_acl
|
178
|
+
query = { 'acl' => true }
|
179
|
+
http.get('/', query: query, bucket: bucket)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Get the location information of the Bucket's data center
|
183
|
+
#
|
184
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLocation Get Bucket Location
|
185
|
+
#
|
186
|
+
# @return [Response]
|
187
|
+
def bucket_get_location
|
188
|
+
query = { 'location' => true }
|
189
|
+
http.get('/', query: query, bucket: bucket)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Get the log configuration of Bucket
|
193
|
+
#
|
194
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLogging Get Bucket Logging
|
195
|
+
#
|
196
|
+
# @raise [RequestError]
|
197
|
+
#
|
198
|
+
# @return [Response]
|
199
|
+
def bucket_get_logging
|
200
|
+
query = { 'logging' => true }
|
201
|
+
http.get('/', query: query, bucket: bucket)
|
202
|
+
end
|
203
|
+
|
204
|
+
# Get the bucket state of static website hosting.
|
205
|
+
#
|
206
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketWebsite Get Bucket Website
|
207
|
+
#
|
208
|
+
# @return [Response]
|
209
|
+
def bucket_get_website
|
210
|
+
query = { 'website' => true }
|
211
|
+
http.get('/', query: query, bucket: bucket)
|
212
|
+
end
|
213
|
+
|
214
|
+
# Get the referer configuration of bucket
|
215
|
+
#
|
216
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketReferer Get Bucket Referer
|
217
|
+
#
|
218
|
+
# @return [Response]
|
219
|
+
def bucket_get_referer
|
220
|
+
query = { 'referer' => true }
|
221
|
+
http.get('/', query: query, bucket: bucket)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Get the lifecycle configuration of bucket
|
225
|
+
#
|
226
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLifecycle Get Bucket Lifecycle
|
227
|
+
#
|
228
|
+
# @return [Response]
|
229
|
+
def bucket_get_lifecycle
|
230
|
+
query = { 'lifecycle' => true }
|
231
|
+
http.get('/', query: query, bucket: bucket)
|
232
|
+
end
|
233
|
+
|
234
|
+
# Get the CORS rules of bucket
|
235
|
+
#
|
236
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/cors&GetBucketcors Get Bucket cors
|
237
|
+
#
|
238
|
+
# @return [Response]
|
239
|
+
def bucket_get_cors
|
240
|
+
query = { 'cors' => true }
|
241
|
+
http.get('/', query: query, bucket: bucket)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Aliyun
|
2
|
+
module Oss
|
3
|
+
module Api
|
4
|
+
module Buckets
|
5
|
+
# List buckets
|
6
|
+
#
|
7
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/service&GetService GetService (ListBucket
|
8
|
+
#
|
9
|
+
# @param options [Hash] options
|
10
|
+
# @option options [String] :prefix Filter buckets with prefix
|
11
|
+
# @option options [String] :marker Bucket name should after marker in alphabetical order
|
12
|
+
# @option options [Integer] :max-keys (100) Limit number of buckets, the maxinum should <= 1000
|
13
|
+
#
|
14
|
+
# @return [Response]
|
15
|
+
def list_buckets(options = {})
|
16
|
+
Utils.stringify_keys!(options)
|
17
|
+
query = Utils.hash_slice(options, 'prefix', 'marker', 'max-keys')
|
18
|
+
http.get('/', query: query)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Create bucket
|
22
|
+
#
|
23
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucket Put Bucket
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# oss.client.bucket_create('oss-sdk-dev-hangzhou-xxx')
|
27
|
+
#
|
28
|
+
# @param name [String] Specify bucket name
|
29
|
+
# @param location [String] Specify the bucket's data center location, can be one of below:
|
30
|
+
# oss-cn-hangzhou,oss-cn-qingdao,oss-cn-beijing,oss-cn-hongkong,
|
31
|
+
# oss-cn-shenzhen,oss-cn-shanghai,oss-us-west-1 ,oss-ap-southeast-1
|
32
|
+
# @param acl [String] Specify the bucket's access. (see #bucket_set_acl)
|
33
|
+
#
|
34
|
+
# @raise [RequestError]
|
35
|
+
#
|
36
|
+
# @return [Response]
|
37
|
+
def bucket_create(name, location = 'oss-cn-hangzhou', acl = 'private')
|
38
|
+
query = { 'acl' => true }
|
39
|
+
headers = { 'x-oss-acl' => acl }
|
40
|
+
|
41
|
+
body = XmlGenerator.generate_create_bucket_xml(location)
|
42
|
+
|
43
|
+
http.put('/', query: query, headers: headers, body: body, bucket: name, location: location)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Delete bucket
|
47
|
+
#
|
48
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucket Delete Bucket
|
49
|
+
#
|
50
|
+
# @param name [String] bucket name want to delete
|
51
|
+
#
|
52
|
+
# @raise [RequestError]
|
53
|
+
#
|
54
|
+
# @return [Response]
|
55
|
+
def bucket_delete(name)
|
56
|
+
http.delete('/', bucket: name)
|
57
|
+
end
|
58
|
+
|
59
|
+
# OPTIONS Object
|
60
|
+
#
|
61
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/cors&OptionObject OPTIONS Object
|
62
|
+
#
|
63
|
+
# @param object_key [String] the object name want to visit.
|
64
|
+
# @param origin [String] the requested source domain, denoting cross-domain request.
|
65
|
+
# @param request_method [String] the actual request method will be used.
|
66
|
+
# @param request_headers [Array<String>] the actual used headers except simple headers will be used.
|
67
|
+
#
|
68
|
+
# @raise [RequestError]
|
69
|
+
#
|
70
|
+
# @return [Response]
|
71
|
+
def bucket_preflight(object_key, origin, request_method, request_headers = [])
|
72
|
+
path = object_key ? "/#{object_key}" : '/'
|
73
|
+
|
74
|
+
headers = {
|
75
|
+
'Origin' => origin,
|
76
|
+
'Access-Control-Request-Method' => request_method
|
77
|
+
}
|
78
|
+
|
79
|
+
unless request_headers.empty?
|
80
|
+
value = request_headers.join(',')
|
81
|
+
headers.merge!('Access-Control-Request-Headers' => value)
|
82
|
+
end
|
83
|
+
|
84
|
+
http.options(path, headers: headers, bucket: bucket, key: object_key)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|