td-client 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/td/client.rb +8 -0
- data/lib/td/client/api/table.rb +9 -0
- data/lib/td/client/version.rb +1 -1
- data/spec/spec_helper.rb +1 -5
- data/spec/td/client/api_ssl_connection_spec.rb +7 -10
- data/spec/td/client/table_api_spec.rb +39 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bfa8466ceb0e2dc014d9222e5bb295d7f9102951828531d993f9d92eb6592457
|
4
|
+
data.tar.gz: 8521a0ec4855d3d266fceabe8bbb7a42fcf52c38bdf4f6d8e8af96cae97add7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 477518baf02db8ec6f126f847d54b2b9fe5885a4bb3c5d6d07dfb4a8110d997ca4288541260932abd0e69dc56c50dd0ed1d62b5fbd9884cc6be10b31329b8440
|
7
|
+
data.tar.gz: f13066abdba694a7dd28f3fe67efac2c598f25b67f1fa7948dc85b4cdd6d9c476ea12eddd63b3229cb275ba193cb397f3a803a2c6ccc56cf7c08e56498d93e34
|
data/lib/td/client.rb
CHANGED
@@ -173,6 +173,14 @@ class Client
|
|
173
173
|
@api.tail(db_name, table_name, count, to, from, &block)
|
174
174
|
end
|
175
175
|
|
176
|
+
# @param [String] db_name
|
177
|
+
# @param [String] table_name
|
178
|
+
# @param [String] new_db_name
|
179
|
+
# @return [true]
|
180
|
+
def change_database(db_name, table_name, new_db_name)
|
181
|
+
@api.change_database(db_name, table_name, new_db_name)
|
182
|
+
end
|
183
|
+
|
176
184
|
# @param [String] db_name
|
177
185
|
# @param [String] q
|
178
186
|
# @param [String] result_url
|
data/lib/td/client/api/table.rb
CHANGED
@@ -140,5 +140,14 @@ module Table
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
+
def change_database(db, table, dest_db)
|
144
|
+
params = { 'dest_database_name' => dest_db }
|
145
|
+
code, body, res = post("/v3/table/change_database/#{e db}/#{e table}", params)
|
146
|
+
if code != "200"
|
147
|
+
raise_error("Change database failed", res)
|
148
|
+
end
|
149
|
+
return true
|
150
|
+
end
|
151
|
+
|
143
152
|
end
|
144
153
|
end
|
data/lib/td/client/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -49,11 +49,7 @@ shared_context 'common helper' do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
let :headers do
|
52
|
-
|
53
|
-
{'Accept' => '*/*', 'Accept-Encoding' => /gzip/, 'Date' => /.*/, 'User-Agent' => /Ruby/}
|
54
|
-
else
|
55
|
-
{'Accept' => '*/*', 'Date' => /.*/, 'User-Agent' => /Ruby/}
|
56
|
-
end
|
52
|
+
{'Accept' => '*/*', 'Accept-Encoding' => /gzip/, 'Date' => /.*/, 'User-Agent' => /Ruby/}
|
57
53
|
end
|
58
54
|
|
59
55
|
def stub_api_request(method, path, opts = nil)
|
@@ -43,16 +43,13 @@ describe 'API SSL connection' do
|
|
43
43
|
}.to raise_error OpenSSL::SSL::SSLError
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
api.
|
52
|
-
|
53
|
-
api.delete_database('no_such_database')
|
54
|
-
}.to raise_error TreasureData::NotFoundError
|
55
|
-
end
|
46
|
+
it 'should success to connect TLSv1 only server' do
|
47
|
+
@server = setup_server(:TLSv1)
|
48
|
+
api = API.new(nil, :endpoint => "https://localhost:#{@serverport}", :retry_post_requests => false)
|
49
|
+
api.ssl_ca_file = File.join(DIR, 'ca-all.cert')
|
50
|
+
expect {
|
51
|
+
api.delete_database('no_such_database')
|
52
|
+
}.to raise_error TreasureData::NotFoundError
|
56
53
|
end
|
57
54
|
|
58
55
|
def setup_server(ssl_version)
|
@@ -301,4 +301,43 @@ describe 'Table API' do
|
|
301
301
|
expect(r.read).to eq(%Q(parameter "to" and "from" no longer work\n))
|
302
302
|
end
|
303
303
|
end
|
304
|
+
|
305
|
+
describe 'change_database' do
|
306
|
+
it 'should change the database belonging to' do
|
307
|
+
stub_api_request(:post, "/v3/table/change_database/src_db/table").
|
308
|
+
with(:body => {'dest_database_name' => 'dst_db'}).
|
309
|
+
to_return(:body => {'database' => 'dst_db', 'table' => 'table', 'type' => 'log'}.to_json)
|
310
|
+
expect(api.change_database('src_db', 'table', 'dst_db')).to be true
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'should return 403 error if dest database is inaccessible' do
|
314
|
+
err_msg = 'Access denied for the destination'
|
315
|
+
stub_api_request(:post, "/v3/table/change_database/src_db/table").
|
316
|
+
with(:body => {'dest_database_name' => 'inaccessible_db'}).
|
317
|
+
to_return(:status => 403, :body => {'message' => err_msg}.to_json)
|
318
|
+
expect {
|
319
|
+
api.change_database('src_db', 'table', 'inaccessible_db')
|
320
|
+
}.to raise_error(TreasureData::ForbiddenError, /#{err_msg}/)
|
321
|
+
end
|
322
|
+
|
323
|
+
it 'should return 403 error if there is a same name table in the dest database' do
|
324
|
+
err_msg = 'Table table already exists in the destination'
|
325
|
+
stub_api_request(:post, "/v3/table/change_database/src_db/table").
|
326
|
+
with(:body => {'dest_database_name' => 'dst_db'}).
|
327
|
+
to_return(:status => 403, :body => {'message' => err_msg}.to_json)
|
328
|
+
expect {
|
329
|
+
api.change_database('src_db', 'table', 'dst_db')
|
330
|
+
}.to raise_error(TreasureData::ForbiddenError, /#{err_msg}/)
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'should return 404 error if the dest database does not exist' do
|
334
|
+
err_msg = 'Destination database is not found'
|
335
|
+
stub_api_request(:post, "/v3/table/change_database/src_db/table").
|
336
|
+
with(:body => {'dest_database_name' => 'notexist_db'}).
|
337
|
+
to_return(:status => 404, :body => {'message' => err_msg}.to_json)
|
338
|
+
expect {
|
339
|
+
api.change_database('src_db', 'table', 'notexist_db')
|
340
|
+
}.to raise_error(TreasureData::NotFoundError, /#{err_msg}/)
|
341
|
+
end
|
342
|
+
end
|
304
343
|
end
|
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.
|
4
|
+
version: 1.0.7
|
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:
|
11
|
+
date: 2019-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -198,8 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
198
|
- !ruby/object:Gem::Version
|
199
199
|
version: '0'
|
200
200
|
requirements: []
|
201
|
-
|
202
|
-
rubygems_version: 2.6.13
|
201
|
+
rubygems_version: 3.0.0.beta3
|
203
202
|
signing_key:
|
204
203
|
specification_version: 4
|
205
204
|
summary: Treasure Data API library for Ruby
|