baidubce-sdk 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,4 +1,7 @@
1
1
  ---
2
+ SHA256:
3
+ metadata.gz: 54459c307d8f0e22399d42565dc66f5895deaa489cf88a51ee868aa6c27cb342
4
+ data.tar.gz: 52f14924396670c789493344807183f2255d2ccd1bdd17651b8d74e66334f96a
2
5
  SHA512:
3
- metadata.gz: 165934a1406f4fe922c2b3240f3924e0fce9412d003420eaf6aa121120c7b66647f118c954da4f1bdf81514a04173e8856b4b125becfafa280ebb46545b18eac
4
- data.tar.gz: 79bda68cf94da4ccadfe92ae501e8d8676b5fc647617b2f09dc46da23af421086e71730973c9df0a1c80549eab802d371d183ec69b16cba53d0872e218b0ad9b
6
+ metadata.gz: 014507f6ddf03fe3f0755a3648d81d5d91fb6e8a56d7e70cce8df332d33d0a402eb7215bf1aa01ea4b55e8f1675355ffcc54dabfbcfc36a6fef07c52b2b0c8ee
7
+ data.tar.gz: d5a179e2b931199b2f5f4b74d85a4cca4058db3c4049c6174382bd3dec07859df1d746b9fe3f9138d1e1a88a8952da94c5ea878cdca843237d833023e9ce7816
@@ -15,6 +15,7 @@
15
15
  module Baidubce
16
16
 
17
17
  DEFAULT_SERVICE_DOMAIN = 'baidubce.com'
18
+ DEFAULT_BOS_DOMAIN = 'bcebos.com'
18
19
  DEFAULT_ENCODING = 'UTF-8'
19
20
 
20
21
  SOCKET_ERROR_CODE = -100
@@ -21,11 +21,10 @@ module Baidubce
21
21
  module Services
22
22
 
23
23
  class BosClient < BceBaseClient
24
-
25
24
  # List buckets of user.
26
25
  # returns all buckets owned by the user.
27
26
  def list_buckets()
28
- send_request(GET)
27
+ send_request(GET, "", {}, "", {}, "", nil, false, true)
29
28
  end
30
29
 
31
30
  # Create bucket with specific name.
@@ -162,9 +161,6 @@ module Baidubce
162
161
 
163
162
  def get_object(bucket_name, key, range, save_path=nil, return_body=true)
164
163
  headers = range.nil? ? {} : get_range_header_dict(range)
165
- if key.size == 0 || key =~ /^\/+$/
166
- raise BceClientException.new("Key can not be empty or all is '/'.")
167
- end
168
164
  send_request(GET, bucket_name, {}, key, headers, "", save_path, return_body)
169
165
  end
170
166
 
@@ -251,7 +247,7 @@ module Baidubce
251
247
  def generate_pre_signed_url(bucket_name, key, options={})
252
248
  headers = options['headers'].nil? ? {} : options['headers']
253
249
  params = options['params'].nil? ? {} : options['params']
254
-
250
+ gen_host(bucket_name, false)
255
251
  path = Utils.append_uri("/", key)
256
252
  url, headers[HOST] = Utils.parse_url_host(@config)
257
253
  unless @config.cname_enabled || Utils.is_cname_like_host(@config.endpoint)
@@ -425,13 +421,45 @@ module Baidubce
425
421
  send_request(DELETE, bucket_name, params, key)
426
422
  end
427
423
 
428
- def send_request(http_method, bucket_name="", params={}, key="", headers={}, body="", save_path=nil, return_body=false, &block)
424
+ def gen_host(bucket_name, is_bucket_api)
425
+ endpoint = @config.endpoint
426
+ unless endpoint.include?"://"
427
+ protocol = @config.protocol.downcase
428
+ raise "Invalid protocol #{protocol}." if protocol != "http" && protocol != 'https'
429
+ endpoint = sprintf("%s://%s", protocol, endpoint)
430
+ end
431
+ parsed_endpoint = URI.parse(endpoint)
432
+ scheme = parsed_endpoint.scheme.downcase
433
+ host = parsed_endpoint.host
434
+ parts = host.split('.')
435
+ if is_bucket_api == true
436
+ @config.cname_enabled = false
437
+ if host.include?(DEFAULT_BOS_DOMAIN)
438
+ last_three_elements = parts.last(3)
439
+ host = last_three_elements.join('.')
440
+ end
441
+ else
442
+ if @config.cname_enabled == false
443
+ @config.cname_enabled = true
444
+ if parts.length == 3
445
+ host = [bucket_name, parts[0], parts[1], parts[2]].join('.')
446
+ end
447
+ end
448
+ end
449
+ port = parsed_endpoint.port
450
+ host += ":#{port}" unless scheme == 'http' && port == 80 || scheme == 'https' && port == 443
451
+ @config.endpoint = host
452
+ end
453
+
454
+ def send_request(http_method, bucket_name="", params={}, key="", headers={}, body="", save_path=nil, return_body=false, is_bucket_api=false, &block)
455
+ gen_host(bucket_name, is_bucket_api)
429
456
  if @config.cname_enabled || Utils.is_cname_like_host(@config.endpoint)
