-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
86 lines (72 loc) · 2.43 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// vim:set sts=2 sw=2 tw=0 et:
var config = require('./config.json');
var kii = require('./lib/kii');
var util = require('util');
var ktx = new kii.Context(config.region, config.appID, config.appKey);
ktx.setupAccessToken(config.clientID, config.clientSecret, checkCurrentACL);
//ktx.setupAccessToken(config.clientID, config.clientSecret, listUsers);
//ktx.setupAccessToken(config.clientID, config.clientSecret, addUser('foo1234'));
//ktx.setupAccessToken(config.clientID, config.clientSecret, addUser('bar1234'));
//ktx.setupAccessToken(config.clientID, config.clientSecret, getAnUser);
//ktx.setupAccessToken(config.clientID, config.clientSecret, addACL(config.userID2));
function checkCurrentACL(token) {
console.log('ktx: ' + util.inspect(ktx));
ktx.adminRequest(null, null, handleAppInfo);
function handleAppInfo(res, obj) {
console.log();
console.log('appInfo: ' + util.inspect(obj));
ktx.adminRequest('acl', null, handleAppACLInfo);
}
function handleAppACLInfo(res, obj) {
console.log();
console.log('handleAppACLInfo: ' + util.inspect(obj));
ktx.adminRequest('acl/CREATE_NEW_TOPIC', null, handleACLCreateNewTopic);
}
function handleACLCreateNewTopic(res, obj) {
console.log();
console.log('handleACL1: ' + util.inspect(obj));
}
}
function listUsers(token) {
ktx.adminRequest('users', null, handleUser);
function handleUser(res, obj) {
console.log();
console.log('statusCode:%d obj:%s', res.statusCode, util.inspect(obj));
}
}
function addUser(loginName) {
return function (token) {
var user = {
loginName: loginName,
password: '123456',
}
ktx.adminRequest('users', user, handleAddUser);
function handleAddUser(res, obj) {
console.log();
console.log('statusCode:%d obj:%s', res.statusCode, util.inspect(obj));
}
};
}
function getAnUser(token) {
ktx.adminRequest('users/LOGIN_NAME:foo1234', null, handleGetAnUser);
function handleGetAnUser(res, obj) {
console.log();
console.log('statusCode:%d', res.statusCode);
console.log('obj: %s', util.inspect(obj));
}
}
function addACL(userId) {
return function(token) {
var param = {
method: 'PUT',
path: 'acl/CREATE_NEW_TOPIC/UserID:' + userId,
callback: handleAddACL,
};
ktx.adminRequest(param);
function handleAddACL(res, obj) {
console.log();
console.log('statusCode:%d', res.statusCode);
console.log('obj: %s', util.inspect(obj));
}
}
}