@alwaysai/device-agent 1.5.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 +8 -3
- 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 +8 -7
- package/lib/application-control/install.js.map +1 -1
- package/lib/application-control/models.d.ts +0 -11
- package/lib/application-control/models.d.ts.map +1 -1
- package/lib/application-control/models.js +5 -54
- package/lib/application-control/models.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 +1 -24
- 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 +10 -15
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +279 -250
- 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 -28
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +54 -169
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js +71 -165
- package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
- package/lib/cloud-connection/passthrough-handler.d.ts +4 -1
- package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
- package/lib/cloud-connection/passthrough-handler.js +30 -11
- package/lib/cloud-connection/passthrough-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.d.ts +5 -3
- package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
- package/lib/cloud-connection/shadow-handler.js +59 -27
- 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 +4 -2
- package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
- package/lib/cloud-connection/transaction-manager.js +18 -29
- package/lib/cloud-connection/transaction-manager.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.test.js +3 -3
- package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
- package/lib/device-control/device-control.d.ts +8 -8
- package/lib/device-control/device-control.d.ts.map +1 -1
- package/lib/device-control/device-control.js +95 -71
- package/lib/device-control/device-control.js.map +1 -1
- package/lib/docker/docker-compose.d.ts.map +1 -1
- package/lib/docker/docker-compose.js +2 -1
- package/lib/docker/docker-compose.js.map +1 -1
- package/lib/infrastructure/agent-config.d.ts +2 -1
- package/lib/infrastructure/agent-config.d.ts.map +1 -1
- package/lib/infrastructure/agent-config.js +7 -7
- package/lib/infrastructure/agent-config.js.map +1 -1
- package/lib/infrastructure/agent-config.test.js +3 -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 +14 -14
- package/lib/local-connection/rabbitmq-connection.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.d.ts +9 -9
- package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.js +21 -16
- package/lib/secure-tunneling/secure-tunneling.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.test.js +11 -13
- 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 +23 -13
- package/lib/subcommands/device/clean.js.map +1 -1
- package/lib/subcommands/device/index.d.ts.map +1 -1
- package/lib/subcommands/device/index.js +3 -1
- package/lib/subcommands/device/index.js.map +1 -1
- package/lib/subcommands/device/init.js +8 -8
- package/lib/subcommands/device/init.js.map +1 -1
- 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.map +1 -1
- package/lib/subcommands/device/refresh.js +1 -0
- package/lib/subcommands/device/refresh.js.map +1 -1
- 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.map +1 -1
- package/lib/util/check-for-updates.js +5 -28
- package/lib/util/check-for-updates.js.map +1 -1
- 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 +4 -0
- package/lib/util/file.d.ts.map +1 -1
- package/lib/util/file.js +65 -4
- package/lib/util/file.js.map +1 -1
- 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 +19 -17
- package/readme.md +12 -32
- package/src/application-control/config.ts +9 -12
- 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 +15 -10
- package/src/application-control/models.ts +6 -87
- package/src/application-control/utils.ts +0 -28
- package/src/cloud-connection/bootstrap-provision.ts +7 -7
- package/src/cloud-connection/device-agent-cloud-connection.ts +639 -525
- package/src/cloud-connection/device-agent.ts +16 -7
- package/src/cloud-connection/live-updates-handler.test.ts +121 -189
- package/src/cloud-connection/live-updates-handler.ts +99 -234
- package/src/cloud-connection/passthrough-handler.ts +55 -18
- package/src/cloud-connection/shadow-handler.test.ts +45 -57
- package/src/cloud-connection/shadow-handler.ts +103 -57
- package/src/cloud-connection/shadow.ts +4 -1
- package/src/cloud-connection/transaction-manager.test.ts +3 -3
- package/src/cloud-connection/transaction-manager.ts +53 -39
- package/src/device-control/device-control.ts +102 -70
- package/src/docker/docker-compose.ts +3 -2
- package/src/infrastructure/agent-config.test.ts +6 -2
- package/src/infrastructure/agent-config.ts +8 -7
- 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 +22 -17
- package/src/secure-tunneling/secure-tunneling.test.ts +20 -22
- package/src/secure-tunneling/secure-tunneling.ts +41 -29
- 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 +31 -17
- package/src/subcommands/device/index.ts +3 -1
- package/src/subcommands/device/init.ts +11 -11
- package/src/subcommands/device/migrate.ts +20 -0
- package/src/subcommands/device/refresh.ts +1 -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 +14 -30
- package/src/util/clean-certs.ts +8 -4
- package/src/util/directories.ts +23 -67
- package/src/util/file.ts +83 -3
- package/src/util/get-device-id.ts +7 -7
- package/src/util/http-client.ts +2 -2
- 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/src/util/download-file.ts +0 -25
- package/src/util/fetch-with-timeout.ts +0 -35
- package/src/util/parsing.ts +0 -11
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { DeviceConfigFile } from 'alwaysai/lib/core/device';
|
|
2
|
+
import {
|
|
3
|
+
DEVICE_CONFIG_FILE_NAME,
|
|
4
|
+
LocalAaiCfg,
|
|
5
|
+
LocalDeviceCertificates,
|
|
6
|
+
getDeviceConfigPath
|
|
7
|
+
} from 'alwaysai/lib/infrastructure';
|
|
8
|
+
import { exists, stringifyError } from 'alwaysai/lib/util';
|
|
9
|
+
import { join } from 'path';
|
|
10
|
+
import { logger } from '../util/logger';
|
|
11
|
+
|
|
12
|
+
export const validConfigMessage = 'Device config is present and valid.';
|
|
13
|
+
|
|
14
|
+
export async function checkDeviceConfigPresent(
|
|
15
|
+
baseDir?: string
|
|
16
|
+
): Promise<boolean> {
|
|
17
|
+
logger.debug('Checking for required device configuraton file.');
|
|
18
|
+
const deviceConfig = DeviceConfigFile(
|
|
19
|
+
baseDir
|
|
20
|
+
? join(baseDir, getDeviceConfigPath(), DEVICE_CONFIG_FILE_NAME)
|
|
21
|
+
: undefined
|
|
22
|
+
);
|
|
23
|
+
if (deviceConfig.exists()) {
|
|
24
|
+
try {
|
|
25
|
+
deviceConfig.read();
|
|
26
|
+
logger.debug(validConfigMessage);
|
|
27
|
+
return true;
|
|
28
|
+
} catch (e) {
|
|
29
|
+
logger.debug(stringifyError(e));
|
|
30
|
+
logger.debug(`${JSON.stringify(deviceConfig.getErrors(), null, 2)}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function checkCertificatesPresent(baseDir?: string) {
|
|
37
|
+
logger.debug('Checking for required certificates.');
|
|
38
|
+
const deviceCertificates = new LocalDeviceCertificates(baseDir);
|
|
39
|
+
|
|
40
|
+
const certificateFilesPresent = await checkAllFilesArePresent([
|
|
41
|
+
deviceCertificates.getCertificateFilePath(),
|
|
42
|
+
deviceCertificates.getPrivateKeyFilePath(),
|
|
43
|
+
deviceCertificates.getRootCertificateFilePath()
|
|
44
|
+
]);
|
|
45
|
+
return certificateFilesPresent;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function checkAaiConfigPresent(
|
|
49
|
+
baseDir?: string
|
|
50
|
+
): Promise<boolean> {
|
|
51
|
+
logger.debug('Checking for required alwaysai configuraton file.');
|
|
52
|
+
const localAaiCfg = new LocalAaiCfg(baseDir);
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
await localAaiCfg.readAaiCfgFile();
|
|
56
|
+
logger.debug(validConfigMessage);
|
|
57
|
+
return true;
|
|
58
|
+
} catch (e) {
|
|
59
|
+
logger.debug(stringifyError(e));
|
|
60
|
+
logger.debug(
|
|
61
|
+
`${JSON.stringify(localAaiCfg.getValidationErrors(), null, 2)}`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function checkAllFilesArePresent(requiredFiles: string[]) {
|
|
68
|
+
for (const path of requiredFiles) {
|
|
69
|
+
logger.debug(`Checking if file ${path} is present`);
|
|
70
|
+
if (!(await exists(path))) {
|
|
71
|
+
logger.debug(`${path} not present.`);
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
logger.debug('All files are present');
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LocalDeviceCertificates,
|
|
3
|
+
getDeviceConfigPath,
|
|
4
|
+
getLocalDeviceConfigDirectoryPath
|
|
5
|
+
} from 'alwaysai/lib/infrastructure';
|
|
6
|
+
import { LOCAL_AAI_CFG_DIR } from 'alwaysai/lib/paths';
|
|
7
|
+
import { join } from 'path';
|
|
8
|
+
import {
|
|
9
|
+
getBootstrapCertificateDirectoryPath,
|
|
10
|
+
getBootstrapCertificateFileName,
|
|
11
|
+
getBootstrapIDFileName,
|
|
12
|
+
getBootstrapPrivateKeyFileName
|
|
13
|
+
} from './device-certificate';
|
|
14
|
+
|
|
15
|
+
describe('test different bootstrap certificate file paths', () => {
|
|
16
|
+
it('test bootstrap certificate directory paths and filenames', async () => {
|
|
17
|
+
const boostrapDir = getBootstrapCertificateDirectoryPath();
|
|
18
|
+
const mainConfigDir = getLocalDeviceConfigDirectoryPath();
|
|
19
|
+
const certificates = new LocalDeviceCertificates();
|
|
20
|
+
const mainCertDir = certificates.getCertificateDirectoryPath();
|
|
21
|
+
expect(mainConfigDir).toEqual(
|
|
22
|
+
join(LOCAL_AAI_CFG_DIR, getDeviceConfigPath())
|
|
23
|
+
);
|
|
24
|
+
expect(mainCertDir).toEqual(
|
|
25
|
+
join(LOCAL_AAI_CFG_DIR, getDeviceConfigPath(), 'certificates')
|
|
26
|
+
);
|
|
27
|
+
expect(boostrapDir).toEqual(join(mainCertDir, 'bootstrap-certificates'));
|
|
28
|
+
|
|
29
|
+
const boostrapCertFileName = getBootstrapCertificateFileName();
|
|
30
|
+
expect(boostrapCertFileName).toEqual('aai-claim-cert_prod.pem.crt');
|
|
31
|
+
|
|
32
|
+
const boostrapIDFileName = getBootstrapIDFileName();
|
|
33
|
+
expect(boostrapIDFileName).toEqual('aai-claim-cert-id_prod.txt');
|
|
34
|
+
|
|
35
|
+
const boostrapPrivateKeyFileName = getBootstrapPrivateKeyFileName();
|
|
36
|
+
expect(boostrapPrivateKeyFileName).toEqual(
|
|
37
|
+
'aai-claim-private-key_prod.pem.key'
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEVICE_CERTIFICATES_DIRECTORY_NAME,
|
|
3
|
+
getDeviceConfigPath,
|
|
4
|
+
getLocalDeviceConfigDirectoryPath
|
|
5
|
+
} from 'alwaysai/lib/infrastructure';
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
import { shortenSystemId } from '../util/directories';
|
|
8
|
+
|
|
9
|
+
/*===================================================================
|
|
10
|
+
Bootstrap Certificates
|
|
11
|
+
===================================================================*/
|
|
12
|
+
|
|
13
|
+
export const BOOTSTRAP_DIR_NAME = 'bootstrap-certificates';
|
|
14
|
+
|
|
15
|
+
export function getBootstrapPrivateKeyFileName() {
|
|
16
|
+
return `aai-claim-private-key_${shortenSystemId()}.pem.key`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getBootstrapCertificateFileName() {
|
|
20
|
+
return `aai-claim-cert_${shortenSystemId()}.pem.crt`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getBootstrapIDFileName() {
|
|
24
|
+
return `aai-claim-cert-id_${shortenSystemId()}.txt`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const CERTIFICATE_OWNERSHIP_TOKEN_FILE_NAME =
|
|
28
|
+
'certificate-ownership-token.txt';
|
|
29
|
+
|
|
30
|
+
export function getBootstrapCertificateDirectoryPath(baseDir?) {
|
|
31
|
+
const LOCAL_DEVICE_DIRECTORY_PATH = baseDir
|
|
32
|
+
? join(baseDir, getDeviceConfigPath())
|
|
33
|
+
: getLocalDeviceConfigDirectoryPath();
|
|
34
|
+
const bootstrapCertificateDirectoryPath = join(
|
|
35
|
+
LOCAL_DEVICE_DIRECTORY_PATH, // {homedir}/.config/alwaysai/device{systemId},
|
|
36
|
+
DEVICE_CERTIFICATES_DIRECTORY_NAME, // certificates
|
|
37
|
+
BOOTSTRAP_DIR_NAME // bootstrap-certificates
|
|
38
|
+
);
|
|
39
|
+
return bootstrapCertificateDirectoryPath;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getBootstrapPrivateKeyFilePath() {
|
|
43
|
+
return join(
|
|
44
|
+
getBootstrapCertificateDirectoryPath(),
|
|
45
|
+
getBootstrapPrivateKeyFileName()
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getBootstrapCertificateFilePath() {
|
|
50
|
+
return join(
|
|
51
|
+
getBootstrapCertificateDirectoryPath(),
|
|
52
|
+
getBootstrapCertificateFileName()
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function getBootstrapIDFilePath() {
|
|
57
|
+
return join(getBootstrapCertificateDirectoryPath(), getBootstrapIDFileName());
|
|
58
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ConfigFileSchemaReturnType } from '@alwaysai/config-nodejs/lib/config-file-schema';
|
|
2
|
+
import {
|
|
3
|
+
AaiConfig,
|
|
4
|
+
DEVICE_CERTIFICATES_DIRECTORY_NAME
|
|
5
|
+
} from 'alwaysai/lib/infrastructure';
|
|
6
|
+
import {
|
|
7
|
+
ALWAYSAI_CONFIG_FILE_NAME,
|
|
8
|
+
DEVICE_TOKEN_FILE_NAME
|
|
9
|
+
} from 'alwaysai/lib/paths';
|
|
10
|
+
import { JsSpawner } from 'alwaysai/lib/util';
|
|
11
|
+
import { join } from 'path';
|
|
12
|
+
import { rimraf } from 'rimraf';
|
|
13
|
+
import * as tempy from 'tempy';
|
|
14
|
+
import { AGENT_CONFIG_FILE_NAME } from '../agent-config';
|
|
15
|
+
import {
|
|
16
|
+
LegacyAaiConfig,
|
|
17
|
+
LegacyAaiConfigFile,
|
|
18
|
+
LegacyFiles
|
|
19
|
+
} from './legacy-files';
|
|
20
|
+
|
|
21
|
+
describe('test LegacyFiles function', () => {
|
|
22
|
+
let tmpDir;
|
|
23
|
+
tmpDir = tempy.directory();
|
|
24
|
+
|
|
25
|
+
beforeAll(async () => {
|
|
26
|
+
jest.resetModules();
|
|
27
|
+
jest.clearAllMocks();
|
|
28
|
+
tmpDir = tempy.directory();
|
|
29
|
+
});
|
|
30
|
+
afterAll(async () => {
|
|
31
|
+
await rimraf(tmpDir);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('test LegacyAaiConfigFile', async () => {
|
|
35
|
+
const deviceId = '123-4567-8910-1234';
|
|
36
|
+
const systemId = 'production';
|
|
37
|
+
const aaiConfig: LegacyAaiConfig = {
|
|
38
|
+
systemId: systemId,
|
|
39
|
+
deviceUuid: deviceId
|
|
40
|
+
};
|
|
41
|
+
const spawner = JsSpawner({ path: tmpDir });
|
|
42
|
+
await spawner.writeFile(
|
|
43
|
+
join(tmpDir, ALWAYSAI_CONFIG_FILE_NAME),
|
|
44
|
+
JSON.stringify(aaiConfig)
|
|
45
|
+
);
|
|
46
|
+
const legacyAaiConfig = LegacyAaiConfigFile(tmpDir);
|
|
47
|
+
const parsedAaiConfig = legacyAaiConfig.read();
|
|
48
|
+
expect(parsedAaiConfig.deviceUuid).toEqual(deviceId);
|
|
49
|
+
expect(parsedAaiConfig.systemId).toEqual(systemId);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('test invalid LegacyAaiConfigFile', async () => {
|
|
53
|
+
const deviceId = '123-4567-8910-1234';
|
|
54
|
+
const invalidAaiConfig = {
|
|
55
|
+
deviceUuid: deviceId
|
|
56
|
+
};
|
|
57
|
+
const spawner = JsSpawner({ path: tmpDir });
|
|
58
|
+
await spawner.writeFile(
|
|
59
|
+
join(tmpDir, ALWAYSAI_CONFIG_FILE_NAME),
|
|
60
|
+
JSON.stringify(invalidAaiConfig)
|
|
61
|
+
);
|
|
62
|
+
const legacyAaiConfig = LegacyAaiConfigFile(tmpDir);
|
|
63
|
+
expect(() => {
|
|
64
|
+
legacyAaiConfig.read();
|
|
65
|
+
}).toThrowError();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('test LegacyFiles with baseDir return values', async () => {
|
|
69
|
+
const legacyFiles = LegacyFiles(tmpDir);
|
|
70
|
+
const filePath = legacyFiles.getFilePath();
|
|
71
|
+
expect(filePath).toBe(tmpDir);
|
|
72
|
+
const legacyCerts = legacyFiles.getLegacyCertificates();
|
|
73
|
+
expect(legacyCerts.getBaseCertificateDirectoryPath()).toBe(tmpDir);
|
|
74
|
+
const legacyMigrationFiles = legacyFiles.getLegacyFileMigrationPaths();
|
|
75
|
+
expect(legacyMigrationFiles.agentConfig).toEqual(
|
|
76
|
+
join(tmpDir, AGENT_CONFIG_FILE_NAME)
|
|
77
|
+
);
|
|
78
|
+
expect(legacyMigrationFiles.aaiConfig).toEqual(
|
|
79
|
+
join(tmpDir, ALWAYSAI_CONFIG_FILE_NAME)
|
|
80
|
+
);
|
|
81
|
+
expect(legacyMigrationFiles.credentialsConfig).toEqual(
|
|
82
|
+
join(tmpDir, DEVICE_TOKEN_FILE_NAME)
|
|
83
|
+
);
|
|
84
|
+
expect(legacyMigrationFiles.deviceCerts).toEqual(
|
|
85
|
+
join(tmpDir, DEVICE_CERTIFICATES_DIRECTORY_NAME)
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigFileSchema,
|
|
3
|
+
ConfigFileSchemaReturnType
|
|
4
|
+
} from '@alwaysai/config-nodejs';
|
|
5
|
+
import Ajv, { JSONSchemaType } from 'ajv';
|
|
6
|
+
import { SYSTEM_IDS, SystemId } from 'alwaysai/lib/constants';
|
|
7
|
+
import { LocalLegacyDeviceCertificates } from 'alwaysai/lib/infrastructure';
|
|
8
|
+
import {
|
|
9
|
+
ALWAYSAI_CONFIG_FILE_NAME,
|
|
10
|
+
DEVICE_TOKEN_FILE_NAME,
|
|
11
|
+
LOCAL_AAI_CFG_DIR
|
|
12
|
+
} from 'alwaysai/lib/paths';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
import { DEVICE_AGENT_CFG_DIR } from '../../util/directories';
|
|
15
|
+
import { AGENT_CONFIG_FILE_NAME, AgentConfigFile } from '../agent-config';
|
|
16
|
+
|
|
17
|
+
// alwaysai.config.json
|
|
18
|
+
export const LEGACY_AAI_CONFIG_FILE_DIR = join(
|
|
19
|
+
LOCAL_AAI_CFG_DIR,
|
|
20
|
+
ALWAYSAI_CONFIG_FILE_NAME
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export interface LegacyAaiConfig {
|
|
24
|
+
systemId: SystemId;
|
|
25
|
+
deviceUuid: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const legacyAaiConfigSchema: JSONSchemaType<LegacyAaiConfig> = {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
systemId: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
enum: SYSTEM_IDS
|
|
34
|
+
},
|
|
35
|
+
deviceUuid: {
|
|
36
|
+
type: 'string'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
required: ['systemId', 'deviceUuid']
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const ajv = new Ajv();
|
|
43
|
+
|
|
44
|
+
export const validateLegacyAaiConfig = ajv.compile(legacyAaiConfigSchema);
|
|
45
|
+
|
|
46
|
+
export function LegacyAaiConfigFile(
|
|
47
|
+
baseDir?: string
|
|
48
|
+
): ConfigFileSchemaReturnType<LegacyAaiConfig> {
|
|
49
|
+
const filePath = baseDir
|
|
50
|
+
? join(baseDir, ALWAYSAI_CONFIG_FILE_NAME)
|
|
51
|
+
: LEGACY_AAI_CONFIG_FILE_DIR;
|
|
52
|
+
const configFile = ConfigFileSchema({
|
|
53
|
+
path: filePath,
|
|
54
|
+
validateFunction: validateLegacyAaiConfig
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return configFile;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function LegacyFiles(baseDir?: string) {
|
|
61
|
+
const filePath = baseDir ?? LOCAL_AAI_CFG_DIR;
|
|
62
|
+
const legacyCertificates = new LocalLegacyDeviceCertificates(filePath);
|
|
63
|
+
const legacyCredentialsFileDirPath = join(filePath, DEVICE_TOKEN_FILE_NAME);
|
|
64
|
+
const legacyCertificateDirPath =
|
|
65
|
+
legacyCertificates.getCertificateDirectoryPath();
|
|
66
|
+
const legacyAgentConfigFile = AgentConfigFile(
|
|
67
|
+
join(filePath, AGENT_CONFIG_FILE_NAME)
|
|
68
|
+
);
|
|
69
|
+
const legacyAaiCfgFileDirPath = join(filePath, ALWAYSAI_CONFIG_FILE_NAME);
|
|
70
|
+
const legacyAgentCfgFileDirPath = join(filePath, AGENT_CONFIG_FILE_NAME);
|
|
71
|
+
const legacyDeviceAgentCfgPath = join(filePath, DEVICE_AGENT_CFG_DIR);
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
getFilePath() {
|
|
75
|
+
return filePath;
|
|
76
|
+
},
|
|
77
|
+
getLegacyAgentConfigFile() {
|
|
78
|
+
return legacyAgentConfigFile;
|
|
79
|
+
},
|
|
80
|
+
getLegacyCertificates() {
|
|
81
|
+
return legacyCertificates;
|
|
82
|
+
},
|
|
83
|
+
getLegacyDeviceAgentConfigDirPath() {
|
|
84
|
+
return legacyDeviceAgentCfgPath;
|
|
85
|
+
},
|
|
86
|
+
getLegacyFileMigrationPaths() {
|
|
87
|
+
return {
|
|
88
|
+
deviceCerts: legacyCertificateDirPath,
|
|
89
|
+
credentialsConfig: legacyCredentialsFileDirPath,
|
|
90
|
+
aaiConfig: legacyAaiCfgFileDirPath,
|
|
91
|
+
agentConfig: legacyAgentCfgFileDirPath
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// alwaysai.credentials.json
|
|
98
|
+
export const LEGACY_CREDENTIALS_FILE_DIR = join(
|
|
99
|
+
LOCAL_AAI_CFG_DIR,
|
|
100
|
+
DEVICE_TOKEN_FILE_NAME
|
|
101
|
+
);
|