@alwaysai/device-agent 1.4.0 → 2.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/lib/application-control/config.d.ts.map +1 -1
- package/lib/application-control/config.js +10 -5
- package/lib/application-control/config.js.map +1 -1
- package/lib/application-control/environment-variables.d.ts +1 -5
- package/lib/application-control/environment-variables.d.ts.map +1 -1
- package/lib/application-control/environment-variables.js +9 -26
- package/lib/application-control/environment-variables.js.map +1 -1
- package/lib/application-control/environment-variables.test.js +27 -7
- package/lib/application-control/environment-variables.test.js.map +1 -1
- package/lib/application-control/index.d.ts +4 -4
- package/lib/application-control/index.d.ts.map +1 -1
- package/lib/application-control/index.js +1 -4
- package/lib/application-control/index.js.map +1 -1
- package/lib/application-control/install.d.ts.map +1 -1
- package/lib/application-control/install.js +9 -7
- package/lib/application-control/install.js.map +1 -1
- package/lib/application-control/models.d.ts +5 -11
- package/lib/application-control/models.d.ts.map +1 -1
- package/lib/application-control/models.js +27 -64
- 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 +10 -12
- package/lib/application-control/status.js.map +1 -1
- package/lib/application-control/utils.d.ts +0 -4
- package/lib/application-control/utils.d.ts.map +1 -1
- package/lib/application-control/utils.js +3 -26
- package/lib/application-control/utils.js.map +1 -1
- package/lib/cloud-connection/bootstrap-provision.js +3 -2
- package/lib/cloud-connection/bootstrap-provision.js.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +11 -16
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +295 -246
- package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
- package/lib/cloud-connection/device-agent.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent.js +11 -9
- package/lib/cloud-connection/device-agent.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts +18 -27
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +58 -170
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js +76 -54
- package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
- package/lib/cloud-connection/passthrough-handler.d.ts +9 -4
- package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
- package/lib/cloud-connection/passthrough-handler.js +95 -62
- package/lib/cloud-connection/passthrough-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.d.ts +5 -1
- package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
- package/lib/cloud-connection/shadow-handler.js +63 -31
- package/lib/cloud-connection/shadow-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.test.js +45 -57
- package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
- package/lib/cloud-connection/shadow.d.ts.map +1 -1
- package/lib/cloud-connection/shadow.js +2 -1
- package/lib/cloud-connection/shadow.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.d.ts +7 -2
- package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
- package/lib/cloud-connection/transaction-manager.js +29 -29
- package/lib/cloud-connection/transaction-manager.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.test.js +105 -3
- package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
- package/lib/device-control/device-control.d.ts +14 -6
- package/lib/device-control/device-control.d.ts.map +1 -1
- package/lib/device-control/device-control.js +172 -72
- 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 +57 -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 +46 -14
- package/lib/infrastructure/agent-config.d.ts.map +1 -1
- package/lib/infrastructure/agent-config.js +36 -21
- package/lib/infrastructure/agent-config.js.map +1 -1
- package/lib/infrastructure/agent-config.test.js +6 -1
- package/lib/infrastructure/agent-config.test.js.map +1 -1
- package/lib/infrastructure/config-check-utility.d.ts +6 -0
- package/lib/infrastructure/config-check-utility.d.ts.map +1 -0
- package/lib/infrastructure/config-check-utility.js +67 -0
- package/lib/infrastructure/config-check-utility.js.map +1 -0
- package/lib/infrastructure/config-check-utility.test.d.ts +2 -0
- package/lib/infrastructure/config-check-utility.test.d.ts.map +1 -0
- package/lib/infrastructure/config-check-utility.test.js +109 -0
- package/lib/infrastructure/config-check-utility.test.js.map +1 -0
- package/lib/infrastructure/device-certificate.d.ts +10 -0
- package/lib/infrastructure/device-certificate.d.ts.map +1 -0
- package/lib/infrastructure/device-certificate.js +47 -0
- package/lib/infrastructure/device-certificate.js.map +1 -0
- package/lib/infrastructure/device-certificate.test.d.ts +2 -0
- package/lib/infrastructure/device-certificate.test.d.ts.map +1 -0
- package/lib/infrastructure/device-certificate.test.js +24 -0
- package/lib/infrastructure/device-certificate.test.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts +2 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.js +61 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-files.d.ts +75 -0
- package/lib/infrastructure/legacy-migration/legacy-files.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-files.js +75 -0
- package/lib/infrastructure/legacy-migration/legacy-files.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.d.ts +6 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.js +149 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts +2 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.js +226 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.js.map +1 -0
- package/lib/infrastructure/require-files-present-ready.test.d.ts +2 -0
- package/lib/infrastructure/require-files-present-ready.test.d.ts.map +1 -0
- package/lib/infrastructure/require-files-present-ready.test.js +44 -0
- package/lib/infrastructure/require-files-present-ready.test.js.map +1 -0
- package/lib/infrastructure/required-config-checks.d.ts +2 -0
- package/lib/infrastructure/required-config-checks.d.ts.map +1 -0
- package/lib/infrastructure/required-config-checks.js +30 -0
- package/lib/infrastructure/required-config-checks.js.map +1 -0
- package/lib/infrastructure/tokens-and-device-cfg.d.ts.map +1 -1
- package/lib/infrastructure/tokens-and-device-cfg.js +11 -8
- package/lib/infrastructure/tokens-and-device-cfg.js.map +1 -1
- package/lib/local-connection/rabbitmq-connection.d.ts.map +1 -1
- package/lib/local-connection/rabbitmq-connection.js +21 -21
- package/lib/local-connection/rabbitmq-connection.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.d.ts +15 -23
- package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.js +52 -47
- package/lib/secure-tunneling/secure-tunneling.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.test.js +29 -31
- package/lib/secure-tunneling/secure-tunneling.test.js.map +1 -1
- package/lib/subcommands/app/analytics.d.ts.map +1 -1
- package/lib/subcommands/app/analytics.js +1 -2
- package/lib/subcommands/app/analytics.js.map +1 -1
- package/lib/subcommands/app/env-vars.d.ts +4 -0
- package/lib/subcommands/app/env-vars.d.ts.map +1 -1
- package/lib/subcommands/app/env-vars.js +52 -6
- package/lib/subcommands/app/env-vars.js.map +1 -1
- package/lib/subcommands/app/index.d.ts.map +1 -1
- package/lib/subcommands/app/index.js +1 -3
- package/lib/subcommands/app/index.js.map +1 -1
- package/lib/subcommands/app/models.d.ts +0 -11
- package/lib/subcommands/app/models.d.ts.map +1 -1
- package/lib/subcommands/app/models.js +2 -58
- package/lib/subcommands/app/models.js.map +1 -1
- package/lib/subcommands/app/shadow.d.ts.map +1 -1
- package/lib/subcommands/app/shadow.js +6 -5
- package/lib/subcommands/app/shadow.js.map +1 -1
- package/lib/subcommands/app/version.d.ts.map +1 -1
- package/lib/subcommands/app/version.js +2 -4
- package/lib/subcommands/app/version.js.map +1 -1
- package/lib/subcommands/config.d.ts +2 -0
- package/lib/subcommands/config.d.ts.map +1 -0
- package/lib/subcommands/config.js +39 -0
- package/lib/subcommands/config.js.map +1 -0
- package/lib/subcommands/device/clean.d.ts +1 -1
- package/lib/subcommands/device/clean.d.ts.map +1 -1
- package/lib/subcommands/device/clean.js +25 -15
- 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 +13 -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} +10 -49
- package/lib/subcommands/device/init.js.map +1 -0
- package/lib/subcommands/device/migrate.d.ts +2 -0
- package/lib/subcommands/device/migrate.d.ts.map +1 -0
- package/lib/subcommands/device/migrate.js +24 -0
- package/lib/subcommands/device/migrate.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 +25 -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/subcommands/index.d.ts +1 -1
- package/lib/subcommands/index.d.ts.map +1 -1
- package/lib/subcommands/index.js +3 -1
- package/lib/subcommands/index.js.map +1 -1
- package/lib/subcommands/rabbitmq-connection.d.ts +1 -1
- package/lib/subcommands/rabbitmq-connection.d.ts.map +1 -1
- package/lib/util/aai-error.d.ts +12 -0
- package/lib/util/aai-error.d.ts.map +1 -0
- package/lib/util/aai-error.js +11 -0
- package/lib/util/aai-error.js.map +1 -0
- package/lib/util/aws-regions.d.ts +2 -0
- package/lib/util/aws-regions.d.ts.map +1 -0
- package/lib/util/{cloud-mode-ready.js → aws-regions.js} +2 -20
- package/lib/util/aws-regions.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 +46 -0
- package/lib/util/check-for-updates.js.map +1 -0
- package/lib/util/clean-certs.d.ts.map +1 -1
- package/lib/util/clean-certs.js +5 -4
- package/lib/util/clean-certs.js.map +1 -1
- package/lib/util/directories.d.ts +4 -18
- package/lib/util/directories.d.ts.map +1 -1
- package/lib/util/directories.js +18 -32
- package/lib/util/directories.js.map +1 -1
- package/lib/util/file.d.ts +11 -0
- package/lib/util/file.d.ts.map +1 -0
- package/lib/util/file.js +127 -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/lib/util/get-device-id.d.ts.map +1 -1
- package/lib/util/get-device-id.js +7 -1
- package/lib/util/get-device-id.js.map +1 -1
- package/lib/util/http-client.js +3 -3
- package/lib/util/http-client.js.map +1 -1
- package/package.json +22 -19
- package/readme.md +15 -35
- package/src/application-control/config.ts +10 -13
- package/src/application-control/environment-variables.test.ts +28 -7
- package/src/application-control/environment-variables.ts +13 -40
- package/src/application-control/index.ts +3 -16
- package/src/application-control/install.ts +16 -10
- package/src/application-control/models.ts +40 -98
- package/src/application-control/status.ts +9 -7
- package/src/application-control/utils.ts +1 -29
- package/src/cloud-connection/bootstrap-provision.ts +7 -7
- package/src/cloud-connection/device-agent-cloud-connection.ts +647 -509
- package/src/cloud-connection/device-agent.ts +16 -7
- package/src/cloud-connection/live-updates-handler.test.ts +137 -64
- package/src/cloud-connection/live-updates-handler.ts +103 -234
- package/src/cloud-connection/passthrough-handler.ts +134 -75
- package/src/cloud-connection/shadow-handler.test.ts +45 -57
- package/src/cloud-connection/shadow-handler.ts +114 -56
- package/src/cloud-connection/shadow.ts +4 -1
- package/src/cloud-connection/transaction-manager.test.ts +127 -3
- package/src/cloud-connection/transaction-manager.ts +68 -39
- package/src/device-control/device-control.ts +179 -72
- package/src/docker/docker-compose.ts +61 -0
- package/src/index.ts +2 -6
- package/src/infrastructure/agent-config.test.ts +9 -2
- package/src/infrastructure/agent-config.ts +45 -46
- package/src/infrastructure/config-check-utility.test.ts +154 -0
- package/src/infrastructure/config-check-utility.ts +77 -0
- package/src/infrastructure/device-certificate.test.ts +40 -0
- package/src/infrastructure/device-certificate.ts +58 -0
- package/src/infrastructure/legacy-migration/legacy-file.test.ts +88 -0
- package/src/infrastructure/legacy-migration/legacy-files.ts +101 -0
- package/src/infrastructure/legacy-migration/legacy-migration.test.ts +396 -0
- package/src/infrastructure/legacy-migration/legacy-migration.ts +229 -0
- package/src/infrastructure/require-files-present-ready.test.ts +53 -0
- package/src/infrastructure/required-config-checks.ts +33 -0
- package/src/infrastructure/tokens-and-device-cfg.ts +12 -10
- package/src/local-connection/rabbitmq-connection.ts +28 -23
- package/src/secure-tunneling/secure-tunneling.test.ts +37 -39
- package/src/secure-tunneling/secure-tunneling.ts +74 -69
- package/src/subcommands/app/analytics.ts +2 -4
- package/src/subcommands/app/env-vars.ts +72 -9
- package/src/subcommands/app/index.ts +3 -11
- package/src/subcommands/app/models.ts +5 -81
- package/src/subcommands/app/shadow.ts +6 -5
- package/src/subcommands/app/version.ts +3 -4
- package/src/subcommands/config.ts +42 -0
- package/src/subcommands/device/clean.ts +32 -18
- package/src/subcommands/device/get-info.ts +49 -0
- package/src/subcommands/device/index.ts +13 -2
- package/src/subcommands/device/{device.ts → init.ts} +11 -69
- package/src/subcommands/device/migrate.ts +20 -0
- package/src/subcommands/device/refresh.ts +23 -0
- package/src/subcommands/device/restart.ts +11 -0
- package/src/subcommands/index.ts +3 -1
- package/src/util/aai-error.ts +20 -0
- package/src/util/{cloud-mode-ready.ts → aws-regions.ts} +0 -24
- package/src/util/check-for-updates.ts +53 -0
- package/src/util/clean-certs.ts +8 -4
- package/src/util/directories.ts +23 -67
- package/src/util/file.test.ts +90 -0
- package/src/util/file.ts +156 -0
- package/src/util/get-device-id.ts +7 -7
- package/src/util/http-client.ts +2 -2
- 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/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/cloud-mode-ready.d.ts +0 -3
- package/lib/util/cloud-mode-ready.d.ts.map +0 -1
- package/lib/util/cloud-mode-ready.js.map +0 -1
- package/lib/util/download-file.d.ts +0 -6
- package/lib/util/download-file.d.ts.map +0 -1
- package/lib/util/download-file.js +0 -25
- package/lib/util/download-file.js.map +0 -1
- package/lib/util/fetch-with-timeout.d.ts +0 -4
- package/lib/util/fetch-with-timeout.d.ts.map +0 -1
- package/lib/util/fetch-with-timeout.js +0 -30
- package/lib/util/fetch-with-timeout.js.map +0 -1
- package/lib/util/parsing.d.ts +0 -2
- package/lib/util/parsing.d.ts.map +0 -1
- package/lib/util/parsing.js +0 -17
- package/lib/util/parsing.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/util/download-file.ts +0 -25
- package/src/util/fetch-with-timeout.ts +0 -35
- package/src/util/parsing.ts +0 -11
- package/src/util/safe-rimraf.ts +0 -14
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { logger } from '../util/logger';
|
|
2
|
-
import { microServiceHttpClient } from '../util/http-client';
|
|
3
|
-
import { requireLoggedInAndPaidPlan } from '../util/require-logged-in-and-paid-plan';
|
|
4
1
|
import {
|
|
5
2
|
DeviceTokens,
|
|
6
|
-
writeOrValidateDeviceCfgFile
|
|
7
|
-
writeTokens
|
|
3
|
+
writeOrValidateDeviceCfgFile
|
|
8
4
|
} from 'alwaysai/lib/core/device';
|
|
9
|
-
import {
|
|
5
|
+
import { getDeviceConfigPath } from 'alwaysai/lib/infrastructure';
|
|
10
6
|
import { LOCAL_AAI_CFG_DIR } from 'alwaysai/lib/paths';
|
|
7
|
+
import { JsSpawner } from 'alwaysai/lib/util';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
import { microServiceHttpClient } from '../util/http-client';
|
|
10
|
+
import { logger } from '../util/logger';
|
|
11
|
+
import { requireLoggedInAndPaidPlan } from '../util/require-logged-in-and-paid-plan';
|
|
11
12
|
|
|
12
13
|
// NOTE: This closely follows the flow of deviceCheckAndUpdateComponent in the CLI
|
|
13
14
|
export async function writeTokenAndDeviceCfg(props: { deviceUuid: string }) {
|
|
@@ -21,14 +22,15 @@ export async function writeTokenAndDeviceCfg(props: { deviceUuid: string }) {
|
|
|
21
22
|
);
|
|
22
23
|
|
|
23
24
|
const tokens: DeviceTokens = {
|
|
24
|
-
|
|
25
|
+
deviceUuid,
|
|
25
26
|
accessToken,
|
|
26
27
|
refreshToken,
|
|
27
28
|
idToken
|
|
28
29
|
};
|
|
29
|
-
const tokenSpawner = JsSpawner({
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const tokenSpawner = JsSpawner({
|
|
31
|
+
path: join(LOCAL_AAI_CFG_DIR, getDeviceConfigPath())
|
|
32
|
+
});
|
|
33
|
+
await writeOrValidateDeviceCfgFile({ spawner: tokenSpawner, ...tokens });
|
|
32
34
|
|
|
33
35
|
logger.info('Updated tokens and certificate');
|
|
34
36
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import sleep from '../util/sleep';
|
|
3
|
-
import compose from 'docker-compose';
|
|
1
|
+
import { JsSpawner, stringifyError } from 'alwaysai/lib/util';
|
|
4
2
|
import * as YAML from 'yaml';
|
|
5
|
-
|
|
3
|
+
import { compose } from '../docker/docker-compose';
|
|
6
4
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
getDeviceAgentConfigPath,
|
|
6
|
+
getDeviceAgentDockerComposePath
|
|
9
7
|
} from '../util/directories';
|
|
10
|
-
import {
|
|
8
|
+
import { logger } from '../util/logger';
|
|
9
|
+
import sleep from '../util/sleep';
|
|
11
10
|
import { LOCAL_CONNECTION_PORT } from './constants';
|
|
12
11
|
|
|
13
12
|
export const rabbitMQServiceName = 'alwaysAIRabbitMQ';
|
|
@@ -16,33 +15,33 @@ export const rabbitMQContainerName = 'alwaysAIRabbitMQContainer';
|
|
|
16
15
|
export async function checkRabbitMQContainerRunning() {
|
|
17
16
|
logger.debug('Checking alwaysAI Local Connection Container status');
|
|
18
17
|
const spawner = JsSpawner();
|
|
19
|
-
if (!(await spawner.exists(
|
|
18
|
+
if (!(await spawner.exists(getDeviceAgentDockerComposePath()))) {
|
|
20
19
|
logger.warn(
|
|
21
20
|
'alwaysAI Location Connection configuration file is not present'
|
|
22
21
|
);
|
|
23
22
|
return false;
|
|
24
23
|
}
|
|
25
|
-
const containerData = await compose.ps({ cwd:
|
|
26
|
-
if (
|
|
24
|
+
const containerData = await compose.ps({ cwd: getDeviceAgentConfigPath() });
|
|
25
|
+
if (containerData !== undefined) {
|
|
27
26
|
const rabbitmqService = containerData.data.services[0];
|
|
28
27
|
if (
|
|
29
|
-
rabbitmqService
|
|
30
|
-
rabbitmqService.state
|
|
28
|
+
rabbitmqService?.name === rabbitMQContainerName &&
|
|
29
|
+
rabbitmqService.state.includes('Up')
|
|
31
30
|
) {
|
|
32
|
-
logger.debug('alwaysAI Local Connection is
|
|
31
|
+
logger.debug('alwaysAI Local Connection Container is up');
|
|
33
32
|
return true;
|
|
34
33
|
}
|
|
35
|
-
logger.debug('alwaysAI Local Connection is not
|
|
34
|
+
logger.debug('alwaysAI Local Connection Container is not up');
|
|
36
35
|
return false;
|
|
37
36
|
}
|
|
38
|
-
logger.warn('alwaysAI Local Connection
|
|
37
|
+
logger.warn('alwaysAI Local Connection Container is undefined');
|
|
39
38
|
return false;
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
export async function writeRabbitMQDockerComposeFile() {
|
|
43
42
|
const spawner = JsSpawner();
|
|
44
|
-
if (!(await spawner.exists(
|
|
45
|
-
await JsSpawner().mkdirp(
|
|
43
|
+
if (!(await spawner.exists(getDeviceAgentConfigPath()))) {
|
|
44
|
+
await JsSpawner().mkdirp(getDeviceAgentConfigPath());
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
logger.debug(
|
|
@@ -68,7 +67,7 @@ export async function writeRabbitMQDockerComposeFile() {
|
|
|
68
67
|
|
|
69
68
|
const RabbitMQDockerComposeYaml = YAML.stringify(rabbitmqDockerComposeCmd);
|
|
70
69
|
await spawner.writeFile(
|
|
71
|
-
|
|
70
|
+
getDeviceAgentDockerComposePath(),
|
|
72
71
|
RabbitMQDockerComposeYaml
|
|
73
72
|
);
|
|
74
73
|
}
|
|
@@ -79,12 +78,14 @@ export async function setupRabbitMQContainer() {
|
|
|
79
78
|
await writeRabbitMQDockerComposeFile();
|
|
80
79
|
} catch (e) {
|
|
81
80
|
logger.error(
|
|
82
|
-
`An error occurred setting up docker-compose.yaml for Device Agent pass through
|
|
81
|
+
`An error occurred setting up docker-compose.yaml for Device Agent pass through!\n${stringifyError(
|
|
82
|
+
e
|
|
83
|
+
)}`
|
|
83
84
|
);
|
|
84
85
|
}
|
|
85
86
|
try {
|
|
86
87
|
const upOut = await compose.upAll({
|
|
87
|
-
cwd:
|
|
88
|
+
cwd: getDeviceAgentConfigPath()
|
|
88
89
|
});
|
|
89
90
|
logger.debug(
|
|
90
91
|
`Docker compose up for alwaysAI Local Connection:\n${JSON.stringify(
|
|
@@ -97,14 +98,16 @@ export async function setupRabbitMQContainer() {
|
|
|
97
98
|
}
|
|
98
99
|
} catch (e) {
|
|
99
100
|
logger.error(
|
|
100
|
-
`Unable to start alwaysAI Device Agent Local Connection Container
|
|
101
|
+
`Unable to start alwaysAI Device Agent Local Connection Container!\n${stringifyError(
|
|
102
|
+
e
|
|
103
|
+
)}`
|
|
101
104
|
);
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
|
|
105
108
|
export async function stopRabbitMQContainer() {
|
|
106
109
|
try {
|
|
107
|
-
const downOut = await compose.down({ cwd:
|
|
110
|
+
const downOut = await compose.down({ cwd: getDeviceAgentConfigPath() });
|
|
108
111
|
logger.debug(`Stopping alwaysAI Local Connection container`);
|
|
109
112
|
logger.debug(
|
|
110
113
|
`Docker compose down for alwaysAI Local Connection:\n${JSON.stringify(
|
|
@@ -113,7 +116,9 @@ export async function stopRabbitMQContainer() {
|
|
|
113
116
|
);
|
|
114
117
|
} catch (e) {
|
|
115
118
|
logger.error(
|
|
116
|
-
`Unable to stop alwaysAI Device Agent Local Connection Container
|
|
119
|
+
`Unable to stop alwaysAI Device Agent Local Connection Container!\n${stringifyError(
|
|
120
|
+
e
|
|
121
|
+
)}`
|
|
117
122
|
);
|
|
118
123
|
}
|
|
119
124
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SecureTunnelPortInfo,
|
|
3
|
+
SecureTunnelShadowUpdate
|
|
4
|
+
} from '@alwaysai/device-agent-schemas';
|
|
1
5
|
import { AAI_DIR } from 'alwaysai/lib/paths';
|
|
6
|
+
import { downloadToFile } from '../util/file';
|
|
7
|
+
import { ChildProcess } from 'child_process';
|
|
2
8
|
import { join } from 'path';
|
|
3
9
|
import { aaiArtifactsBucketUrl } from '../urls';
|
|
4
10
|
import {
|
|
@@ -7,18 +13,12 @@ import {
|
|
|
7
13
|
SECURE_TUNNEL_BIN_NAME,
|
|
8
14
|
SECURE_TUNNEL_BIN_PATH
|
|
9
15
|
} from '../util/directories';
|
|
10
|
-
import { downloadFile } from '../util/download-file';
|
|
11
16
|
import { getArch, getDistribution, getOsVersion } from '../util/system-info';
|
|
12
17
|
import {
|
|
13
18
|
SecureTunnelHandlerSingleton,
|
|
14
|
-
SecureTunnelPortInfo,
|
|
15
|
-
SecureTunnelShadowDesRep,
|
|
16
19
|
SecureTunnelShadowUpdateDelta
|
|
17
20
|
} from './secure-tunneling';
|
|
18
|
-
// import { JsSpawner } from 'alwaysai/lib/util/spawner';
|
|
19
|
-
import { ChildProcess } from 'child_process';
|
|
20
21
|
import { killDetachedProcess, runDetachedProcess } from './spawner-detached';
|
|
21
|
-
|
|
22
22
|
//-----------------------------------------------------------------------------
|
|
23
23
|
// mocks
|
|
24
24
|
//-----------------------------------------------------------------------------
|
|
@@ -49,9 +49,8 @@ jest.mock('../util/system-info', () => ({
|
|
|
49
49
|
getDistribution: jest.fn()
|
|
50
50
|
}));
|
|
51
51
|
|
|
52
|
-
jest.mock('../util/
|
|
53
|
-
|
|
54
|
-
}));
|
|
52
|
+
jest.mock('../util/file');
|
|
53
|
+
const mockDownloadToFile = jest.mocked(downloadToFile);
|
|
55
54
|
|
|
56
55
|
jest.mock('./spawner-detached', () => ({
|
|
57
56
|
runDetachedProcess: jest.fn(),
|
|
@@ -173,9 +172,9 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
173
172
|
|
|
174
173
|
function transformDeltaToUpdateReported(
|
|
175
174
|
deltaMsg: SecureTunnelShadowUpdateDelta
|
|
176
|
-
):
|
|
175
|
+
): SecureTunnelShadowUpdate {
|
|
177
176
|
const { version, state } = deltaMsg;
|
|
178
|
-
const reportedStateReported:
|
|
177
|
+
const reportedStateReported: SecureTunnelShadowUpdate = JSON.parse(
|
|
179
178
|
JSON.stringify(state)
|
|
180
179
|
);
|
|
181
180
|
return reportedStateReported;
|
|
@@ -671,16 +670,16 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
671
670
|
//---------------------------------------------------------------------------
|
|
672
671
|
// test secureTunnelNotifyHandler function
|
|
673
672
|
//---------------------------------------------------------------------------
|
|
674
|
-
it('should start Secure Tunnel, given
|
|
673
|
+
it('should start Secure Tunnel, given local proxy already downloaded and default shadow is not enabled, that is default SSH connection', async () => {
|
|
675
674
|
// Arrange
|
|
676
675
|
// --------------------------------------------------------------------
|
|
677
|
-
mockJsSpawner.exists.mockResolvedValueOnce(true); // mock that
|
|
676
|
+
mockJsSpawner.exists.mockResolvedValueOnce(true); // mock that local proxy already exists on file system
|
|
678
677
|
const message: SecureTunnelNotifyMsg = {
|
|
679
678
|
clientAccessToken: 'DefaultSSHConnection_001',
|
|
680
679
|
region: 'us-west-2',
|
|
681
680
|
services: ['SSH']
|
|
682
681
|
};
|
|
683
|
-
const
|
|
682
|
+
const expectedLocalProxyArgs = [
|
|
684
683
|
'--destination-app',
|
|
685
684
|
'22',
|
|
686
685
|
'--region',
|
|
@@ -705,16 +704,16 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
705
704
|
expect(getDistribution).not.toHaveBeenCalled();
|
|
706
705
|
expect(mockJsSpawner.mkdirp).not.toHaveBeenCalled();
|
|
707
706
|
expect(mockJsSpawner.run).not.toHaveBeenCalled();
|
|
708
|
-
expect(
|
|
707
|
+
expect(mockDownloadToFile).not.toHaveBeenCalled();
|
|
709
708
|
expect(runDetachedProcess).toHaveBeenCalledTimes(1);
|
|
710
709
|
expect(runDetachedProcess).toHaveBeenCalledWith(
|
|
711
710
|
SECURE_TUNNEL_BIN_PATH,
|
|
712
|
-
|
|
711
|
+
expectedLocalProxyArgs
|
|
713
712
|
);
|
|
714
713
|
expect(killDetachedProcess).not.toHaveBeenCalled();
|
|
715
714
|
});
|
|
716
715
|
|
|
717
|
-
const
|
|
716
|
+
const testCasesForDIfferentLocalProxyEnv: [string, string, string][] = [
|
|
718
717
|
// linuxDistro, osVersion, arch
|
|
719
718
|
['debian', '12', 'aarch64'],
|
|
720
719
|
['debian', '12', 'arm64'],
|
|
@@ -734,12 +733,12 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
734
733
|
['ubuntu', '23.10', 'amd64'],
|
|
735
734
|
['ubuntu', '23.10', 'arm64']
|
|
736
735
|
];
|
|
737
|
-
test.each(
|
|
738
|
-
'should start Secure Tunnel, given
|
|
736
|
+
test.each(testCasesForDIfferentLocalProxyEnv)(
|
|
737
|
+
'should start Secure Tunnel, given local proxy downloaded needed and default shadow is not enabled, that is default SSH connection',
|
|
739
738
|
async (linuxDistro: string, osVersion: string, arch: string) => {
|
|
740
739
|
// Arrange
|
|
741
740
|
// --------------------------------------------------------------------
|
|
742
|
-
mockJsSpawner.exists.mockResolvedValueOnce(false); // mock that
|
|
741
|
+
mockJsSpawner.exists.mockResolvedValueOnce(false); // mock that local proxy does not exist on file system
|
|
743
742
|
jest.mocked(getArch).mockResolvedValueOnce(arch);
|
|
744
743
|
jest.mocked(getOsVersion).mockResolvedValueOnce(osVersion);
|
|
745
744
|
jest.mocked(getDistribution).mockResolvedValueOnce(linuxDistro);
|
|
@@ -749,7 +748,7 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
749
748
|
region: 'us-west-2',
|
|
750
749
|
services: ['SSH']
|
|
751
750
|
};
|
|
752
|
-
const
|
|
751
|
+
const expectedLocalProxyArgs = [
|
|
753
752
|
'--destination-app',
|
|
754
753
|
'22',
|
|
755
754
|
'--region',
|
|
@@ -782,16 +781,15 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
782
781
|
exe: 'chmod',
|
|
783
782
|
args: ['+x', SECURE_TUNNEL_BIN_PATH]
|
|
784
783
|
});
|
|
785
|
-
expect(
|
|
786
|
-
expect(
|
|
784
|
+
expect(mockDownloadToFile).toHaveBeenCalledTimes(1);
|
|
785
|
+
expect(mockDownloadToFile).toHaveBeenCalledWith({
|
|
787
786
|
url: expectedUrl,
|
|
788
|
-
path: SECURE_TUNNEL_BIN_PATH
|
|
789
|
-
errorMessage: `Secure Tunnel bin for ${linuxDistro} ${osVersion} ${arch} not found}`
|
|
787
|
+
path: SECURE_TUNNEL_BIN_PATH
|
|
790
788
|
});
|
|
791
789
|
expect(runDetachedProcess).toHaveBeenCalledTimes(1);
|
|
792
790
|
expect(runDetachedProcess).toHaveBeenCalledWith(
|
|
793
791
|
SECURE_TUNNEL_BIN_PATH,
|
|
794
|
-
|
|
792
|
+
expectedLocalProxyArgs
|
|
795
793
|
);
|
|
796
794
|
expect(killDetachedProcess).not.toHaveBeenCalled();
|
|
797
795
|
}
|
|
@@ -891,8 +889,8 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
891
889
|
async (message) => {
|
|
892
890
|
// Arrange
|
|
893
891
|
// --------------------------------------------------------------------
|
|
894
|
-
mockJsSpawner.exists.mockResolvedValueOnce(true); // mock that
|
|
895
|
-
const
|
|
892
|
+
mockJsSpawner.exists.mockResolvedValueOnce(true); // mock that local proxy already exists on file system
|
|
893
|
+
const expectedLocalProxyArgs = [
|
|
896
894
|
'--destination-app',
|
|
897
895
|
'22',
|
|
898
896
|
'--region',
|
|
@@ -916,7 +914,7 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
916
914
|
expect(getOsVersion).not.toHaveBeenCalled();
|
|
917
915
|
expect(getDistribution).not.toHaveBeenCalled();
|
|
918
916
|
expect(mockJsSpawner.mkdirp).not.toHaveBeenCalled();
|
|
919
|
-
expect(
|
|
917
|
+
expect(mockDownloadToFile).not.toHaveBeenCalled();
|
|
920
918
|
expect(mockJsSpawner.run).not.toHaveBeenCalled();
|
|
921
919
|
expect(runDetachedProcess).not.toHaveBeenCalled();
|
|
922
920
|
expect(killDetachedProcess).not.toHaveBeenCalled();
|
|
@@ -1003,8 +1001,8 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
1003
1001
|
expect(actualReportedShadow).toEqual(updateReported);
|
|
1004
1002
|
jest.clearAllMocks(); // after setting up the shadow, we need to reset mocks again
|
|
1005
1003
|
jest.resetModules();
|
|
1006
|
-
mockJsSpawner.exists.mockResolvedValueOnce(true); // mock that
|
|
1007
|
-
const
|
|
1004
|
+
mockJsSpawner.exists.mockResolvedValueOnce(true); // mock that local proxy already exists on file system
|
|
1005
|
+
const expectedLocalProxyArgs = [
|
|
1008
1006
|
'--destination-app',
|
|
1009
1007
|
'22',
|
|
1010
1008
|
'--region',
|
|
@@ -1028,7 +1026,7 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
1028
1026
|
expect(getOsVersion).not.toHaveBeenCalled();
|
|
1029
1027
|
expect(getDistribution).not.toHaveBeenCalled();
|
|
1030
1028
|
expect(mockJsSpawner.mkdirp).not.toHaveBeenCalled();
|
|
1031
|
-
expect(
|
|
1029
|
+
expect(mockDownloadToFile).not.toHaveBeenCalled();
|
|
1032
1030
|
expect(runDetachedProcess).not.toHaveBeenCalled();
|
|
1033
1031
|
expect(killDetachedProcess).not.toHaveBeenCalled();
|
|
1034
1032
|
}
|
|
@@ -1128,8 +1126,8 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
1128
1126
|
expect(actualReportedShadow).toEqual(updateReported);
|
|
1129
1127
|
jest.clearAllMocks(); // after setting up the shadow, we need to reset mocks again
|
|
1130
1128
|
jest.resetModules();
|
|
1131
|
-
mockJsSpawner.exists.mockResolvedValueOnce(true); // mock that
|
|
1132
|
-
const
|
|
1129
|
+
mockJsSpawner.exists.mockResolvedValueOnce(true); // mock that local proxy already exists on file system
|
|
1130
|
+
const expectedLocalProxyArgs = [
|
|
1133
1131
|
'--destination-app',
|
|
1134
1132
|
expectedPortMapping,
|
|
1135
1133
|
'--region',
|
|
@@ -1153,12 +1151,12 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
1153
1151
|
expect(getOsVersion).not.toHaveBeenCalled();
|
|
1154
1152
|
expect(getDistribution).not.toHaveBeenCalled();
|
|
1155
1153
|
expect(mockJsSpawner.mkdirp).not.toHaveBeenCalled();
|
|
1156
|
-
expect(
|
|
1154
|
+
expect(mockDownloadToFile).not.toHaveBeenCalled();
|
|
1157
1155
|
expect(mockJsSpawner.run).not.toHaveBeenCalled();
|
|
1158
1156
|
expect(runDetachedProcess).toHaveBeenCalledTimes(1);
|
|
1159
1157
|
expect(runDetachedProcess).toHaveBeenCalledWith(
|
|
1160
1158
|
SECURE_TUNNEL_BIN_PATH,
|
|
1161
|
-
|
|
1159
|
+
expectedLocalProxyArgs
|
|
1162
1160
|
);
|
|
1163
1161
|
expect(killDetachedProcess).toHaveBeenCalledTimes(0);
|
|
1164
1162
|
}
|
|
@@ -1192,8 +1190,8 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
1192
1190
|
expect(beforeReportedShadow).toEqual(updateReported);
|
|
1193
1191
|
jest.clearAllMocks(); // after setting up the shadow, we need to reset mocks again
|
|
1194
1192
|
jest.resetModules();
|
|
1195
|
-
mockJsSpawner.exists.mockResolvedValueOnce(true); // mock that
|
|
1196
|
-
const
|
|
1193
|
+
mockJsSpawner.exists.mockResolvedValueOnce(true); // mock that local proxy already exists on file system
|
|
1194
|
+
const expectedLocalProxyArgs = [
|
|
1197
1195
|
'--destination-app',
|
|
1198
1196
|
expectedPortMapping,
|
|
1199
1197
|
'--region',
|
|
@@ -1228,7 +1226,7 @@ describe('SecureTunnelHandlerSingleton', () => {
|
|
|
1228
1226
|
expect(getOsVersion).not.toHaveBeenCalled();
|
|
1229
1227
|
expect(getDistribution).not.toHaveBeenCalled();
|
|
1230
1228
|
expect(mockJsSpawner.mkdirp).not.toHaveBeenCalled();
|
|
1231
|
-
expect(
|
|
1229
|
+
expect(mockDownloadToFile).not.toHaveBeenCalled();
|
|
1232
1230
|
expect(mockJsSpawner.run).not.toHaveBeenCalled();
|
|
1233
1231
|
expect(runDetachedProcess).toHaveBeenCalledTimes(0);
|
|
1234
1232
|
expect(killDetachedProcess).toHaveBeenCalledTimes(2);
|