430
457
  path = Utils.append_uri("/", key)
431
458
  else
432
- path = Utils.append_uri("/", bucket_name, key)
459
+ if is_bucket_api == false
460
+ path = Utils.append_uri("/", bucket_name, key)
461
+ end
433
462
  end
434
-
435
463
  begin
436
464
  resp_body, resp_headers = @http_client.send_request(@config, @signer, http_method, path, params,
437
465
  headers, body, save_path, false, &block)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Baidubce
4
4
 
5
- VERSION = "0.9.3"
5
+ VERSION = "0.9.4"
6
6
 
7
7
  end
@@ -19,8 +19,8 @@ include Baidubce
19
19
 
20
20
  # debug
21
21
  credentials = Auth::BceCredentials.new(
22
- # "your ak",
23
- # "your sk"
22
+ # "your ak",
23
+ # "your sk"
24
24
  )
25
25
 
26
26
  conf = BceClientConfiguration.new(
@@ -176,7 +176,6 @@ demo "put object" do
176
176
  'Content-Disposition' => 'inline',
177
177
  'user-metadata' => user_metadata
178
178
  }
179
-
180
179
  client.put_object_from_string(bucket_name, "obj.txt", "obj", options)
181
180
  puts client.get_object_as_string(bucket_name, "obj.txt")
182
181
  puts client.get_object_to_file(bucket_name, "obj.txt", "obj_file.txt")
metadata CHANGED
@@ -1,115 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baidubce-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - xiaoyong
8
8
  autorequire:
9
9
  bindir: lib/baidubce
10
10
  cert_chain: []
11
- date: 2021-08-20 00:00:00.000000000 Z
11
+ date: 2024-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.15'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.15'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rest-client
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.0'
62
- - - '>='
62
+ - - ">="
63
63
  - !ruby/object:Gem::Version
64
64
  version: 2.0.2
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - ~>
69
+ - - "~>"
70
70
  - !ruby/object:Gem::Version
71
71
  version: '2.0'
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: 2.0.2
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: logger
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ~>
79
+ - - "~>"
80
80
  - !ruby/object:Gem::Version
81
81
  version: '1.2'
82
- - - '>='
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: 1.2.8
85
85
  type: :runtime
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ~>
89
+ - - "~>"
90
90
  - !ruby/object:Gem::Version
91
91
  version: '1.2'
92
- - - '>='
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: 1.2.8
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: mimemagic
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - ~>
99
+ - - "~>"
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0.3'
102
- - - '>='
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: 0.3.2
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ~>
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0.3'
112
- - - '>='
112
+ - - ">="
113
113
  - !ruby/object:Gem::Version
114
114
  version: 0.3.2
115
115
  - !ruby/object:Gem::Dependency
@@ -133,7 +133,7 @@ executables: []
133
133
  extensions: []
134
134
  extra_rdoc_files: []
135
135
  files:
136
- - .gitignore
136
+ - ".gitignore"
137
137
  - CODE_OF_CONDUCT.md
138
138
  - Gemfile
139
139
  - LICENSE
@@ -169,16 +169,16 @@ require_paths:
169
169
  - lib
170
170
  required_ruby_version: !ruby/object:Gem::Requirement
171
171
  requirements:
172
- - - '>='
172
+ - - ">="
173
173
  - !ruby/object:Gem::Version
174
174
  version: 2.0.0
175
175
  required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  requirements:
177
- - - '>='
177
+ - - ">="
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  requirements: []
181
- rubygems_version: 3.0.9
181
+ rubygems_version: 3.5.4
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: BaiduBce BOS Ruby SDK