td-client 1.0.8 → 2.0.0

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: 8650b4fe6267d1edb91dad045ac0b31f77d0d0e37d776ea5433ec88debfe4b81
4
- data.tar.gz: baf35bbd09b187c8f76ee48f68328f23ac09721ddb31641154a97900dc4ac93b
3
+ metadata.gz: 54f6df5e1e0ea43f4a92e837b1793cf9f217cd643c7cecb831c9191fdb0396ae
4
+ data.tar.gz: f28643eb1908f7c6e251b75321a50dd87a0419f5f0982c218829e947a15ac04b
5
5
  SHA512:
6
- metadata.gz: 643dc4c3d7ec6e5e73b506f3b18750a7aeaf73e915890c68ccd7b590f8d539a1fb047f5adbb4652bb0a732f2e8466658be112384d9d57aae1cb72b902b8a4b46
7
- data.tar.gz: fbf3228a704dd954299becd06462920f72934674d8cae49ba1db91d169441fe4a079348e33ec8f2e3b08c986b5383fbf476f7161de8711a3677583da1b4b3169
6
+ metadata.gz: 29eed4ae7f9957391958faaaa9a86ddb64040fbb640deb5922614f95806de48455f94c20602ee39240df16adeae0257a7ff2db4036459e3285ca84b486e54370
7
+ data.tar.gz: c0de46e029df837aa5decfb1cead811d24bd783444cabd7fe97da114818641f0cd7476756d94f273dbef72f1673856e4b16fda51ae150e5ef840a144aaf67948
@@ -22,24 +22,5 @@ module Account
22
22
  return [account_id, plan, storage_size, guaranteed_cores, maximum_cores, created_at]
23
23
  end
24
24
 
25
- # @param [Fixnum] from
26
- # @param [Fixnum] to
27
- # @return [Array]
28
- def account_core_utilization(from, to)
29
- params = { }
30
- params['from'] = from.to_s if from
31
- params['to'] = to.to_s if to
32
- code, body, res = get("/v3/account/core_utilization", params)
33
- if code != "200"
34
- raise_error("Show account failed", res)
35
- end
36
- js = checked_json(body, %w[from to interval history])
37
- from = Time.parse(js['from']).utc
38
- to = Time.parse(js['to']).utc
39
- interval = js['interval'].to_i
40
- history = js['history']
41
- return [from, to, interval, history]
42
- end
43
-
44
25
  end
45
26
  end
@@ -126,7 +126,7 @@ module Job
126
126
  job_result_download(job_id) do |chunk|
127
127
  unpacker.feed_each(chunk) do |row|
128
128
  result << row
129
- end
129
+ end unless chunk.empty?
130
130
  end
131
131
  return result
132
132
  end
@@ -163,7 +163,7 @@ module Job
163
163
  upkr = MessagePack::Unpacker.new
164
164
  # default to decompressing the response since format is fixed to 'msgpack'
165
165
  job_result_download(job_id) do |chunk|
166
- upkr.feed_each(chunk, &block)
166
+ upkr.feed_each(chunk, &block) unless chunk.empty?
167
167
  end
168
168
  nil
169
169
  end
@@ -177,9 +177,9 @@ module Job
177
177
  upkr = MessagePack::Unpacker.new
178
178
  # default to decompressing the response since format is fixed to 'msgpack'
179
179
  job_result_download(job_id) do |chunk, total|
180
- upkr.feed_each(chunk) {|unpacked|
180
+ upkr.feed_each(chunk) do |unpacked|
181
181
  yield unpacked, total if block_given?
182
- }
182
+ end unless chunk.empty?
183
183
  end
184
184
  nil
185
185
  end
data/lib/td/client/api.rb CHANGED
@@ -74,6 +74,7 @@ class API
74
74
  @retry_post_requests = opts[:retry_post_requests] || false
75
75
  @retry_delay = opts[:retry_delay] || 5
