td-client 1.0.8 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8650b4fe6267d1edb91dad045ac0b31f77d0d0e37d776ea5433ec88debfe4b81
4
- data.tar.gz: baf35bbd09b187c8f76ee48f68328f23ac09721ddb31641154a97900dc4ac93b
3
+ metadata.gz: a815afcaf4e457f68fa81175e3359b29b4054454d817cafdccc12d2921d88bb6
4
+ data.tar.gz: 49b578a5af81fa21262ebc1c0a5974ac8dab57901513318f408afeeeeb58f082
5
5
  SHA512:
6
- metadata.gz: 643dc4c3d7ec6e5e73b506f3b18750a7aeaf73e915890c68ccd7b590f8d539a1fb047f5adbb4652bb0a732f2e8466658be112384d9d57aae1cb72b902b8a4b46
7
- data.tar.gz: fbf3228a704dd954299becd06462920f72934674d8cae49ba1db91d169441fe4a079348e33ec8f2e3b08c986b5383fbf476f7161de8711a3677583da1b4b3169
6
+ metadata.gz: b2183a16af8bca14b53503444322b4fea765c1a9ef374c15a4549f349fcd3874f234df85202cef2c7e428d2e6481c570e3589a34116935da71a8bcf853f8dabc
7
+ data.tar.gz: b0290f67090890cb71579bf2dc58a4aa7cd76448e8847fe6a3514e4bd6b871d3528625559856640155c980d44433183ab5c08985b36725eb39ef5593633afc67
@@ -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
@@ -7,7 +7,6 @@ require 'td/client/api/database'
7
7
  require 'td/client/api/export'
8
8
  require 'td/client/api/import'
9
9
  require 'td/client/api/job'
10
- require 'td/client/api/partial_delete'
11
10
  require 'td/client/api/result'
12
11
  require 'td/client/api/schedule'
13
12
  require 'td/client/api/server_status'
@@ -27,7 +26,6 @@ class API
27
26
  include API::Export
28
27
  include API::Import
29
28
  include API::Job
30
- include API::PartialDelete
31
29
  include API::Result
32
30
  include API::Schedule
33
31
  include API::ServerStatus
@@ -74,6 +72,7 @@ class API
74
72
  @retry_post_requests = opts[:retry_post_requests] || false
75
73
  @retry_delay = opts[:retry_delay] || 5
76
74
  @max_cumul_retry_delay = opts[:max_cumul_retry_delay] || 600
75
+ @verify = opts[:verify]
77
76
 
78
77
  case uri.scheme
79
78
  when 'http', 'https'
@@ -526,6 +525,14 @@ private
526
525
  client.ssl_config.options |= OpenSSL::SSL::OP_NO_SSLv3
527
526
  end
528
527
 
528
+ # allow users to use their own custom ca
529
+ # or disable verification
530
+ if @verify == false
531
+ client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
532
+ elsif @verify.is_a? String
533
+ client.ssl_config.add_trust_ca(@verify)
534
+ end
535
+
529
536
  header = {}
530
537
  if @apikey
531
538
  header['Authorization'] = "TD1 #{apikey}"
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
  class Client
3
- VERSION = '1.0.8'
3
+ VERSION = '3.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
@@ -191,7 +183,7 @@ class Client
191
183
  def query(db_name, q, result_url=nil, priority=nil, retry_limit=nil, opts={})
192
184
  # for compatibility, assume type is hive unless specifically specified
193
185
  type = opts[:type] || opts['type'] || :hive
194
- raise ArgumentError, "The specified query type is not supported: #{type}" unless [:hive, :pig, :impala, :presto].include?(type)
186
+ raise ArgumentError, "The specified query type is not supported: #{type}" unless [:hive, :pig, :impala, :presto, :trino].include?(type)
195
187
  job_id = @api.query(q, type, db_name, result_url, priority, retry_limit, opts)
196
188
  Job.new(self, job_id, type, q)
197
189
  end
@@ -285,17 +277,6 @@ class Client
285
277
  Job.new(self, job_id, :result_export, nil)
286
278
  end
287
279
 
288
- # @param [String] db_name
289
- # @param [String] table_name
290
- # @param [Fixnum] to
291
- # @param [Fixnum] from
292
- # @param [Hash] opts
293
- # @return [Job]
294
- def partial_delete(db_name, table_name, to, from, opts={})
295
- job_id = @api.partial_delete(db_name, table_name, to, from, opts)
296
- Job.new(self, job_id, :partialdelete, nil)
297
- end
298
-
299
280
  # @param [String] name
300
281
  # @param [String] database
301
282
  # @param [String] table
