mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
const os = require('os');
|
|
const { JSONPath } = require('jsonpath-plus');
|
|
|
|
const FILTERABLE = ['userInfo', 'cpus'];
|
|
|
|
module.exports.templateTags = [
|
|
{
|
|
displayName: 'OS',
|
|
name: 'os',
|
|
description: 'get OS info',
|
|
args: [
|
|
{
|
|
displayName: 'Function',
|
|
type: 'enum',
|
|
options: [
|
|
{ displayName: 'arch', value: 'arch' },
|
|
{ displayName: 'cpus', value: 'cpus' },
|
|
{ displayName: 'freemem', value: 'freemem' },
|
|
{ displayName: 'hostname', value: 'hostname' },
|
|
{ displayName: 'platform', value: 'platform' },
|
|
{ displayName: 'release', value: 'release' },
|
|
{ displayName: 'userInfo', value: 'userInfo' },
|
|
],
|
|
},
|
|
{
|
|
displayName: 'JSONPath Filter',
|
|
help: 'Some OS functions return objects. Use JSONPath queries to extract desired values.',
|
|
hide: args => !FILTERABLE.includes(args[0].value),
|
|
type: 'string',
|
|
},
|
|
],
|
|
run(context, fnName, filter) {
|
|
let value = os[fnName]();
|
|
|
|
if (JSONPath && FILTERABLE.includes(fnName)) {
|
|
try {
|
|
value = JSONPath({ json: value, path: filter })[0];
|
|
} catch (err) {}
|
|
}
|
|
|
|
if (typeof value !== 'string') {
|
|
return JSON.stringify(value);
|
|
} else {
|
|
return value;
|
|
}
|
|
},
|
|
},
|
|
];
|