qingstor-sdk 2.4.0 → 2.5.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/README.md +41 -2
- data/lib/qingstor/sdk/general/config.rb +108 -11
- data/lib/qingstor/sdk/general/contract.rb +6 -3
- data/lib/qingstor/sdk/request/preprocessor.rb +52 -8
- data/lib/qingstor/sdk/request/request.rb +12 -2
- data/lib/qingstor/sdk/request/signer.rb +23 -7
- data/lib/qingstor/sdk/service/bucket.rb +1 -4
- data/lib/qingstor/sdk/service/qingstor.rb +1 -0
- data/lib/qingstor/sdk/version.rb +1 -1
- metadata +5 -6
- data/lib/qingstor/sdk/general/default/config.yaml +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4067ee8cebe68b7a6ff943ce45aab389887fec3eb3725311eb8fd0bbf44fa50
|
4
|
+
data.tar.gz: 97d3720cb4c6ac65b45fa66a1ac8b117300f96489894c19381972ed945b59c79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d09dc5817005d1645473bddb4f5a354a4fef382dcf34775dee845cbffe1188d28d8684df73daf7440d58a83d6aa3e26d1c1e2199dacedf294f40fae915f25ec
|
7
|
+
data.tar.gz: a0a940c7419f8acc356977c9d336a7c982b67282624baa0e0b44e0f8b31a37cf3dd4b6e4d3f5b19ca84c6bf11a7d14c0169a522fc44d3390d297d29598be675b
|
data/README.md
CHANGED
@@ -14,7 +14,9 @@ This Gem uses Ruby's _keyword arguments_ feature, thus Ruby v2.1.5 or higher is
|
|
14
14
|
required. See [this article](https://robots.thoughtbot.com/ruby-2-keyword-arguments)
|
15
15
|
for more details about _keyword arguments_.
|
16
16
|
|
17
|
-
_Notice:_
|
17
|
+
_Notice:_ As of sdk v2.4, we no longer support Ruby 2.4 and earlier versions since Ruby 2.4 has been marked as EOL.
|
18
|
+
If you are still using Ruby 2.4 and earlier, you may not be able to use some new features of our sdk,
|
19
|
+
so please upgrade your version of Ruby as soon as possible.
|
18
20
|
|
19
21
|
### Install from RubyGems
|
20
22
|
|
@@ -122,6 +124,11 @@ server (in case of QingStor is deployed in private environment, thus has
|
|
122
124
|
different endpoint with public QingStor) either in the config file, or in
|
123
125
|
the program dynamically.
|
124
126
|
|
127
|
+
**Notice:** config will not be checked available when `new`, `load` and `update`,
|
128
|
+
which will be done right before initializing `service` or `bucket`.
|
129
|
+
If you need to check config, you should call `config.check` whenever you want.
|
130
|
+
If `check` failed, a `ConfigurationError` will be raised.
|
131
|
+
|
125
132
|
___Code Example:___
|
126
133
|
|
127
134
|
``` ruby
|
@@ -131,6 +138,7 @@ require 'qingstor/sdk'
|
|
131
138
|
config = QingStor::SDK::Config.new.load_default_config
|
132
139
|
|
133
140
|
# Create with default value
|
141
|
+
# priority from high to low: param > env > user config > default config
|
134
142
|
config = QingStor::SDK::Config.new({
|
135
143
|
host: 'qingstor.dev',
|
136
144
|
log_level: 'debug',
|
@@ -144,6 +152,13 @@ config = QingStor::SDK::Config.init ENV['ENV_ACCESS_KEY_ID'],
|
|
144
152
|
config = QingStor::SDK::Config.new
|
145
153
|
config = config.load_config_from_file '~/qingstor/config.yaml'
|
146
154
|
|
155
|
+
# Load configuration from env variable:
|
156
|
+
# QINGSTOR_ACCESS_KEY_ID for access_key_id
|
157
|
+
# QINGSTOR_SECRET_ACCESS_KEY for secret_access_key
|
158
|
+
# QINGSTOR_ENABLE_VIRTUAL_HOST_STYLE for enable_virtual_host_style
|
159
|
+
# QINGSTOR_ENDPOINT for endpoint
|
160
|
+
config = QingStor::SDK::Config.new.load_env_config
|
161
|
+
|
147
162
|
# Change API server
|
148
163
|
config.update({host: 'test.qingstor.com'})
|
149
164
|
```
|
@@ -159,15 +174,38 @@ secret_access_key: 'SECRET_ACCESS_KEY'
|
|
159
174
|
host: 'qingstor.com'
|
160
175
|
port: 443
|
161
176
|
protocol: 'https'
|
177
|
+
# or set endpoint directly
|
178
|
+
# endpoint: https://qingstor.com:443
|
179
|
+
|
162
180
|
connection_retries: 3
|
163
181
|
|
182
|
+
# Additional User-Agent
|
183
|
+
additional_user_agent: ""
|
184
|
+
|
164
185
|
# Valid log levels are "debug", "info", "warn", "error", and "fatal".
|
165
|
-
log_level:
|
186
|
+
log_level: warn
|
187
|
+
|
188
|
+
# SDK will use virtual host style for all API calls if enabled
|
189
|
+
enable_virtual_host_style: false
|
166
190
|
```
|
167
191
|
|
168
192
|
## Change Log
|
169
193
|
All notable changes to QingStor SDK for Ruby will be documented here.
|
170
194
|
|
195
|
+
### [v2.5.0] - 2021-02-09
|
196
|
+
|
197
|
+
### Added
|
198
|
+
|
199
|
+
- config: Add env variable support (#52)
|
200
|
+
- signer: Add support for anonymous API call (#53)
|
201
|
+
- config: Add support for endpoint (#55)
|
202
|
+
- config: Add support for enable_vhost_style (#56)
|
203
|
+
|
204
|
+
### Changed
|
205
|
+
|
206
|
+
- Request: Modify Metadata in header to apply rfc 02 (#49)
|
207
|
+
- config: Refactor config check (#54)
|
208
|
+
|
171
209
|
### [v2.4.0] - 2021-01-05
|
172
210
|
|
173
211
|
### Added
|
@@ -274,6 +312,7 @@ All notable changes to QingStor SDK for Ruby will be documented here.
|
|
274
312
|
The Apache License (Version 2.0, January 2004).
|
275
313
|
|
276
314
|
[compatible]: https://github.com/yunify/qingstor-sdk-ruby/tree/compatible
|
315
|
+
[v2.5.0]: https://github.com/yunify/qingstor-sdk-ruby/compare/v2.4.0...v2.5.0
|
277
316
|
[v2.4.0]: https://github.com/yunify/qingstor-sdk-ruby/compare/v2.3.0...v2.4.0
|
278
317
|
[v2.3.0]: https://github.com/yunify/qingstor-sdk-ruby/compare/v2.2.3...v2.3.0
|
279
318
|
[v2.2.3]: https://github.com/yunify/qingstor-sdk-ruby/compare/v2.2.2...v2.2.3
|
@@ -15,10 +15,13 @@
|
|
15
15
|
# +-------------------------------------------------------------------------
|
16
16
|
|
17
17
|
require 'fileutils'
|
18
|
+
require 'ipaddr'
|
19
|
+
require 'uri'
|
18
20
|
require 'yaml'
|
19
21
|
|
20
22
|
require 'active_support/core_ext/hash/keys'
|
21
23
|
require 'active_support/core_ext/hash/deep_merge'
|
24
|
+
require 'active_support/core_ext/object/blank'
|
22
25
|
require 'net/http/persistent'
|
23
26
|
|
24
27
|
module QingStor
|
@@ -26,6 +29,15 @@ module QingStor
|
|
26
29
|
class Config < Hash
|
27
30
|
attr_accessor :connection
|
28
31
|
|
32
|
+
DEFAULT_AS_HASH = {
|
33
|
+
host: 'qingstor.com'.freeze,
|
34
|
+
port: 443,
|
35
|
+
protocol: 'https'.freeze,
|
36
|
+
connection_retries: 3,
|
37
|
+
log_level: 'warn'.freeze,
|
38
|
+
enable_virtual_host_style: false
|
39
|
+
}
|
40
|
+
|
29
41
|
def self.init(access_key_id, secret_access_key)
|
30
42
|
initial_config = {
|
31
43
|
access_key_id: access_key_id,
|
@@ -36,23 +48,64 @@ module QingStor
|
|
36
48
|
|
37
49
|
def initialize(initial_config = {})
|
38
50
|
self.connection = Net::HTTP::Persistent.new
|
51
|
+
# load default config as basic
|
39
52
|
load_default_config
|
53
|
+
# load from config, env path superior to ~/.qingstor/config.yaml
|
54
|
+
load_user_config_path_exist
|
55
|
+
# load envs, cover corresponding config if env exists
|
56
|
+
load_env_config
|
57
|
+
# cover by user's param
|
40
58
|
update initial_config
|
41
59
|
end
|
42
60
|
|
43
61
|
def update(another_config = {})
|
44
62
|
deep_merge! another_config.deep_symbolize_keys!
|
63
|
+
parse_boolean(:enable_virtual_host_style)
|
45
64
|
Logger.set_level self[:log_level]
|
46
65
|
self
|
47
66
|
end
|
48
67
|
|
49
68
|
def check
|
50
|
-
|
51
|
-
|
52
|
-
|
69
|
+
if self[:access_key_id].blank? && self[:secret_access_key].present? ||
|
70
|
+
self[:access_key_id].present? && self[:secret_access_key].blank?
|
71
|
+
raise ConfigurationError, 'ak and sk should be both both empty or not empty'
|
72
|
+
end
|
73
|
+
|
74
|
+
if self[:access_key_id].blank? && self[:secret_access_key].blank?
|
75
|
+
Logger.warn 'Both ak and sk not configured, will call api as anonymous user'
|
76
|
+
end
|
77
|
+
|
78
|
+
# check endpoint and host/port/protocol
|
79
|
+
if self[:endpoint].blank?
|
80
|
+
# host/port/protocol must set if endpoint not set
|
81
|
+
%i[host port protocol].each do |x|
|
82
|
+
if self[x].blank?
|
83
|
+
raise ConfigurationError, "#{x.to_sym} not specified"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
else
|
87
|
+
# if endpoint set, host/port/protocol ignore, and warn
|
88
|
+
%i[host port protocol].each do |x|
|
89
|
+
if self[x].present? && !Config.is_default?(x, self[x])
|
90
|
+
Logger.warn "Endpoint configured, #{x.to_sym} will be ignored"
|
91
|
+
end
|
53
92
|
end
|
54
93
|
end
|
55
|
-
|
94
|
+
|
95
|
+
# add ip check for vhost enabled
|
96
|
+
if self[:enable_virtual_host_style]
|
97
|
+
if self[:endpoint].present?
|
98
|
+
uri = Preprocessor.parse_endpoint self[:endpoint]
|
99
|
+
ip = uri.host
|
100
|
+
else
|
101
|
+
ip = self[:host]
|
102
|
+
end
|
103
|
+
if is_valid_ip? ip
|
104
|
+
raise ConfigurationError, 'ip host not allowed if vhost enabled'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if self[:additional_user_agent].present?
|
56
109
|
self[:additional_user_agent].each_byte do |x|
|
57
110
|
# Allow space(32) to ~(126) in ASCII Table, exclude "(34).
|
58
111
|
if x < 32 || x > 126 || x == 32 || x == 34
|
@@ -64,12 +117,36 @@ module QingStor
|
|
64
117
|
end
|
65
118
|
|
66
119
|
def load_default_config
|
67
|
-
|
120
|
+
update DEFAULT_AS_HASH
|
68
121
|
end
|
69
122
|
|
70
123
|
def load_user_config
|
71
|
-
|
72
|
-
|
124
|
+
if !ENV[Contract::ENV_CONFIG_PATH].nil?
|
125
|
+
load_config_from_file ENV[Contract::ENV_CONFIG_PATH]
|
126
|
+
else
|
127
|
+
load_config_from_file Contract::USER_CONFIG_FILEPATH
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def load_env_config
|
132
|
+
another_config = {}
|
133
|
+
unless ENV[Contract::ENV_ACCESS_KEY_ID].nil?
|
134
|
+
another_config[:access_key_id] =
|
135
|
+
ENV[Contract::ENV_ACCESS_KEY_ID]
|
136
|
+
end
|
137
|
+
unless ENV[Contract::ENV_SECRET_ACCESS_KEY].nil?
|
138
|
+
another_config[:secret_access_key] =
|
139
|
+
ENV[Contract::ENV_SECRET_ACCESS_KEY]
|
140
|
+
end
|
141
|
+
unless ENV[Contract::ENV_ENABLE_VIRTUAL_HOST_STYLE].nil?
|
142
|
+
another_config[:enable_virtual_host_style] =
|
143
|
+
ENV[Contract::ENV_ENABLE_VIRTUAL_HOST_STYLE]
|
144
|
+
end
|
145
|
+
unless ENV[Contract::ENV_ENDPOINT].nil?
|
146
|
+
another_config[:endpoint] =
|
147
|
+
ENV[Contract::ENV_ENDPOINT]
|
148
|
+
end
|
149
|
+
update another_config
|
73
150
|
end
|
74
151
|
|
75
152
|
def load_config_from_file(path)
|
@@ -79,10 +156,30 @@ module QingStor
|
|
79
156
|
|
80
157
|
private
|
81
158
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
159
|
+
# load user config if path exist, and skip check
|
160
|
+
def load_user_config_path_exist
|
161
|
+
# if env path configured, update from env; otherwise, if ~/.qingstor/config.yaml exists, update from this
|
162
|
+
if !ENV[Contract::ENV_CONFIG_PATH].nil? && File.exist?(ENV[Contract::ENV_CONFIG_PATH])
|
163
|
+
load_config_from_file ENV[Contract::ENV_CONFIG_PATH]
|
164
|
+
elsif File.exist? Contract::USER_CONFIG_FILEPATH
|
165
|
+
load_config_from_file Contract::USER_CONFIG_FILEPATH
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def parse_boolean(key)
|
170
|
+
self[key.to_sym] = self[key.to_sym].to_s.downcase == 'true'
|
171
|
+
end
|
172
|
+
|
173
|
+
def is_valid_ip?(ip)
|
174
|
+
IPAddr.new ip
|
175
|
+
true
|
176
|
+
rescue
|
177
|
+
false
|
178
|
+
end
|
179
|
+
|
180
|
+
# @return boolean
|
181
|
+
def self.is_default?(key, value)
|
182
|
+
DEFAULT_AS_HASH[key.to_sym].present? && DEFAULT_AS_HASH[key.to_sym] == value
|
86
183
|
end
|
87
184
|
end
|
88
185
|
end
|
@@ -23,9 +23,12 @@ module QingStor
|
|
23
23
|
|
24
24
|
# GEM_DIRECTORY = Gem::Specification.find_by_name('qingcloud-sdk').gem_dir
|
25
25
|
# DEFAULT_SUPPORT_DIRECTORY = GEM_DIRECTORY + '/lib/qingcloud/sdk/commons/default'
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
|
27
|
+
ENV_ACCESS_KEY_ID = 'QINGSTOR_ACCESS_KEY_ID'.freeze
|
28
|
+
ENV_SECRET_ACCESS_KEY = 'QINGSTOR_SECRET_ACCESS_KEY'.freeze
|
29
|
+
ENV_CONFIG_PATH = 'QINGSTOR_CONFIG_PATH'.freeze
|
30
|
+
ENV_ENABLE_VIRTUAL_HOST_STYLE = 'QINGSTOR_ENABLE_VIRTUAL_HOST_STYLE'.freeze
|
31
|
+
ENV_ENDPOINT = 'QINGSTOR_ENDPOINT'.freeze
|
29
32
|
end
|
30
33
|
end
|
31
34
|
end
|
@@ -17,8 +17,10 @@
|
|
17
17
|
require 'cgi'
|
18
18
|
require 'base64'
|
19
19
|
require 'digest'
|
20
|
+
require 'uri'
|
20
21
|
|
21
22
|
require 'active_support/core_ext/hash/keys'
|
23
|
+
require 'active_support/core_ext/object/blank'
|
22
24
|
require 'mimemagic'
|
23
25
|
|
24
26
|
module QingStor
|
@@ -41,6 +43,15 @@ module QingStor
|
|
41
43
|
def self.request_endpoint(input)
|
42
44
|
config = input[:config]
|
43
45
|
zone = input[:properties] ? input[:properties][:zone] : nil
|
46
|
+
# handle endpoint directly if it exists
|
47
|
+
if config[:endpoint].present?
|
48
|
+
uri = parse_endpoint(config[:endpoint].to_s)
|
49
|
+
if zone
|
50
|
+
uri.host = "#{zone}.#{uri.host}"
|
51
|
+
end
|
52
|
+
return uri.to_s
|
53
|
+
end
|
54
|
+
|
44
55
|
if zone
|
45
56
|
"#{config[:protocol]}://#{zone}.#{config[:host]}:#{config[:port]}"
|
46
57
|
else
|
@@ -49,6 +60,16 @@ module QingStor
|
|
49
60
|
end
|
50
61
|
|
51
62
|
def self.request_uri(input)
|
63
|
+
config = input[:config]
|
64
|
+
# if enable vhost, and uri property contains bucket-name
|
65
|
+
if config[:enable_virtual_host_style] && input[:properties].present? && input[:properties][:"bucket-name"]
|
66
|
+
uri = parse_endpoint input[:request_endpoint]
|
67
|
+
# modify host, add bucket before
|
68
|
+
uri.host = "#{input[:properties][:"bucket-name"]}.#{uri.host}"
|
69
|
+
input[:request_endpoint] = uri.to_s
|
70
|
+
# handle request_uri, remove prefix (bucket-name)
|
71
|
+
input[:request_uri].delete_prefix! URI_BUCKET_PREFIX if input[:request_uri].start_with? URI_BUCKET_PREFIX
|
72
|
+
end
|
52
73
|
unless input[:properties].nil?
|
53
74
|
input[:properties].each do |k, v|
|
54
75
|
input[:request_uri].gsub! "<#{k}>", (escape v.to_s)
|
@@ -102,21 +123,18 @@ module QingStor
|
|
102
123
|
input[:request_headers][:'Content-MD5'] = Base64.encode64(Digest::MD5.digest(input[:request_body])).strip
|
103
124
|
end
|
104
125
|
|
126
|
+
# X-QS-MetaData used to handle meta data
|
105
127
|
unless input[:request_headers][:'X-QS-MetaData'].nil?
|
106
128
|
if input[:request_headers][:'X-QS-MetaData'].is_a?(Hash) && !input[:request_headers][:'X-QS-MetaData'].empty?
|
107
129
|
prefix = 'x-qs-meta-'
|
108
130
|
input[:request_headers][:'X-QS-MetaData'].each do |k, v|
|
109
131
|
k = k.to_s
|
110
|
-
#
|
111
|
-
|
112
|
-
suffix_len = prefix.size - k.size
|
113
|
-
k = prefix + k[suffix_len, -suffix_len]
|
114
|
-
else
|
115
|
-
k = prefix + k
|
116
|
-
end
|
132
|
+
# add prefix for meta data in header
|
133
|
+
k = prefix + k
|
117
134
|
input[:request_headers][:"#{k}"] = v
|
118
135
|
end
|
119
136
|
end
|
137
|
+
# remove X-QS-MetaData from request header
|
120
138
|
input[:request_headers].delete :'X-QS-MetaData'
|
121
139
|
end
|
122
140
|
|
@@ -145,7 +163,7 @@ module QingStor
|
|
145
163
|
def self.compact(object)
|
146
164
|
object.each do |k, v|
|
147
165
|
object[k] = compact v if v.is_a? Hash
|
148
|
-
object.delete k if v.nil? || v == ''
|
166
|
+
object.delete k if v.nil? || v == ''
|
149
167
|
end
|
150
168
|
object
|
151
169
|
end
|
@@ -157,6 +175,32 @@ module QingStor
|
|
157
175
|
origin.gsub! '+', '%20'
|
158
176
|
origin
|
159
177
|
end
|
178
|
+
|
179
|
+
# try to parse endpoint:
|
180
|
+
# if endpoint invalid, means ip host without scheme, like: 192.168.0.1:3000
|
181
|
+
# if endpoint parsed, and no scheme find, means host without scheme, like: qingstor.dev
|
182
|
+
# both above will add default schema at the start, and parse again
|
183
|
+
def self.parse_endpoint(endpoint)
|
184
|
+
if endpoint.blank?
|
185
|
+
raise 'endpoint should not be empty when parse'
|
186
|
+
end
|
187
|
+
|
188
|
+
begin
|
189
|
+
uri = URI.parse endpoint
|
190
|
+
unless uri.scheme.nil?
|
191
|
+
return uri
|
192
|
+
end
|
193
|
+
rescue URI::InvalidURIError
|
194
|
+
# Ignored and continue, add scheme prefix then
|
195
|
+
end
|
196
|
+
|
197
|
+
endpoint = "http://#{endpoint}" # add default scheme for endpoint
|
198
|
+
URI.parse endpoint
|
199
|
+
end
|
200
|
+
|
201
|
+
private
|
202
|
+
|
203
|
+
URI_BUCKET_PREFIX = '/<bucket-name>'.freeze
|
160
204
|
end
|
161
205
|
end
|
162
206
|
end
|
@@ -19,6 +19,7 @@ require 'json'
|
|
19
19
|
require 'net/http'
|
20
20
|
|
21
21
|
require 'active_support/core_ext/hash/keys'
|
22
|
+
require 'active_support/core_ext/object/blank'
|
22
23
|
|
23
24
|
module QingStor
|
24
25
|
module SDK
|
@@ -52,11 +53,19 @@ module QingStor
|
|
52
53
|
|
53
54
|
def sign
|
54
55
|
check
|
56
|
+
if Signer.is_anonymous? input
|
57
|
+
Logger.warn 'anonymous api call, skip sign'
|
58
|
+
return
|
59
|
+
end
|
55
60
|
self.input = Signer.sign input
|
56
61
|
end
|
57
62
|
|
58
63
|
def sign_query(timeout_seconds)
|
59
64
|
check
|
65
|
+
if Signer.is_anonymous? input
|
66
|
+
Logger.warn 'anonymous api call, skip sign query'
|
67
|
+
return
|
68
|
+
end
|
60
69
|
self.input = Signer.sign_query input, Time.now.to_i + timeout_seconds
|
61
70
|
end
|
62
71
|
|
@@ -97,10 +106,11 @@ module QingStor
|
|
97
106
|
private
|
98
107
|
|
99
108
|
def check
|
100
|
-
|
109
|
+
# ak and sk should be both set or not set
|
110
|
+
if input[:config][:access_key_id].blank? && input[:config][:secret_access_key].present?
|
101
111
|
raise SDKError, 'access key not provided'
|
102
112
|
end
|
103
|
-
|
113
|
+
if input[:config][:secret_access_key].blank? && input[:config][:access_key_id].present?
|
104
114
|
raise SDKError, 'secret access key not provided'
|
105
115
|
end
|
106
116
|
end
|
@@ -18,23 +18,31 @@ require 'base64'
|
|
18
18
|
require 'cgi'
|
19
19
|
require 'openssl'
|
20
20
|
|
21
|
+
require 'active_support/core_ext/object/blank'
|
22
|
+
|
21
23
|
module QingStor
|
22
24
|
module SDK
|
23
25
|
class Signer
|
24
26
|
def self.sign(input)
|
25
|
-
|
26
|
-
|
27
|
+
unless is_anonymous? input
|
28
|
+
authorization = "QS #{input[:config][:access_key_id]}:#{signature input}"
|
29
|
+
input[:request_headers][:Authorization] = authorization
|
30
|
+
|
31
|
+
Logger.debug "QingStor request authorization: [#{input[:id]}] #{authorization}"
|
32
|
+
end
|
27
33
|
|
28
|
-
Logger.debug "QingStor request authorization: [#{input[:id]}] #{authorization}"
|
29
34
|
input
|
30
35
|
end
|
31
36
|
|
32
37
|
def self.sign_query(input, expires)
|
33
|
-
|
34
|
-
|
35
|
-
|
38
|
+
unless is_anonymous? input
|
39
|
+
input[:request_params][:signature] = query_signature input, expires
|
40
|
+
input[:request_params][:access_key_id] = input[:config][:access_key_id]
|
41
|
+
input[:request_params][:expires] = expires
|
42
|
+
|
43
|
+
Logger.debug "QingStor query signature: [#{input[:id]}] #{input[:request_params][:signature]}"
|
44
|
+
end
|
36
45
|
|
37
|
-
Logger.debug "QingStor query signature: [#{input[:id]}] #{input[:request_params][:signature]}"
|
38
46
|
input
|
39
47
|
end
|
40
48
|
|
@@ -105,6 +113,14 @@ module QingStor
|
|
105
113
|
response-content-language response-content-encoding response-content-disposition
|
106
114
|
].include? key
|
107
115
|
end
|
116
|
+
|
117
|
+
def self.is_anonymous?(input)
|
118
|
+
if input[:config].nil?
|
119
|
+
return true
|
120
|
+
end
|
121
|
+
|
122
|
+
input[:config][:access_key_id].blank? && input[:config][:secret_access_key].blank?
|
123
|
+
end
|
108
124
|
end
|
109
125
|
end
|
110
126
|
end
|
@@ -22,6 +22,7 @@ module QingStor
|
|
22
22
|
attr_accessor :config, :properties
|
23
23
|
|
24
24
|
def initialize(config, properties)
|
25
|
+
config.check
|
25
26
|
self.config = config
|
26
27
|
self.properties = properties.deep_symbolize_keys
|
27
28
|
end
|
@@ -1058,10 +1059,6 @@ module QingStor
|
|
1058
1059
|
def put_bucket_acl_input_validate(input)
|
1059
1060
|
input.deep_stringify_keys!
|
1060
1061
|
|
1061
|
-
unless !input['request_elements']['acl'].nil? && !input['request_elements']['acl'].empty?
|
1062
|
-
raise ParameterRequiredError.new('acl', 'PutBucketACLInput')
|
1063
|
-
end
|
1064
|
-
|
1065
1062
|
input['request_elements']['acl'].each do |x|
|
1066
1063
|
unless x['grantee'].nil?
|
1067
1064
|
|
data/lib/qingstor/sdk/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qingstor-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yunify SDK Group
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -78,14 +78,14 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 5.
|
81
|
+
version: 5.3.0
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 5.
|
88
|
+
version: 5.3.0
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rake
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,7 +157,6 @@ files:
|
|
157
157
|
- lib/qingstor/sdk.rb
|
158
158
|
- lib/qingstor/sdk/general/config.rb
|
159
159
|
- lib/qingstor/sdk/general/contract.rb
|
160
|
-
- lib/qingstor/sdk/general/default/config.yaml
|
161
160
|
- lib/qingstor/sdk/general/error.rb
|
162
161
|
- lib/qingstor/sdk/general/logger.rb
|
163
162
|
- lib/qingstor/sdk/request/preprocessor.rb
|
@@ -187,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
186
|
- !ruby/object:Gem::Version
|
188
187
|
version: '0'
|
189
188
|
requirements: []
|
190
|
-
rubygems_version: 3.
|
189
|
+
rubygems_version: 3.1.4
|
191
190
|
signing_key:
|
192
191
|
specification_version: 4
|
193
192
|
summary: SDK for QingStor
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# QingStor services configuration
|
2
|
-
|
3
|
-
#access_key_id: ACCESS_KEY_ID
|
4
|
-
#secret_access_key: SECRET_ACCESS_KEY
|
5
|
-
|
6
|
-
host: qingstor.com
|
7
|
-
port: 443
|
8
|
-
protocol: https
|
9
|
-
connection_retries: 3
|
10
|
-
|
11
|
-
# Additional User-Agent
|
12
|
-
additional_user_agent: ""
|
13
|
-
|
14
|
-
# Valid log levels are "debug", "info", "warn", "error", and "fatal".
|
15
|
-
log_level: warn
|