@@ -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(
@@ -57,8 +57,7 @@ shared_context 'job resources' do
57
57
  [
58
58
  ['HiveJob', 'hive'],
59
59
  ['ExportJob', 'export'],
60
- ['BulkImportJob', 'bulk_import'],
61
- ['PartialDeleteJob', 'partialdelete']
60
+ ['BulkImportJob', 'bulk_import']
62
61
  ]
63
62
  end
64
63
 
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: 3.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: 2025-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -59,7 +59,7 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '3.0'
61
61
  - !ruby/object:Gem::Dependency
62
- name: coveralls
62
+ name: coveralls_reborn
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
@@ -78,28 +78,42 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '1.16'
81
+ version: 3.25.1
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: '1.16'
88
+ version: 3.25.1
89
+ - !ruby/object:Gem::Dependency
90
+ name: mutex_m
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: simplecov
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
107
  - - ">="
94
108
  - !ruby/object:Gem::Version
95
- version: 0.5.4
109
+ version: 0.21.2
96
110
  type: :development
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
114
  - - ">="
101
115
  - !ruby/object:Gem::Version
102
- version: 0.5.4
116
+ version: 0.21.2
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: rake
105
119
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +173,6 @@ files:
159
173
  - lib/td/client/api/export.rb
160
174
  - lib/td/client/api/import.rb
161
175
  - lib/td/client/api/job.rb
162
- - lib/td/client/api/partial_delete.rb
163
176
  - lib/td/client/api/result.rb
164
177
  - lib/td/client/api/schedule.rb
165
178
  - lib/td/client/api/server_status.rb
@@ -184,7 +197,6 @@ files:
184
197
  - spec/td/client/model_job_spec.rb
185
198
  - spec/td/client/model_schedule_spec.rb
186
199
  - spec/td/client/model_schema_spec.rb
187
- - spec/td/client/partial_delete_api_spec.rb
188
200
  - spec/td/client/result_api_spec.rb
189
201
  - spec/td/client/sched_api_spec.rb
190
202
  - spec/td/client/server_status_api_spec.rb
@@ -212,29 +224,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
224
  - !ruby/object:Gem::Version
213
225
  version: '0'
214
226
  requirements: []
215
- rubygems_version: 3.0.9
227
+ rubygems_version: 3.3.7
216
228
  signing_key:
217
229
  specification_version: 4
218
230
  summary: Treasure Data API library for Ruby
219
231
  test_files:
220
- - spec/td/client_spec.rb
221
- - spec/td/client_sched_spec.rb
222
- - spec/td/client/partial_delete_api_spec.rb
232
+ - spec/td/client/account_api_spec.rb
233
+ - spec/td/client/api_error_spec.rb
223
234
  - spec/td/client/api_spec.rb
235
+ - spec/td/client/api_ssl_connection_spec.rb
236
+ - spec/td/client/bulk_import_spec.rb
237
+ - spec/td/client/bulk_load_spec.rb
224
238
  - spec/td/client/db_api_spec.rb
225
- - spec/td/client/result_api_spec.rb
226
239
  - spec/td/client/export_api_spec.rb
240
+ - spec/td/client/import_api_spec.rb
241
+ - spec/td/client/job_api_spec.rb
242
+ - spec/td/client/model_job_spec.rb
243
+ - spec/td/client/model_schedule_spec.rb
227
244
  - spec/td/client/model_schema_spec.rb
228
- - spec/td/client/api_error_spec.rb
245
+ - spec/td/client/result_api_spec.rb
229
246
  - spec/td/client/sched_api_spec.rb
247
+ - spec/td/client/server_status_api_spec.rb
230
248
  - 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
249
  - 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
250
+ - spec/td/client_sched_spec.rb
251
+ - spec/td/client_spec.rb
@@ -1,27 +0,0 @@
1
- class TreasureData::API
2
- module PartialDelete
3
-
4
- ####
5
- ## Partial delete API
6
- ##
7
-
8
- # @param [String] db
9
- # @param [String] table
10
- # @param [Fixnum] to
11
- # @param [Fixnum] from
12
- # @param [Hash] opts
13
- # @return [String]
14
- def partial_delete(db, table, to, from, opts={})
15
- params = opts.dup
16
- params['to'] = to.to_s
17
- params['from'] = from.to_s
18
- code, body, res = post("/v3/table/partialdelete/#{e db}/#{e table}", params)
19
- if code != "200"
20
- raise_error("Partial delete failed", res)
21
- end
22
- js = checked_json(body, %w[job_id])
23
- return js['job_id'].to_s
24
- end
25
-
26
- end
27
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
- require 'td/client/spec_resources'
3
-
4
- describe 'PartialDelete API' do
5
- include_context 'spec symbols'
6
- include_context 'common helper'
7
-
8
- let :api do
9
- API.new(nil)
10
- end
11
-
12
- describe 'partialdelete' do
13
- let :from do
14
- 0
15
- end
16
-
17
- let :to do
18
- 3600 * 10
19
- end
20
-
21
- let :from_to do
22
- {'from' => from.to_s, 'to' => to.to_s}
23
- end
24
-
25
- it 'should partial_delete successfully' do
26
- # TODO: Use correnty values
27
- stub_api_request(:post, "/v3/table/partialdelete/#{e(db_name)}/#{e(table_name)}").with(:body => from_to).
28
- to_return(:body => {'database' => db_name, 'table' => table_name, 'job_id' => '1'}.to_json)
29
-
30
- expect(api.partial_delete(db_name, table_name, to, from)).to eq('1')
31
- end
32
-
33
- it 'should return 404 error with non exist database name' do
34
- db = 'no_such_db'
35
- err_msg = "Couldn't find UserDatabase with name = #{db}"
36
- stub_api_request(:post, "/v3/table/partialdelete/#{e(db)}/#{e(table_name)}").with(:body => from_to).
37
- to_return(:status => 404, :body => {'message' => err_msg}.to_json)
38
-
39
- expect {
40
- api.partial_delete(db, table_name, to, from)
41
- }.to raise_error(TreasureData::APIError, /#{err_msg}/)
42
- end
43
-
44
- it 'should return 404 error with non exist table name' do
45
- table = 'no_such_table'
46
- err_msg = "Unknown table: #{table}"
47
- stub_api_request(:post, "/v3/table/partialdelete/#{e(db_name)}/#{e(table)}").with(:body => from_to).
48
- to_return(:status => 404, :body => {'message' => err_msg}.to_json)
49
-
50
- expect {
51
- api.partial_delete(db_name, table, to, from)
52
- }.to raise_error(TreasureData::APIError, /#{err_msg}/)
53
- end
54
-
55
- # TODO: Add from / to parameters spec
56
- end
57
- end
58
-