76
76
  @max_cumul_retry_delay = opts[:max_cumul_retry_delay] || 600
77
+ @verify = opts[:verify]
77
78
 
78
79
  case uri.scheme
79
80
  when 'http', 'https'
@@ -526,6 +527,14 @@ private
526
527
  client.ssl_config.options |= OpenSSL::SSL::OP_NO_SSLv3
527
528
  end
528
529
 
530
+ # allow users to use their own custom ca
531
+ # or disable verification
532
+ if @verify == false
533
+ client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
534
+ elsif @verify.is_a? String
535
+ client.ssl_config.add_trust_ca(@verify)
536
+ end
537
+
529
538
  header = {}
530
539
  if @apikey
531
540
  header['Authorization'] = "TD1 #{apikey}"
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
  class Client
3
- VERSION = '1.0.8'
3
+ VERSION = '2.0.0'
4
4
  end
5
5
  end
data/lib/td/client.rb CHANGED
@@ -60,14 +60,6 @@ class Client
60
60
  return Account.new(self, account_id, plan, storage, guaranteed_cores, maximum_cores, created_at)
61
61
  end
62
62
 
63
- # @param [Fixnum] from
64
- # @param [Fixnum] to
65
- # @return [Array] from, to, interval, history
66
- def core_utilization(from, to)
67
- from, to, interval, history = @api.account_core_utilization(from, to)
68
- return from, to, interval, history
69
- end
70
-
71
63
  # @return [Array] databases
72
64
  def databases
73
65
  m = @api.list_databases
@@ -18,17 +18,4 @@ describe 'Account API' do
18
18
  end
19
19
  end
20
20
 
21
- describe 'account_core_utilization' do
22
- it 'returns core utilization' do
23
- from = '2014-12-01T00:00:00+0900'
24
- to = '2015-01-01T00:00:00+0900'
25
- stub_api_request(:get, "/v3/account/core_utilization", :query => {'from' => from, 'to' => to}).
26
- to_return(:body => {'from' => from, 'to' => to, 'interval' => 1, 'history' => ['dummy']}.to_json)
27
- r = api.account_core_utilization(from, to)
28
- expect(r[0]).to eq(Time.parse(from))
29
- expect(r[1]).to eq(Time.parse(to))
30
- expect(r[2]).to eq(1)
31
- expect(r[3]).to eq(['dummy'])
32
- end
33
- end
34
21
  end
@@ -37,7 +37,7 @@ describe 'API SSL connection' do
37
37
  it 'should fail to connect SSLv3 only server' do
38
38
  @server = setup_server(:SSLv3)
39
39
  api = API.new(nil, :endpoint => "https://localhost:#{@serverport}", :retry_post_requests => false)
40
- api.ssl_ca_file = File.join(DIR, 'ca-all.cert')
40
+ api.ssl_ca_file = File.join(DIR, 'testRootCA.crt')
41
41
  expect {
42
42
  begin
43
43
  api.delete_database('no_such_database')
@@ -47,10 +47,26 @@ describe 'API SSL connection' do
47
47
  }.to raise_error OpenSSL::SSL::SSLError
48
48
  end
49
49
 
50
- it 'should success to connect TLSv1 only server' do
51
- @server = setup_server(:TLSv1)
50
+ it 'should succeed to access to the server with verify false option' do
51
+ @server = setup_server(:TLSv1_2)
52
+ api = API.new(nil, :endpoint => "https://localhost:#{@serverport}", :retry_post_requests => false, :verify => false)
53
+ expect {
54
+ api.delete_database('no_such_database')
55
+ }.to raise_error TreasureData::NotFoundError
56
+ end
57
+
58
+ it 'should succeed to access to the server with self signed certificate' do
59
+ @server = setup_server(:TLSv1_2)
60
+ api = API.new(nil, :endpoint => "https://localhost:#{@serverport}", :retry_post_requests => false, :verify => File.join(DIR, 'testRootCA.crt'))
61
+ expect {
62
+ api.delete_database('no_such_database')
63
+ }.to raise_error TreasureData::NotFoundError
64
+ end
65
+
66
+ it 'should success to connect TLSv1_2 only server' do
67
+ @server = setup_server(:TLSv1_2)
52
68
  api = API.new(nil, :endpoint => "https://localhost:#{@serverport}", :retry_post_requests => false)
