-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
57 lines (50 loc) · 1.88 KB
/
test.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
var ClientAPI = require('./taas-client')
, speakeasy = require('speakeasy')
;
var steward = new ClientAPI.ClientAPI(
{ steward : { name : 'steward.local'
, crtPath : 'server.crt'
}
, cloud : { service : 'taas.thethingsystem.net'
, crtPath : 'cloud.crt'
}
}).on('open', function(channel, loginP) {
console.log('open ' + channel);
if (!loginP) {
if (channel === 'management') console.log('steward in developer mode, no need to log in.');
return;
}
// please open https://steward.local:8888/client.html and create a 'resident' account and enter the information below.
var clientID = '.../...'
, loginCode = speakeasy.totp({ key : '................................................................'
, length : 6
, encoding : 'base32'
, step : 30 })
;
if (clientID === '.../...') {
console.log('please fill-in values for clientID and loginCode, cf., the comment in the code');
process.exit(1);
}
steward.login(clientID, loginCode, function(err, result) {
if (!!err) {
console.log('login error: ' + JSON.stringify(result));
process.exit(1);
}
console.log('logged in');
});
}).on('ready', function(channel, data) {
console.log('ready ' + channel + ' data='+ JSON.stringify(data));
if (channel !== 'management') return;
console.log('ready, set, go!');
steward.listActors(null, { depth: 'all' }, function(message) {
console.log(require('util').inspect(message, { depth: null }));
});
}).on('actor', function(whoami, whatami) {
console.log('actor ' + whoami + ': ' + whatami);
}).on('close', function(channel) {
console.log(channel + ' close');
process.exit(1);
}).on('error', function(err, channel) {
console.log(channel + ' error: ' + err.message);
process.exit(1);
});