hb-nb-tools 2.0.7 → 2.0.8
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.
- package/lib/NbTool.js +39 -40
- package/package.json +1 -1
package/lib/NbTool.js
CHANGED
|
@@ -18,7 +18,7 @@ const { UsageError } = CommandLineParser
|
|
|
18
18
|
const usage = {
|
|
19
19
|
nb: `${b('nb')} [${b('-hVD')}] [${b('-H')} ${u('hostname')}[${b(':')}${u('port')}]] [${b('-T')} ${u('token')}] [${b('-E')} [${b('none')}|${b('hasedToken')}|${b('encryptedToken')}]] [${b('-t')} ${u('timeout')}] ${u('command')} [${u('argument')} ...]`,
|
|
20
20
|
|
|
21
|
-
discover: `${b('discover')} [${b('-h')}]
|
|
21
|
+
discover: `${b('discover')} [${b('-h')}]`,
|
|
22
22
|
|
|
23
23
|
auth: `${b('auth')} [${b('-h')}]`,
|
|
24
24
|
info: `${b('info')} [${b('-h')}]`,
|
|
@@ -316,6 +316,7 @@ class NbTool extends CommandLineTool {
|
|
|
316
316
|
const clargs = {
|
|
317
317
|
options: {
|
|
318
318
|
host: process.env.NB_HOST,
|
|
319
|
+
timeout: 5,
|
|
319
320
|
token: process.env.NB_TOKEN
|
|
320
321
|
}
|
|
321
322
|
}
|
|
@@ -365,7 +366,41 @@ class NbTool extends CommandLineTool {
|
|
|
365
366
|
this.usage = usage.nb
|
|
366
367
|
const clargs = this.parseArguments()
|
|
367
368
|
this.jsonFormatter = new JsonFormatter({ sortKeys: true })
|
|
368
|
-
if (clargs.command
|
|
369
|
+
if (clargs.command === 'discover') {
|
|
370
|
+
this.nbDiscovery = new NbDiscovery({
|
|
371
|
+
timeout: clargs.options.timeout
|
|
372
|
+
})
|
|
373
|
+
this.nbDiscovery
|
|
374
|
+
.on('error', (error) => {
|
|
375
|
+
this.log(
|
|
376
|
+
'%s: request %d: %s %s', error.request.name, error.request.id,
|
|
377
|
+
error.request.method, error.request.resource
|
|
378
|
+
)
|
|
379
|
+
this.warn(
|
|
380
|
+
'%s: request %d: error: %s', error.request.name, error.request.id, error
|
|
381
|
+
)
|
|
382
|
+
})
|
|
383
|
+
.on('request', (request) => {
|
|
384
|
+
this.debug(
|
|
385
|
+
'%s: request %d: %s %s', request.name, request.id,
|
|
386
|
+
request.method, request.resource
|
|
387
|
+
)
|
|
388
|
+
this.vdebug(
|
|
389
|
+
'%s: request %d: %s %s', request.name, request.id,
|
|
390
|
+
request.method, request.url
|
|
391
|
+
)
|
|
392
|
+
})
|
|
393
|
+
.on('response', (response) => {
|
|
394
|
+
this.vdebug(
|
|
395
|
+
'%s: request %d: response: %j', response.request.name, response.request.id,
|
|
396
|
+
response.body
|
|
397
|
+
)
|
|
398
|
+
this.debug(
|
|
399
|
+
'%s: request %d: %d %s', response.request.name, response.request.id,
|
|
400
|
+
response.statusCode, response.statusMessage
|
|
401
|
+
)
|
|
402
|
+
})
|
|
403
|
+
} else {
|
|
369
404
|
if (clargs.options.host == null) {
|
|
370
405
|
await this.fatal(`Missing host. Set ${b('NB_HOST')} or specify ${b('-H')}.`)
|
|
371
406
|
}
|
|
@@ -425,44 +460,8 @@ class NbTool extends CommandLineTool {
|
|
|
425
460
|
}
|
|
426
461
|
|
|
427
462
|
async discover (...args) {
|
|
428
|
-
|
|
429
|
-
this.
|
|
430
|
-
.option('t', 'timeout', (value, key) => {
|
|
431
|
-
options.timeout = OptionParser.toInt('timeout', value, 1, 60, true)
|
|
432
|
-
})
|
|
433
|
-
.parse(...args)
|
|
434
|
-
const nbDiscovery = new NbDiscovery(options)
|
|
435
|
-
nbDiscovery
|
|
436
|
-
.on('error', (error) => {
|
|
437
|
-
this.log(
|
|
438
|
-
'%s: request %d: %s %s', error.request.name, error.request.id,
|
|
439
|
-
error.request.method, error.request.resource
|
|
440
|
-
)
|
|
441
|
-
this.warn(
|
|
442
|
-
'%s: request %d: error: %s', error.request.name, error.request.id, error
|
|
443
|
-
)
|
|
444
|
-
})
|
|
445
|
-
.on('request', (request) => {
|
|
446
|
-
this.debug(
|
|
447
|
-
'%s: request %d: %s %s', request.name, request.id,
|
|
448
|
-
request.method, request.resource
|
|
449
|
-
)
|
|
450
|
-
this.vdebug(
|
|
451
|
-
'%s: request %d: %s %s', request.name, request.id,
|
|
452
|
-
request.method, request.url
|
|
453
|
-
)
|
|
454
|
-
})
|
|
455
|
-
.on('response', (response) => {
|
|
456
|
-
this.vdebug(
|
|
457
|
-
'%s: request %d: response: %j', response.request.name, response.request.id,
|
|
458
|
-
response.body
|
|
459
|
-
)
|
|
460
|
-
this.debug(
|
|
461
|
-
'%s: request %d: %d %s', response.request.name, response.request.id,
|
|
462
|
-
response.statusCode, response.statusMessage
|
|
463
|
-
)
|
|
464
|
-
})
|
|
465
|
-
const bridges = await nbDiscovery.discover()
|
|
463
|
+
this.parser.parse(...args)
|
|
464
|
+
const bridges = await this.nbDiscovery.discover()
|
|
466
465
|
this.print(this.jsonFormatter.stringify(bridges))
|
|
467
466
|
}
|
|
468
467
|
|