53
- api.ssl_ca_file = File.join(DIR, 'ca-all.cert')
69
+ api.ssl_ca_file = File.join(DIR, 'testRootCA.crt')
54
70
  expect {
55
71
  api.delete_database('no_such_database')
56
72
  }.to raise_error TreasureData::NotFoundError
@@ -66,9 +82,9 @@ describe 'API SSL connection' do
66
82
  :AccessLog => [],
67
83
  :DocumentRoot => '.',
68
84
  :SSLEnable => true,
69
- :SSLCACertificateFile => File.join(DIR, 'ca.cert'),
70
- :SSLCertificate => cert('server.cert'),
71
- :SSLPrivateKey => key('server.key')
85
+ :SSLCACertificateFile => File.join(DIR, 'testRootCA.crt'),
86
+ :SSLCertificate => cert('testServer.crt'),
87
+ :SSLPrivateKey => key('testServer.key')
72
88
  )
73
89
  @serverport = @server.config[:Port]
74
90
  @server.mount(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Treasure Data, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-04 00:00:00.000000000 Z
11
+ date: 2023-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -212,29 +212,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  - !ruby/object:Gem::Version
213
213
  version: '0'
214
214
  requirements: []
215
- rubygems_version: 3.0.9
215
+ rubygems_version: 3.4.10
216
216
  signing_key:
217
217
  specification_version: 4
218
218
  summary: Treasure Data API library for Ruby
219
219
  test_files:
220
- - spec/td/client_spec.rb
221
- - spec/td/client_sched_spec.rb
222
- - spec/td/client/partial_delete_api_spec.rb
220
+ - spec/td/client/account_api_spec.rb
221
+ - spec/td/client/api_error_spec.rb
223
222
  - spec/td/client/api_spec.rb
223
+ - spec/td/client/api_ssl_connection_spec.rb
224
+ - spec/td/client/bulk_import_spec.rb
225
+ - spec/td/client/bulk_load_spec.rb
224
226
  - spec/td/client/db_api_spec.rb
225
- - spec/td/client/result_api_spec.rb
226
227
  - spec/td/client/export_api_spec.rb
228
+ - spec/td/client/import_api_spec.rb
229
+ - spec/td/client/job_api_spec.rb
230
+ - spec/td/client/model_job_spec.rb
231
+ - spec/td/client/model_schedule_spec.rb
227
232
  - spec/td/client/model_schema_spec.rb
228
- - spec/td/client/api_error_spec.rb
233
+ - spec/td/client/partial_delete_api_spec.rb
234
+ - spec/td/client/result_api_spec.rb
229
235
  - spec/td/client/sched_api_spec.rb
236
+ - spec/td/client/server_status_api_spec.rb
230
237
  - spec/td/client/table_api_spec.rb
231
- - spec/td/client/bulk_load_spec.rb
232
- - spec/td/client/api_ssl_connection_spec.rb
233
- - spec/td/client/job_api_spec.rb
234
- - spec/td/client/account_api_spec.rb
235
238
  - spec/td/client/user_api_spec.rb
236
- - spec/td/client/bulk_import_spec.rb
237
- - spec/td/client/model_schedule_spec.rb
238
- - spec/td/client/import_api_spec.rb
239
- - spec/td/client/server_status_api_spec.rb
240
- - spec/td/client/model_job_spec.rb
239
+ - spec/td/client_sched_spec.rb
240
+ - spec/td/client_spec.rb