td-client 0.8.55 → 0.8.56
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.
- data/ChangeLog +6 -0
- data/lib/td/client.rb +2 -63
- data/lib/td/client/api.rb +27 -149
- data/lib/td/client/model.rb +0 -46
- data/lib/td/client/version.rb +1 -1
- metadata +2 -2
data/ChangeLog
CHANGED
data/lib/td/client.rb
CHANGED
@@ -77,8 +77,8 @@ class Client
|
|
77
77
|
end
|
78
78
|
|
79
79
|
# => true
|
80
|
-
def create_item_table(db_name, table_name)
|
81
|
-
@api.create_item_table(db_name, table_name)
|
80
|
+
def create_item_table(db_name, table_name, primary_key, primary_key_type)
|
81
|
+
@api.create_item_table(db_name, table_name, primary_key, primary_key_type)
|
82
82
|
end
|
83
83
|
|
84
84
|
# => true
|
@@ -310,52 +310,6 @@ class Client
|
|
310
310
|
@api.delete_result(name)
|
311
311
|
end
|
312
312
|
|
313
|
-
# => [Organization]
|
314
|
-
def organizations
|
315
|
-
list = @api.list_organizations
|
316
|
-
list.map {|name|
|
317
|
-
Organization.new(self, name)
|
318
|
-
}
|
319
|
-
end
|
320
|
-
|
321
|
-
# => true
|
322
|
-
def create_organization(organization)
|
323
|
-
@api.create_organization(organization)
|
324
|
-
end
|
325
|
-
|
326
|
-
# => true
|
327
|
-
def delete_organization(organization)
|
328
|
-
@api.delete_organization(organization)
|
329
|
-
end
|
330
|
-
|
331
|
-
# => [Role]
|
332
|
-
def roles
|
333
|
-
list = @api.list_roles
|
334
|
-
list.map {|name,org,users|
|
335
|
-
Role.new(self, name, org, users)
|
336
|
-
}
|
337
|
-
end
|
338
|
-
|
339
|
-
# => true
|
340
|
-
def create_role(role, org)
|
341
|
-
@api.create_role(role, org)
|
342
|
-
end
|
343
|
-
|
344
|
-
# => true
|
345
|
-
def delete_role(role)
|
346
|
-
@api.delete_role(role)
|
347
|
-
end
|
348
|
-
|
349
|
-
# => true
|
350
|
-
def grant_role(role, user)
|
351
|
-
@api.grant_role(role, user)
|
352
|
-
end
|
353
|
-
|
354
|
-
# => true
|
355
|
-
def revoke_role(role, user)
|
356
|
-
@api.revoke_role(role, user)
|
357
|
-
end
|
358
|
-
|
359
313
|
# => [User]
|
360
314
|
def users
|
361
315
|
list = @api.list_users
|
@@ -427,21 +381,6 @@ class Client
|
|
427
381
|
@api.test_access_control(user, action, scope)
|
428
382
|
end
|
429
383
|
|
430
|
-
def ip_limits
|
431
|
-
ips = @api.list_ip_limits
|
432
|
-
ips.map { |org, ipaddr, mask|
|
433
|
-
IpLimit.new(self, org, ipaddr, mask)
|
434
|
-
}
|
435
|
-
end
|
436
|
-
|
437
|
-
def set_ip_limit(org, ip_ranges)
|
438
|
-
@api.set_ip_limit(org, ip_ranges.to_json)
|
439
|
-
end
|
440
|
-
|
441
|
-
def delete_ip_limit(org)
|
442
|
-
@api.delete_ip_limit(org)
|
443
|
-
end
|
444
|
-
|
445
384
|
# => [AggregationSchema]
|
446
385
|
def aggregation_schemas
|
447
386
|
list = @api.list_aggregation_schema
|
data/lib/td/client/api.rb
CHANGED
@@ -80,6 +80,8 @@ class API
|
|
80
80
|
else
|
81
81
|
@http_class = Net::HTTP
|
82
82
|
end
|
83
|
+
|
84
|
+
@headers = opts[:headers] || {}
|
83
85
|
end
|
84
86
|
|
85
87
|
# TODO error check & raise appropriate errors
|
@@ -169,6 +171,15 @@ class API
|
|
169
171
|
end
|
170
172
|
end
|
171
173
|
|
174
|
+
# for fluent-plugin-td / td command to check table existence with import onlt user
|
175
|
+
def self.create_empty_gz_data
|
176
|
+
require 'zlib'
|
177
|
+
require 'stringio'
|
178
|
+
|
179
|
+
io = StringIO.new
|
180
|
+
Zlib::GzipWriter.new(io).close
|
181
|
+
io.string
|
182
|
+
end
|
172
183
|
|
173
184
|
####
|
174
185
|
## Account API
|
@@ -224,8 +235,7 @@ class API
|
|
224
235
|
count = m['count']
|
225
236
|
created_at = m['created_at']
|
226
237
|
updated_at = m['updated_at']
|
227
|
-
|
228
|
-
result[name] = [count, created_at, updated_at, organization]
|
238
|
+
result[name] = [count, created_at, updated_at, nil] # set nil to org for API compatibiilty
|
229
239
|
}
|
230
240
|
return result
|
231
241
|
end
|
@@ -293,13 +303,14 @@ class API
|
|
293
303
|
end
|
294
304
|
|
295
305
|
# => true
|
296
|
-
def create_item_table(db, table)
|
297
|
-
|
306
|
+
def create_item_table(db, table, primary_key, primary_key_type)
|
307
|
+
params = {'primary_key' => primary_key, 'primary_key_type' => primary_key_type}
|
308
|
+
create_table(db, table, :item, params)
|
298
309
|
end
|
299
310
|
|
300
|
-
def create_table(db, table, type)
|
311
|
+
def create_table(db, table, type, params={})
|
301
312
|
schema = schema.to_s
|
302
|
-
code, body, res = post("/v3/table/create/#{e db}/#{e table}/#{type}")
|
313
|
+
code, body, res = post("/v3/table/create/#{e db}/#{e table}/#{type}", params)
|
303
314
|
if code != "200"
|
304
315
|
raise_error("Create #{type} table failed", res)
|
305
316
|
end
|
@@ -395,8 +406,7 @@ class API
|
|
395
406
|
result_url = m['result']
|
396
407
|
priority = m['priority']
|
397
408
|
retry_limit = m['retry_limit']
|
398
|
-
|
399
|
-
result << [job_id, type, status, query, start_at, end_at, result_url, priority, retry_limit, organization, database]
|
409
|
+
result << [job_id, type, status, query, start_at, end_at, result_url, priority, retry_limit, nil, database] # same as database
|
400
410
|
}
|
401
411
|
return result
|
402
412
|
end
|
@@ -427,8 +437,7 @@ class API
|
|
427
437
|
end
|
428
438
|
priority = js['priority']
|
429
439
|
retry_limit = js['retry_limit']
|
430
|
-
|
431
|
-
return [type, query, status, url, debug, start_at, end_at, result, hive_result_schema, priority, retry_limit, organization, database]
|
440
|
+
return [type, query, status, url, debug, start_at, end_at, result, hive_result_schema, priority, retry_limit, nil, database] # same as above
|
432
441
|
end
|
433
442
|
|
434
443
|
def job_status(job_id)
|
@@ -749,8 +758,7 @@ class API
|
|
749
758
|
next_time = m['next_time']
|
750
759
|
priority = m['priority']
|
751
760
|
retry_limit = m['retry_limit']
|
752
|
-
|
753
|
-
result << [name, cron, query, database, result_url, timezone, delay, next_time, priority, retry_limit, organization]
|
761
|
+
result << [name, cron, query, database, result_url, timezone, delay, next_time, priority, retry_limit, nil] # same as database
|
754
762
|
}
|
755
763
|
return result
|
756
764
|
end
|
@@ -844,7 +852,7 @@ class API
|
|
844
852
|
js = checked_json(body, %w[results])
|
845
853
|
result = []
|
846
854
|
js['results'].map {|m|
|
847
|
-
result << [m['name'], m['url'],
|
855
|
+
result << [m['name'], m['url'], nil] # same as database
|
848
856
|
}
|
849
857
|
return result
|
850
858
|
end
|
@@ -999,101 +1007,6 @@ class API
|
|
999
1007
|
end
|
1000
1008
|
|
1001
1009
|
|
1002
|
-
####
|
1003
|
-
## Organization API
|
1004
|
-
##
|
1005
|
-
|
1006
|
-
# => [name:String]
|
1007
|
-
def list_organizations
|
1008
|
-
code, body, res = get("/v3/organization/list")
|
1009
|
-
if code != "200"
|
1010
|
-
raise_error("List organizations failed", res)
|
1011
|
-
end
|
1012
|
-
js = checked_json(body, %w[organizations])
|
1013
|
-
result = js["organizations"].map {|orginfo|
|
1014
|
-
name = orginfo['name'].to_s
|
1015
|
-
name
|
1016
|
-
}
|
1017
|
-
return result
|
1018
|
-
end
|
1019
|
-
|
1020
|
-
# => true
|
1021
|
-
def create_organization(org)
|
1022
|
-
code, body, res = post("/v3/organization/create/#{e org}")
|
1023
|
-
if code != "200"
|
1024
|
-
raise_error("Creating organization failed", res)
|
1025
|
-
end
|
1026
|
-
return true
|
1027
|
-
end
|
1028
|
-
|
1029
|
-
# => true
|
1030
|
-
def delete_organization(org)
|
1031
|
-
code, body, res = post("/v3/organization/delete/#{e org}")
|
1032
|
-
if code != "200"
|
1033
|
-
raise_error("Deleting organization failed", res)
|
1034
|
-
end
|
1035
|
-
return true
|
1036
|
-
end
|
1037
|
-
|
1038
|
-
|
1039
|
-
####
|
1040
|
-
## Role API
|
1041
|
-
##
|
1042
|
-
|
1043
|
-
# => [[name:String,organization:String,[user:String]]]
|
1044
|
-
def list_roles
|
1045
|
-
code, body, res = get("/v3/role/list")
|
1046
|
-
if code != "200"
|
1047
|
-
raise_error("List roles failed", res)
|
1048
|
-
end
|
1049
|
-
js = checked_json(body, %w[roles])
|
1050
|
-
result = js["roles"].map {|roleinfo|
|
1051
|
-
name = roleinfo['name']
|
1052
|
-
organization = roleinfo['organization']
|
1053
|
-
users = roleinfo['users']
|
1054
|
-
[name, organization, users]
|
1055
|
-
}
|
1056
|
-
return result
|
1057
|
-
end
|
1058
|
-
|
1059
|
-
# => true
|
1060
|
-
def create_role(role, org)
|
1061
|
-
params = {'organization'=>org}
|
1062
|
-
code, body, res = post("/v3/role/create/#{e role}", params)
|
1063
|
-
if code != "200"
|
1064
|
-
raise_error("Creating role failed", res)
|
1065
|
-
end
|
1066
|
-
return true
|
1067
|
-
end
|
1068
|
-
|
1069
|
-
# => true
|
1070
|
-
def delete_role(role)
|
1071
|
-
code, body, res = post("/v3/role/delete/#{e role}")
|
1072
|
-
if code != "200"
|
1073
|
-
raise_error("Creating role failed", res)
|
1074
|
-
end
|
1075
|
-
return true
|
1076
|
-
end
|
1077
|
-
|
1078
|
-
# => true
|
1079
|
-
def grant_role(role, user)
|
1080
|
-
code, body, res = post("/v3/role/grant/#{e role}/#{e user}")
|
1081
|
-
if code != "200"
|
1082
|
-
raise_error("Granting role failed", res)
|
1083
|
-
end
|
1084
|
-
return true
|
1085
|
-
end
|
1086
|
-
|
1087
|
-
# => true
|
1088
|
-
def revoke_role(role, user)
|
1089
|
-
code, body, res = post("/v3/role/revoke/#{e role}/#{e user}")
|
1090
|
-
if code != "200"
|
1091
|
-
raise_error("Revoking role failed", res)
|
1092
|
-
end
|
1093
|
-
return true
|
1094
|
-
end
|
1095
|
-
|
1096
|
-
|
1097
1010
|
####
|
1098
1011
|
## User API
|
1099
1012
|
##
|
@@ -1122,10 +1035,8 @@ class API
|
|
1122
1035
|
js = checked_json(body, %w[users])
|
1123
1036
|
result = js["users"].map {|roleinfo|
|
1124
1037
|
name = roleinfo['name']
|
1125
|
-
organization = roleinfo['organization']
|
1126
|
-
roles = roleinfo['roles']
|
1127
1038
|
email = roleinfo['email']
|
1128
|
-
[name,
|
1039
|
+
[name, nil, nil, email] # set nil to org and role for API compatibiilty
|
1129
1040
|
}
|
1130
1041
|
return result
|
1131
1042
|
end
|
@@ -1266,43 +1177,6 @@ class API
|
|
1266
1177
|
return acl
|
1267
1178
|
end
|
1268
1179
|
|
1269
|
-
####
|
1270
|
-
## IP Range Limit API
|
1271
|
-
##
|
1272
|
-
|
1273
|
-
def list_ip_limits
|
1274
|
-
code, body, res = get("/v3/ip_limit/list")
|
1275
|
-
if code != "200"
|
1276
|
-
raise_error("Listing IP limitations failed", res)
|
1277
|
-
end
|
1278
|
-
js = checked_json(body, %w[ip_limits])
|
1279
|
-
lists = js["ip_limits"].map { |ip_limit|
|
1280
|
-
organization = ip_limit['organization']
|
1281
|
-
address = ip_limit['address']
|
1282
|
-
mask = ip_limit['mask']
|
1283
|
-
[organization, address, mask]
|
1284
|
-
}
|
1285
|
-
return lists
|
1286
|
-
end
|
1287
|
-
|
1288
|
-
def set_ip_limit(organization, ip_ranges)
|
1289
|
-
params = {'organization' => organization, 'ip_ranges' => ip_ranges}
|
1290
|
-
code, body, res = post("/v3/ip_limit/set", params)
|
1291
|
-
if code != "200"
|
1292
|
-
raise_error("Setting IP limitation failed", res)
|
1293
|
-
end
|
1294
|
-
return true
|
1295
|
-
end
|
1296
|
-
|
1297
|
-
def delete_ip_limit(organization)
|
1298
|
-
params = {'organization' => organization}
|
1299
|
-
code, body, res = post("/v3/ip_limit/delete", params)
|
1300
|
-
if code != "200"
|
1301
|
-
raise_error("Deleting IP range limitation failed", res)
|
1302
|
-
end
|
1303
|
-
return true
|
1304
|
-
end
|
1305
|
-
|
1306
1180
|
####
|
1307
1181
|
## Server Status API
|
1308
1182
|
##
|
@@ -1453,6 +1327,8 @@ class API
|
|
1453
1327
|
header['Date'] = Time.now.rfc2822
|
1454
1328
|
header['User-Agent'] = @user_agent
|
1455
1329
|
|
1330
|
+
header.merge!(@headers)
|
1331
|
+
|
1456
1332
|
return http, header
|
1457
1333
|
end
|
1458
1334
|
|
@@ -1471,15 +1347,17 @@ class API
|
|
1471
1347
|
end
|
1472
1348
|
header['Date'] = Time.now.rfc2822
|
1473
1349
|
|
1350
|
+
header.merge!(@headers)
|
1351
|
+
|
1474
1352
|
return client, header
|
1475
1353
|
end
|
1476
1354
|
|
1477
1355
|
def raise_error(msg, res, klass=nil)
|
1478
1356
|
begin
|
1357
|
+
status_code = res.code.to_s
|
1479
1358
|
js = JSON.load(res.body)
|
1480
1359
|
msg = js['message']
|
1481
1360
|
error_code = js['error_code']
|
1482
|
-
status_code = res.code.to_s
|
1483
1361
|
|
1484
1362
|
if klass
|
1485
1363
|
raise klass, "#{error_code}: #{msg}"
|
data/lib/td/client/model.rb
CHANGED
@@ -48,7 +48,6 @@ class Database < Model
|
|
48
48
|
@count = count
|
49
49
|
@created_at = created_at
|
50
50
|
@updated_at = updated_at
|
51
|
-
@org_name = org_name
|
52
51
|
end
|
53
52
|
|
54
53
|
attr_reader :org_name
|
@@ -251,7 +250,6 @@ class Job < Model
|
|
251
250
|
@hive_result_schema = hive_result_schema
|
252
251
|
@priority = priority
|
253
252
|
@retry_limit = retry_limit
|
254
|
-
@org_name = org_name
|
255
253
|
@db_name = db_name
|
256
254
|
end
|
257
255
|
|
@@ -361,7 +359,6 @@ class Job < Model
|
|
361
359
|
@hive_result_schema = hive_result_schema
|
362
360
|
@priority = priority
|
363
361
|
@retry_limit = retry_limit
|
364
|
-
@org_name = org_name
|
365
362
|
@db_name = db_name
|
366
363
|
self
|
367
364
|
end
|
@@ -393,7 +390,6 @@ class Schedule < Model
|
|
393
390
|
@next_time = next_time
|
394
391
|
@priority = priority
|
395
392
|
@retry_limit = retry_limit
|
396
|
-
@org_name = org_name
|
397
393
|
end
|
398
394
|
|
399
395
|
attr_reader :name, :cron, :query, :database, :result_url, :timezone, :delay, :priority, :retry_limit, :org_name
|
@@ -413,7 +409,6 @@ class Result < Model
|
|
413
409
|
super(client)
|
414
410
|
@name = name
|
415
411
|
@url = url
|
416
|
-
@org_name = org_name
|
417
412
|
end
|
418
413
|
|
419
414
|
attr_reader :name, :url, :org_name
|
@@ -433,7 +428,6 @@ class BulkImport < Model
|
|
433
428
|
@error_records = data['error_records']
|
434
429
|
@valid_parts = data['valid_parts']
|
435
430
|
@error_parts = data['error_parts']
|
436
|
-
@org_name = data['organization']
|
437
431
|
end
|
438
432
|
|
439
433
|
attr_reader :name
|
@@ -453,34 +447,10 @@ class BulkImport < Model
|
|
453
447
|
end
|
454
448
|
|
455
449
|
|
456
|
-
class Organization < Model
|
457
|
-
def initialize(client, name)
|
458
|
-
super(client)
|
459
|
-
@name = name
|
460
|
-
end
|
461
|
-
|
462
|
-
attr_reader :client, :name
|
463
|
-
end
|
464
|
-
|
465
|
-
|
466
|
-
class Role < Model
|
467
|
-
def initialize(client, name, org_name, user_names)
|
468
|
-
super(client)
|
469
|
-
@name = name
|
470
|
-
@org_name = org_name
|
471
|
-
@user_names = user_names
|
472
|
-
end
|
473
|
-
|
474
|
-
attr_reader :client, :name, :org_name, :user_names
|
475
|
-
end
|
476
|
-
|
477
|
-
|
478
450
|
class User < Model
|
479
451
|
def initialize(client, name, org_name, role_names, email)
|
480
452
|
super(client)
|
481
453
|
@name = name
|
482
|
-
@org_name = org_name
|
483
|
-
@role_names = role_names
|
484
454
|
@email = email
|
485
455
|
end
|
486
456
|
|
@@ -501,22 +471,6 @@ class AccessControl < Model
|
|
501
471
|
end
|
502
472
|
|
503
473
|
|
504
|
-
class IpLimit < Model
|
505
|
-
def initialize(client, org, address, mask)
|
506
|
-
super(client)
|
507
|
-
@org = org
|
508
|
-
@address = address
|
509
|
-
@mask = mask
|
510
|
-
end
|
511
|
-
|
512
|
-
def ip_range
|
513
|
-
"#{address}/#{mask}"
|
514
|
-
end
|
515
|
-
|
516
|
-
attr_reader :org, :address, :mask
|
517
|
-
end
|
518
|
-
|
519
|
-
|
520
474
|
class AggregationSchema < Model
|
521
475
|
def initialize(client, name, relation_key, logs=nil, attributes=nil, timezone=nil)
|
522
476
|
super(client)
|
data/lib/td/client/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.56
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|