@webos-tools/cli 3.0.3 → 3.0.5
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/.eslintignore +1 -1
- package/.eslintrc.js +52 -52
- package/APIs.js +79 -79
- package/CHANGELOG.md +128 -123
- package/LICENSE +201 -201
- package/README.md +218 -218
- package/bin/ares-config.js +199 -199
- package/bin/ares-device-info.js +30 -30
- package/bin/ares-device.js +219 -219
- package/bin/ares-generate.js +270 -270
- package/bin/ares-inspect.js +179 -179
- package/bin/ares-install.js +223 -223
- package/bin/ares-launch.js +318 -318
- package/bin/ares-log.js +255 -255
- package/bin/ares-novacom.js +223 -223
- package/bin/ares-package.js +336 -336
- package/bin/ares-pull.js +156 -156
- package/bin/ares-push.js +155 -155
- package/bin/ares-server.js +174 -174
- package/bin/ares-setup-device.js +520 -520
- package/bin/ares-shell.js +132 -132
- package/bin/ares.js +166 -166
- package/files/conf/ares.json +49 -49
- package/files/conf/command-service.json +73 -73
- package/files/conf/config.json +22 -22
- package/files/conf/ipk.json +30 -30
- package/files/conf/novacom-devices.json +35 -35
- package/files/conf/query/query-app.json +14 -14
- package/files/conf/query/query-hosted.json +18 -18
- package/files/conf/query/query-package.json +10 -10
- package/files/conf/query/query-service.json +6 -6
- package/files/conf/sdk.json +8 -8
- package/files/conf/template.json +57 -57
- package/files/conf/webos_emul +27 -27
- package/files/conf-base/env/sdk-ose.json +8 -8
- package/files/conf-base/env/sdk-tv.json +8 -8
- package/files/conf-base/profile/config-ose.json +21 -21
- package/files/conf-base/profile/config-tv.json +22 -22
- package/files/conf-base/query/query-app.json +14 -14
- package/files/conf-base/query/query-hosted.json +18 -18
- package/files/conf-base/query/query-package.json +10 -10
- package/files/conf-base/query/query-service.json +6 -6
- package/files/conf-base/template-conf/ose-templates.json +67 -67
- package/files/conf-base/template-conf/tv-sdk-templates.json +57 -57
- package/files/help/ares-config.help +43 -43
- package/files/help/ares-device.help +94 -94
- package/files/help/ares-generate.help +65 -65
- package/files/help/ares-inspect.help +70 -70
- package/files/help/ares-install.help +90 -90
- package/files/help/ares-launch.help +100 -100
- package/files/help/ares-log-pmlogd.help +84 -84
- package/files/help/ares-log.help +101 -101
- package/files/help/ares-novacom.help +68 -68
- package/files/help/ares-package.help +101 -101
- package/files/help/ares-pull.help +38 -38
- package/files/help/ares-push.help +38 -38
- package/files/help/ares-server.help +39 -39
- package/files/help/ares-setup-device.help +75 -75
- package/files/help/ares-shell.help +42 -42
- package/files/help/ares.help +47 -47
- package/files/help/readme.help +23 -23
- package/files/schema/ApplicationDescription.schema +319 -319
- package/files/schema/NovacomDevices.schema +61 -61
- package/files/templates/ose-sdk-templates/appinfo/appinfo.json +10 -10
- package/files/templates/ose-sdk-templates/bootplate-web/index.html +88 -88
- package/files/templates/ose-sdk-templates/hosted-webapp/index.html +13 -13
- package/files/templates/ose-sdk-templates/icon/icon.png +0 -0
- package/files/templates/ose-sdk-templates/js-service/helloclient.js +31 -31
- package/files/templates/ose-sdk-templates/js-service/helloworld_webos_service.js +188 -188
- package/files/templates/ose-sdk-templates/qml-app/main.qml +68 -68
- package/files/templates/ose-sdk-templates/qmlappinfo/appinfo.json +10 -10
- package/files/templates/ose-sdk-templates/serviceinfo/package.json +11 -11
- package/files/templates/ose-sdk-templates/serviceinfo/services.json +8 -8
- package/files/templates/tv-sdk-templates/appinfo/appinfo.json +10 -10
- package/files/templates/tv-sdk-templates/bootplate-web/index.html +58 -58
- package/files/templates/tv-sdk-templates/bootplate-web/webOSTVjs-1.2.10/LICENSE-2.0.txt +202 -202
- package/files/templates/tv-sdk-templates/hosted-webapp/index.html +14 -14
- package/files/templates/tv-sdk-templates/js-service/helloworld_service.js +39 -39
- package/files/templates/tv-sdk-templates/packageinfo/packageinfo.json +3 -3
- package/files/templates/tv-sdk-templates/serviceinfo/package.json +11 -11
- package/files/templates/tv-sdk-templates/serviceinfo/services.json +8 -8
- package/files/templates/tv-sdk-templates/webicon/icon.png +0 -0
- package/files/templates/tv-sdk-templates/webicon/largeIcon.png +0 -0
- package/lib/base/ares.html +40 -40
- package/lib/base/cli-appdata.js +290 -301
- package/lib/base/cli-control.js +44 -44
- package/lib/base/common-tools.js +29 -29
- package/lib/base/error-handler.js +265 -265
- package/lib/base/file-watcher.js +155 -155
- package/lib/base/help-format.js +147 -147
- package/lib/base/luna.js +178 -178
- package/lib/base/novacom.js +1191 -1191
- package/lib/base/sdkenv.js +59 -59
- package/lib/base/server.js +137 -137
- package/lib/base/setup-device.js +328 -328
- package/lib/base/version-tools.js +79 -79
- package/lib/device.js +1419 -1419
- package/lib/generator.js +377 -377
- package/lib/inspect.js +494 -494
- package/lib/install.js +463 -463
- package/lib/launch.js +605 -605
- package/lib/log.js +584 -584
- package/lib/package.js +2129 -2129
- package/lib/pull.js +231 -231
- package/lib/pusher.js +210 -210
- package/lib/session.js +74 -74
- package/lib/shell.js +193 -193
- package/lib/tar-filter-pack.js +62 -62
- package/lib/util/copy.js +31 -31
- package/lib/util/createFileName.js +40 -40
- package/lib/util/eof.js +30 -30
- package/lib/util/json.js +63 -63
- package/lib/util/merge.js +14 -14
- package/lib/util/objclone.js +40 -40
- package/lib/util/spinner.js +37 -37
- package/npm-shrinkwrap.json +9115 -9115
- package/package.json +100 -97
- package/scripts/postinstall.js +24 -0
- package/spec/helpers/reporter.js +65 -65
- package/spec/jsSpecs/apiTest/generator.spec.js +372 -372
- package/spec/jsSpecs/apiTest/inspector.spec.js +89 -89
- package/spec/jsSpecs/apiTest/installer.spec.js +67 -67
- package/spec/jsSpecs/apiTest/launcher.spec.js +150 -150
- package/spec/jsSpecs/apiTest/packager.spec.js +194 -194
- package/spec/jsSpecs/apiTest/puller.spec.js +101 -101
- package/spec/jsSpecs/apiTest/pusher.spec.js +103 -103
- package/spec/jsSpecs/apiTest/server.spec.js +115 -115
- package/spec/jsSpecs/apiTest/setupDevice.spec.js +93 -93
- package/spec/jsSpecs/apiTest/shell.spec.js +49 -49
- package/spec/jsSpecs/ares-config.spec.js +78 -78
- package/spec/jsSpecs/ares-device.spec.js +443 -443
- package/spec/jsSpecs/ares-generate.spec.js +397 -397
- package/spec/jsSpecs/ares-inspect.spec.js +252 -252
- package/spec/jsSpecs/ares-install.spec.js +150 -150
- package/spec/jsSpecs/ares-launch.spec.js +301 -301
- package/spec/jsSpecs/ares-log.spec.js +824 -824
- package/spec/jsSpecs/ares-novacom.spec.js +149 -149
- package/spec/jsSpecs/ares-package.spec.js +1211 -1211
- package/spec/jsSpecs/ares-pull.spec.js +157 -157
- package/spec/jsSpecs/ares-push.spec.js +146 -146
- package/spec/jsSpecs/ares-server.spec.js +160 -160
- package/spec/jsSpecs/ares-setup-device.spec.js +281 -281
- package/spec/jsSpecs/ares-shell.spec.js +220 -220
- package/spec/jsSpecs/ares.spec.js +83 -83
- package/spec/jsSpecs/common-spec.js +169 -169
- package/spec/support/jasmine.json +22 -22
- package/spec/tempFiles/nativeApp/auto/pkg_arm64/GLES2 +0 -0
- package/spec/tempFiles/nativeApp/auto/pkg_arm64/appinfo.json +9 -9
- package/spec/tempFiles/nativeApp/ose/pkg_arm/Hello +0 -0
- package/spec/tempFiles/nativeApp/ose/pkg_arm/appinfo.json +8 -8
- package/spec/tempFiles/nativeApp/ose/pkg_arm/package.properties +2 -2
- package/spec/tempFiles/nativeApp/oseEmul/pkg_x86/Hello +0 -0
- package/spec/tempFiles/nativeApp/oseEmul/pkg_x86/appinfo.json +9 -9
- package/spec/tempFiles/nativeApp/rsi/pkg_x86/GLES2 +0 -0
- package/spec/tempFiles/nativeApp/rsi/pkg_x86/appinfo.json +9 -9
- package/spec/tempFiles/sign/sign.crt +32 -32
- package/spec/tempFiles/sign/signPriv.key +52 -52
- package/spec/test_data/ares-generate.json +41 -41
- package/spec/test_data/ares.json +33 -33
package/lib/base/setup-device.js
CHANGED
|
@@ -1,328 +1,328 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020-2024 LG Electronics Inc.
|
|
3
|
-
*
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const async = require('async'),
|
|
8
|
-
chalk = require('chalk'),
|
|
9
|
-
Table = require('easy-table'),
|
|
10
|
-
npmlog = require('npmlog'),
|
|
11
|
-
Appdata = require('./cli-appdata'),
|
|
12
|
-
errHndl = require('./error-handler'),
|
|
13
|
-
novacom = require('./novacom');
|
|
14
|
-
|
|
15
|
-
(function() {
|
|
16
|
-
const log = npmlog;
|
|
17
|
-
log.heading = 'setup-device';
|
|
18
|
-
log.level = 'warn';
|
|
19
|
-
|
|
20
|
-
const appdata = new Appdata(),
|
|
21
|
-
devicetools = {},
|
|
22
|
-
defaultDeviceInfo = {
|
|
23
|
-
profile: appdata.getConfig(true).profile,
|
|
24
|
-
host: "127.0.0.1",
|
|
25
|
-
port: 22,
|
|
26
|
-
username: "root",
|
|
27
|
-
description: "new device description",
|
|
28
|
-
files: "stream",
|
|
29
|
-
default: false
|
|
30
|
-
};
|
|
31
|
-
if(defaultDeviceInfo.profile !== "ose"){
|
|
32
|
-
defaultDeviceInfo.type = "starfish";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (typeof module !== 'undefined' && module.exports) {
|
|
36
|
-
module.exports = devicetools;
|
|
37
|
-
module.exports.isValidDeviceName = isValidDeviceName;
|
|
38
|
-
module.exports.isValidIpv4 = isValidIpv4;
|
|
39
|
-
module.exports.isValidPort =isValidPort;
|
|
40
|
-
module.exports.replaceDefaultDeviceInfo = replaceDefaultDeviceInfo;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function isValidDeviceName(name) {
|
|
44
|
-
const re = new RegExp("^[_a-zA-Z][a-zA-Z0-9#_-]*");
|
|
45
|
-
return (name === String(name.match(re)));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function isValidIpv4(host) {
|
|
49
|
-
return host === "localhost" || host.match(/^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function isValidPort(port) {
|
|
53
|
-
const intPort = Number(port);
|
|
54
|
-
return Number.isInteger(intPort) && intPort > 0 && intPort <= 65535;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
devicetools.showDeviceList = function(next) {
|
|
58
|
-
async.waterfall([
|
|
59
|
-
_getDeviceInfo.bind(this, 'list'),
|
|
60
|
-
function(data, next) {
|
|
61
|
-
const table = new Table();
|
|
62
|
-
data.forEach(function(item) {
|
|
63
|
-
if (!isValidDeviceName(item.name)) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
table.cell('name', (item.default === true) ? item.name + chalk.green(' (default)') : item.name);
|
|
67
|
-
table.cell('deviceinfo', item.info);
|
|
68
|
-
table.cell('connection', item.connection);
|
|
69
|
-
table.cell('profile', item.profile);
|
|
70
|
-
table.newRow();
|
|
71
|
-
});
|
|
72
|
-
next(null, table.toString());
|
|
73
|
-
}
|
|
74
|
-
], function(err, results) {
|
|
75
|
-
next(err, {msg: results});
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
devicetools.showDeviceListFull = function(next) {
|
|
80
|
-
async.waterfall([
|
|
81
|
-
_getDeviceInfo.bind(this, 'full'),
|
|
82
|
-
function(data, next) {
|
|
83
|
-
next(null, JSON.stringify(data, null, 4));
|
|
84
|
-
}
|
|
85
|
-
], function(err, results) {
|
|
86
|
-
next(err, {msg: results});
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
devicetools.resetDeviceList = function(next) {
|
|
91
|
-
async.series([
|
|
92
|
-
function(next) {
|
|
93
|
-
appdata.resetDeviceList(next);
|
|
94
|
-
},
|
|
95
|
-
this.showDeviceList.bind(this, next)
|
|
96
|
-
], function(err) {
|
|
97
|
-
next(err);
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
devicetools.setDefaultDevice = function(name, next) {
|
|
102
|
-
try {
|
|
103
|
-
const resolver = this.resolver || (this.resolver = new novacom.Resolver()),
|
|
104
|
-
inDevice = {name: name, default: true};
|
|
105
|
-
async.series([
|
|
106
|
-
resolver.load.bind(resolver),
|
|
107
|
-
resolver.modifyDeviceFile.bind(resolver, 'default', inDevice),
|
|
108
|
-
this.showDeviceList.bind(this, next)
|
|
109
|
-
], function(err) {
|
|
110
|
-
if (err) {
|
|
111
|
-
return next(err);
|
|
112
|
-
}
|
|
113
|
-
next();
|
|
114
|
-
});
|
|
115
|
-
} catch (err) {
|
|
116
|
-
next(err);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
devicetools.removeDeviceInfo = function(options, next) {
|
|
121
|
-
try {
|
|
122
|
-
// For CLI
|
|
123
|
-
if (options.remove === 'true') {
|
|
124
|
-
next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
|
|
125
|
-
}
|
|
126
|
-
// For API
|
|
127
|
-
if (!options.remove) {
|
|
128
|
-
next(errHndl.getErrMsg("INVALID_REMOVE_MODE"));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const resolver = this.resolver || (this.resolver = new novacom.Resolver()),
|
|
132
|
-
inDevice = {name: options.remove, profile: defaultDeviceInfo.profile};
|
|
133
|
-
async.series([
|
|
134
|
-
resolver.load.bind(resolver),
|
|
135
|
-
resolver.modifyDeviceFile.bind(resolver, 'remove', inDevice),
|
|
136
|
-
this.showDeviceList.bind(this, next)
|
|
137
|
-
], function(err) {
|
|
138
|
-
if (err) {
|
|
139
|
-
return next(err);
|
|
140
|
-
}
|
|
141
|
-
next();
|
|
142
|
-
});
|
|
143
|
-
} catch (err) {
|
|
144
|
-
next(err);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
devicetools.modifyDeviceInfo = function(options, next) {
|
|
149
|
-
try {
|
|
150
|
-
const mode = (options.add) ? "add" : (options.modify) ? "modify" : null;
|
|
151
|
-
if (!mode) {
|
|
152
|
-
return next(errHndl.getErrMsg("INVALID_MODE"));
|
|
153
|
-
}
|
|
154
|
-
if (options[mode].match(/^-/)) {
|
|
155
|
-
return next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
|
|
156
|
-
}
|
|
157
|
-
const argName = (options.info) ? "info" : mode;
|
|
158
|
-
const inDevice = _getParams(options, argName);
|
|
159
|
-
if (!inDevice.name) {
|
|
160
|
-
if (options[mode] === "true") {
|
|
161
|
-
return next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
|
|
162
|
-
}
|
|
163
|
-
inDevice.name = options[mode];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
log.info("modifyDeviceInfo()", "devicename:", inDevice.name, ", mode:", mode);
|
|
167
|
-
|
|
168
|
-
if (inDevice.default !== undefined && mode === "modify") {
|
|
169
|
-
log.verbose("modifyDeviceInfo()", "Ignoring invalid arguments:default");
|
|
170
|
-
inDevice.default = undefined;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (inDevice.privateKey) {
|
|
174
|
-
inDevice.privatekey = inDevice.privateKey;
|
|
175
|
-
}
|
|
176
|
-
if (typeof inDevice.privatekey === "string") {
|
|
177
|
-
inDevice.privateKey = inDevice.privatekey;
|
|
178
|
-
inDevice.privateKey = { "openSsh": inDevice.privateKey };
|
|
179
|
-
delete inDevice.privatekey;
|
|
180
|
-
inDevice.password = "@DELETE@";
|
|
181
|
-
}
|
|
182
|
-
if (typeof inDevice.password !== "undefined" && inDevice.password !== "@DELETE@") {
|
|
183
|
-
inDevice.privateKey = "@DELETE@";
|
|
184
|
-
inDevice.passphrase = "@DELETE@";
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (mode === "add") {
|
|
188
|
-
replaceDefaultDeviceInfo(inDevice);
|
|
189
|
-
if (!inDevice.privateKey && !inDevice.password) {
|
|
190
|
-
inDevice.password = "";
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
// check validation
|
|
194
|
-
if (!isValidDeviceName(inDevice.name)) {
|
|
195
|
-
return next(errHndl.getErrMsg("INVALID_DEVICENAME"));
|
|
196
|
-
}
|
|
197
|
-
if (inDevice.host && !isValidIpv4(inDevice.host)) {
|
|
198
|
-
return next(errHndl.getErrMsg("INVALID_VALUE", "host", inDevice.host));
|
|
199
|
-
}
|
|
200
|
-
if (inDevice.port && !isValidPort(inDevice.port)) {
|
|
201
|
-
return next(errHndl.getErrMsg("INVALID_VALUE", "port", inDevice.port));
|
|
202
|
-
}
|
|
203
|
-
if (inDevice.port) {
|
|
204
|
-
inDevice.port = Number(inDevice.port);
|
|
205
|
-
}
|
|
206
|
-
if (!inDevice.profile) {
|
|
207
|
-
inDevice.profile = defaultDeviceInfo.profile;
|
|
208
|
-
}
|
|
209
|
-
const resolver = this.resolver || (this.resolver = new novacom.Resolver());
|
|
210
|
-
async.series([
|
|
211
|
-
resolver.load.bind(resolver),
|
|
212
|
-
resolver.modifyDeviceFile.bind(resolver, mode, inDevice),
|
|
213
|
-
this.showDeviceList.bind(this, next)
|
|
214
|
-
], function(err) {
|
|
215
|
-
if (err) {
|
|
216
|
-
return next(err);
|
|
217
|
-
}
|
|
218
|
-
next();
|
|
219
|
-
});
|
|
220
|
-
} catch (err) {
|
|
221
|
-
next(err);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
function _getDeviceInfo(mode, next) {
|
|
226
|
-
const datas= [],
|
|
227
|
-
resolver = new novacom.Resolver();
|
|
228
|
-
async.waterfall([
|
|
229
|
-
resolver.load.bind(resolver),
|
|
230
|
-
resolver.list.bind(resolver),
|
|
231
|
-
function(devices, next) {
|
|
232
|
-
if (Array.isArray(devices)) {
|
|
233
|
-
devices.forEach(function(device) {
|
|
234
|
-
const conn = device.conn.concat([]),
|
|
235
|
-
info = (device.username && device.host && device.port) ? device.username + '@' + device.host + ':' + device.port : device.id,
|
|
236
|
-
item = {
|
|
237
|
-
profile: device.profile,
|
|
238
|
-
name: device.name,
|
|
239
|
-
default: device.default,
|
|
240
|
-
deviceinfo: {},
|
|
241
|
-
connection: device.conn || ['ssh'],
|
|
242
|
-
details: {
|
|
243
|
-
platform: device.type
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
if (conn.length === 1 && conn.indexOf('novacom') !== -1) {
|
|
248
|
-
item.deviceinfo.uid = device.id;
|
|
249
|
-
item.details.type = device.name.slice(0, 3);
|
|
250
|
-
} else {
|
|
251
|
-
item.deviceinfo = {
|
|
252
|
-
ip: device.host,
|
|
253
|
-
port: String(device.port),
|
|
254
|
-
user: device.username
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
item.details.password = device.password;
|
|
258
|
-
item.details.privatekey = device.privateKeyName;
|
|
259
|
-
item.details.passphrase = device.passphrase;
|
|
260
|
-
item.details.description = device.description;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (device.id) {
|
|
264
|
-
item.deviceinfo.uid = device.id;
|
|
265
|
-
item.details.type = device.name.slice(0, 3);
|
|
266
|
-
}
|
|
267
|
-
const data = (mode === 'full') ? item : {name: device.name, default: device.default, info:info, connection: (device.conn || 'ssh'), profile: device.profile };
|
|
268
|
-
datas.push(data);
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
next(null, datas);
|
|
272
|
-
}
|
|
273
|
-
], function(err, results) {
|
|
274
|
-
next(err, results);
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function _getParams(argv, option) {
|
|
279
|
-
let inputParams = [];
|
|
280
|
-
const params = {};
|
|
281
|
-
if (argv[option]) {
|
|
282
|
-
inputParams = [].concat(argv[option]);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (inputParams.length === 1 && inputParams[0].indexOf('{') !== -1 && inputParams[0].indexOf('}') !== -1 &&
|
|
286
|
-
((inputParams[0].split("'").length - 1) % 2) === 0) {
|
|
287
|
-
// eslint-disable-next-line no-useless-escape
|
|
288
|
-
inputParams[0] = inputParams[0].replace(/\'/g, '"');
|
|
289
|
-
}
|
|
290
|
-
inputParams.forEach(function(strParam) {
|
|
291
|
-
try {
|
|
292
|
-
const data = JSON.parse(strParam);
|
|
293
|
-
for (const k in data) {
|
|
294
|
-
params[k] = data[k];
|
|
295
|
-
}
|
|
296
|
-
} catch (err) {
|
|
297
|
-
const tokens = strParam.split('=');
|
|
298
|
-
if (tokens.length === 2) {
|
|
299
|
-
params[tokens[0]] = tokens[1];
|
|
300
|
-
log.verbose("_getParams()", "Inserting params ", tokens[0] + " = " + tokens[1]);
|
|
301
|
-
} else {
|
|
302
|
-
log.verbose("_getParams()", "Ignoring invalid arguments:", strParam);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
// FIXME : -i default=true is set as "true" string
|
|
308
|
-
if (params.default !== undefined && typeof params.default === "string") {
|
|
309
|
-
params.default = (params.default === "true");
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
log.silly("_getParams()", "params:", JSON.stringify(params));
|
|
313
|
-
return params;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function replaceDefaultDeviceInfo(inDevice) {
|
|
317
|
-
if (inDevice) {
|
|
318
|
-
inDevice.profile = inDevice.profile || defaultDeviceInfo.profile;
|
|
319
|
-
inDevice.type = inDevice.type || defaultDeviceInfo.type;
|
|
320
|
-
inDevice.host = inDevice.host || defaultDeviceInfo.host;
|
|
321
|
-
inDevice.port = inDevice.port || defaultDeviceInfo.port;
|
|
322
|
-
inDevice.username = inDevice.username || defaultDeviceInfo.username;
|
|
323
|
-
inDevice.files = inDevice.files || defaultDeviceInfo.files;
|
|
324
|
-
inDevice.description = inDevice.description || defaultDeviceInfo.description;
|
|
325
|
-
inDevice.default = inDevice.default || defaultDeviceInfo.default;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}());
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020-2024 LG Electronics Inc.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const async = require('async'),
|
|
8
|
+
chalk = require('chalk'),
|
|
9
|
+
Table = require('easy-table'),
|
|
10
|
+
npmlog = require('npmlog'),
|
|
11
|
+
Appdata = require('./cli-appdata'),
|
|
12
|
+
errHndl = require('./error-handler'),
|
|
13
|
+
novacom = require('./novacom');
|
|
14
|
+
|
|
15
|
+
(function() {
|
|
16
|
+
const log = npmlog;
|
|
17
|
+
log.heading = 'setup-device';
|
|
18
|
+
log.level = 'warn';
|
|
19
|
+
|
|
20
|
+
const appdata = new Appdata(),
|
|
21
|
+
devicetools = {},
|
|
22
|
+
defaultDeviceInfo = {
|
|
23
|
+
profile: appdata.getConfig(true).profile,
|
|
24
|
+
host: "127.0.0.1",
|
|
25
|
+
port: 22,
|
|
26
|
+
username: "root",
|
|
27
|
+
description: "new device description",
|
|
28
|
+
files: "stream",
|
|
29
|
+
default: false
|
|
30
|
+
};
|
|
31
|
+
if(defaultDeviceInfo.profile !== "ose"){
|
|
32
|
+
defaultDeviceInfo.type = "starfish";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
36
|
+
module.exports = devicetools;
|
|
37
|
+
module.exports.isValidDeviceName = isValidDeviceName;
|
|
38
|
+
module.exports.isValidIpv4 = isValidIpv4;
|
|
39
|
+
module.exports.isValidPort =isValidPort;
|
|
40
|
+
module.exports.replaceDefaultDeviceInfo = replaceDefaultDeviceInfo;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isValidDeviceName(name) {
|
|
44
|
+
const re = new RegExp("^[_a-zA-Z][a-zA-Z0-9#_-]*");
|
|
45
|
+
return (name === String(name.match(re)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isValidIpv4(host) {
|
|
49
|
+
return host === "localhost" || host.match(/^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isValidPort(port) {
|
|
53
|
+
const intPort = Number(port);
|
|
54
|
+
return Number.isInteger(intPort) && intPort > 0 && intPort <= 65535;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
devicetools.showDeviceList = function(next) {
|
|
58
|
+
async.waterfall([
|
|
59
|
+
_getDeviceInfo.bind(this, 'list'),
|
|
60
|
+
function(data, next) {
|
|
61
|
+
const table = new Table();
|
|
62
|
+
data.forEach(function(item) {
|
|
63
|
+
if (!isValidDeviceName(item.name)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
table.cell('name', (item.default === true) ? item.name + chalk.green(' (default)') : item.name);
|
|
67
|
+
table.cell('deviceinfo', item.info);
|
|
68
|
+
table.cell('connection', item.connection);
|
|
69
|
+
table.cell('profile', item.profile);
|
|
70
|
+
table.newRow();
|
|
71
|
+
});
|
|
72
|
+
next(null, table.toString());
|
|
73
|
+
}
|
|
74
|
+
], function(err, results) {
|
|
75
|
+
next(err, {msg: results});
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
devicetools.showDeviceListFull = function(next) {
|
|
80
|
+
async.waterfall([
|
|
81
|
+
_getDeviceInfo.bind(this, 'full'),
|
|
82
|
+
function(data, next) {
|
|
83
|
+
next(null, JSON.stringify(data, null, 4));
|
|
84
|
+
}
|
|
85
|
+
], function(err, results) {
|
|
86
|
+
next(err, {msg: results});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
devicetools.resetDeviceList = function(next) {
|
|
91
|
+
async.series([
|
|
92
|
+
function(next) {
|
|
93
|
+
appdata.resetDeviceList(next);
|
|
94
|
+
},
|
|
95
|
+
this.showDeviceList.bind(this, next)
|
|
96
|
+
], function(err) {
|
|
97
|
+
next(err);
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
devicetools.setDefaultDevice = function(name, next) {
|
|
102
|
+
try {
|
|
103
|
+
const resolver = this.resolver || (this.resolver = new novacom.Resolver()),
|
|
104
|
+
inDevice = {name: name, default: true};
|
|
105
|
+
async.series([
|
|
106
|
+
resolver.load.bind(resolver),
|
|
107
|
+
resolver.modifyDeviceFile.bind(resolver, 'default', inDevice),
|
|
108
|
+
this.showDeviceList.bind(this, next)
|
|
109
|
+
], function(err) {
|
|
110
|
+
if (err) {
|
|
111
|
+
return next(err);
|
|
112
|
+
}
|
|
113
|
+
next();
|
|
114
|
+
});
|
|
115
|
+
} catch (err) {
|
|
116
|
+
next(err);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
devicetools.removeDeviceInfo = function(options, next) {
|
|
121
|
+
try {
|
|
122
|
+
// For CLI
|
|
123
|
+
if (options.remove === 'true') {
|
|
124
|
+
next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
|
|
125
|
+
}
|
|
126
|
+
// For API
|
|
127
|
+
if (!options.remove) {
|
|
128
|
+
next(errHndl.getErrMsg("INVALID_REMOVE_MODE"));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const resolver = this.resolver || (this.resolver = new novacom.Resolver()),
|
|
132
|
+
inDevice = {name: options.remove, profile: defaultDeviceInfo.profile};
|
|
133
|
+
async.series([
|
|
134
|
+
resolver.load.bind(resolver),
|
|
135
|
+
resolver.modifyDeviceFile.bind(resolver, 'remove', inDevice),
|
|
136
|
+
this.showDeviceList.bind(this, next)
|
|
137
|
+
], function(err) {
|
|
138
|
+
if (err) {
|
|
139
|
+
return next(err);
|
|
140
|
+
}
|
|
141
|
+
next();
|
|
142
|
+
});
|
|
143
|
+
} catch (err) {
|
|
144
|
+
next(err);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
devicetools.modifyDeviceInfo = function(options, next) {
|
|
149
|
+
try {
|
|
150
|
+
const mode = (options.add) ? "add" : (options.modify) ? "modify" : null;
|
|
151
|
+
if (!mode) {
|
|
152
|
+
return next(errHndl.getErrMsg("INVALID_MODE"));
|
|
153
|
+
}
|
|
154
|
+
if (options[mode].match(/^-/)) {
|
|
155
|
+
return next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
|
|
156
|
+
}
|
|
157
|
+
const argName = (options.info) ? "info" : mode;
|
|
158
|
+
const inDevice = _getParams(options, argName);
|
|
159
|
+
if (!inDevice.name) {
|
|
160
|
+
if (options[mode] === "true") {
|
|
161
|
+
return next(errHndl.getErrMsg("EMPTY_VALUE", "DEVICE_NAME"));
|
|
162
|
+
}
|
|
163
|
+
inDevice.name = options[mode];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
log.info("modifyDeviceInfo()", "devicename:", inDevice.name, ", mode:", mode);
|
|
167
|
+
|
|
168
|
+
if (inDevice.default !== undefined && mode === "modify") {
|
|
169
|
+
log.verbose("modifyDeviceInfo()", "Ignoring invalid arguments:default");
|
|
170
|
+
inDevice.default = undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (inDevice.privateKey) {
|
|
174
|
+
inDevice.privatekey = inDevice.privateKey;
|
|
175
|
+
}
|
|
176
|
+
if (typeof inDevice.privatekey === "string") {
|
|
177
|
+
inDevice.privateKey = inDevice.privatekey;
|
|
178
|
+
inDevice.privateKey = { "openSsh": inDevice.privateKey };
|
|
179
|
+
delete inDevice.privatekey;
|
|
180
|
+
inDevice.password = "@DELETE@";
|
|
181
|
+
}
|
|
182
|
+
if (typeof inDevice.password !== "undefined" && inDevice.password !== "@DELETE@") {
|
|
183
|
+
inDevice.privateKey = "@DELETE@";
|
|
184
|
+
inDevice.passphrase = "@DELETE@";
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (mode === "add") {
|
|
188
|
+
replaceDefaultDeviceInfo(inDevice);
|
|
189
|
+
if (!inDevice.privateKey && !inDevice.password) {
|
|
190
|
+
inDevice.password = "";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// check validation
|
|
194
|
+
if (!isValidDeviceName(inDevice.name)) {
|
|
195
|
+
return next(errHndl.getErrMsg("INVALID_DEVICENAME"));
|
|
196
|
+
}
|
|
197
|
+
if (inDevice.host && !isValidIpv4(inDevice.host)) {
|
|
198
|
+
return next(errHndl.getErrMsg("INVALID_VALUE", "host", inDevice.host));
|
|
199
|
+
}
|
|
200
|
+
if (inDevice.port && !isValidPort(inDevice.port)) {
|
|
201
|
+
return next(errHndl.getErrMsg("INVALID_VALUE", "port", inDevice.port));
|
|
202
|
+
}
|
|
203
|
+
if (inDevice.port) {
|
|
204
|
+
inDevice.port = Number(inDevice.port);
|
|
205
|
+
}
|
|
206
|
+
if (!inDevice.profile) {
|
|
207
|
+
inDevice.profile = defaultDeviceInfo.profile;
|
|
208
|
+
}
|
|
209
|
+
const resolver = this.resolver || (this.resolver = new novacom.Resolver());
|
|
210
|
+
async.series([
|
|
211
|
+
resolver.load.bind(resolver),
|
|
212
|
+
resolver.modifyDeviceFile.bind(resolver, mode, inDevice),
|
|
213
|
+
this.showDeviceList.bind(this, next)
|
|
214
|
+
], function(err) {
|
|
215
|
+
if (err) {
|
|
216
|
+
return next(err);
|
|
217
|
+
}
|
|
218
|
+
next();
|
|
219
|
+
});
|
|
220
|
+
} catch (err) {
|
|
221
|
+
next(err);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
function _getDeviceInfo(mode, next) {
|
|
226
|
+
const datas= [],
|
|
227
|
+
resolver = new novacom.Resolver();
|
|
228
|
+
async.waterfall([
|
|
229
|
+
resolver.load.bind(resolver),
|
|
230
|
+
resolver.list.bind(resolver),
|
|
231
|
+
function(devices, next) {
|
|
232
|
+
if (Array.isArray(devices)) {
|
|
233
|
+
devices.forEach(function(device) {
|
|
234
|
+
const conn = device.conn.concat([]),
|
|
235
|
+
info = (device.username && device.host && device.port) ? device.username + '@' + device.host + ':' + device.port : device.id,
|
|
236
|
+
item = {
|
|
237
|
+
profile: device.profile,
|
|
238
|
+
name: device.name,
|
|
239
|
+
default: device.default,
|
|
240
|
+
deviceinfo: {},
|
|
241
|
+
connection: device.conn || ['ssh'],
|
|
242
|
+
details: {
|
|
243
|
+
platform: device.type
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
if (conn.length === 1 && conn.indexOf('novacom') !== -1) {
|
|
248
|
+
item.deviceinfo.uid = device.id;
|
|
249
|
+
item.details.type = device.name.slice(0, 3);
|
|
250
|
+
} else {
|
|
251
|
+
item.deviceinfo = {
|
|
252
|
+
ip: device.host,
|
|
253
|
+
port: String(device.port),
|
|
254
|
+
user: device.username
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
item.details.password = device.password;
|
|
258
|
+
item.details.privatekey = device.privateKeyName;
|
|
259
|
+
item.details.passphrase = device.passphrase;
|
|
260
|
+
item.details.description = device.description;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (device.id) {
|
|
264
|
+
item.deviceinfo.uid = device.id;
|
|
265
|
+
item.details.type = device.name.slice(0, 3);
|
|
266
|
+
}
|
|
267
|
+
const data = (mode === 'full') ? item : {name: device.name, default: device.default, info:info, connection: (device.conn || 'ssh'), profile: device.profile };
|
|
268
|
+
datas.push(data);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
next(null, datas);
|
|
272
|
+
}
|
|
273
|
+
], function(err, results) {
|
|
274
|
+
next(err, results);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function _getParams(argv, option) {
|
|
279
|
+
let inputParams = [];
|
|
280
|
+
const params = {};
|
|
281
|
+
if (argv[option]) {
|
|
282
|
+
inputParams = [].concat(argv[option]);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (inputParams.length === 1 && inputParams[0].indexOf('{') !== -1 && inputParams[0].indexOf('}') !== -1 &&
|
|
286
|
+
((inputParams[0].split("'").length - 1) % 2) === 0) {
|
|
287
|
+
// eslint-disable-next-line no-useless-escape
|
|
288
|
+
inputParams[0] = inputParams[0].replace(/\'/g, '"');
|
|
289
|
+
}
|
|
290
|
+
inputParams.forEach(function(strParam) {
|
|
291
|
+
try {
|
|
292
|
+
const data = JSON.parse(strParam);
|
|
293
|
+
for (const k in data) {
|
|
294
|
+
params[k] = data[k];
|
|
295
|
+
}
|
|
296
|
+
} catch (err) {
|
|
297
|
+
const tokens = strParam.split('=');
|
|
298
|
+
if (tokens.length === 2) {
|
|
299
|
+
params[tokens[0]] = tokens[1];
|
|
300
|
+
log.verbose("_getParams()", "Inserting params ", tokens[0] + " = " + tokens[1]);
|
|
301
|
+
} else {
|
|
302
|
+
log.verbose("_getParams()", "Ignoring invalid arguments:", strParam);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// FIXME : -i default=true is set as "true" string
|
|
308
|
+
if (params.default !== undefined && typeof params.default === "string") {
|
|
309
|
+
params.default = (params.default === "true");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
log.silly("_getParams()", "params:", JSON.stringify(params));
|
|
313
|
+
return params;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function replaceDefaultDeviceInfo(inDevice) {
|
|
317
|
+
if (inDevice) {
|
|
318
|
+
inDevice.profile = inDevice.profile || defaultDeviceInfo.profile;
|
|
319
|
+
inDevice.type = inDevice.type || defaultDeviceInfo.type;
|
|
320
|
+
inDevice.host = inDevice.host || defaultDeviceInfo.host;
|
|
321
|
+
inDevice.port = inDevice.port || defaultDeviceInfo.port;
|
|
322
|
+
inDevice.username = inDevice.username || defaultDeviceInfo.username;
|
|
323
|
+
inDevice.files = inDevice.files || defaultDeviceInfo.files;
|
|
324
|
+
inDevice.description = inDevice.description || defaultDeviceInfo.description;
|
|
325
|
+
inDevice.default = inDevice.default || defaultDeviceInfo.default;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}());
|