td-client 0.8.20 → 0.8.21
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +6 -0
- data/lib/td/client.rb +112 -0
- data/lib/td/client/api.rb +240 -0
- data/lib/td/client/model.rb +48 -0
- data/lib/td/client/version.rb +1 -1
- metadata +2 -2
data/ChangeLog
CHANGED
data/lib/td/client.rb
CHANGED
@@ -285,6 +285,118 @@ class Client
|
|
285
285
|
@api.delete_result(name)
|
286
286
|
end
|
287
287
|
|
288
|
+
# => [Organization]
|
289
|
+
def organizations
|
290
|
+
list = @api.list_organizations
|
291
|
+
list.map {|name|
|
292
|
+
Organization.new(self, name)
|
293
|
+
}
|
294
|
+
end
|
295
|
+
|
296
|
+
# => true
|
297
|
+
def create_organization(organization)
|
298
|
+
@api.create_organization(organization)
|
299
|
+
end
|
300
|
+
|
301
|
+
# => true
|
302
|
+
def delete_organization(organization)
|
303
|
+
@api.delete_organization(organization)
|
304
|
+
end
|
305
|
+
|
306
|
+
# => [Role]
|
307
|
+
def roles
|
308
|
+
list = @api.list_roles
|
309
|
+
list.map {|name,org,users|
|
310
|
+
Role.new(self, name, org, users)
|
311
|
+
}
|
312
|
+
end
|
313
|
+
|
314
|
+
# => true
|
315
|
+
def create_role(role, org)
|
316
|
+
@api.create_role(role, org)
|
317
|
+
end
|
318
|
+
|
319
|
+
# => true
|
320
|
+
def delete_role(role)
|
321
|
+
@api.delete_role(role)
|
322
|
+
end
|
323
|
+
|
324
|
+
# => true
|
325
|
+
def grant_role(role, user)
|
326
|
+
@api.grant_role(role, user)
|
327
|
+
end
|
328
|
+
|
329
|
+
# => true
|
330
|
+
def revoke_role(role, user)
|
331
|
+
@api.revoke_role(role, user)
|
332
|
+
end
|
333
|
+
|
334
|
+
# => [User]
|
335
|
+
def users
|
336
|
+
list = @api.list_users
|
337
|
+
list.map {|name,org,roles,email|
|
338
|
+
User.new(self, name, org, roles, email)
|
339
|
+
}
|
340
|
+
end
|
341
|
+
|
342
|
+
# => true
|
343
|
+
def add_user(user, org)
|
344
|
+
@api.add_user(user, org)
|
345
|
+
end
|
346
|
+
|
347
|
+
# => true
|
348
|
+
def remove_user(user)
|
349
|
+
@api.remove_user(user)
|
350
|
+
end
|
351
|
+
|
352
|
+
# => true
|
353
|
+
def change_email(user, email)
|
354
|
+
@api.change_email(user, email)
|
355
|
+
end
|
356
|
+
|
357
|
+
# => [apikey:String]
|
358
|
+
def list_apikeys(user)
|
359
|
+
@api.list_apikeys(user)
|
360
|
+
end
|
361
|
+
|
362
|
+
# => true
|
363
|
+
def add_apikey(user)
|
364
|
+
@api.add_apikey(user)
|
365
|
+
end
|
366
|
+
|
367
|
+
# => true
|
368
|
+
def remove_apikey(user, apikey)
|
369
|
+
@api.remove_apikey(user, apikey)
|
370
|
+
end
|
371
|
+
|
372
|
+
# => true
|
373
|
+
def change_password(user, password)
|
374
|
+
@api.change_password(user, password)
|
375
|
+
end
|
376
|
+
|
377
|
+
# => [User]
|
378
|
+
def access_controls
|
379
|
+
list = @api.list_access_controls
|
380
|
+
list.map {|subject,action,scope,grant_option|
|
381
|
+
AccessControl.new(self, subject, action, scope, grant_option)
|
382
|
+
}
|
383
|
+
end
|
384
|
+
|
385
|
+
# => true
|
386
|
+
def grant_access_control(subject, action, scope, grant_option)
|
387
|
+
@api.grant_access_control(subject, action, scope, grant_option)
|
388
|
+
end
|
389
|
+
|
390
|
+
# => true
|
391
|
+
def revoke_access_control(subject, action, scope)
|
392
|
+
@api.revoke_access_control(subject, action, scope)
|
393
|
+
end
|
394
|
+
|
395
|
+
# => true
|
396
|
+
def test_access_control(user, action, scope)
|
397
|
+
@api.test_access_control(user, action, scope)
|
398
|
+
end
|
399
|
+
|
288
400
|
# => [AggregationSchema]
|
289
401
|
def aggregation_schemas
|
290
402
|
list = @api.list_aggregation_schema
|
data/lib/td/client/api.rb
CHANGED
@@ -852,6 +852,101 @@ class API
|
|
852
852
|
end
|
853
853
|
|
854
854
|
|
855
|
+
####
|
856
|
+
## Organization API
|
857
|
+
##
|
858
|
+
|
859
|
+
# => [name:String]
|
860
|
+
def list_organizations
|
861
|
+
code, body, res = get("/v3/organization/list")
|
862
|
+
if code != "200"
|
863
|
+
raise_error("List aggregation schema failed", res)
|
864
|
+
end
|
865
|
+
js = checked_json(body, %w[organizations])
|
866
|
+
result = js["organizations"].map {|orginfo|
|
867
|
+
name = orginfo['name'].to_s
|
868
|
+
name
|
869
|
+
}
|
870
|
+
return result
|
871
|
+
end
|
872
|
+
|
873
|
+
# => true
|
874
|
+
def create_organization(org)
|
875
|
+
code, body, res = post("/v3/organization/create/#{e org}")
|
876
|
+
if code != "200"
|
877
|
+
raise_error("Creating organization failed", res)
|
878
|
+
end
|
879
|
+
return true
|
880
|
+
end
|
881
|
+
|
882
|
+
# => true
|
883
|
+
def delete_organization(org)
|
884
|
+
code, body, res = post("/v3/organization/delete/#{e org}")
|
885
|
+
if code != "200"
|
886
|
+
raise_error("Deleting organization failed", res)
|
887
|
+
end
|
888
|
+
return true
|
889
|
+
end
|
890
|
+
|
891
|
+
|
892
|
+
####
|
893
|
+
## Role API
|
894
|
+
##
|
895
|
+
|
896
|
+
# => [[name:String,organization:String,[user:String]]]
|
897
|
+
def list_roles
|
898
|
+
code, body, res = get("/v3/role/list")
|
899
|
+
if code != "200"
|
900
|
+
raise_error("List roles failed", res)
|
901
|
+
end
|
902
|
+
js = checked_json(body, %w[roles])
|
903
|
+
result = js["roles"].map {|roleinfo|
|
904
|
+
name = roleinfo['name']
|
905
|
+
organization = roleinfo['organization']
|
906
|
+
users = roleinfo['users']
|
907
|
+
[name, organization, users]
|
908
|
+
}
|
909
|
+
return result
|
910
|
+
end
|
911
|
+
|
912
|
+
# => true
|
913
|
+
def create_role(role, org)
|
914
|
+
params = {'organization'=>org}
|
915
|
+
code, body, res = post("/v3/role/create/#{e role}", params)
|
916
|
+
if code != "200"
|
917
|
+
raise_error("Creating role failed", res)
|
918
|
+
end
|
919
|
+
return true
|
920
|
+
end
|
921
|
+
|
922
|
+
# => true
|
923
|
+
def delete_role(role)
|
924
|
+
code, body, res = post("/v3/role/delete/#{e role}")
|
925
|
+
if code != "200"
|
926
|
+
raise_error("Creating role failed", res)
|
927
|
+
end
|
928
|
+
return true
|
929
|
+
end
|
930
|
+
|
931
|
+
# => true
|
932
|
+
def grant_role(role, user)
|
933
|
+
code, body, res = post("/v3/role/grant/#{e role}/#{e user}")
|
934
|
+
if code != "200"
|
935
|
+
raise_error("Granting role failed", res)
|
936
|
+
end
|
937
|
+
return true
|
938
|
+
end
|
939
|
+
|
940
|
+
# => true
|
941
|
+
def revoke_role(role, user)
|
942
|
+
code, body, res = post("/v3/role/revoke/#{e role}/#{e user}")
|
943
|
+
if code != "200"
|
944
|
+
raise_error("Revoking role failed", res)
|
945
|
+
end
|
946
|
+
return true
|
947
|
+
end
|
948
|
+
|
949
|
+
|
855
950
|
####
|
856
951
|
## User API
|
857
952
|
##
|
@@ -871,6 +966,150 @@ class API
|
|
871
966
|
return apikey
|
872
967
|
end
|
873
968
|
|
969
|
+
# => [[name:String,organization:String,[user:String]]
|
970
|
+
def list_users
|
971
|
+
code, body, res = get("/v3/user/list")
|
972
|
+
if code != "200"
|
973
|
+
raise_error("List aggregation schema failed", res)
|
974
|
+
end
|
975
|
+
js = checked_json(body, %w[users])
|
976
|
+
result = js["users"].map {|roleinfo|
|
977
|
+
name = roleinfo['name']
|
978
|
+
organization = roleinfo['organization']
|
979
|
+
roles = roleinfo['roles']
|
980
|
+
email = roleinfo['email']
|
981
|
+
[name, organization, roles, email]
|
982
|
+
}
|
983
|
+
return result
|
984
|
+
end
|
985
|
+
|
986
|
+
# => true
|
987
|
+
def add_user(user, org)
|
988
|
+
params = {'organization'=>org}
|
989
|
+
code, body, res = post("/v3/user/add/#{e user}", params)
|
990
|
+
if code != "200"
|
991
|
+
raise_error("Adding user failed", res)
|
992
|
+
end
|
993
|
+
return true
|
994
|
+
end
|
995
|
+
|
996
|
+
# => true
|
997
|
+
def remove_user(user)
|
998
|
+
code, body, res = post("/v3/user/remove/#{e user}")
|
999
|
+
if code != "200"
|
1000
|
+
raise_error("Removing user failed", res)
|
1001
|
+
end
|
1002
|
+
return true
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
# => true
|
1006
|
+
def change_email(user, email)
|
1007
|
+
params = {'email' => email}
|
1008
|
+
code, body, res = post("/v3/user/email/change/#{e user}", params)
|
1009
|
+
if code != "200"
|
1010
|
+
raise_error("Changing email failed", res)
|
1011
|
+
end
|
1012
|
+
return true
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
# => [apikey:String]
|
1016
|
+
def list_apikeys(user)
|
1017
|
+
code, body, res = get("/v3/user/apikey/list/#{e user}")
|
1018
|
+
if code != "200"
|
1019
|
+
raise_error("List API keys failed", res)
|
1020
|
+
end
|
1021
|
+
js = checked_json(body, %w[apikeys])
|
1022
|
+
return js['apikeys']
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
# => true
|
1026
|
+
def add_apikey(user)
|
1027
|
+
code, body, res = post("/v3/user/apikey/add/#{e user}")
|
1028
|
+
if code != "200"
|
1029
|
+
raise_error("Adding API key failed", res)
|
1030
|
+
end
|
1031
|
+
return true
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
# => true
|
1035
|
+
def remove_apikey(user, apikey)
|
1036
|
+
params = {'apikey' => apikey}
|
1037
|
+
code, body, res = post("/v3/user/apikey/remove/#{e user}", params)
|
1038
|
+
if code != "200"
|
1039
|
+
raise_error("Removing API key failed", res)
|
1040
|
+
end
|
1041
|
+
return true
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
# => true
|
1045
|
+
def change_password(user, password)
|
1046
|
+
params = {'password' => password}
|
1047
|
+
code, body, res = post("/v3/user/password/change/#{e user}", params)
|
1048
|
+
if code != "200"
|
1049
|
+
raise_error("Changing password failed", res)
|
1050
|
+
end
|
1051
|
+
return true
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
|
1055
|
+
####
|
1056
|
+
## Access Control API
|
1057
|
+
##
|
1058
|
+
|
1059
|
+
def grant_access_control(subject, action, scope, grant_option)
|
1060
|
+
params = {'subject'=>subject, 'action'=>action, 'scope'=>scope, 'grant_option'=>grant_option.to_s}
|
1061
|
+
code, body, res = post("/v3/acl/grant", params)
|
1062
|
+
if code != "200"
|
1063
|
+
raise_error("Granting access control failed", res)
|
1064
|
+
end
|
1065
|
+
return true
|
1066
|
+
end
|
1067
|
+
|
1068
|
+
def revoke_access_control(subject, action, scope)
|
1069
|
+
params = {'subject'=>subject, 'action'=>action, 'scope'=>scope}
|
1070
|
+
code, body, res = post("/v3/acl/revoke", params)
|
1071
|
+
if code != "200"
|
1072
|
+
raise_error("Revoking access control failed", res)
|
1073
|
+
end
|
1074
|
+
return true
|
1075
|
+
end
|
1076
|
+
|
1077
|
+
# [true, [{subject:String,action:String,scope:String}]]
|
1078
|
+
def test_access_control(user, action, scope)
|
1079
|
+
params = {'user'=>user, 'action'=>action, 'scope'=>scope}
|
1080
|
+
code, body, res = get("/v3/acl/test", params)
|
1081
|
+
if code != "200"
|
1082
|
+
raise_error("Testing access control failed", res)
|
1083
|
+
end
|
1084
|
+
js = checked_json(body, %w[permission access_controls])
|
1085
|
+
perm = js["permission"]
|
1086
|
+
acl = js["access_controls"].map {|roleinfo|
|
1087
|
+
subject = roleinfo['subject']
|
1088
|
+
action = roleinfo['action']
|
1089
|
+
scope = roleinfo['scope']
|
1090
|
+
[name, action, scope]
|
1091
|
+
}
|
1092
|
+
return perm, acl
|
1093
|
+
end
|
1094
|
+
|
1095
|
+
# [{subject:String,action:String,scope:String}]
|
1096
|
+
def list_access_controls
|
1097
|
+
code, body, res = get("/v3/acl/list")
|
1098
|
+
if code != "200"
|
1099
|
+
raise_error("Listing access control failed", res)
|
1100
|
+
end
|
1101
|
+
js = checked_json(body, %w[access_controls])
|
1102
|
+
acl = js["access_controls"].map {|roleinfo|
|
1103
|
+
subject = roleinfo['subject']
|
1104
|
+
action = roleinfo['action']
|
1105
|
+
scope = roleinfo['scope']
|
1106
|
+
grant_option = roleinfo['grant_option']
|
1107
|
+
[subject, action, scope, grant_option]
|
1108
|
+
}
|
1109
|
+
return acl
|
1110
|
+
end
|
1111
|
+
|
1112
|
+
|
874
1113
|
####
|
875
1114
|
## Server Status API
|
876
1115
|
##
|
@@ -886,6 +1125,7 @@ class API
|
|
886
1125
|
return status
|
887
1126
|
end
|
888
1127
|
|
1128
|
+
|
889
1129
|
private
|
890
1130
|
def get(url, params=nil, &block)
|
891
1131
|
http, header = new_http
|
data/lib/td/client/model.rb
CHANGED
@@ -376,6 +376,54 @@ class BulkImport < Model
|
|
376
376
|
end
|
377
377
|
|
378
378
|
|
379
|
+
class Organization < Model
|
380
|
+
def initialize(client, name)
|
381
|
+
super(client)
|
382
|
+
@name = name
|
383
|
+
end
|
384
|
+
|
385
|
+
attr_reader :client, :name
|
386
|
+
end
|
387
|
+
|
388
|
+
|
389
|
+
class Role < Model
|
390
|
+
def initialize(client, name, org_name, user_names)
|
391
|
+
super(client)
|
392
|
+
@name = name
|
393
|
+
@org_name = org_name
|
394
|
+
@user_names = user_names
|
395
|
+
end
|
396
|
+
|
397
|
+
attr_reader :client, :name, :org_name, :user_names
|
398
|
+
end
|
399
|
+
|
400
|
+
|
401
|
+
class User < Model
|
402
|
+
def initialize(client, name, org_name, role_names, email)
|
403
|
+
super(client)
|
404
|
+
@name = name
|
405
|
+
@org_name = org_name
|
406
|
+
@role_names = role_names
|
407
|
+
@email = email
|
408
|
+
end
|
409
|
+
|
410
|
+
attr_reader :client, :name, :org_name, :role_names, :email
|
411
|
+
end
|
412
|
+
|
413
|
+
|
414
|
+
class AccessControl < Model
|
415
|
+
def initialize(client, subject, action, scope, grant_option)
|
416
|
+
super(client)
|
417
|
+
@subject = subject
|
418
|
+
@action = action
|
419
|
+
@scope = scope
|
420
|
+
@grant_option = grant_option
|
421
|
+
end
|
422
|
+
|
423
|
+
attr_reader :subject, :action, :scope, :grant_option
|
424
|
+
end
|
425
|
+
|
426
|
+
|
379
427
|
class AggregationSchema < Model
|
380
428
|
def initialize(client, name, relation_key, logs=nil, attributes=nil, timezone=nil)
|
381
429
|
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.21
|
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: 2012-07
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|