@alwaysai/device-agent 1.3.1 → 1.4.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/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 +6 -2
- package/lib/application-control/install.js.map +1 -1
- package/lib/application-control/models.d.ts.map +1 -1
- package/lib/application-control/models.js +4 -2
- package/lib/application-control/models.js.map +1 -1
- package/lib/application-control/status.js +4 -5
- package/lib/application-control/status.js.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +3 -3
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +114 -99
- package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts +1 -0
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +22 -4
- package/lib/cloud-connection/live-updates-handler.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/shadow-handler.d.ts +14 -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/device-control/device-control.d.ts +7 -14
- package/lib/device-control/device-control.d.ts.map +1 -1
- package/lib/device-control/device-control.js +37 -14
- package/lib/device-control/device-control.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.d.ts +105 -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 +3 -1
- package/lib/subcommands/device/clean.js.map +1 -1
- package/lib/subcommands/device/device.d.ts.map +1 -1
- package/lib/subcommands/device/device.js +14 -6
- package/lib/subcommands/device/device.js.map +1 -1
- 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/package.json +2 -2
- 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 +7 -3
- package/src/application-control/models.ts +11 -6
- package/src/application-control/status.ts +8 -8
- package/src/cloud-connection/device-agent-cloud-connection.ts +161 -131
- package/src/cloud-connection/live-updates-handler.ts +34 -6
- package/src/cloud-connection/messages.ts +3 -4
- package/src/cloud-connection/shadow-handler.test.ts +101 -84
- package/src/cloud-connection/shadow-handler.ts +275 -133
- package/src/device-control/device-control.ts +46 -19
- package/src/secure-tunneling/secure-tunneling.test.ts +1239 -0
- package/src/secure-tunneling/secure-tunneling.ts +606 -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 +4 -1
- package/src/subcommands/device/device.ts +26 -10
- package/src/util/cloud-mode-ready.ts +36 -0
- 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/src/secure-tunneling/index.ts +0 -74
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ChildProcess, spawn } from 'child_process';
|
|
2
|
+
import { JsSpawner } from 'alwaysai/lib/util';
|
|
3
|
+
import { logger } from '../util/logger';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_TIMEOUT_MS = 5000;
|
|
6
|
+
|
|
7
|
+
export async function runDetachedProcess(
|
|
8
|
+
command: string,
|
|
9
|
+
args: string[],
|
|
10
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
11
|
+
): Promise<ChildProcess> {
|
|
12
|
+
logger.debug('-> runDetachedProcess');
|
|
13
|
+
|
|
14
|
+
let isSpawned = false; // Flag to indicate if process has been successfully spawned
|
|
15
|
+
|
|
16
|
+
const child = spawn(command, args, {
|
|
17
|
+
detached: true,
|
|
18
|
+
stdio: 'ignore'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
child.unref();
|
|
22
|
+
|
|
23
|
+
// Create a promise that resolves after the specified timeout
|
|
24
|
+
const timeoutPromise = new Promise<ChildProcess>((resolve, reject) => {
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
if (!isSpawned) {
|
|
27
|
+
logger.error('Timeout spawning off detached process');
|
|
28
|
+
resolve(child); // Resolve the promise with the child process even if timeout occurs
|
|
29
|
+
}
|
|
30
|
+
}, timeoutMs);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Handle 'spawn' event
|
|
34
|
+
child.once('spawn', () => {
|
|
35
|
+
isSpawned = true;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Race between the actual process spawning and the timeout
|
|
39
|
+
await Promise.race([
|
|
40
|
+
new Promise<ChildProcess>((resolve) => {
|
|
41
|
+
if (isSpawned) {
|
|
42
|
+
resolve(child); // Resolve immediately if process has already been spawned
|
|
43
|
+
} else {
|
|
44
|
+
child.once('spawn', () => resolve(child));
|
|
45
|
+
}
|
|
46
|
+
}),
|
|
47
|
+
timeoutPromise
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
logger.debug('<- runDetachedProcess');
|
|
51
|
+
return child;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function killDetachedProcess(
|
|
55
|
+
detachedProcess: ChildProcess,
|
|
56
|
+
processName?: string[],
|
|
57
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
58
|
+
): Promise<void> {
|
|
59
|
+
logger.debug('-> killDetachedProcess');
|
|
60
|
+
return new Promise<void>((resolve, reject) => {
|
|
61
|
+
const timeout = setTimeout(() => {
|
|
62
|
+
if (processName) {
|
|
63
|
+
killDetachedProcessByName(processName, timeoutMs)
|
|
64
|
+
.then(() => resolve())
|
|
65
|
+
.catch((err) => reject(err));
|
|
66
|
+
} else {
|
|
67
|
+
reject(new Error('killDetachedProcess timeout'));
|
|
68
|
+
}
|
|
69
|
+
}, timeoutMs);
|
|
70
|
+
|
|
71
|
+
detachedProcess.on('exit', (code) => {
|
|
72
|
+
clearTimeout(timeout);
|
|
73
|
+
logger.debug(`Process exited with code ${code}`);
|
|
74
|
+
resolve();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
detachedProcess.on('error', (error) => {
|
|
78
|
+
clearTimeout(timeout);
|
|
79
|
+
if (processName) {
|
|
80
|
+
killDetachedProcessByName(processName, timeoutMs)
|
|
81
|
+
.then(() => resolve())
|
|
82
|
+
.catch((err) => reject(err));
|
|
83
|
+
} else {
|
|
84
|
+
logger.error('killDetachedProcess error occurred:', error);
|
|
85
|
+
reject(error);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
detachedProcess.kill('SIGTERM');
|
|
90
|
+
logger.debug('<- killDetachedProcess');
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function killDetachedProcessByName(
|
|
95
|
+
processName: string[],
|
|
96
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
97
|
+
): Promise<void> {
|
|
98
|
+
logger.debug('-> killDetachedProcessByName');
|
|
99
|
+
return new Promise<void>((resolve, reject) => {
|
|
100
|
+
const timeout = setTimeout(() => {
|
|
101
|
+
logger.error('Timeout waiting for process kill by name');
|
|
102
|
+
reject(new Error('killDetachedProcessByName timeout'));
|
|
103
|
+
}, timeoutMs);
|
|
104
|
+
|
|
105
|
+
JsSpawner()
|
|
106
|
+
.run({
|
|
107
|
+
exe: 'pkill',
|
|
108
|
+
args: processName
|
|
109
|
+
})
|
|
110
|
+
.then(() => {
|
|
111
|
+
clearTimeout(timeout);
|
|
112
|
+
resolve();
|
|
113
|
+
})
|
|
114
|
+
.catch((error) => {
|
|
115
|
+
clearTimeout(timeout);
|
|
116
|
+
logger.error('killDetachedProcessByName error occurred:', error);
|
|
117
|
+
reject(error);
|
|
118
|
+
})
|
|
119
|
+
.finally(() => {
|
|
120
|
+
logger.debug('<- killDetachedProcessByName');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -9,6 +9,10 @@ import { DeviceAgentCloudConnection } from '../../cloud-connection/device-agent-
|
|
|
9
9
|
import sleep from '../../util/sleep';
|
|
10
10
|
import { logger } from '../../util/logger';
|
|
11
11
|
import { assign, merge } from 'lodash';
|
|
12
|
+
import {
|
|
13
|
+
buildUpdateProjectShadowMessage,
|
|
14
|
+
getShadowTopic
|
|
15
|
+
} from '@alwaysai/device-agent-schemas';
|
|
12
16
|
|
|
13
17
|
export const getAnalyticsCfgCliLeaf = CliLeaf({
|
|
14
18
|
name: 'get-analytics-cfg',
|
|
@@ -73,21 +77,20 @@ export const setAnalyticsCfgCliLeaf = CliLeaf({
|
|
|
73
77
|
const appCfg = assign(existingAppCfg, merge(existingAppCfg, newAppCfg));
|
|
74
78
|
|
|
75
79
|
// Update the shadow as a client
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
[project]: {
|
|
81
|
-
appConfig: JSON.stringify(appCfg) // Pack app config as string as dictated by schema
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
clientToken: 'client'
|
|
80
|
+
const toDesire = {
|
|
81
|
+
[project]: {
|
|
82
|
+
appConfig: JSON.stringify(appCfg) // Pack app config as string as dictated by schema
|
|
83
|
+
}
|
|
86
84
|
};
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
deviceAgent.publisher.publish(
|
|
86
|
+
getShadowTopic(deviceAgent.getClientId(), 'projects', 'update'),
|
|
87
|
+
JSON.stringify(
|
|
88
|
+
buildUpdateProjectShadowMessage({
|
|
89
|
+
clientId: 'client',
|
|
90
|
+
desired: toDesire
|
|
91
|
+
})
|
|
92
|
+
)
|
|
89
93
|
);
|
|
90
|
-
deviceAgent.publisher.publish(topic, JSON.stringify(packet));
|
|
91
94
|
// Sleep for extra time to ensure time for shadow response
|
|
92
95
|
await sleep(10000);
|
|
93
96
|
|
|
@@ -8,6 +8,10 @@ import { EnvVars, getAllEnvs } from '../../application-control';
|
|
|
8
8
|
import { DeviceAgentCloudConnection } from '../../cloud-connection/device-agent-cloud-connection';
|
|
9
9
|
import sleep from '../../util/sleep';
|
|
10
10
|
import { logger } from '../../util/logger';
|
|
11
|
+
import {
|
|
12
|
+
buildUpdateProjectShadowMessage,
|
|
13
|
+
getShadowTopic
|
|
14
|
+
} from '@alwaysai/device-agent-schemas';
|
|
11
15
|
|
|
12
16
|
export const getAllEnvsCliLeaf = CliLeaf({
|
|
13
17
|
name: 'get-all-envs',
|
|
@@ -43,7 +47,7 @@ export const setEnvCliLeaf = CliLeaf({
|
|
|
43
47
|
})
|
|
44
48
|
},
|
|
45
49
|
async action(args, opts) {
|
|
46
|
-
const { project, service } = opts;
|
|
50
|
+
const { project: projectId, service } = opts;
|
|
47
51
|
const envVars: EnvVars = { [service]: {} };
|
|
48
52
|
args.forEach((arg: string) => {
|
|
49
53
|
const nameVal = arg.split('=');
|
|
@@ -56,26 +60,24 @@ export const setEnvCliLeaf = CliLeaf({
|
|
|
56
60
|
const deviceAgent = new DeviceAgentCloudConnection();
|
|
57
61
|
await deviceAgent.setupHandlers();
|
|
58
62
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
desired: {
|
|
64
|
-
[project]: {
|
|
65
|
-
envVars
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
clientToken: 'client'
|
|
63
|
+
const toDesire = {
|
|
64
|
+
[projectId]: {
|
|
65
|
+
envVars
|
|
66
|
+
}
|
|
70
67
|
};
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
deviceAgent.publisher.publish(
|
|
69
|
+
getShadowTopic(deviceAgent.getClientId(), 'projects', 'update'),
|
|
70
|
+
JSON.stringify(
|
|
71
|
+
buildUpdateProjectShadowMessage({
|
|
72
|
+
clientId: 'client',
|
|
73
|
+
desired: toDesire
|
|
74
|
+
})
|
|
75
|
+
)
|
|
73
76
|
);
|
|
74
|
-
deviceAgent.publisher.publish(topic, JSON.stringify(packet));
|
|
75
77
|
// Sleep for extra time to ensure time for shadow response
|
|
76
78
|
await sleep(10000);
|
|
77
79
|
|
|
78
|
-
while (deviceAgent.isCmdInProgress(
|
|
80
|
+
while (deviceAgent.isCmdInProgress(projectId)) {
|
|
79
81
|
await sleep(1000);
|
|
80
82
|
}
|
|
81
83
|
await deviceAgent.stop();
|
|
@@ -14,6 +14,11 @@ import {
|
|
|
14
14
|
import { DeviceAgentCloudConnection } from '../../cloud-connection/device-agent-cloud-connection';
|
|
15
15
|
import sleep from '../../util/sleep';
|
|
16
16
|
import { logger } from '../../util/logger';
|
|
17
|
+
import {
|
|
18
|
+
buildUpdateProjectShadowMessage,
|
|
19
|
+
getShadowTopic,
|
|
20
|
+
validateShadowProjectsUpdateAll
|
|
21
|
+
} from '@alwaysai/device-agent-schemas';
|
|
17
22
|
|
|
18
23
|
export const showAppModelsCliLeaf = CliLeaf({
|
|
19
24
|
name: 'show-models',
|
|
@@ -49,34 +54,33 @@ export const addModelCliLeaf = CliLeaf({
|
|
|
49
54
|
})
|
|
50
55
|
},
|
|
51
56
|
async action(_, opts) {
|
|
52
|
-
const { project, model, version } = opts;
|
|
57
|
+
const { project: projectId, model, version } = opts;
|
|
53
58
|
const deviceAgent = new DeviceAgentCloudConnection();
|
|
54
59
|
await deviceAgent.setupHandlers();
|
|
55
60
|
|
|
56
61
|
// Update the shadow as a client
|
|
57
|
-
const topic = deviceAgent.getShadowTopics().projects.update;
|
|
58
62
|
|
|
59
|
-
const newAppCfg = await readAppCfgFile({ projectId:
|
|
63
|
+
const newAppCfg = await readAppCfgFile({ projectId: projectId });
|
|
60
64
|
newAppCfg.models[model] = Number(version);
|
|
61
65
|
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
appConfig: JSON.stringify(newAppCfg)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
clientToken: 'client'
|
|
66
|
+
const toDesire = {
|
|
67
|
+
[projectId]: {
|
|
68
|
+
appConfig: JSON.stringify(newAppCfg)
|
|
69
|
+
}
|
|
71
70
|
};
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
deviceAgent.publisher.publish(
|
|
72
|
+
getShadowTopic(deviceAgent.getClientId(), 'projects', 'update'),
|
|
73
|
+
JSON.stringify(
|
|
74
|
+
buildUpdateProjectShadowMessage({
|
|
75
|
+
clientId: 'client',
|
|
76
|
+
desired: toDesire
|
|
77
|
+
})
|
|
78
|
+
)
|
|
74
79
|
);
|
|
75
|
-
deviceAgent.publisher.publish(topic, JSON.stringify(packet));
|
|
76
80
|
// Sleep for extra time to ensure time for shadow response
|
|
77
81
|
await sleep(10000);
|
|
78
82
|
|
|
79
|
-
while (deviceAgent.isCmdInProgress(
|
|
83
|
+
while (deviceAgent.isCmdInProgress(projectId)) {
|
|
80
84
|
await sleep(1000);
|
|
81
85
|
}
|
|
82
86
|
await deviceAgent.stop();
|
|
@@ -36,10 +36,13 @@ export const cleanCliLeaf = CliLeaf({
|
|
|
36
36
|
|
|
37
37
|
logger.debug('Checking for alwaysAI applications still running');
|
|
38
38
|
const apps = await AgentConfigFile().getApps();
|
|
39
|
+
const stopAppPromises: Promise<void>[] = [];
|
|
39
40
|
for (const app of apps) {
|
|
40
41
|
const { projectId } = app;
|
|
41
|
-
|
|
42
|
+
stopAppPromises.push(stopApp({ projectId }));
|
|
42
43
|
}
|
|
44
|
+
await Promise.all(stopAppPromises);
|
|
45
|
+
|
|
43
46
|
await safeRimraf(LOCAL_CERT_AND_KEY_DIR);
|
|
44
47
|
|
|
45
48
|
logger.debug(`Removing ${AgentConfigFile().path}`);
|
|
@@ -95,9 +95,13 @@ export const initCliLeaf = CliLeaf({
|
|
|
95
95
|
const certSpawner = JsSpawner({
|
|
96
96
|
path: BOOTSTRAP_CERTIFICATES_DIR_PATH()
|
|
97
97
|
});
|
|
98
|
+
const writeCertFilePromises: Promise<void>[] = [];
|
|
98
99
|
for (const key in response.claimCertificate) {
|
|
99
|
-
|
|
100
|
+
writeCertFilePromises.push(
|
|
101
|
+
certSpawner.writeFile(key, response.claimCertificate[key])
|
|
102
|
+
);
|
|
100
103
|
}
|
|
104
|
+
await Promise.all(writeCertFilePromises);
|
|
101
105
|
|
|
102
106
|
logger.info(`Initialized device ${name}: UUID=${response.deviceUuid}`);
|
|
103
107
|
}
|
|
@@ -112,15 +116,27 @@ export const getInfoCliLeaf = CliLeaf({
|
|
|
112
116
|
const diskDetails = await getDiskDetails();
|
|
113
117
|
const memDetails = await getMemDetails();
|
|
114
118
|
const out = {
|
|
115
|
-
'CPU Utilization':
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
'CPU Utilization': `${
|
|
120
|
+
cpuDetails?.usedPerc && cpuDetails.temperature
|
|
121
|
+
? `Used ${cpuDetails?.usedPerc?.toFixed(2)}%, Temperature ${
|
|
122
|
+
cpuDetails?.temperature
|
|
123
|
+
} °C`
|
|
124
|
+
: 'Unavailable'
|
|
125
|
+
}`,
|
|
126
|
+
'Disk Utilization': `${
|
|
127
|
+
diskDetails?.usedGb && diskDetails.freeGb
|
|
128
|
+
? `${diskDetails?.usedGb} GB / ${
|
|
129
|
+
diskDetails?.usedGb + diskDetails?.freeGb
|
|
130
|
+
} GB`
|
|
131
|
+
: 'Unavailable'
|
|
132
|
+
}`,
|
|
133
|
+
'Memory Utilization': `${
|
|
134
|
+
memDetails?.usedMb && memDetails.freeMb
|
|
135
|
+
? `${memDetails.usedMb} MB / ${
|
|
136
|
+
memDetails.usedMb + memDetails.freeMb
|
|
137
|
+
} MB`
|
|
138
|
+
: 'Unavailable'
|
|
139
|
+
}`
|
|
124
140
|
};
|
|
125
141
|
console.table(out);
|
|
126
142
|
const systemInfo = await getSystemInformation();
|
|
@@ -5,6 +5,42 @@ import {
|
|
|
5
5
|
DEVICE_CERTIFICATE_FILE_PATH
|
|
6
6
|
} from '../util/directories';
|
|
7
7
|
|
|
8
|
+
const VALID_AWS_REGIONS = [
|
|
9
|
+
// 'af-south-1', // Africa (Cape Town)
|
|
10
|
+
// 'ap-east-1', // Asia Pacific (Hong Kong)
|
|
11
|
+
// 'ap-south-2', // Asia Pacific (Hyderabad)
|
|
12
|
+
// 'ap-northeast-1', // Asia Pacific (Tokyo)
|
|
13
|
+
// 'ap-northeast-2', // Asia Pacific (Seoul)
|
|
14
|
+
// 'ap-northeast-3', // Asia Pacific (Osaka)
|
|
15
|
+
// 'ap-south-1', // Asia Pacific (Mumbai)
|
|
16
|
+
// 'ap-southeast-1', // Asia Pacific (Singapore)
|
|
17
|
+
// 'ap-southeast-2', // Asia Pacific (Sydney)
|
|
18
|
+
// 'ap-southeast-3', // Asia Pacific (Jakarta)
|
|
19
|
+
// 'ap-southeast-4', // Asia Pacific (Melbourne)
|
|
20
|
+
// 'ca-central-1', // Canada (Central)
|
|
21
|
+
// 'ca-west-1', // Canada West (Calgary)
|
|
22
|
+
// 'eu-west-2', // Europe (London)
|
|
23
|
+
// 'eu-west-3', // Europe (Paris)
|
|
24
|
+
// 'eu-central-1', // Europe (Frankfurt)
|
|
25
|
+
// 'eu-central-2', // Europe (Zurich)
|
|
26
|
+
// 'eu-north-1', // Europe (Stockholm)
|
|
27
|
+
// 'eu-south-1', // Europe (Milan)
|
|
28
|
+
// 'eu-south-2', // Europe (Spain)
|
|
29
|
+
// 'eu-west-1', // Europe (Ireland)
|
|
30
|
+
// 'il-central-1', // Israel (Tel Aviv)
|
|
31
|
+
// 'me-south-1', // Middle East (Bahrain)
|
|
32
|
+
// 'me-central-1', // Middle East (UAE)
|
|
33
|
+
// 'sa-east-1' // South America (São Paulo)
|
|
34
|
+
// 'us-east-2', // US East (Ohio)
|
|
35
|
+
// 'us-east-1', // US East (Virginia)
|
|
36
|
+
// 'us-west-1', // US West (N. California)
|
|
37
|
+
'us-west-2' // US West (Oregon)
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
export function isValidAwsRegion(region: string): boolean {
|
|
41
|
+
return VALID_AWS_REGIONS.includes(region);
|
|
42
|
+
}
|
|
43
|
+
|
|
8
44
|
export function cloudModeReady() {
|
|
9
45
|
let ready = true;
|
|
10
46
|
const requiredFiles = [
|
|
@@ -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,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
|
-
}
|