@zerothreatai/cli 4.0.0 → 6.0.0
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/commands/install-docker.js +1 -0
- package/dist/src/commands/start-setup.js +15 -2
- package/dist/src/commands/system-check.js +57 -0
- package/dist/src/constants/app-constants.js +6 -6
- package/dist/src/services/acr-token-service.js +4 -2
- package/dist/src/services/api-service.js +10 -1
- package/dist/src/services/license-api-service.js +0 -1
- package/package.json +1 -1
|
@@ -9,6 +9,8 @@ const ask_que_1 = require("../utils/ask-que");
|
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
10
|
const activate_1 = __importDefault(require("./activate"));
|
|
11
11
|
const acr_error_1 = __importDefault(require("../utils/acr-error"));
|
|
12
|
+
const acr_token_service_1 = __importDefault(require("../services/acr-token-service"));
|
|
13
|
+
const app_constants_1 = require("../constants/app-constants");
|
|
12
14
|
const validateEmail = (email) => {
|
|
13
15
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
14
16
|
return emailRegex.test(email);
|
|
@@ -17,6 +19,16 @@ const validateLicenseKey = (key) => {
|
|
|
17
19
|
const licenseRegex = /^[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}$/;
|
|
18
20
|
return licenseRegex.test(key);
|
|
19
21
|
};
|
|
22
|
+
const deleteAcr = () => {
|
|
23
|
+
// Acr token Delete
|
|
24
|
+
const acrTokenService = new acr_token_service_1.default();
|
|
25
|
+
try {
|
|
26
|
+
if (app_constants_1.acrTokenName)
|
|
27
|
+
acrTokenService.deleteAcrToken(app_constants_1.acrTokenName);
|
|
28
|
+
}
|
|
29
|
+
catch { }
|
|
30
|
+
return;
|
|
31
|
+
};
|
|
20
32
|
async function startSetup() {
|
|
21
33
|
console.log("\nActivating License...\n");
|
|
22
34
|
let email;
|
|
@@ -39,6 +51,7 @@ async function startSetup() {
|
|
|
39
51
|
token = await (0, license_service_1.firstIgnition)(licenseKey, email);
|
|
40
52
|
}
|
|
41
53
|
catch (err) {
|
|
54
|
+
deleteAcr();
|
|
42
55
|
if (err instanceof acr_error_1.default) {
|
|
43
56
|
console.log(chalk_1.default.red(`Error : ${err.message}`));
|
|
44
57
|
return;
|
|
@@ -51,11 +64,11 @@ async function startSetup() {
|
|
|
51
64
|
try {
|
|
52
65
|
console.log("Setting up your license ...");
|
|
53
66
|
await (0, activate_1.default)(token);
|
|
54
|
-
return;
|
|
55
67
|
}
|
|
56
68
|
catch (err) {
|
|
57
69
|
console.error(chalk_1.default.redBright(err));
|
|
58
|
-
return;
|
|
59
70
|
}
|
|
71
|
+
deleteAcr();
|
|
72
|
+
return;
|
|
60
73
|
}
|
|
61
74
|
;
|
|
@@ -0,0 +1,57 @@
|
|
|
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.SysteCheck = SysteCheck;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const util_1 = require("util");
|
|
9
|
+
const ask_que_1 = require("../utils/ask-que");
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
12
|
+
async function SysteCheck() {
|
|
13
|
+
try {
|
|
14
|
+
// Check OS
|
|
15
|
+
const platform = process.platform;
|
|
16
|
+
if (platform !== 'linux') {
|
|
17
|
+
console.log('Error: Linux/Ubuntu is required for this installation.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// Check if Docker is available
|
|
21
|
+
try {
|
|
22
|
+
await execAsync('docker --version');
|
|
23
|
+
console.log(chalk_1.default.greenBright.bold('✓ System requirements are met. Docker is already installed.'));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
console.log(chalk_1.default.red('Docker is not installed.'));
|
|
28
|
+
}
|
|
29
|
+
// Ask user permission to install Docker
|
|
30
|
+
const answer = await (0, ask_que_1.ask)(chalk_1.default.yellowBright.bold('Do you want to install Docker? (yes/no): '));
|
|
31
|
+
if (answer.toLowerCase() !== 'yes' && answer.toLowerCase() !== 'y') {
|
|
32
|
+
console.log('Installation cancelled.');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
console.log(chalk_1.default.bold('Installing Docker...'));
|
|
36
|
+
const commands = [
|
|
37
|
+
'sudo apt update',
|
|
38
|
+
'sudo apt install apt-transport-https ca-certificates curl software-properties-common -y',
|
|
39
|
+
'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg',
|
|
40
|
+
'echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null',
|
|
41
|
+
'sudo apt update',
|
|
42
|
+
'sudo apt install docker-ce -y',
|
|
43
|
+
'sudo usermod -aG docker ${USER}',
|
|
44
|
+
];
|
|
45
|
+
for (const cmd of commands) {
|
|
46
|
+
console.log(`Running: ${cmd}`);
|
|
47
|
+
await execAsync(cmd);
|
|
48
|
+
}
|
|
49
|
+
// Check if Docker is available
|
|
50
|
+
await execAsync('docker --version');
|
|
51
|
+
console.log(chalk_1.default.greenBright.bold('✓ System requirements are met. ✓ Docker installed successfully.'));
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error(chalk_1.default.redBright.bold('Error during system check:', error));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.isLicenseClaimed = false;
|
|
3
|
+
exports.setAcrTokenName = exports.setDockerComposeAcr = exports.acrTokenName = exports.dockerComposeAcr = void 0;
|
|
5
4
|
exports.dockerComposeAcr = '';
|
|
6
|
-
|
|
7
|
-
exports.isLicenseClaimed = value;
|
|
8
|
-
};
|
|
9
|
-
exports.setLicenseClaimed = setLicenseClaimed;
|
|
5
|
+
exports.acrTokenName = '';
|
|
10
6
|
const setDockerComposeAcr = (value) => {
|
|
11
7
|
exports.dockerComposeAcr = value;
|
|
12
8
|
};
|
|
13
9
|
exports.setDockerComposeAcr = setDockerComposeAcr;
|
|
10
|
+
const setAcrTokenName = (value) => {
|
|
11
|
+
exports.acrTokenName = value;
|
|
12
|
+
};
|
|
13
|
+
exports.setAcrTokenName = setAcrTokenName;
|
|
@@ -17,7 +17,6 @@ class AcrTokenService extends api_service_1.default {
|
|
|
17
17
|
constructor() {
|
|
18
18
|
super({
|
|
19
19
|
baseURL: (0, api_config_1.API_CONFIG)().onPremLicenseCloudeApi,
|
|
20
|
-
timeout: 15000,
|
|
21
20
|
});
|
|
22
21
|
}
|
|
23
22
|
async getAcrToken(licenseKey, emailId, systemId) {
|
|
@@ -29,7 +28,6 @@ class AcrTokenService extends api_service_1.default {
|
|
|
29
28
|
});
|
|
30
29
|
const api = axios_1.default.create({
|
|
31
30
|
httpsAgent,
|
|
32
|
-
timeout: 15000,
|
|
33
31
|
headers: { "Content-Type": "application/json" },
|
|
34
32
|
});
|
|
35
33
|
const response = await this.post('/acr-token', {
|
|
@@ -48,6 +46,7 @@ class AcrTokenService extends api_service_1.default {
|
|
|
48
46
|
fs_1.default.writeFileSync(filePath, decodedDockerComposeAcr);
|
|
49
47
|
(0, app_constants_1.setDockerComposeAcr)(filePath);
|
|
50
48
|
}
|
|
49
|
+
(0, app_constants_1.setAcrTokenName)(username);
|
|
51
50
|
return {
|
|
52
51
|
dockerAuth: {
|
|
53
52
|
username,
|
|
@@ -61,5 +60,8 @@ class AcrTokenService extends api_service_1.default {
|
|
|
61
60
|
throw new acr_error_1.default(`${error.message}`);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
63
|
+
async deleteAcrToken(acrTokenName) {
|
|
64
|
+
await this.put(`/acr-token/delete?acrTokenName=${acrTokenName}`, {});
|
|
65
|
+
}
|
|
64
66
|
}
|
|
65
67
|
exports.default = AcrTokenService;
|
|
@@ -11,7 +11,7 @@ class ApiService {
|
|
|
11
11
|
constructor(config) {
|
|
12
12
|
this.client = axios_1.default.create({
|
|
13
13
|
baseURL: config.baseURL,
|
|
14
|
-
timeout: config.timeout ||
|
|
14
|
+
timeout: config.timeout || 0,
|
|
15
15
|
headers: {
|
|
16
16
|
'Content-Type': 'application/json',
|
|
17
17
|
},
|
|
@@ -38,6 +38,15 @@ class ApiService {
|
|
|
38
38
|
throw this.handleError(error);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
async put(endpoint, data) {
|
|
42
|
+
try {
|
|
43
|
+
const response = await this.client.put(endpoint, data);
|
|
44
|
+
return response.data;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw this.handleError(error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
41
50
|
handleError(error) {
|
|
42
51
|
if (error.response) {
|
|
43
52
|
return new Error(`${error.response.data?.message || 'Unknown error'}`);
|