-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbl-resource-query.js
executable file
·48 lines (43 loc) · 1.64 KB
/
bl-resource-query.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
#!/usr/bin/env node
const request = require('request');
const config = require('./config');
const fs = require('fs');
const async = require('async');
const jsonwebtoken = require('jsonwebtoken');
const commander = require('commander');
const util = require('./util');
commander
.option('-i, --id <id>', 'filter resources by id')
.option('-q, --query <query>', 'filter resources by name')
.option('-t, --status <status>', 'filter resources by status')
.option('-v, --service <service>', 'filter resources by service')
.option('-s, --skip <skip>', 'number of results to skip')
.option('-l, --limit <limit>', 'maximum number of results to show')
.option('-j, --json', 'output data in json format')
.parse(process.argv);
util.loadJwt().then(jwt => {
let headers = { "Authorization": "Bearer " + jwt };
util.queryResources(headers, {
id: commander.id,
search: commander.query,
status: commander.status,
service: commander.service,
}, {
skip: commander.skip,
limit: commander.limit
}).then(resources=>{
if (commander.json) console.log(JSON.stringify(resources));
else outputResources(resources);
}).catch(err=>{
console.error(err);
});
});
function outputResources(resources) {
resources.forEach(resource => {
console.log("Id: " + resource._id);
console.log("Name: " + resource.name);
console.log("Type: " + resource.type);
if (resource.config) console.log(resource.type + ": " + resource.config.username + "@" + (resource.config.hostname || '[' + resource.resource_id + ']'));
console.log("");
});
}