@alwaysai/device-agent 0.1.4 → 0.1.5

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.
Files changed (71) hide show
  1. package/lib/application-control/install.d.ts.map +1 -1
  2. package/lib/application-control/install.js +4 -3
  3. package/lib/application-control/install.js.map +1 -1
  4. package/lib/application-control/models.d.ts.map +1 -1
  5. package/lib/application-control/models.js +4 -4
  6. package/lib/application-control/models.js.map +1 -1
  7. package/lib/application-control/utils.d.ts.map +1 -1
  8. package/lib/application-control/utils.js +4 -18
  9. package/lib/application-control/utils.js.map +1 -1
  10. package/lib/cloud-connection/device-agent-cloud-connection.d.ts +1 -0
  11. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  12. package/lib/cloud-connection/device-agent-cloud-connection.js +6 -0
  13. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  14. package/lib/cloud-connection/device-agent.js +2 -2
  15. package/lib/cloud-connection/device-agent.js.map +1 -1
  16. package/lib/docker/secure-tunnel-docker.d.ts +2 -0
  17. package/lib/docker/secure-tunnel-docker.d.ts.map +1 -0
  18. package/lib/docker/secure-tunnel-docker.js +49 -0
  19. package/lib/docker/secure-tunnel-docker.js.map +1 -0
  20. package/lib/index.js +0 -0
  21. package/lib/infrastructure/tokens-and-device-cfg.js +2 -2
  22. package/lib/infrastructure/tokens-and-device-cfg.js.map +1 -1
  23. package/lib/secure-tunneling/index.d.ts +5 -0
  24. package/lib/secure-tunneling/index.d.ts.map +1 -0
  25. package/lib/secure-tunneling/index.js +66 -0
  26. package/lib/secure-tunneling/index.js.map +1 -0
  27. package/lib/subcommands/device/clean.js +3 -3
  28. package/lib/subcommands/device/clean.js.map +1 -1
  29. package/lib/subcommands/device/device.js +2 -2
  30. package/lib/subcommands/device/device.js.map +1 -1
  31. package/lib/urls.d.ts +2 -0
  32. package/lib/urls.d.ts.map +1 -0
  33. package/lib/urls.js +5 -0
  34. package/lib/urls.js.map +1 -0
  35. package/lib/util/clean-certs.js +2 -2
  36. package/lib/util/clean-certs.js.map +1 -1
  37. package/lib/util/directories.d.ts +3 -0
  38. package/lib/util/directories.d.ts.map +1 -1
  39. package/lib/util/directories.js +19 -13
  40. package/lib/util/directories.js.map +1 -1
  41. package/lib/util/download-file.d.ts +6 -0
  42. package/lib/util/download-file.d.ts.map +1 -0
  43. package/lib/util/download-file.js +25 -0
  44. package/lib/util/download-file.js.map +1 -0
  45. package/lib/util/fetch-with-timeout.d.ts +1 -1
  46. package/lib/util/fetch-with-timeout.d.ts.map +1 -1
  47. package/lib/util/fetch-with-timeout.js +16 -1
  48. package/lib/util/fetch-with-timeout.js.map +1 -1
  49. package/lib/util/logger.js +2 -2
  50. package/lib/util/logger.js.map +1 -1
  51. package/lib/util/system-info.d.ts +4 -0
  52. package/lib/util/system-info.d.ts.map +1 -0
  53. package/lib/util/system-info.js +30 -0
  54. package/lib/util/system-info.js.map +1 -0
  55. package/package.json +3 -3
  56. package/src/application-control/install.ts +2 -5
  57. package/src/application-control/models.ts +3 -3
  58. package/src/application-control/utils.ts +2 -21
  59. package/src/cloud-connection/device-agent-cloud-connection.ts +7 -0
  60. package/src/cloud-connection/device-agent.ts +1 -1
  61. package/src/infrastructure/tokens-and-device-cfg.ts +1 -1
  62. package/src/secure-tunneling/index.ts +76 -0
  63. package/src/subcommands/device/clean.ts +1 -1
  64. package/src/subcommands/device/device.ts +1 -1
  65. package/src/urls.ts +1 -0
  66. package/src/util/clean-certs.ts +1 -1
  67. package/src/util/directories.ts +12 -1
  68. package/src/util/download-file.ts +25 -0
  69. package/src/util/fetch-with-timeout.ts +18 -1
  70. package/src/util/logger.ts +1 -1
  71. package/src/util/system-info.ts +25 -0
