@alwaysai/device-agent 0.0.14 → 0.0.15
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/cloud-connection/bootstrap-provision.d.ts +1 -1
- package/lib/cloud-connection/bootstrap-provision.d.ts.map +1 -1
- package/lib/cloud-connection/bootstrap-provision.js +9 -9
- package/lib/cloud-connection/bootstrap-provision.js.map +1 -1
- package/lib/cloud-connection/cmd-status.d.ts +3 -11
- package/lib/cloud-connection/cmd-status.d.ts.map +1 -1
- package/lib/cloud-connection/cmd-status.js +24 -11
- package/lib/cloud-connection/cmd-status.js.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +2 -3
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +93 -43
- 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 +4 -3
- package/lib/cloud-connection/device-agent.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts +10 -18
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +50 -50
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/messages.d.ts +3 -1
- package/lib/cloud-connection/messages.d.ts.map +1 -1
- package/lib/cloud-connection/messages.js +13 -1
- package/lib/cloud-connection/messages.js.map +1 -1
- package/lib/cloud-connection/passthrough-handler.js +1 -1
- package/lib/cloud-connection/passthrough-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.test.js +3 -3
- package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
- package/lib/environment.d.ts.map +1 -1
- package/lib/environment.js +1 -1
- package/lib/environment.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/subcommands/app/app.d.ts +2 -2
- package/lib/subcommands/app/app.d.ts.map +1 -1
- package/lib/subcommands/app/app.js +28 -10
- package/lib/subcommands/app/app.js.map +1 -1
- package/lib/subcommands/app/index.js +2 -2
- package/lib/subcommands/device/device.d.ts.map +1 -1
- package/lib/subcommands/device/device.js +2 -1
- package/lib/subcommands/device/device.js.map +1 -1
- package/lib/util/directories.d.ts +11 -12
- package/lib/util/directories.d.ts.map +1 -1
- package/lib/util/directories.js +24 -29
- package/lib/util/directories.js.map +1 -1
- package/lib/util/logger.js +1 -0
- package/lib/util/logger.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +3 -3
- package/src/cloud-connection/bootstrap-provision.ts +13 -10
- package/src/cloud-connection/cmd-status.ts +30 -11
- package/src/cloud-connection/device-agent-cloud-connection.ts +128 -66
- package/src/cloud-connection/device-agent.ts +7 -4
- package/src/cloud-connection/live-updates-handler.ts +79 -86
- package/src/cloud-connection/messages.ts +22 -1
- package/src/cloud-connection/passthrough-handler.ts +1 -1
- package/src/cloud-connection/shadow-handler.test.ts +3 -3
- package/src/environment.ts +1 -1
- package/src/index.ts +2 -2
- package/src/subcommands/app/app.ts +27 -10
- package/src/subcommands/app/index.ts +4 -4
- package/src/subcommands/device/device.ts +5 -2
- package/src/util/directories.ts +31 -29
- package/src/util/logger.ts +2 -0
- package/lib/cloud-connection/app-install-status.d.ts +0 -16
- package/lib/cloud-connection/app-install-status.d.ts.map +0 -1
- package/lib/cloud-connection/app-install-status.js +0 -53
- package/lib/cloud-connection/app-install-status.js.map +0 -1
- package/lib/util/timer.d.ts +0 -2
- package/lib/util/timer.d.ts.map +0 -1
- package/lib/util/timer.js +0 -6
- package/lib/util/timer.js.map +0 -1
- package/src/cloud-connection/app-install-status.ts +0 -62
- package/src/util/timer.ts +0 -1
|
@@ -8,13 +8,15 @@ import { getAppLogs } from '../application-control';
|
|
|
8
8
|
import { logger } from '../util/logger';
|
|
9
9
|
import sleep from '../util/sleep';
|
|
10
10
|
import { Publisher } from './publisher';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
getAppInstallStatusMessage,
|
|
13
|
+
getAppStateMessage,
|
|
14
|
+
getDeviceStatsMessage
|
|
15
|
+
} from './messages';
|
|
12
16
|
import { AgentMessageTypeValue } from '@alwaysai/device-agent-schemas/lib/constants';
|
|
13
|
-
import { AppInstallStatusManager } from './app-install-status';
|
|
14
17
|
|
|
15
18
|
export class LiveUpdatesHandler {
|
|
16
19
|
private publisher: Publisher;
|
|
17
|
-
private appInstallStatusMgr: AppInstallStatusManager;
|
|
18
20
|
|
|
19
21
|
private liveUpdatesTimeout: ReturnType<typeof setTimeout>;
|
|
20
22
|
private liveUpdatesAlive = {
|
|
@@ -32,14 +34,6 @@ export class LiveUpdatesHandler {
|
|
|
32
34
|
private appLogStreams = new Set<string>();
|
|
33
35
|
private appInstallStatuses = new Set<string>();
|
|
34
36
|
|
|
35
|
-
constructor(
|
|
36
|
-
publisher: Publisher,
|
|
37
|
-
appInstallStatusMgr: AppInstallStatusManager
|
|
38
|
-
) {
|
|
39
|
-
this.publisher = publisher;
|
|
40
|
-
this.appInstallStatusMgr = appInstallStatusMgr;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
37
|
private async startAppLogStream(projectId: string) {
|
|
44
38
|
logger.info(`Starting log stream for ${projectId}`);
|
|
45
39
|
this.appLogStreams.add(projectId);
|
|
@@ -77,50 +71,19 @@ export class LiveUpdatesHandler {
|
|
|
77
71
|
});
|
|
78
72
|
}
|
|
79
73
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const appInstallStatusMessage = {
|
|
85
|
-
messageType: keyMirrors.agentMessageType.app_install_status,
|
|
86
|
-
appInstallStatus
|
|
87
|
-
};
|
|
88
|
-
return appInstallStatusMessage;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
public async startPublishingLiveUpdates<T extends any[]>(
|
|
92
|
-
messageType: AgentMessageTypeValue,
|
|
93
|
-
getMessageData: (...args: T) => Promise<DeviceAgentMessagePayload>,
|
|
94
|
-
args: T
|
|
95
|
-
) {
|
|
96
|
-
logger.info(`Turned on live updates for ${messageType}`);
|
|
97
|
-
// eslint-disable-next-line no-constant-condition
|
|
98
|
-
while (true) {
|
|
99
|
-
try {
|
|
100
|
-
const message = await getMessageData(...args);
|
|
101
|
-
this.publisher.publishToClient(message);
|
|
102
|
-
} catch (e) {
|
|
103
|
-
logger.error(
|
|
104
|
-
`Error publishing live updates for ${messageType}: ${e.message}`
|
|
105
|
-
);
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
if (!this.continuePublishing(messageType, ...args)) {
|
|
109
|
-
logger.info(`Turned off live updates for ${messageType}`);
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
await sleep(this.getLiveUpdatesInterval(messageType));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private continuePublishing(flag: AgentMessageTypeValue, data?: any): boolean {
|
|
74
|
+
private continuePublishing(
|
|
75
|
+
flag: AgentMessageTypeValue,
|
|
76
|
+
projectId?: string
|
|
77
|
+
): boolean {
|
|
117
78
|
switch (flag) {
|
|
118
79
|
case keyMirrors.agentMessageType.device_stats:
|
|
119
80
|
case keyMirrors.agentMessageType.app_state:
|
|
120
81
|
return this.liveUpdatesAlive[flag];
|
|
121
82
|
case keyMirrors.agentMessageType.app_install_status: {
|
|
122
|
-
|
|
123
|
-
|
|
83
|
+
if (!projectId) {
|
|
84
|
+
throw new Error(`Project ID not provided to continuePublishing!`);
|
|
85
|
+
}
|
|
86
|
+
return this.appInstallStatuses.has(projectId);
|
|
124
87
|
}
|
|
125
88
|
default:
|
|
126
89
|
logger.error(`Unrecognized publishable flag ${flag}`);
|
|
@@ -158,28 +121,73 @@ export class LiveUpdatesHandler {
|
|
|
158
121
|
}, 600000); // 10 min
|
|
159
122
|
}
|
|
160
123
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
124
|
+
private async startPublishingLiveUpdates<T extends any[]>(
|
|
125
|
+
messageType: AgentMessageTypeValue,
|
|
126
|
+
getMessageData: (...args: T) => Promise<DeviceAgentMessagePayload>,
|
|
127
|
+
args: T,
|
|
128
|
+
projectId?: string
|
|
129
|
+
) {
|
|
130
|
+
logger.info(`Turned on live updates for ${messageType}`);
|
|
131
|
+
// eslint-disable-next-line no-constant-condition
|
|
132
|
+
while (true) {
|
|
133
|
+
try {
|
|
134
|
+
const message = await getMessageData(...args);
|
|
135
|
+
this.publisher.publishToClient(message);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
logger.error(
|
|
138
|
+
`Error publishing live updates for ${messageType}: ${e.message}`
|
|
139
|
+
);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
if (!this.continuePublishing(messageType, projectId)) {
|
|
143
|
+
logger.info(`Turned off live updates for ${messageType}`);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
await sleep(this.getLiveUpdatesInterval(messageType));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/*=================================================================
|
|
151
|
+
Public interface
|
|
152
|
+
=================================================================*/
|
|
153
|
+
|
|
154
|
+
constructor(publisher: Publisher) {
|
|
155
|
+
this.publisher = publisher;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public async enableAppInstallStatus(props: {
|
|
159
|
+
projectId: string;
|
|
160
|
+
appReleaseHash: string;
|
|
177
161
|
}) {
|
|
162
|
+
const { projectId, appReleaseHash } = props;
|
|
163
|
+
this.liveUpdatesAlive.app_install_status = true;
|
|
164
|
+
this.appInstallStatuses.add(projectId);
|
|
165
|
+
// Don't wait for this call to finish since it loops until disabled
|
|
166
|
+
void this.startPublishingLiveUpdates(
|
|
167
|
+
keyMirrors.agentMessageType.app_install_status,
|
|
168
|
+
getAppInstallStatusMessage,
|
|
169
|
+
[keyMirrors.appInstallStatus.in_progress, '', appReleaseHash],
|
|
170
|
+
projectId
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public async disableAppInstallStatus(props: { projectId: string }) {
|
|
175
|
+
const { projectId } = props;
|
|
176
|
+
this.appInstallStatuses.delete(projectId);
|
|
177
|
+
|
|
178
|
+
if (this.appInstallStatuses.size === 0) {
|
|
179
|
+
this.liveUpdatesAlive.app_install_status = false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public async handleToggles(toggles: LiveUpdatesToggles) {
|
|
184
|
+
const { deviceStats, appState, appLogs } = toggles;
|
|
178
185
|
this.restartLiveUpdatesTimeout();
|
|
179
186
|
if (deviceStats !== undefined) {
|
|
180
187
|
this.liveUpdatesAlive.device_stats = deviceStats;
|
|
181
188
|
if (deviceStats) {
|
|
182
|
-
this
|
|
189
|
+
// Don't wait for this call to finish since it loops until disabled
|
|
190
|
+
void this.startPublishingLiveUpdates(
|
|
183
191
|
keyMirrors.agentMessageType.device_stats,
|
|
184
192
|
getDeviceStatsMessage,
|
|
185
193
|
[]
|
|
@@ -190,7 +198,8 @@ export class LiveUpdatesHandler {
|
|
|
190
198
|
if (appState !== undefined) {
|
|
191
199
|
this.liveUpdatesAlive.app_state = appState;
|
|
192
200
|
if (appState) {
|
|
193
|
-
this
|
|
201
|
+
// Don't wait for this call to finish since it loops until disabled
|
|
202
|
+
void this.startPublishingLiveUpdates(
|
|
194
203
|
keyMirrors.agentMessageType.app_state,
|
|
195
204
|
getAppStateMessage,
|
|
196
205
|
[]
|
|
@@ -200,27 +209,11 @@ export class LiveUpdatesHandler {
|
|
|
200
209
|
|
|
201
210
|
if (appLogs !== undefined) {
|
|
202
211
|
if (appLogs.toggle) {
|
|
203
|
-
this
|
|
212
|
+
// Don't wait for this call to finish since it loops until disabled
|
|
213
|
+
void this.startAppLogStream(appLogs.projectId);
|
|
204
214
|
} else {
|
|
205
215
|
this.appLogStreams.delete(appLogs.projectId);
|
|
206
216
|
}
|
|
207
217
|
}
|
|
208
|
-
|
|
209
|
-
if (appInstallStatus !== undefined) {
|
|
210
|
-
if (appInstallStatus.toggle) {
|
|
211
|
-
this.liveUpdatesAlive.app_install_status = appInstallStatus.toggle;
|
|
212
|
-
this.appInstallStatuses.add(appInstallStatus.appReleaseHash);
|
|
213
|
-
this.startPublishingLiveUpdates(
|
|
214
|
-
keyMirrors.agentMessageType.app_install_status,
|
|
215
|
-
this.getAppInstallStatusMessage,
|
|
216
|
-
[appInstallStatus.appReleaseHash]
|
|
217
|
-
);
|
|
218
|
-
} else {
|
|
219
|
-
this.appInstallStatuses.delete(appInstallStatus.appReleaseHash);
|
|
220
|
-
}
|
|
221
|
-
if (this.appInstallStatuses.size === 0) {
|
|
222
|
-
this.liveUpdatesAlive.app_install_status = false;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
218
|
}
|
|
226
219
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AppInstallStatusMessage,
|
|
3
|
+
AppStatePacket,
|
|
4
|
+
keyMirrors
|
|
5
|
+
} from '@alwaysai/device-agent-schemas';
|
|
6
|
+
import { AppInstallStatusValue } from '@alwaysai/device-agent-schemas/lib/constants';
|
|
2
7
|
import { getAppStatus } from '../application-control';
|
|
3
8
|
import {
|
|
4
9
|
getCpuUtil,
|
|
@@ -22,6 +27,22 @@ export async function getAppStateMessage() {
|
|
|
22
27
|
return appStatePackage;
|
|
23
28
|
}
|
|
24
29
|
|
|
30
|
+
export async function getAppInstallStatusMessage(
|
|
31
|
+
status: AppInstallStatusValue,
|
|
32
|
+
message: string,
|
|
33
|
+
appReleaseHash: string
|
|
34
|
+
): Promise<AppInstallStatusMessage> {
|
|
35
|
+
const appInstallStatusMessage: AppInstallStatusMessage = {
|
|
36
|
+
messageType: keyMirrors.agentMessageType.app_install_status,
|
|
37
|
+
appInstallStatus: {
|
|
38
|
+
status,
|
|
39
|
+
message,
|
|
40
|
+
appReleaseHash
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return appInstallStatusMessage;
|
|
44
|
+
}
|
|
45
|
+
|
|
25
46
|
export async function getDeviceStatsMessage() {
|
|
26
47
|
const cpuUsage = await getCpuUtil();
|
|
27
48
|
const diskUtil = await getDiskUtil();
|
|
@@ -29,7 +29,7 @@ export class PassthroughHandler {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
function processPublish(passthroughHandler: PassthroughHandler) {
|
|
33
33
|
while (messageQueue.length > 0) {
|
|
34
34
|
const entry = messageQueue.shift();
|
|
35
35
|
const { packet, msg } = entry;
|
|
@@ -21,8 +21,8 @@ describe('Test Shadow Handler', () => {
|
|
|
21
21
|
|
|
22
22
|
test.skip('reject buffer payload', async () => {
|
|
23
23
|
//FIXME: Invalid input is silently ignored, need input validation
|
|
24
|
-
expect(() => {
|
|
25
|
-
shadowHandler.handleShadowTopic({
|
|
24
|
+
expect(async () => {
|
|
25
|
+
await shadowHandler.handleShadowTopic({
|
|
26
26
|
topic: shadowHandler.shadowTopics.projects.updateDelta,
|
|
27
27
|
payload: Buffer.from('test-payload')
|
|
28
28
|
});
|
|
@@ -317,7 +317,7 @@ describe('Test Shadow Handler', () => {
|
|
|
317
317
|
};
|
|
318
318
|
jest.mocked(readAppCfgFile).mockResolvedValue(testAppCfg);
|
|
319
319
|
|
|
320
|
-
shadowHandler.publishAppState(projectId1);
|
|
320
|
+
await shadowHandler.publishAppState(projectId1);
|
|
321
321
|
expect(jest.mocked(readAppCfgFile)).toBeCalledWith({ projectId1 });
|
|
322
322
|
const packet = {
|
|
323
323
|
state: {
|
package/src/environment.ts
CHANGED
|
@@ -8,7 +8,7 @@ export const ALWAYSAI_SHOW_HIDDEN = parseBoolean(
|
|
|
8
8
|
);
|
|
9
9
|
export const ALWAYSAI_DEVICE_AGENT_MODE =
|
|
10
10
|
process.env.ALWAYSAI_DEVICE_AGENT_MODE;
|
|
11
|
-
export const ALWAYSAI_LOG_LEVEL = process.env.
|
|
11
|
+
export const ALWAYSAI_LOG_LEVEL = process.env.ALWAYSAI_LOG_LEVEL;
|
|
12
12
|
export const ALWAYSAI_LOG_TO_CONSOLE = process.env.ALWAYSAI_LOG_TO_CONSOLE;
|
|
13
13
|
export const ALWAYSAI_ANALYTICS_PASSTHROUGH = parseBoolean(
|
|
14
14
|
process.env.ALWAYSAI_ANALYTICS_PASSTHROUGH
|
package/src/index.ts
CHANGED
|
@@ -18,13 +18,12 @@ import {
|
|
|
18
18
|
setEnv,
|
|
19
19
|
startApp,
|
|
20
20
|
stopApp,
|
|
21
|
-
uninstallApp,
|
|
22
21
|
updateModels
|
|
23
22
|
} from '../../application-control';
|
|
24
23
|
import { DeviceAgentCloudConnection } from '../../cloud-connection/device-agent-cloud-connection';
|
|
25
24
|
import { AgentConfigFile } from '../../infrastructure/agent-config';
|
|
26
25
|
import { logger } from '../../util/logger';
|
|
27
|
-
import
|
|
26
|
+
import sleep from '../../util/sleep';
|
|
28
27
|
|
|
29
28
|
export const listAppsCliLeaf = CliLeaf({
|
|
30
29
|
name: 'list',
|
|
@@ -96,9 +95,9 @@ export const installAppCliLeaf = CliLeaf({
|
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
};
|
|
99
|
-
await deviceAgent.
|
|
100
|
-
while (deviceAgent.
|
|
101
|
-
await
|
|
98
|
+
await deviceAgent.handleMessage(topic, message);
|
|
99
|
+
while (deviceAgent.isCmdInProgress(project)) {
|
|
100
|
+
await sleep(1000);
|
|
102
101
|
}
|
|
103
102
|
deviceAgent.stop();
|
|
104
103
|
}
|
|
@@ -198,7 +197,25 @@ export const uninstallAppCliLeaf = CliLeaf({
|
|
|
198
197
|
},
|
|
199
198
|
async action(_, opts) {
|
|
200
199
|
const { project } = opts;
|
|
201
|
-
|
|
200
|
+
const deviceAgent = new DeviceAgentCloudConnection();
|
|
201
|
+
await deviceAgent.setupHandlers();
|
|
202
|
+
const topic = deviceAgent.getToDeviceTopic();
|
|
203
|
+
const message: ClientMessage = {
|
|
204
|
+
timestamp: '',
|
|
205
|
+
topic,
|
|
206
|
+
payload: {
|
|
207
|
+
messageType: keyMirrors.clientMessageType.app_version_control,
|
|
208
|
+
appVersionControl: {
|
|
209
|
+
baseCommand: keyMirrors.appVersionControl.uninstall,
|
|
210
|
+
projectId: project
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
await deviceAgent.handleMessage(topic, message);
|
|
215
|
+
while (deviceAgent.isCmdInProgress(project)) {
|
|
216
|
+
await sleep(1000);
|
|
217
|
+
}
|
|
218
|
+
deviceAgent.stop();
|
|
202
219
|
}
|
|
203
220
|
});
|
|
204
221
|
|
|
@@ -273,8 +290,8 @@ export const addModelCliLeaf = CliLeaf({
|
|
|
273
290
|
};
|
|
274
291
|
|
|
275
292
|
await deviceAgent.handleMessage(topic, message);
|
|
276
|
-
while (deviceAgent.
|
|
277
|
-
await
|
|
293
|
+
while (deviceAgent.isCmdInProgress(project)) {
|
|
294
|
+
await sleep(1000);
|
|
278
295
|
}
|
|
279
296
|
deviceAgent.stop();
|
|
280
297
|
}
|
|
@@ -333,7 +350,7 @@ export const updateModelsCliLeaf = CliLeaf({
|
|
|
333
350
|
}
|
|
334
351
|
});
|
|
335
352
|
|
|
336
|
-
export const
|
|
353
|
+
export const getAllEnvsCliLeaf = CliLeaf({
|
|
337
354
|
name: 'get-all-envs',
|
|
338
355
|
description: 'Get environment variables for an application',
|
|
339
356
|
namedInputs: {
|
|
@@ -348,7 +365,7 @@ export const getAllEnvsCLiLeaf = CliLeaf({
|
|
|
348
365
|
}
|
|
349
366
|
});
|
|
350
367
|
|
|
351
|
-
export const
|
|
368
|
+
export const setEnvCliLeaf = CliLeaf({
|
|
352
369
|
name: 'set-env',
|
|
353
370
|
description: 'Set environment variables for a service',
|
|
354
371
|
positionalInput: CliStringArrayInput({
|
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
restartAppCliLeaf,
|
|
17
17
|
replaceModelsCliLeaf,
|
|
18
18
|
showAppModelsCliLeaf,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
getAllEnvsCliLeaf,
|
|
20
|
+
setEnvCliLeaf
|
|
21
21
|
} from './app';
|
|
22
22
|
|
|
23
23
|
export const appCliBranch = CliBranch({
|
|
@@ -40,7 +40,7 @@ export const appCliBranch = CliBranch({
|
|
|
40
40
|
removeModelCliLeaf,
|
|
41
41
|
replaceModelsCliLeaf,
|
|
42
42
|
updateModelsCliLeaf,
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
getAllEnvsCliLeaf,
|
|
44
|
+
setEnvCliLeaf
|
|
45
45
|
]
|
|
46
46
|
});
|
|
@@ -7,7 +7,7 @@ import { httpClient, microServiceHttpClient } from '../../util/http-client';
|
|
|
7
7
|
import {
|
|
8
8
|
AWS_ROOT_CERTIFICATE_FILE_NAME,
|
|
9
9
|
BOOTSTRAP_CERTIFICATES_DIR_PATH,
|
|
10
|
-
|
|
10
|
+
DEVICE_PRIVATE_KEY_FILE_PATH
|
|
11
11
|
} from '../../util/directories';
|
|
12
12
|
|
|
13
13
|
import { LOCAL_CERT_AND_KEY_DIR } from 'alwaysai/lib/constants';
|
|
@@ -39,7 +39,10 @@ export const initCliLeaf = CliLeaf({
|
|
|
39
39
|
let { name } = opts;
|
|
40
40
|
name = name || uuidv4();
|
|
41
41
|
|
|
42
|
-
if (
|
|
42
|
+
if (
|
|
43
|
+
DeviceConfigFile().exists() ||
|
|
44
|
+
existsSync(DEVICE_PRIVATE_KEY_FILE_PATH)
|
|
45
|
+
) {
|
|
43
46
|
throw new Error(
|
|
44
47
|
"Device has been previously provisioned. Run 'aai-agent device clean' to re-provision"
|
|
45
48
|
);
|
package/src/util/directories.ts
CHANGED
|
@@ -33,52 +33,54 @@ export const shortenSystemId = () => {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
/*===================================================================
|
|
37
|
+
Bootstrap Certificates
|
|
38
|
+
===================================================================*/
|
|
39
|
+
|
|
36
40
|
export const BOOTSTRAP_DIR_NAME = 'bootstrap-certificates';
|
|
37
|
-
export const
|
|
41
|
+
export const BOOTSTRAP_PRIVATE_KEY_FILE_NAME = () =>
|
|
38
42
|
`aai-claim-private-key_${shortenSystemId()}.pem.key`;
|
|
39
|
-
export const
|
|
43
|
+
export const BOOTSTRAP_CERTIFICATE_FILE_NAME = () =>
|
|
40
44
|
`aai-claim-cert_${shortenSystemId()}.pem.crt`;
|
|
41
|
-
export const
|
|
45
|
+
export const BOOTSTRAP_ID_FILE_NAME = () =>
|
|
42
46
|
`aai-claim-cert-id_${shortenSystemId()}.txt`;
|
|
43
47
|
export const CERTIFICATE_OWNERSHIP_TOKEN_FILE_NAME =
|
|
44
48
|
'certificate-ownership-token.txt';
|
|
45
|
-
export const DEVICE_PRIVATE_KEY_FILE_NAME = () =>
|
|
46
|
-
`aai-claim-private-key_${shortenSystemId()}.pem.key`;
|
|
47
|
-
export const DEVICE_CERTIFICATE_FILE_NAME = () =>
|
|
48
|
-
`aai-claim-cert_${shortenSystemId()}.pem.crt`;
|
|
49
|
-
export const DEVICE_CLAIM_ID_FILE_NAME = () =>
|
|
50
|
-
`aai-claim-cert-id_${shortenSystemId()}.txt`;
|
|
51
|
-
|
|
52
|
-
export function getPrivateKeyFilePath() {
|
|
53
|
-
return join(LOCAL_CERT_AND_KEY_DIR, DEVICE_PRIVATE_KEY_FILE_NAME());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function getCertificateFilePath() {
|
|
57
|
-
return join(LOCAL_CERT_AND_KEY_DIR, DEVICE_CERTIFICATE_FILE_NAME());
|
|
58
|
-
}
|
|
59
49
|
|
|
60
50
|
export const BOOTSTRAP_CERTIFICATES_DIR_PATH = () =>
|
|
61
51
|
join(LOCAL_CERT_AND_KEY_DIR, BOOTSTRAP_DIR_NAME);
|
|
62
|
-
export const DEVICE_CLAIM_ID_FILE_PATH = () =>
|
|
63
|
-
join(LOCAL_CERT_AND_KEY_DIR, DEVICE_TOKEN_FILE_NAME);
|
|
64
52
|
|
|
65
|
-
export const
|
|
53
|
+
export const BOOTSTRAP_PRIVATE_KEY_FILE_PATH = () =>
|
|
66
54
|
join(
|
|
67
55
|
LOCAL_CERT_AND_KEY_DIR,
|
|
68
56
|
BOOTSTRAP_DIR_NAME,
|
|
69
|
-
|
|
57
|
+
BOOTSTRAP_PRIVATE_KEY_FILE_NAME()
|
|
70
58
|
);
|
|
71
59
|
|
|
72
|
-
export const
|
|
60
|
+
export const BOOTSTRAP_CERTIFICATE_FILE_PATH = () =>
|
|
73
61
|
join(
|
|
74
62
|
LOCAL_CERT_AND_KEY_DIR,
|
|
75
63
|
BOOTSTRAP_DIR_NAME,
|
|
76
|
-
|
|
64
|
+
BOOTSTRAP_CERTIFICATE_FILE_NAME()
|
|
77
65
|
);
|
|
78
66
|
|
|
79
|
-
export const
|
|
80
|
-
join(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
export const BOOTSTRAP_ID_FILE_PATH = () =>
|
|
68
|
+
join(LOCAL_CERT_AND_KEY_DIR, BOOTSTRAP_DIR_NAME, BOOTSTRAP_ID_FILE_NAME());
|
|
69
|
+
|
|
70
|
+
/*===================================================================
|
|
71
|
+
Device Certificates
|
|
72
|
+
===================================================================*/
|
|
73
|
+
|
|
74
|
+
export const DEVICE_PRIVATE_KEY_FILE_NAME = 'aai-device-private-key.pem.key';
|
|
75
|
+
export const DEVICE_CERTIFICATE_FILE_NAME = 'aai-device-cert.pem.crt';
|
|
76
|
+
export const DEVICE_ID_FILE_NAME = 'aai-device-cert-id.txt';
|
|
77
|
+
|
|
78
|
+
export const DEVICE_PRIVATE_KEY_FILE_PATH = join(
|
|
79
|
+
LOCAL_CERT_AND_KEY_DIR,
|
|
80
|
+
DEVICE_PRIVATE_KEY_FILE_NAME
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export const DEVICE_CERTIFICATE_FILE_PATH = join(
|
|
84
|
+
LOCAL_CERT_AND_KEY_DIR,
|
|
85
|
+
DEVICE_CERTIFICATE_FILE_NAME
|
|
86
|
+
);
|
package/src/util/logger.ts
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { AppInstallStatusPacket } from '@alwaysai/device-agent-schemas';
|
|
2
|
-
export declare class AppInstallStatus {
|
|
3
|
-
private appReleaseHash;
|
|
4
|
-
private status;
|
|
5
|
-
private message?;
|
|
6
|
-
constructor(appReleaseHash: any, status: any, message?: any);
|
|
7
|
-
getAppReleaseHash(): string;
|
|
8
|
-
update(status: any, message?: any): void;
|
|
9
|
-
getStatusPacket(): AppInstallStatusPacket;
|
|
10
|
-
}
|
|
11
|
-
export declare class AppInstallStatusManager {
|
|
12
|
-
private appList;
|
|
13
|
-
update(appReleaseHash: any, status: any, message?: any): void;
|
|
14
|
-
getStatusPacket(appReleaseHash: any): AppInstallStatusPacket;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=app-install-status.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app-install-status.d.ts","sourceRoot":"","sources":["../../src/cloud-connection/app-install-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAGxE,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,OAAO,CAAC,CAAS;gBAEb,cAAc,KAAA,EAAE,MAAM,KAAA,EAAE,OAAO,CAAC,KAAA;IAMrC,iBAAiB;IAIjB,MAAM,CAAC,MAAM,KAAA,EAAE,OAAO,CAAC,KAAA;IAKvB,eAAe,IAAI,sBAAsB;CAOjD;AAED,qBAAa,uBAAuB;IAClC,OAAO,CAAC,OAAO,CAA0B;IAElC,MAAM,CAAC,cAAc,KAAA,EAAE,MAAM,KAAA,EAAE,OAAO,CAAC,KAAA;IAkBvC,eAAe,CAAC,cAAc,KAAA;CAQtC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppInstallStatusManager = exports.AppInstallStatus = void 0;
|
|
4
|
-
class AppInstallStatus {
|
|
5
|
-
constructor(appReleaseHash, status, message) {
|
|
6
|
-
this.appReleaseHash = appReleaseHash;
|
|
7
|
-
this.status = status;
|
|
8
|
-
this.message = message;
|
|
9
|
-
}
|
|
10
|
-
getAppReleaseHash() {
|
|
11
|
-
return this.appReleaseHash;
|
|
12
|
-
}
|
|
13
|
-
update(status, message) {
|
|
14
|
-
this.status = status;
|
|
15
|
-
this.message = message;
|
|
16
|
-
}
|
|
17
|
-
getStatusPacket() {
|
|
18
|
-
return {
|
|
19
|
-
status: this.status,
|
|
20
|
-
message: this.message,
|
|
21
|
-
appReleaseHash: this.appReleaseHash
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.AppInstallStatus = AppInstallStatus;
|
|
26
|
-
class AppInstallStatusManager {
|
|
27
|
-
constructor() {
|
|
28
|
-
this.appList = [];
|
|
29
|
-
}
|
|
30
|
-
update(appReleaseHash, status, message) {
|
|
31
|
-
// Update status if existing
|
|
32
|
-
// TODO: Reimplement this as a map
|
|
33
|
-
for (const app of this.appList) {
|
|
34
|
-
if (app.getAppReleaseHash() === appReleaseHash) {
|
|
35
|
-
app.update(status, message);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// App was not found, so add to list
|
|
40
|
-
const appInstallStatus = new AppInstallStatus(appReleaseHash, status, message);
|
|
41
|
-
this.appList.push(appInstallStatus);
|
|
42
|
-
}
|
|
43
|
-
getStatusPacket(appReleaseHash) {
|
|
44
|
-
for (const app of this.appList) {
|
|
45
|
-
if (app.getAppReleaseHash() === appReleaseHash) {
|
|
46
|
-
return app.getStatusPacket();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
throw new Error(`No status for ${appReleaseHash}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.AppInstallStatusManager = AppInstallStatusManager;
|
|
53
|
-
//# sourceMappingURL=app-install-status.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app-install-status.js","sourceRoot":"","sources":["../../src/cloud-connection/app-install-status.ts"],"names":[],"mappings":";;;AAGA,MAAa,gBAAgB;IAK3B,YAAY,cAAc,EAAE,MAAM,EAAE,OAAQ;QAC1C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,iBAAiB;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAEM,MAAM,CAAC,MAAM,EAAE,OAAQ;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,eAAe;QACpB,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,cAAc,EAAE,IAAI,CAAC,cAAc;SACpC,CAAC;IACJ,CAAC;CACF;AA3BD,4CA2BC;AAED,MAAa,uBAAuB;IAApC;QACU,YAAO,GAAuB,EAAE,CAAC;IA4B3C,CAAC;IA1BQ,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,OAAQ;QAC5C,4BAA4B;QAC5B,kCAAkC;QAClC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE;YAC9B,IAAI,GAAG,CAAC,iBAAiB,EAAE,KAAK,cAAc,EAAE;gBAC9C,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAC5B,OAAO;aACR;SACF;QACD,oCAAoC;QACpC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAC3C,cAAc,EACd,MAAM,EACN,OAAO,CACR,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACtC,CAAC;IAEM,eAAe,CAAC,cAAc;QACnC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE;YAC9B,IAAI,GAAG,CAAC,iBAAiB,EAAE,KAAK,cAAc,EAAE;gBAC9C,OAAO,GAAG,CAAC,eAAe,EAAE,CAAC;aAC9B;SACF;QACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,cAAc,EAAE,CAAC,CAAC;IACrD,CAAC;CACF;AA7BD,0DA6BC"}
|
package/lib/util/timer.d.ts
DELETED
package/lib/util/timer.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../src/util/timer.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,OAAQ,MAAM,qBAA8C,CAAC"}
|
package/lib/util/timer.js
DELETED
package/lib/util/timer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/util/timer.ts"],"names":[],"mappings":";;;AAAO,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;AAAlE,QAAA,KAAK,SAA6D"}
|