@alwaysai/device-agent 1.3.1 → 1.5.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/lib/application-control/config.js +2 -2
- package/lib/application-control/config.js.map +1 -1
- package/lib/application-control/environment-variables.d.ts.map +1 -1
- package/lib/application-control/environment-variables.js +9 -4
- package/lib/application-control/environment-variables.js.map +1 -1
- package/lib/application-control/environment-variables.test.js +1 -1
- package/lib/application-control/environment-variables.test.js.map +1 -1
- package/lib/application-control/install.d.ts.map +1 -1
- package/lib/application-control/install.js +7 -2
- package/lib/application-control/install.js.map +1 -1
- package/lib/application-control/models.d.ts +5 -0
- package/lib/application-control/models.d.ts.map +1 -1
- package/lib/application-control/models.js +28 -14
- package/lib/application-control/models.js.map +1 -1
- package/lib/application-control/status.d.ts.map +1 -1
- package/lib/application-control/status.js +14 -17
- package/lib/application-control/status.js.map +1 -1
- package/lib/application-control/utils.js +2 -2
- package/lib/application-control/utils.js.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +5 -5
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +140 -105
- package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts +4 -2
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +46 -25
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js +132 -16
- package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
- package/lib/cloud-connection/messages.d.ts.map +1 -1
- package/lib/cloud-connection/messages.js +3 -4
- package/lib/cloud-connection/messages.js.map +1 -1
- package/lib/cloud-connection/passthrough-handler.d.ts +5 -3
- package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
- package/lib/cloud-connection/passthrough-handler.js +76 -62
- package/lib/cloud-connection/passthrough-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.d.ts +16 -21
- package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
- package/lib/cloud-connection/shadow-handler.js +162 -108
- package/lib/cloud-connection/shadow-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.test.js +100 -83
- package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.d.ts +3 -0
- package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
- package/lib/cloud-connection/transaction-manager.js +11 -0
- package/lib/cloud-connection/transaction-manager.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.test.js +102 -0
- package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
- package/lib/device-control/device-control.d.ts +16 -15
- package/lib/device-control/device-control.d.ts.map +1 -1
- package/lib/device-control/device-control.js +117 -18
- package/lib/device-control/device-control.js.map +1 -1
- package/lib/docker/docker-compose.d.ts +14 -0
- package/lib/docker/docker-compose.d.ts.map +1 -0
- package/lib/docker/docker-compose.js +56 -0
- package/lib/docker/docker-compose.js.map +1 -0
- package/lib/index.js +2 -5
- package/lib/index.js.map +1 -1
- package/lib/infrastructure/agent-config.d.ts +45 -14
- package/lib/infrastructure/agent-config.d.ts.map +1 -1
- package/lib/infrastructure/agent-config.js +30 -15
- package/lib/infrastructure/agent-config.js.map +1 -1
- package/lib/infrastructure/agent-config.test.js +3 -0
- package/lib/infrastructure/agent-config.test.js.map +1 -1
- package/lib/local-connection/rabbitmq-connection.js +11 -11
- package/lib/local-connection/rabbitmq-connection.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.d.ts +97 -0
- package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -0
- package/lib/secure-tunneling/secure-tunneling.js +435 -0
- package/lib/secure-tunneling/secure-tunneling.js.map +1 -0
- package/lib/secure-tunneling/secure-tunneling.test.d.ts +2 -0
- package/lib/secure-tunneling/secure-tunneling.test.d.ts.map +1 -0
- package/lib/secure-tunneling/secure-tunneling.test.js +1070 -0
- package/lib/secure-tunneling/secure-tunneling.test.js.map +1 -0
- package/lib/secure-tunneling/spawner-detached.d.ts +6 -0
- package/lib/secure-tunneling/spawner-detached.d.ts.map +1 -0
- package/lib/secure-tunneling/spawner-detached.js +107 -0
- package/lib/secure-tunneling/spawner-detached.js.map +1 -0
- package/lib/subcommands/app/analytics.d.ts.map +1 -1
- package/lib/subcommands/app/analytics.js +9 -13
- package/lib/subcommands/app/analytics.js.map +1 -1
- package/lib/subcommands/app/env-vars.d.ts.map +1 -1
- package/lib/subcommands/app/env-vars.js +11 -16
- package/lib/subcommands/app/env-vars.js.map +1 -1
- package/lib/subcommands/app/models.d.ts.map +1 -1
- package/lib/subcommands/app/models.js +12 -16
- package/lib/subcommands/app/models.js.map +1 -1
- package/lib/subcommands/device/clean.d.ts.map +1 -1
- package/lib/subcommands/device/clean.js +8 -6
- package/lib/subcommands/device/clean.js.map +1 -1
- package/lib/subcommands/device/get-info.d.ts +2 -0
- package/lib/subcommands/device/get-info.d.ts.map +1 -0
- package/lib/subcommands/device/get-info.js +36 -0
- package/lib/subcommands/device/get-info.js.map +1 -0
- package/lib/subcommands/device/index.d.ts.map +1 -1
- package/lib/subcommands/device/index.js +11 -2
- package/lib/subcommands/device/index.js.map +1 -1
- package/lib/subcommands/device/init.d.ts +5 -0
- package/lib/subcommands/device/init.d.ts.map +1 -0
- package/lib/subcommands/device/{device.js → init.js} +5 -36
- package/lib/subcommands/device/init.js.map +1 -0
- package/lib/subcommands/device/refresh.d.ts +2 -0
- package/lib/subcommands/device/refresh.d.ts.map +1 -0
- package/lib/subcommands/device/refresh.js +24 -0
- package/lib/subcommands/device/refresh.js.map +1 -0
- package/lib/subcommands/device/restart.d.ts +2 -0
- package/lib/subcommands/device/restart.d.ts.map +1 -0
- package/lib/subcommands/device/restart.js +14 -0
- package/lib/subcommands/device/restart.js.map +1 -0
- package/lib/util/check-for-updates.d.ts +3 -0
- package/lib/util/check-for-updates.d.ts.map +1 -0
- package/lib/util/check-for-updates.js +69 -0
- package/lib/util/check-for-updates.js.map +1 -0
- package/lib/util/cloud-mode-ready.d.ts +1 -0
- package/lib/util/cloud-mode-ready.d.ts.map +1 -1
- package/lib/util/cloud-mode-ready.js +36 -1
- package/lib/util/cloud-mode-ready.js.map +1 -1
- package/lib/util/file.d.ts +7 -0
- package/lib/util/file.d.ts.map +1 -0
- package/lib/util/file.js +66 -0
- package/lib/util/file.js.map +1 -0
- package/lib/util/file.test.d.ts +2 -0
- package/lib/util/file.test.d.ts.map +1 -0
- package/lib/util/file.test.js +87 -0
- package/lib/util/file.test.js.map +1 -0
- package/package.json +8 -7
- package/readme.md +3 -3
- package/src/application-control/config.ts +1 -1
- package/src/application-control/environment-variables.test.ts +1 -1
- package/src/application-control/environment-variables.ts +9 -6
- package/src/application-control/install.ts +8 -3
- package/src/application-control/models.ts +47 -19
- package/src/application-control/status.ts +16 -14
- package/src/application-control/utils.ts +1 -1
- package/src/cloud-connection/device-agent-cloud-connection.ts +202 -148
- package/src/cloud-connection/live-updates-handler.test.ts +161 -20
- package/src/cloud-connection/live-updates-handler.ts +63 -31
- package/src/cloud-connection/messages.ts +3 -4
- package/src/cloud-connection/passthrough-handler.ts +98 -76
- package/src/cloud-connection/shadow-handler.test.ts +101 -84
- package/src/cloud-connection/shadow-handler.ts +287 -133
- package/src/cloud-connection/transaction-manager.test.ts +124 -0
- package/src/cloud-connection/transaction-manager.ts +15 -0
- package/src/device-control/device-control.ts +125 -23
- package/src/docker/docker-compose.ts +60 -0
- package/src/index.ts +2 -6
- package/src/infrastructure/agent-config.test.ts +3 -0
- package/src/infrastructure/agent-config.ts +38 -40
- package/src/local-connection/rabbitmq-connection.ts +8 -8
- package/src/secure-tunneling/secure-tunneling.test.ts +1239 -0
- package/src/secure-tunneling/secure-tunneling.ts +599 -0
- package/src/secure-tunneling/spawner-detached.ts +123 -0
- package/src/subcommands/app/analytics.ts +16 -13
- package/src/subcommands/app/env-vars.ts +18 -16
- package/src/subcommands/app/models.ts +20 -16
- package/src/subcommands/device/clean.ts +5 -2
- package/src/subcommands/device/get-info.ts +49 -0
- package/src/subcommands/device/index.ts +11 -2
- package/src/subcommands/device/{device.ts → init.ts} +5 -47
- package/src/subcommands/device/refresh.ts +22 -0
- package/src/subcommands/device/restart.ts +11 -0
- package/src/util/check-for-updates.ts +69 -0
- package/src/util/cloud-mode-ready.ts +36 -0
- package/src/util/file.test.ts +90 -0
- package/src/util/file.ts +76 -0
- package/lib/docker/docker-compose-cmd.d.ts +0 -5
- package/lib/docker/docker-compose-cmd.d.ts.map +0 -1
- package/lib/docker/docker-compose-cmd.js +0 -16
- package/lib/docker/docker-compose-cmd.js.map +0 -1
- package/lib/secure-tunneling/index.d.ts +0 -5
- package/lib/secure-tunneling/index.d.ts.map +0 -1
- package/lib/secure-tunneling/index.js +0 -64
- package/lib/secure-tunneling/index.js.map +0 -1
- package/lib/subcommands/device/device.d.ts +0 -7
- package/lib/subcommands/device/device.d.ts.map +0 -1
- package/lib/subcommands/device/device.js.map +0 -1
- package/lib/util/safe-rimraf.d.ts +0 -2
- package/lib/util/safe-rimraf.d.ts.map +0 -1
- package/lib/util/safe-rimraf.js +0 -16
- package/lib/util/safe-rimraf.js.map +0 -1
- package/src/docker/docker-compose-cmd.ts +0 -15
- package/src/secure-tunneling/index.ts +0 -74
- package/src/util/safe-rimraf.ts +0 -14
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { pruneDir } from '../../src/util/file';
|
|
2
|
+
import { readdir, stat, rmdir, unlink } from 'fs/promises';
|
|
3
|
+
|
|
4
|
+
jest.mock('fs/promises');
|
|
5
|
+
|
|
6
|
+
describe('pruneDir function', () => {
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return true if directory is successfully pruned', async () => {
|
|
12
|
+
const path = '/path/to/directory';
|
|
13
|
+
const files = ['file1.txt', 'file2.txt'];
|
|
14
|
+
(readdir as jest.Mock).mockResolvedValue(files);
|
|
15
|
+
(stat as jest.Mock).mockResolvedValue({ isDirectory: () => false });
|
|
16
|
+
|
|
17
|
+
const result = await pruneDir({ path });
|
|
18
|
+
|
|
19
|
+
expect(result).toBe(true);
|
|
20
|
+
expect(readdir).toHaveBeenCalledWith(path);
|
|
21
|
+
expect(stat).toHaveBeenCalledTimes(2); // Called for each file
|
|
22
|
+
expect(unlink).toHaveBeenCalledTimes(2); // Called for each file
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should exclude specified files from pruning', async () => {
|
|
26
|
+
const path = '/path/to/directory';
|
|
27
|
+
const files = ['file1.txt', 'file2.txt'];
|
|
28
|
+
const exclude = ['file1.txt']; // Exclude file1.txt
|
|
29
|
+
(readdir as jest.Mock).mockResolvedValue(files);
|
|
30
|
+
(stat as jest.Mock).mockResolvedValue({ isDirectory: () => false });
|
|
31
|
+
|
|
32
|
+
const result = await pruneDir({ path, exclude });
|
|
33
|
+
|
|
34
|
+
expect(result).toBe(false);
|
|
35
|
+
expect(readdir).toHaveBeenCalledWith(path);
|
|
36
|
+
expect(stat).toHaveBeenCalledTimes(1); // Called only for file2.txt
|
|
37
|
+
expect(unlink).toHaveBeenCalledTimes(1); // Called only for file2.txt
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should recursively prune directories if recurse option is true', async () => {
|
|
41
|
+
const rootPath = '/path/to/directory';
|
|
42
|
+
const subDirPath = '/path/to/directory/subdir';
|
|
43
|
+
const files = ['file1.txt', 'subdir'];
|
|
44
|
+
const subDirFiles = ['file2.txt'];
|
|
45
|
+
(readdir as jest.Mock).mockImplementation((path) => {
|
|
46
|
+
if (path === rootPath) return files;
|
|
47
|
+
if (path === subDirPath) return subDirFiles;
|
|
48
|
+
});
|
|
49
|
+
(stat as jest.Mock).mockImplementation((path) => {
|
|
50
|
+
if (path === `${rootPath}/file1.txt`) return { isDirectory: () => false };
|
|
51
|
+
if (path === subDirPath) return { isDirectory: () => true };
|
|
52
|
+
if (path === `${subDirPath}/file2.txt`)
|
|
53
|
+
return { isDirectory: () => false };
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const result = await pruneDir({ path: rootPath, recurse: true });
|
|
57
|
+
|
|
58
|
+
expect(result).toBe(true);
|
|
59
|
+
expect(readdir).toHaveBeenCalledWith(rootPath);
|
|
60
|
+
expect(readdir).toHaveBeenCalledWith(subDirPath);
|
|
61
|
+
expect(stat).toHaveBeenCalledTimes(3); // Called for file1.txt, subdir, and file2.txt
|
|
62
|
+
expect(unlink).toHaveBeenCalledWith(`${rootPath}/file1.txt`);
|
|
63
|
+
expect(unlink).toHaveBeenCalledWith(`${subDirPath}/file2.txt`);
|
|
64
|
+
expect(rmdir).toHaveBeenCalledWith(subDirPath);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should not recurse into directories if recurse option is false', async () => {
|
|
68
|
+
const rootPath = '/path/to/directory';
|
|
69
|
+
const subDirPath = '/path/to/directory/subdir';
|
|
70
|
+
const files = ['file1.txt', 'subdir'];
|
|
71
|
+
const subDirFiles = ['file2.txt'];
|
|
72
|
+
(readdir as jest.Mock).mockImplementation((path) => {
|
|
73
|
+
if (path === rootPath) return files;
|
|
74
|
+
if (path === subDirPath) return subDirFiles;
|
|
75
|
+
});
|
|
76
|
+
(stat as jest.Mock).mockImplementation((path) => {
|
|
77
|
+
if (path === `${rootPath}/file1.txt`) return { isDirectory: () => false };
|
|
78
|
+
if (path === subDirPath) return { isDirectory: () => true };
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const result = await pruneDir({ path: rootPath, recurse: false });
|
|
82
|
+
|
|
83
|
+
expect(result).toBe(true);
|
|
84
|
+
expect(readdir).toHaveBeenCalledWith(rootPath);
|
|
85
|
+
expect(stat).toHaveBeenCalledTimes(2); // Called for file1.txt and subdir
|
|
86
|
+
expect(unlink).toHaveBeenCalledWith(`${rootPath}/file1.txt`);
|
|
87
|
+
expect(unlink).not.toHaveBeenCalledWith(`${subDirPath}/file2.txt`);
|
|
88
|
+
expect(rmdir).not.toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
});
|
package/src/util/file.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { rimraf } from 'rimraf';
|
|
2
|
+
import { logger } from '../util/logger';
|
|
3
|
+
import { readdir, stat, unlink, rmdir } from 'fs/promises';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
|
|
6
|
+
export async function safeRimraf(path: string) {
|
|
7
|
+
logger.debug(`Removing ${path}`);
|
|
8
|
+
try {
|
|
9
|
+
await rimraf(path);
|
|
10
|
+
} catch (e) {
|
|
11
|
+
logger.error(
|
|
12
|
+
`Failed to remove ${path}. Please manually delete the file or directory.`
|
|
13
|
+
);
|
|
14
|
+
logger.debug(`Error removing ${path}: ${e}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function pruneDir({
|
|
19
|
+
path,
|
|
20
|
+
exclude,
|
|
21
|
+
recurse
|
|
22
|
+
}: {
|
|
23
|
+
path: string;
|
|
24
|
+
exclude?: string[];
|
|
25
|
+
recurse?: boolean;
|
|
26
|
+
}) {
|
|
27
|
+
/**
|
|
28
|
+
* Deletes all files and directories in a given directory path, excluding specific paths.
|
|
29
|
+
* Will not delete top-level directory
|
|
30
|
+
* @param {string} path path of directory to prune.
|
|
31
|
+
* @param {string[]} exclude list of paths to exclude when pruning
|
|
32
|
+
* @param {boolean} recurse flag to prune recursively into directories
|
|
33
|
+
*/
|
|
34
|
+
try {
|
|
35
|
+
const files = await readdir(path);
|
|
36
|
+
|
|
37
|
+
let canPruneParent = true;
|
|
38
|
+
|
|
39
|
+
for (const file of files) {
|
|
40
|
+
const filePath = join(path, file);
|
|
41
|
+
|
|
42
|
+
const isExcluded = exclude?.some((excludePath) =>
|
|
43
|
+
filePath.endsWith(excludePath)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (isExcluded) {
|
|
47
|
+
logger.debug(`Excluding file ${filePath} during pruning.`);
|
|
48
|
+
canPruneParent = false;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const fileStats = await stat(filePath);
|
|
53
|
+
if (fileStats.isDirectory()) {
|
|
54
|
+
if (recurse) {
|
|
55
|
+
const dirIsEmpty = await pruneDir({
|
|
56
|
+
path: filePath,
|
|
57
|
+
exclude,
|
|
58
|
+
recurse
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (dirIsEmpty) {
|
|
62
|
+
await rmdir(filePath);
|
|
63
|
+
} else {
|
|
64
|
+
canPruneParent = false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
await unlink(filePath);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return canPruneParent;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
logger.error(`Error pruning directory ${path}: ${JSON.stringify(error)}`);
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docker-compose-cmd.d.ts","sourceRoot":"","sources":["../../src/docker/docker-compose-cmd.ts"],"names":[],"mappings":"AAEA,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb,mBASA"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runDockerComposeCmd = void 0;
|
|
4
|
-
const util_1 = require("alwaysai/lib/util");
|
|
5
|
-
async function runDockerComposeCmd(props) {
|
|
6
|
-
const { args, dir } = props;
|
|
7
|
-
const spawner = (0, util_1.JsSpawner)();
|
|
8
|
-
const output = await spawner.run({
|
|
9
|
-
exe: 'docker-compose',
|
|
10
|
-
args,
|
|
11
|
-
cwd: dir
|
|
12
|
-
});
|
|
13
|
-
return output;
|
|
14
|
-
}
|
|
15
|
-
exports.runDockerComposeCmd = runDockerComposeCmd;
|
|
16
|
-
//# sourceMappingURL=docker-compose-cmd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docker-compose-cmd.js","sourceRoot":"","sources":["../../src/docker/docker-compose-cmd.ts"],"names":[],"mappings":";;;AAAA,4CAA8C;AAEvC,KAAK,UAAU,mBAAmB,CAAC,KAGzC;IACC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IAC5B,MAAM,OAAO,GAAG,IAAA,gBAAS,GAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC/B,GAAG,EAAE,gBAAgB;QACrB,IAAI;QACJ,GAAG,EAAE,GAAG;KACT,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAZD,kDAYC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/secure-tunneling/index.ts"],"names":[],"mappings":"AAcA,wBAAsB,yBAAyB,CAAC,OAAO,EAAE;IACvD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB,iBAuBA"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.secureTunnelNotifyHandler = void 0;
|
|
4
|
-
const download_file_1 = require("../util/download-file");
|
|
5
|
-
const directories_1 = require("../util/directories");
|
|
6
|
-
const paths_1 = require("alwaysai/lib/paths");
|
|
7
|
-
const util_1 = require("alwaysai/lib/util");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const logger_1 = require("../util/logger");
|
|
10
|
-
const urls_1 = require("../urls");
|
|
11
|
-
const system_info_1 = require("../util/system-info");
|
|
12
|
-
async function secureTunnelNotifyHandler(message) {
|
|
13
|
-
const { clientAccessToken, region } = message;
|
|
14
|
-
await terminateSecureTunnelProcess();
|
|
15
|
-
await downloadSecureTunnel();
|
|
16
|
-
logger_1.logger.info('Starting Secure Tunnel');
|
|
17
|
-
const args = [
|
|
18
|
-
'--destination-app',
|
|
19
|
-
'22',
|
|
20
|
-
'--region',
|
|
21
|
-
region,
|
|
22
|
-
'--capath',
|
|
23
|
-
directories_1.AWS_ROOT_CERTIFICATE_FILE_PATH,
|
|
24
|
-
'--local-bind-address',
|
|
25
|
-
'0.0.0.0',
|
|
26
|
-
'-t',
|
|
27
|
-
clientAccessToken
|
|
28
|
-
];
|
|
29
|
-
await (0, util_1.JsSpawner)().run({
|
|
30
|
-
exe: `${directories_1.SECURE_TUNNEL_BIN_PATH}`,
|
|
31
|
-
args
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
exports.secureTunnelNotifyHandler = secureTunnelNotifyHandler;
|
|
35
|
-
async function downloadSecureTunnel() {
|
|
36
|
-
const arch = await (0, system_info_1.getArch)();
|
|
37
|
-
const linuxDistro = await (0, system_info_1.getDistribution)();
|
|
38
|
-
const osVersion = await (0, system_info_1.getOsVersion)();
|
|
39
|
-
const url = `${urls_1.aaiArtifactsBucketUrl}/securetunnel/${linuxDistro}/${osVersion}/${arch}/${directories_1.SECURE_TUNNEL_BIN_NAME}`;
|
|
40
|
-
await (0, util_1.JsSpawner)().mkdirp((0, path_1.join)(paths_1.AAI_DIR, directories_1.SECURE_TUNNEL_BIN_DIR));
|
|
41
|
-
await (0, download_file_1.downloadFile)({
|
|
42
|
-
url,
|
|
43
|
-
path: directories_1.SECURE_TUNNEL_BIN_PATH,
|
|
44
|
-
errorMessage: `Secure Tunnel bin for ${linuxDistro} ${osVersion} ${arch} not found}`
|
|
45
|
-
});
|
|
46
|
-
const spawner = (0, util_1.JsSpawner)();
|
|
47
|
-
await spawner.run({
|
|
48
|
-
exe: 'chmod',
|
|
49
|
-
args: ['+x', directories_1.SECURE_TUNNEL_BIN_PATH]
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async function terminateSecureTunnelProcess() {
|
|
53
|
-
const spawner = (0, util_1.JsSpawner)();
|
|
54
|
-
try {
|
|
55
|
-
await spawner.run({
|
|
56
|
-
exe: 'pkill',
|
|
57
|
-
args: [directories_1.SECURE_TUNNEL_BIN_NAME]
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
logger_1.logger.debug('Proccess terminated if status code is 1');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/secure-tunneling/index.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AACrD,qDAK6B;AAC7B,8CAA6C;AAC7C,4CAA8C;AAC9C,+BAA4B;AAC5B,2CAAwC;AACxC,kCAAgD;AAChD,qDAA6E;AAEtE,KAAK,UAAU,yBAAyB,CAAC,OAG/C;IACC,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC9C,MAAM,4BAA4B,EAAE,CAAC;IACrC,MAAM,oBAAoB,EAAE,CAAC;IAC7B,eAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAEtC,MAAM,IAAI,GAAG;QACX,mBAAmB;QACnB,IAAI;QACJ,UAAU;QACV,MAAM;QACN,UAAU;QACV,4CAA8B;QAC9B,sBAAsB;QACtB,SAAS;QACT,IAAI;QACJ,iBAAiB;KAClB,CAAC;IAEF,MAAM,IAAA,gBAAS,GAAE,CAAC,GAAG,CAAC;QACpB,GAAG,EAAE,GAAG,oCAAsB,EAAE;QAChC,IAAI;KACL,CAAC,CAAC;AACL,CAAC;AA1BD,8DA0BC;AAED,KAAK,UAAU,oBAAoB;IACjC,MAAM,IAAI,GAAG,MAAM,IAAA,qBAAO,GAAE,CAAC;IAC7B,MAAM,WAAW,GAAG,MAAM,IAAA,6BAAe,GAAE,CAAC;IAC5C,MAAM,SAAS,GAAG,MAAM,IAAA,0BAAY,GAAE,CAAC;IAEvC,MAAM,GAAG,GAAG,GAAG,4BAAqB,iBAAiB,WAAW,IAAI,SAAS,IAAI,IAAI,IAAI,oCAAsB,EAAE,CAAC;IAElH,MAAM,IAAA,gBAAS,GAAE,CAAC,MAAM,CAAC,IAAA,WAAI,EAAC,eAAO,EAAE,mCAAqB,CAAC,CAAC,CAAC;IAC/D,MAAM,IAAA,4BAAY,EAAC;QACjB,GAAG;QACH,IAAI,EAAE,oCAAsB;QAC5B,YAAY,EAAE,yBAAyB,WAAW,IAAI,SAAS,IAAI,IAAI,aAAa;KACrF,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAA,gBAAS,GAAE,CAAC;IAC5B,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,GAAG,EAAE,OAAO;QACZ,IAAI,EAAE,CAAC,IAAI,EAAE,oCAAsB,CAAC;KACrC,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,4BAA4B;IACzC,MAAM,OAAO,GAAG,IAAA,gBAAS,GAAE,CAAC;IAC5B,IAAI;QACF,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,GAAG,EAAE,OAAO;YACZ,IAAI,EAAE,CAAC,oCAAsB,CAAC;SAC/B,CAAC,CAAC;KACJ;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;KACzD;AACH,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const initCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, {
|
|
2
|
-
name: import("@alwaysai/alwayscli").CliInput<string | undefined, false>;
|
|
3
|
-
description: import("@alwaysai/alwayscli").CliInput<string | undefined, false>;
|
|
4
|
-
}, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
|
|
5
|
-
export declare const getInfoCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, {}, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
|
|
6
|
-
export declare const restartCliLeaf: import("@alwaysai/alwayscli/lib/types").CliLeaf<import("@alwaysai/alwayscli").CliInput<undefined, false>, {}, import("@alwaysai/alwayscli").CliInput<undefined, false>>;
|
|
7
|
-
//# sourceMappingURL=device.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../../src/subcommands/device/device.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,WAAW;;;4DA6EtB,CAAC;AAEH,eAAO,MAAM,cAAc,yKA4BzB,CAAC;AAEH,eAAO,MAAM,cAAc,yKAOzB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"device.js","sourceRoot":"","sources":["../../../src/subcommands/device/device.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAC9D,+CAA8D;AAC9D,+BAAoC;AACpC,gEAAsE;AACtE,2BAAgC;AAChC,wDAA4E;AAC5E,wDAIgC;AAEhC,4CAA8C;AAC9C,wEAM6C;AAC7C,sFAAoF;AACpF,8CAA2C;AAC3C,qDAA4D;AAC5D,gGAAwF;AACxF,8CAA4D;AAE/C,QAAA,WAAW,GAAG,IAAA,mBAAO,EAAC;IACjC,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,mBAAmB;IAChC,WAAW,EAAE;QACX,IAAI,EAAE,IAAA,0BAAc,EAAC;YACnB,WAAW,EAAE,aAAa;YAC1B,QAAQ,EAAE,KAAK;SAChB,CAAC;QACF,WAAW,EAAE,IAAA,0BAAc,EAAC;YAC1B,WAAW,EAAE,oBAAoB;YACjC,QAAQ,EAAE,KAAK;SAChB,CAAC;KACH;IACD,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI;QAClB,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;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AC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,MAAM,UAAU,GAAG,MAAM,IAAA,qCAAoB,GAAE,CAAC;QAChD,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAC7B,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,CAAC,KAAK,CAAC,MAAA,UAAU,CAAC,IAAI,0CAAE,MAAM,CAAC,CAAC;QACvC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;CACF,CAAC,CAAC;AAEU,QAAA,cAAc,GAAG,IAAA,mBAAO,EAAC;IACpC,IAAI,EAAE,SAAS;IACf,WAAW,EAAE,oBAAoB;IACjC,WAAW,EAAE,EAAE;IACf,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI;QAClB,MAAM,IAAA,uBAAM,GAAE,CAAC;IACjB,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"safe-rimraf.d.ts","sourceRoot":"","sources":["../../src/util/safe-rimraf.ts"],"names":[],"mappings":"AAGA,wBAA8B,UAAU,CAAC,IAAI,EAAE,MAAM,iBAUpD"}
|
package/lib/util/safe-rimraf.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const rimraf_1 = require("rimraf");
|
|
4
|
-
const logger_1 = require("../util/logger");
|
|
5
|
-
async function safeRimraf(path) {
|
|
6
|
-
logger_1.logger.debug(`Removing ${path}`);
|
|
7
|
-
try {
|
|
8
|
-
await (0, rimraf_1.rimraf)(path);
|
|
9
|
-
}
|
|
10
|
-
catch (e) {
|
|
11
|
-
logger_1.logger.error(`Failed to remove ${path}. Please manually delete the file or directory.`);
|
|
12
|
-
logger_1.logger.debug(`Error removing ${path}: ${e}`);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.default = safeRimraf;
|
|
16
|
-
//# sourceMappingURL=safe-rimraf.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"safe-rimraf.js","sourceRoot":"","sources":["../../src/util/safe-rimraf.ts"],"names":[],"mappings":";;AAAA,mCAAgC;AAChC,2CAAwC;AAEzB,KAAK,UAAU,UAAU,CAAC,IAAY;IACnD,eAAM,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IACjC,IAAI;QACF,MAAM,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC;KACpB;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CACV,oBAAoB,IAAI,iDAAiD,CAC1E,CAAC;QACF,eAAM,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;KAC9C;AACH,CAAC;AAVD,6BAUC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { JsSpawner } from 'alwaysai/lib/util';
|
|
2
|
-
|
|
3
|
-
export async function runDockerComposeCmd(props: {
|
|
4
|
-
args: string[];
|
|
5
|
-
dir: string;
|
|
6
|
-
}) {
|
|
7
|
-
const { args, dir } = props;
|
|
8
|
-
const spawner = JsSpawner();
|
|
9
|
-
const output = await spawner.run({
|
|
10
|
-
exe: 'docker-compose',
|
|
11
|
-
args,
|
|
12
|
-
cwd: dir
|
|
13
|
-
});
|
|
14
|
-
return output;
|
|
15
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { downloadFile } from '../util/download-file';
|
|
2
|
-
import {
|
|
3
|
-
SECURE_TUNNEL_BIN_DIR,
|
|
4
|
-
SECURE_TUNNEL_BIN_PATH,
|
|
5
|
-
SECURE_TUNNEL_BIN_NAME,
|
|
6
|
-
AWS_ROOT_CERTIFICATE_FILE_PATH
|
|
7
|
-
} from '../util/directories';
|
|
8
|
-
import { AAI_DIR } from 'alwaysai/lib/paths';
|
|
9
|
-
import { JsSpawner } from 'alwaysai/lib/util';
|
|
10
|
-
import { join } from 'path';
|
|
11
|
-
import { logger } from '../util/logger';
|
|
12
|
-
import { aaiArtifactsBucketUrl } from '../urls';
|
|
13
|
-
import { getDistribution, getOsVersion, getArch } from '../util/system-info';
|
|
14
|
-
|
|
15
|
-
export async function secureTunnelNotifyHandler(message: {
|
|
16
|
-
clientAccessToken: string;
|
|
17
|
-
region: string;
|
|
18
|
-
}) {
|
|
19
|
-
const { clientAccessToken, region } = message;
|
|
20
|
-
await terminateSecureTunnelProcess();
|
|
21
|
-
await downloadSecureTunnel();
|
|
22
|
-
logger.info('Starting Secure Tunnel');
|
|
23
|
-
|
|
24
|
-
const args = [
|
|
25
|
-
'--destination-app',
|
|
26
|
-
'22',
|
|
27
|
-
'--region',
|
|
28
|
-
region,
|
|
29
|
-
'--capath',
|
|
30
|
-
AWS_ROOT_CERTIFICATE_FILE_PATH,
|
|
31
|
-
'--local-bind-address',
|
|
32
|
-
'0.0.0.0',
|
|
33
|
-
'-t',
|
|
34
|
-
clientAccessToken
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
await JsSpawner().run({
|
|
38
|
-
exe: `${SECURE_TUNNEL_BIN_PATH}`,
|
|
39
|
-
args
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function downloadSecureTunnel() {
|
|
44
|
-
const arch = await getArch();
|
|
45
|
-
const linuxDistro = await getDistribution();
|
|
46
|
-
const osVersion = await getOsVersion();
|
|
47
|
-
|
|
48
|
-
const url = `${aaiArtifactsBucketUrl}/securetunnel/${linuxDistro}/${osVersion}/${arch}/${SECURE_TUNNEL_BIN_NAME}`;
|
|
49
|
-
|
|
50
|
-
await JsSpawner().mkdirp(join(AAI_DIR, SECURE_TUNNEL_BIN_DIR));
|
|
51
|
-
await downloadFile({
|
|
52
|
-
url,
|
|
53
|
-
path: SECURE_TUNNEL_BIN_PATH,
|
|
54
|
-
errorMessage: `Secure Tunnel bin for ${linuxDistro} ${osVersion} ${arch} not found}`
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const spawner = JsSpawner();
|
|
58
|
-
await spawner.run({
|
|
59
|
-
exe: 'chmod',
|
|
60
|
-
args: ['+x', SECURE_TUNNEL_BIN_PATH]
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function terminateSecureTunnelProcess() {
|
|
65
|
-
const spawner = JsSpawner();
|
|
66
|
-
try {
|
|
67
|
-
await spawner.run({
|
|
68
|
-
exe: 'pkill',
|
|
69
|
-
args: [SECURE_TUNNEL_BIN_NAME]
|
|
70
|
-
});
|
|
71
|
-
} catch (e) {
|
|
72
|
-
logger.debug('Proccess terminated if status code is 1');
|
|
73
|
-
}
|
|
74
|
-
}
|
package/src/util/safe-rimraf.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { rimraf } from 'rimraf';
|
|
2
|
-
import { logger } from '../util/logger';
|
|
3
|
-
|
|
4
|
-
export default async function safeRimraf(path: string) {
|
|
5
|
-
logger.debug(`Removing ${path}`);
|
|
6
|
-
try {
|
|
7
|
-
await rimraf(path);
|
|
8
|
-
} catch (e) {
|
|
9
|
-
logger.error(
|
|
10
|
-
`Failed to remove ${path}. Please manually delete the file or directory.`
|
|
11
|
-
);
|
|
12
|
-
logger.debug(`Error removing ${path}: ${e}`);
|
|
13
|
-
}
|
|
14
|
-
}
|