@@ -4,7 +4,7 @@ import {
4
4
  DOCKER_COMPOSE_FILE,
5
5
  LOCAL_AAI_CFG_DIR,
6
6
  LOCAL_CERT_AND_KEY_DIR
7
- } from 'alwaysai/lib/constants';
7
+ } from 'alwaysai/lib/paths';
8
8
  import { join } from 'path';
9
9
  import { getSystemId } from '../infrastructure/system-id';
10
10
 
@@ -94,3 +94,14 @@ export const DEVICE_CERTIFICATE_FILE_PATH = join(
94
94
  LOCAL_CERT_AND_KEY_DIR,
95
95
  DEVICE_CERTIFICATE_FILE_NAME
96
96
  );
97
+
98
+ /*===================================================================
99
+ Secure Tunnel bin directory
100
+ ===================================================================*/
101
+ export const SECURE_TUNNEL_BIN_NAME = 'localproxy';
102
+ export const SECURE_TUNNEL_BIN_DIR = 'secure-tunnel';
103
+ export const SECURE_TUNNEL_BIN_PATH = join(
104
+ AAI_DIR,
105
+ SECURE_TUNNEL_BIN_DIR,
106
+ SECURE_TUNNEL_BIN_NAME
107
+ );
@@ -0,0 +1,25 @@
1
+ import * as fs from 'fs';
2
+ import { fetchWithTimeout } from './fetch-with-timeout';
3
+ import { logger } from './logger';
4
+
5
+ export async function downloadFile(props: {
6
+ url: string;
7
+ path: string;
8
+ errorMessage: string;
9
+ }): Promise<void> {
10
+ const { url, path, errorMessage } = props;
11
+ logger.debug(`Downloading package from ${url}`);
12
+ let response: any;
13
+ try {
14
+ response = await fetchWithTimeout(url);
15
+ } catch (e) {
16
+ const errorBody = e.type === 'aborted' ? e : await e.response.text();
17
+ throw new Error(`${errorMessage}: Error=${e}\n${errorBody}`);
18
+ }
19
+
20
+ const stream = response.body.pipe(fs.createWriteStream(path));
21
+ await new Promise((resolve, reject) => {
22
+ stream.on('finish', resolve);
23
+ stream.on('error', reject);
24
+ });
25
+ }
@@ -1,5 +1,22 @@
1
1
  import nodeFetch from 'node-fetch';
2
2
 
3
+ class HTTPResponseError extends Error {
4
+ public response;
5
+ constructor(response) {
6
+ super(`HTTP Error Response: ${response.status} ${response.statusText}`);
7
+ this.response = response;
8
+ }
9
+ }
10
+
11
+ const checkStatus = (response) => {
12
+ if (response.ok) {
13
+ // response.status >= 200 && response.status < 300
14
+ return response;
15
+ } else {
16
+ throw new HTTPResponseError(response);
17
+ }
18
+ };
19
+
3
20
  export async function fetchWithTimeout(
4
21
  url: string,
5
22
  options: { timeout?: number } = {}
@@ -14,5 +31,5 @@ export async function fetchWithTimeout(
14
31
  signal: controller.signal
15
32
  });
16
33
  clearTimeout(id);
17
- return response;
34
+ return checkStatus(response);
18
35
  }
@@ -1,7 +1,7 @@
1
1
  import * as winston from 'winston';
2
2
  import 'winston-daily-rotate-file';
3
3
  import * as path from 'path';
4
- import { AAI_DIR } from 'alwaysai/lib/constants';
4
+ import { AAI_DIR } from 'alwaysai/lib/paths';
5
5
  import { ALWAYSAI_LOG_LEVEL, ALWAYSAI_LOG_TO_CONSOLE } from '../environment';
6
6
 
7
7
  const LOG_LEVEL = ALWAYSAI_LOG_LEVEL || 'info';
@@ -0,0 +1,25 @@
1
+ import { JsSpawner } from 'alwaysai/lib/util';
2
+
3
+ export async function getDistribution() {
4
+ const spawner = JsSpawner();
5
+ const os = await spawner.run({
6
+ exe: 'lsb_release',
7
+ args: ['-is']
8
+ });
9
+ return os.toLowerCase();
10
+ }
11
+ export async function getOsVersion() {
12
+ const spawner = JsSpawner();
13
+ return await spawner.run({
14
+ exe: 'lsb_release',
15
+ args: ['-sr']
16
+ });
17
+ }
18
+
19
+ export async function getArch() {
20
+ const spawner = JsSpawner();
21
+ return await spawner.run({
22
+ exe: 'dpkg',
23
+ args: ['--print-architecture']
24
+ });
25
+ }