@zerothreatai/cli 6.0.4 → 6.0.6
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/dist/src/actions/license-service.js +59 -4
- package/dist/src/commands/restart-service.js +14 -7
- package/dist/src/commands/start-setup.js +9 -1
- package/dist/src/commands/update.js +46 -0
- package/dist/src/menu.js +6 -2
- package/dist/src/services/general-api.js +35 -0
- package/dist/src/services/license-api-service.js +29 -0
- package/dist/src/utils/license-table.js +2 -1
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.firstIgnition = firstIgnition;
|
|
7
7
|
exports.licenseDeactivate = licenseDeactivate;
|
|
8
|
+
exports.updateSystemService = updateSystemService;
|
|
8
9
|
const get_mac_1 = require("../utils/get-mac");
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
10
11
|
const child_process_1 = require("child_process");
|
|
@@ -51,7 +52,7 @@ async function pullImages() {
|
|
|
51
52
|
}
|
|
52
53
|
async function runCompose(args) {
|
|
53
54
|
return new Promise((resolve, reject) => {
|
|
54
|
-
const child = (0, child_process_1.spawn)("docker", ["compose", "-f", COMPOSE_FILE, "-p", PROJECT, ...args], {
|
|
55
|
+
const child = (0, child_process_1.spawn)("docker", ["compose", "--profile", "tools", "-f", COMPOSE_FILE, "-p", PROJECT, ...args], {
|
|
55
56
|
stdio: "inherit",
|
|
56
57
|
});
|
|
57
58
|
child.on("close", code => (code === 0 ? resolve() : reject(new Error("compose failed"))));
|
|
@@ -91,12 +92,14 @@ async function firstIgnition(licenseKey, emailId) {
|
|
|
91
92
|
await ensureNetwork();
|
|
92
93
|
await pullImages();
|
|
93
94
|
await runCompose(["up", "-d"]);
|
|
94
|
-
//
|
|
95
|
-
|
|
95
|
+
//Wait for 10 minutes to allow sql server to start
|
|
96
|
+
const sqlContainerWaitSpinner = (0, ora_1.default)('Waiting for SQL Server to start...').start();
|
|
96
97
|
const SqlSuccess = await checkSqlSuccess();
|
|
97
98
|
if (!SqlSuccess) {
|
|
98
|
-
|
|
99
|
+
sqlContainerWaitSpinner.fail("Unable to complete database setup.");
|
|
100
|
+
throw new Error("Please try again later.");
|
|
99
101
|
}
|
|
102
|
+
sqlContainerWaitSpinner.succeed("connected to database.");
|
|
100
103
|
}
|
|
101
104
|
catch (error) {
|
|
102
105
|
if (spinner.isSpinning)
|
|
@@ -104,9 +107,16 @@ async function firstIgnition(licenseKey, emailId) {
|
|
|
104
107
|
throw error;
|
|
105
108
|
}
|
|
106
109
|
finally {
|
|
110
|
+
COMPOSE_FILE = "";
|
|
111
|
+
auth = {
|
|
112
|
+
username: "",
|
|
113
|
+
password: "",
|
|
114
|
+
serveraddress: "",
|
|
115
|
+
};
|
|
107
116
|
if (app_constants_1.dockerComposeAcr) {
|
|
108
117
|
const tempDir = path_1.default.dirname(app_constants_1.dockerComposeAcr);
|
|
109
118
|
fs_1.default.rmSync(tempDir, { recursive: true, force: true });
|
|
119
|
+
(0, app_constants_1.setDockerComposeAcr)('');
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
return token;
|
|
@@ -155,3 +165,48 @@ async function licenseDeactivate() {
|
|
|
155
165
|
console.log(chalk_1.default.redBright(`DeactivateLicense error: ${err.message}`));
|
|
156
166
|
}
|
|
157
167
|
}
|
|
168
|
+
async function updateSystemService() {
|
|
169
|
+
const licenseApi = new license_api_service_1.default();
|
|
170
|
+
const spinner = (0, ora_1.default)('Verifying your subscription…').start();
|
|
171
|
+
try {
|
|
172
|
+
// Fetch update from compose file
|
|
173
|
+
await licenseApi.getSystemUpdate();
|
|
174
|
+
// verify system and get update token (acr token)
|
|
175
|
+
const dockerAuth = await licenseApi.verifySystemForUpdate(app_constants_1.fingerPrint);
|
|
176
|
+
spinner.succeed('Subscription verified.');
|
|
177
|
+
auth = dockerAuth;
|
|
178
|
+
if (app_constants_1.dockerComposeAcr) {
|
|
179
|
+
COMPOSE_FILE = app_constants_1.dockerComposeAcr;
|
|
180
|
+
}
|
|
181
|
+
console.log(">> Setting up application ...");
|
|
182
|
+
await ensureNetwork();
|
|
183
|
+
await pullImages();
|
|
184
|
+
await runCompose(["up", "-d"]);
|
|
185
|
+
//Wait for 10 minutes to allow sql server to start
|
|
186
|
+
const sqlContainerWaitSpinner = (0, ora_1.default)('Waiting for SQL Server to start...').start();
|
|
187
|
+
const SqlSuccess = await checkSqlSuccess();
|
|
188
|
+
if (!SqlSuccess) {
|
|
189
|
+
sqlContainerWaitSpinner.fail("Unable to complete database setup.");
|
|
190
|
+
throw new Error("Unable to complete database setup. Please try again later.");
|
|
191
|
+
}
|
|
192
|
+
sqlContainerWaitSpinner.succeed("connected to database.");
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (spinner.isSpinning)
|
|
196
|
+
spinner.fail(chalk_1.default.red('Verification failed. Please check your details.'));
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
COMPOSE_FILE = "";
|
|
201
|
+
auth = {
|
|
202
|
+
username: "",
|
|
203
|
+
password: "",
|
|
204
|
+
serveraddress: "",
|
|
205
|
+
};
|
|
206
|
+
if (app_constants_1.dockerComposeAcr) {
|
|
207
|
+
const tempDir = path_1.default.dirname(app_constants_1.dockerComposeAcr);
|
|
208
|
+
fs_1.default.rmSync(tempDir, { recursive: true, force: true });
|
|
209
|
+
(0, app_constants_1.setDockerComposeAcr)('');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -40,7 +40,7 @@ async function cleanupContainersFromCompose(composeFilePath) {
|
|
|
40
40
|
async function runCompose() {
|
|
41
41
|
await cleanupContainersFromCompose(app_constants_1.dockerComposeAcr);
|
|
42
42
|
return new Promise((resolve, reject) => {
|
|
43
|
-
const child = (0, child_process_2.spawn)("docker", ["compose", "-f", app_constants_1.dockerComposeAcr, "up", "-d"], {
|
|
43
|
+
const child = (0, child_process_2.spawn)("docker", ["compose", "-f", app_constants_1.dockerComposeAcr, "-p", PROJECT, "up", "-d"], {
|
|
44
44
|
stdio: ["ignore", "ignore", "pipe"],
|
|
45
45
|
});
|
|
46
46
|
child.on("close", code => (code === 0 ? resolve() : reject(new Error("compose failed"))));
|
|
@@ -98,23 +98,30 @@ async function restartService() {
|
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
// Up the docker images
|
|
101
|
+
const TIMEOUT_MS = 2 * 60 * 1000;
|
|
102
|
+
const containerTimeout = setTimeout(() => {
|
|
103
|
+
throw new Error('TIMEOUT: Taking more time to restart, Please try again later');
|
|
104
|
+
}, TIMEOUT_MS);
|
|
101
105
|
try {
|
|
102
|
-
const TIMEOUT_MS = 2 * 60 * 1000;
|
|
103
|
-
const containerTimeout = setTimeout(() => {
|
|
104
|
-
throw new Error('TIMEOUT: Taking more time to restart, Please try again later');
|
|
105
|
-
}, TIMEOUT_MS);
|
|
106
106
|
dockerUpSpinner.start();
|
|
107
107
|
await runCompose();
|
|
108
|
-
clearTimeout(containerTimeout);
|
|
109
108
|
dockerUpSpinner.succeed('Containers are up and running. 🐳🚀');
|
|
110
109
|
console.log(chalk_1.default.gray('➤ You can now continue using ZeroThreat on this url : '));
|
|
111
110
|
console.log(chalk_1.default.bold.blue('http://localhost:3203'));
|
|
112
111
|
}
|
|
113
112
|
catch (error) {
|
|
114
113
|
if (dockerUpSpinner.isSpinning)
|
|
115
|
-
dockerUpSpinner.fail(chalk_1.default.red('Container spin-up failed. 🐳💥'));
|
|
114
|
+
dockerUpSpinner.fail(chalk_1.default.red('Something went wrong Container spin-up failed. 🐳💥'));
|
|
116
115
|
console.log(chalk_1.default.red(error));
|
|
117
116
|
}
|
|
117
|
+
finally {
|
|
118
|
+
clearTimeout(containerTimeout);
|
|
119
|
+
if (app_constants_1.dockerComposeAcr) {
|
|
120
|
+
const tempDir = path_1.default.dirname(app_constants_1.dockerComposeAcr);
|
|
121
|
+
fs_1.default.rmSync(tempDir, { recursive: true, force: true });
|
|
122
|
+
(0, app_constants_1.setDockerComposeAcr)('');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
118
125
|
return;
|
|
119
126
|
}
|
|
120
127
|
;
|
|
@@ -11,6 +11,7 @@ const activate_1 = __importDefault(require("./activate"));
|
|
|
11
11
|
const acr_error_1 = __importDefault(require("../utils/acr-error"));
|
|
12
12
|
const acr_token_service_1 = __importDefault(require("../services/acr-token-service"));
|
|
13
13
|
const app_constants_1 = require("../constants/app-constants");
|
|
14
|
+
const general_api_1 = __importDefault(require("../services/general-api"));
|
|
14
15
|
const validateEmail = (email) => {
|
|
15
16
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
16
17
|
return emailRegex.test(email);
|
|
@@ -26,6 +27,10 @@ const deleteAcr = () => {
|
|
|
26
27
|
acrTokenService.deleteAcrToken(app_constants_1.deleteAcrToken).catch(() => { });
|
|
27
28
|
return;
|
|
28
29
|
};
|
|
30
|
+
const completeProcess = () => {
|
|
31
|
+
const generalService = new general_api_1.default();
|
|
32
|
+
generalService.completeImagePullUp().catch(() => { });
|
|
33
|
+
};
|
|
29
34
|
async function startSetup() {
|
|
30
35
|
console.log("\nActivating License...\n");
|
|
31
36
|
let email;
|
|
@@ -46,9 +51,9 @@ async function startSetup() {
|
|
|
46
51
|
let token = '';
|
|
47
52
|
try {
|
|
48
53
|
token = await (0, license_service_1.firstIgnition)(licenseKey, email);
|
|
54
|
+
completeProcess();
|
|
49
55
|
}
|
|
50
56
|
catch (err) {
|
|
51
|
-
deleteAcr();
|
|
52
57
|
if (err instanceof acr_error_1.default) {
|
|
53
58
|
console.log(chalk_1.default.red(`Error : ${err.message}`));
|
|
54
59
|
return;
|
|
@@ -57,6 +62,9 @@ async function startSetup() {
|
|
|
57
62
|
console.error(chalk_1.default.yellowBright(`Please Retry.`));
|
|
58
63
|
return;
|
|
59
64
|
}
|
|
65
|
+
finally {
|
|
66
|
+
deleteAcr();
|
|
67
|
+
}
|
|
60
68
|
// License Activation call
|
|
61
69
|
try {
|
|
62
70
|
console.log("Setting up your license ...");
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.updateSystem = updateSystem;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const acr_error_1 = __importDefault(require("../utils/acr-error"));
|
|
9
|
+
const acr_token_service_1 = __importDefault(require("../services/acr-token-service"));
|
|
10
|
+
const app_constants_1 = require("../constants/app-constants");
|
|
11
|
+
const license_service_1 = require("../actions/license-service");
|
|
12
|
+
const general_api_1 = __importDefault(require("../services/general-api"));
|
|
13
|
+
const deleteAcr = async () => {
|
|
14
|
+
// Acr token Delete
|
|
15
|
+
const acrTokenService = new acr_token_service_1.default();
|
|
16
|
+
if (app_constants_1.deleteAcrToken)
|
|
17
|
+
acrTokenService.deleteAcrToken(app_constants_1.deleteAcrToken).catch(() => { });
|
|
18
|
+
(0, app_constants_1.setDeleteAcrToken)('');
|
|
19
|
+
return;
|
|
20
|
+
};
|
|
21
|
+
const completeProcess = async () => {
|
|
22
|
+
const generalService = new general_api_1.default();
|
|
23
|
+
await generalService.completeImagePullUp().catch(() => { });
|
|
24
|
+
return;
|
|
25
|
+
};
|
|
26
|
+
async function updateSystem() {
|
|
27
|
+
console.log(chalk_1.default.greenBright("\nUpdating ZeroThreat...\n"));
|
|
28
|
+
try {
|
|
29
|
+
await (0, license_service_1.updateSystemService)();
|
|
30
|
+
await completeProcess();
|
|
31
|
+
console.log(chalk_1.default.greenBright("\nZeroThreat updated successfully.\n"));
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err instanceof acr_error_1.default) {
|
|
35
|
+
console.log(chalk_1.default.red(`Error : ${err.message}`));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
console.error(chalk_1.default.redBright(`Error : ${err.message}`));
|
|
39
|
+
console.error(chalk_1.default.yellowBright(`Please Retry.`));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
await deleteAcr();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
;
|
package/dist/src/menu.js
CHANGED
|
@@ -10,6 +10,7 @@ const start_setup_1 = require("./commands/start-setup");
|
|
|
10
10
|
const deactivate_1 = __importDefault(require("./commands/deactivate"));
|
|
11
11
|
const install_docker_1 = require("./commands/install-docker");
|
|
12
12
|
const restart_service_1 = require("./commands/restart-service");
|
|
13
|
+
const update_1 = require("./commands/update");
|
|
13
14
|
async function showMenu() {
|
|
14
15
|
console.clear();
|
|
15
16
|
// Header with description
|
|
@@ -54,8 +55,8 @@ async function showMenu() {
|
|
|
54
55
|
value: "Deactivate License"
|
|
55
56
|
},
|
|
56
57
|
{
|
|
57
|
-
name: chalk_1.default.yellow("⬆️ Update
|
|
58
|
-
value: "Update
|
|
58
|
+
name: chalk_1.default.yellow("⬆️ Update Application"),
|
|
59
|
+
value: "Update System",
|
|
59
60
|
},
|
|
60
61
|
{
|
|
61
62
|
name: chalk_1.default.white("❌ Exit"),
|
|
@@ -81,6 +82,9 @@ async function showMenu() {
|
|
|
81
82
|
case "Restart":
|
|
82
83
|
await (0, restart_service_1.restartService)();
|
|
83
84
|
break;
|
|
85
|
+
case "Update System":
|
|
86
|
+
await (0, update_1.updateSystem)();
|
|
87
|
+
break;
|
|
84
88
|
default:
|
|
85
89
|
console.log("Exiting...");
|
|
86
90
|
console.clear();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LicenseType = exports.LicenseStatus = void 0;
|
|
7
|
+
const api_service_1 = __importDefault(require("./api-service"));
|
|
8
|
+
const api_config_1 = require("../config/api-config");
|
|
9
|
+
var LicenseStatus;
|
|
10
|
+
(function (LicenseStatus) {
|
|
11
|
+
LicenseStatus[LicenseStatus["Active"] = 1] = "Active";
|
|
12
|
+
LicenseStatus[LicenseStatus["Expired"] = 2] = "Expired";
|
|
13
|
+
LicenseStatus[LicenseStatus["InActive"] = 3] = "InActive";
|
|
14
|
+
LicenseStatus[LicenseStatus["ClaimRequested"] = 4] = "ClaimRequested";
|
|
15
|
+
LicenseStatus[LicenseStatus["Revoked"] = 5] = "Revoked";
|
|
16
|
+
})(LicenseStatus || (exports.LicenseStatus = LicenseStatus = {}));
|
|
17
|
+
var LicenseType;
|
|
18
|
+
(function (LicenseType) {
|
|
19
|
+
LicenseType[LicenseType["FreeCreditUniversal"] = 0] = "FreeCreditUniversal";
|
|
20
|
+
LicenseType[LicenseType["FreeCreditHostnameSpecific"] = 1] = "FreeCreditHostnameSpecific";
|
|
21
|
+
LicenseType[LicenseType["PaidCredit"] = 2] = "PaidCredit";
|
|
22
|
+
LicenseType[LicenseType["SubscriptionCredit"] = 3] = "SubscriptionCredit";
|
|
23
|
+
})(LicenseType || (exports.LicenseType = LicenseType = {}));
|
|
24
|
+
class onpremGeneralServices extends api_service_1.default {
|
|
25
|
+
constructor() {
|
|
26
|
+
super({
|
|
27
|
+
baseURL: new URL((0, api_config_1.API_CONFIG)().licenseApi).origin,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//remove
|
|
31
|
+
async completeImagePullUp() {
|
|
32
|
+
return this.post(`/api/on-prem/release/update/completed`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.default = onpremGeneralServices;
|
|
@@ -13,6 +13,7 @@ const os_1 = __importDefault(require("os"));
|
|
|
13
13
|
const crypto_1 = __importDefault(require("crypto"));
|
|
14
14
|
const app_constants_1 = require("../constants/app-constants");
|
|
15
15
|
const execute_js_1 = require("../utils/execute-js");
|
|
16
|
+
const acr_error_1 = __importDefault(require("../utils/acr-error"));
|
|
16
17
|
var LicenseStatus;
|
|
17
18
|
(function (LicenseStatus) {
|
|
18
19
|
LicenseStatus[LicenseStatus["Active"] = 1] = "Active";
|
|
@@ -93,5 +94,33 @@ class LicenseApiService extends api_service_1.default {
|
|
|
93
94
|
async verifySignature(encryptedFingerprint) {
|
|
94
95
|
return this.post('/verify-signature', { encryptedFingerprint });
|
|
95
96
|
}
|
|
97
|
+
async getSystemUpdate() {
|
|
98
|
+
try {
|
|
99
|
+
const response = await this.get('system/provision');
|
|
100
|
+
const decodedDockerComposeAcr = Buffer.from(response.dockerComposeAcr, 'base64').toString('utf-8');
|
|
101
|
+
const randomDir = crypto_1.default.randomBytes(8).toString('hex');
|
|
102
|
+
const randomFileName = crypto_1.default.randomBytes(8).toString('hex') + '.yml';
|
|
103
|
+
const tempDir = path_1.default.join(os_1.default.tmpdir(), randomDir);
|
|
104
|
+
fs_1.default.mkdirSync(tempDir, { recursive: true });
|
|
105
|
+
const filePath = path_1.default.join(tempDir, randomFileName);
|
|
106
|
+
fs_1.default.writeFileSync(filePath, decodedDockerComposeAcr);
|
|
107
|
+
(0, app_constants_1.setDockerComposeAcr)(filePath);
|
|
108
|
+
// fingerprint fetcher
|
|
109
|
+
const executableProggram = response.fingerprintScript;
|
|
110
|
+
const identity = await (0, execute_js_1.executeJS)(executableProggram);
|
|
111
|
+
(0, app_constants_1.setfingerPrint)(identity);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error(error);
|
|
115
|
+
throw new acr_error_1.default(`${error.message}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async verifySystemForUpdate(encryptedFingerprint) {
|
|
119
|
+
const response = await this.post('verify-and-get-registry-credentials', { encryptedFingerprint });
|
|
120
|
+
const deletionToken = response.deletionToken;
|
|
121
|
+
(0, app_constants_1.setDeleteAcrToken)(deletionToken);
|
|
122
|
+
const { registry, username, password } = response.tokenInfo;
|
|
123
|
+
return { username, password, serveraddress: registry };
|
|
124
|
+
}
|
|
96
125
|
}
|
|
97
126
|
exports.default = LicenseApiService;
|