@edgible-team/cli 1.0.1
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/LICENSE +136 -0
- package/README.md +450 -0
- package/dist/client/api-client.js +1057 -0
- package/dist/client/index.js +21 -0
- package/dist/commands/agent.js +1280 -0
- package/dist/commands/ai.js +608 -0
- package/dist/commands/application.js +885 -0
- package/dist/commands/auth.js +570 -0
- package/dist/commands/base/BaseCommand.js +93 -0
- package/dist/commands/base/CommandHandler.js +7 -0
- package/dist/commands/base/command-wrapper.js +58 -0
- package/dist/commands/base/middleware.js +77 -0
- package/dist/commands/config.js +116 -0
- package/dist/commands/connectivity.js +59 -0
- package/dist/commands/debug.js +98 -0
- package/dist/commands/discover.js +144 -0
- package/dist/commands/examples/migrated-command-example.js +180 -0
- package/dist/commands/gateway.js +494 -0
- package/dist/commands/managedGateway.js +787 -0
- package/dist/commands/utils/config-validator.js +76 -0
- package/dist/commands/utils/gateway-prompt.js +79 -0
- package/dist/commands/utils/input-parser.js +120 -0
- package/dist/commands/utils/output-formatter.js +109 -0
- package/dist/config/app-config.js +99 -0
- package/dist/detection/SystemCapabilityDetector.js +1244 -0
- package/dist/detection/ToolDetector.js +305 -0
- package/dist/detection/WorkloadDetector.js +314 -0
- package/dist/di/bindings.js +99 -0
- package/dist/di/container.js +88 -0
- package/dist/di/types.js +32 -0
- package/dist/index.js +52 -0
- package/dist/interfaces/IDaemonManager.js +3 -0
- package/dist/repositories/config-repository.js +62 -0
- package/dist/repositories/gateway-repository.js +35 -0
- package/dist/scripts/postinstall.js +101 -0
- package/dist/services/AgentStatusManager.js +299 -0
- package/dist/services/ConnectivityTester.js +271 -0
- package/dist/services/DependencyInstaller.js +475 -0
- package/dist/services/LocalAgentManager.js +2216 -0
- package/dist/services/application/ApplicationService.js +299 -0
- package/dist/services/auth/AuthService.js +214 -0
- package/dist/services/aws.js +644 -0
- package/dist/services/daemon/DaemonManagerFactory.js +65 -0
- package/dist/services/daemon/DockerDaemonManager.js +395 -0
- package/dist/services/daemon/LaunchdDaemonManager.js +257 -0
- package/dist/services/daemon/PodmanDaemonManager.js +369 -0
- package/dist/services/daemon/SystemdDaemonManager.js +221 -0
- package/dist/services/daemon/WindowsServiceDaemonManager.js +210 -0
- package/dist/services/daemon/index.js +16 -0
- package/dist/services/edgible.js +3060 -0
- package/dist/services/gateway/GatewayService.js +334 -0
- package/dist/state/config.js +146 -0
- package/dist/types/AgentConfig.js +5 -0
- package/dist/types/AgentStatus.js +5 -0
- package/dist/types/ApiClient.js +5 -0
- package/dist/types/ApiRequests.js +5 -0
- package/dist/types/ApiResponses.js +5 -0
- package/dist/types/Application.js +5 -0
- package/dist/types/CaddyJson.js +5 -0
- package/dist/types/UnifiedAgentStatus.js +56 -0
- package/dist/types/WireGuard.js +5 -0
- package/dist/types/Workload.js +5 -0
- package/dist/types/agent.js +5 -0
- package/dist/types/command-options.js +5 -0
- package/dist/types/connectivity.js +5 -0
- package/dist/types/errors.js +250 -0
- package/dist/types/gateway-types.js +5 -0
- package/dist/types/index.js +48 -0
- package/dist/types/models/ApplicationData.js +5 -0
- package/dist/types/models/CertificateData.js +5 -0
- package/dist/types/models/DeviceData.js +5 -0
- package/dist/types/models/DevicePoolData.js +5 -0
- package/dist/types/models/OrganizationData.js +5 -0
- package/dist/types/models/OrganizationInviteData.js +5 -0
- package/dist/types/models/ProviderConfiguration.js +5 -0
- package/dist/types/models/ResourceData.js +5 -0
- package/dist/types/models/ServiceResourceData.js +5 -0
- package/dist/types/models/UserData.js +5 -0
- package/dist/types/route.js +5 -0
- package/dist/types/validation/schemas.js +218 -0
- package/dist/types/validation.js +5 -0
- package/dist/utils/FileIntegrityManager.js +256 -0
- package/dist/utils/PathMigration.js +219 -0
- package/dist/utils/PathResolver.js +235 -0
- package/dist/utils/PlatformDetector.js +277 -0
- package/dist/utils/console-logger.js +130 -0
- package/dist/utils/docker-compose-parser.js +179 -0
- package/dist/utils/errors.js +130 -0
- package/dist/utils/health-checker.js +155 -0
- package/dist/utils/json-logger.js +72 -0
- package/dist/utils/log-formatter.js +293 -0
- package/dist/utils/logger.js +59 -0
- package/dist/utils/network-utils.js +217 -0
- package/dist/utils/output.js +182 -0
- package/dist/utils/passwordValidation.js +91 -0
- package/dist/utils/progress.js +167 -0
- package/dist/utils/sudo-checker.js +22 -0
- package/dist/utils/urls.js +32 -0
- package/dist/utils/validation.js +31 -0
- package/dist/validation/schemas.js +175 -0
- package/dist/validation/validator.js +67 -0
- package/package.json +83 -0
|
@@ -0,0 +1,787 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setupManagedGatewayCommands = setupManagedGatewayCommands;
|
|
7
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const command_wrapper_1 = require("./base/command-wrapper");
|
|
10
|
+
const container_1 = require("../di/container");
|
|
11
|
+
const types_1 = require("../di/types");
|
|
12
|
+
const config_validator_1 = require("./utils/config-validator");
|
|
13
|
+
const log_formatter_1 = require("../utils/log-formatter");
|
|
14
|
+
/**
|
|
15
|
+
* Managed Gateway debug command group (admin only)
|
|
16
|
+
*/
|
|
17
|
+
function setupManagedGatewayCommands(program) {
|
|
18
|
+
const managedGatewayCommand = program
|
|
19
|
+
.command('managed-gateway')
|
|
20
|
+
.description('Debug commands for managing Edgible-managed gateways (admin only)')
|
|
21
|
+
.alias('mgw');
|
|
22
|
+
managedGatewayCommand
|
|
23
|
+
.command('create')
|
|
24
|
+
.description('Create a new managed gateway')
|
|
25
|
+
.addHelpText('after', `
|
|
26
|
+
Examples:
|
|
27
|
+
$ edgible managed-gateway create --name mygateway --region us-east-1
|
|
28
|
+
$ edgible managed-gateway create --name mygateway --region us-east-1 --instance-type t3.micro
|
|
29
|
+
`)
|
|
30
|
+
.option('-n, --name <name>', 'Gateway name')
|
|
31
|
+
.option('-r, --region <region>', 'AWS region', 'ap-southeast-2')
|
|
32
|
+
.option('-t, --instance-type <type>', 'EC2 instance type', 't3.micro')
|
|
33
|
+
.alias('new')
|
|
34
|
+
.action((0, command_wrapper_1.wrapCommand)(async (options) => {
|
|
35
|
+
const container = (0, container_1.getContainer)();
|
|
36
|
+
const logger = container.get(types_1.TYPES.Logger);
|
|
37
|
+
const configRepository = container.get(types_1.TYPES.ConfigRepository);
|
|
38
|
+
const edgibleService = container.get(types_1.TYPES.EdgibleService);
|
|
39
|
+
(0, config_validator_1.validateConfig)(configRepository, {
|
|
40
|
+
requireAuth: true,
|
|
41
|
+
});
|
|
42
|
+
let gatewayName = options.name;
|
|
43
|
+
const region = options.region || 'ap-southeast-2';
|
|
44
|
+
const instanceType = options.instanceType || 't3.micro';
|
|
45
|
+
if (!gatewayName) {
|
|
46
|
+
const nameAnswer = await inquirer_1.default.prompt([
|
|
47
|
+
{
|
|
48
|
+
type: 'input',
|
|
49
|
+
name: 'name',
|
|
50
|
+
message: 'Enter gateway name:',
|
|
51
|
+
validate: (input) => {
|
|
52
|
+
if (!input.trim()) {
|
|
53
|
+
return 'Gateway name is required';
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
gatewayName = nameAnswer.name.trim();
|
|
60
|
+
}
|
|
61
|
+
logger.info('Creating managed gateway', { name: gatewayName, region, instanceType });
|
|
62
|
+
const result = await edgibleService.createManagedGateway({
|
|
63
|
+
name: gatewayName,
|
|
64
|
+
region,
|
|
65
|
+
instanceType
|
|
66
|
+
});
|
|
67
|
+
console.log(chalk_1.default.green('\n✓ Managed gateway created successfully!'));
|
|
68
|
+
console.log(chalk_1.default.blue('\n📋 Gateway Details:'));
|
|
69
|
+
console.log(chalk_1.default.white(` ID: ${result.gateway.id}`));
|
|
70
|
+
console.log(chalk_1.default.white(` Name: ${result.gateway.name}`));
|
|
71
|
+
console.log(chalk_1.default.white(` IP Address: ${result.gateway.ipAddress || 'N/A'}`));
|
|
72
|
+
console.log(chalk_1.default.white(` Status: ${result.gateway.status || 'N/A'}`));
|
|
73
|
+
console.log(chalk_1.default.white(` Created: ${new Date(result.gateway.createdAt).toLocaleString()}`));
|
|
74
|
+
}, {
|
|
75
|
+
configRepository: (0, container_1.getContainer)().get(types_1.TYPES.ConfigRepository),
|
|
76
|
+
requireAuth: true,
|
|
77
|
+
}));
|
|
78
|
+
managedGatewayCommand
|
|
79
|
+
.command('list')
|
|
80
|
+
.description('List all managed gateways')
|
|
81
|
+
.option('--json', 'Output as JSON')
|
|
82
|
+
.alias('ls')
|
|
83
|
+
.action((0, command_wrapper_1.wrapCommand)(async (options) => {
|
|
84
|
+
const container = (0, container_1.getContainer)();
|
|
85
|
+
const logger = container.get(types_1.TYPES.Logger);
|
|
86
|
+
const configRepository = container.get(types_1.TYPES.ConfigRepository);
|
|
87
|
+
const edgibleService = container.get(types_1.TYPES.EdgibleService);
|
|
88
|
+
(0, config_validator_1.validateConfig)(configRepository, {
|
|
89
|
+
requireAuth: true,
|
|
90
|
+
});
|
|
91
|
+
logger.debug('Listing managed gateways');
|
|
92
|
+
const response = await edgibleService.listManagedGateways();
|
|
93
|
+
if (!response.success || !response.gateways || response.gateways.length === 0) {
|
|
94
|
+
console.log(chalk_1.default.yellow('⚠ No managed gateways found'));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (options.json) {
|
|
98
|
+
console.log(JSON.stringify({
|
|
99
|
+
gateways: response.gateways.map((gateway) => ({
|
|
100
|
+
id: gateway.id,
|
|
101
|
+
name: gateway.name,
|
|
102
|
+
description: gateway.description,
|
|
103
|
+
ipAddress: gateway.ipAddress,
|
|
104
|
+
status: gateway.status,
|
|
105
|
+
lastSeen: gateway.lastSeen,
|
|
106
|
+
createdAt: gateway.createdAt,
|
|
107
|
+
organizationId: gateway.organizationId,
|
|
108
|
+
})),
|
|
109
|
+
}, null, 2));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
console.log(chalk_1.default.blue('\n🌐 Managed Gateways:'));
|
|
113
|
+
response.gateways.forEach((gateway) => {
|
|
114
|
+
console.log(chalk_1.default.white(`\n ID: ${gateway.id}`));
|
|
115
|
+
console.log(chalk_1.default.white(` Name: ${gateway.name}`));
|
|
116
|
+
if (gateway.description) {
|
|
117
|
+
console.log(chalk_1.default.gray(` Description: ${gateway.description}`));
|
|
118
|
+
}
|
|
119
|
+
console.log(chalk_1.default.white(` IP Address: ${gateway.ipAddress || 'N/A'}`));
|
|
120
|
+
console.log(chalk_1.default.white(` Status: ${gateway.status || 'N/A'}`));
|
|
121
|
+
console.log(chalk_1.default.white(` Last Seen: ${gateway.lastSeen ? new Date(gateway.lastSeen).toLocaleString() : 'N/A'}`));
|
|
122
|
+
console.log(chalk_1.default.white(` Created: ${new Date(gateway.createdAt).toLocaleString()}`));
|
|
123
|
+
});
|
|
124
|
+
}, {
|
|
125
|
+
configRepository: (0, container_1.getContainer)().get(types_1.TYPES.ConfigRepository),
|
|
126
|
+
requireAuth: true,
|
|
127
|
+
}));
|
|
128
|
+
managedGatewayCommand
|
|
129
|
+
.command('get')
|
|
130
|
+
.description('Get details of a specific managed gateway')
|
|
131
|
+
.option('-i, --id <id>', 'Gateway ID')
|
|
132
|
+
.alias('status')
|
|
133
|
+
.alias('info')
|
|
134
|
+
.action((0, command_wrapper_1.wrapCommand)(async (options) => {
|
|
135
|
+
const container = (0, container_1.getContainer)();
|
|
136
|
+
const logger = container.get(types_1.TYPES.Logger);
|
|
137
|
+
const configRepository = container.get(types_1.TYPES.ConfigRepository);
|
|
138
|
+
const edgibleService = container.get(types_1.TYPES.EdgibleService);
|
|
139
|
+
(0, config_validator_1.validateConfig)(configRepository, {
|
|
140
|
+
requireAuth: true,
|
|
141
|
+
});
|
|
142
|
+
let gatewayId = options.id;
|
|
143
|
+
if (!gatewayId) {
|
|
144
|
+
// List gateways first to allow selection
|
|
145
|
+
const listResponse = await edgibleService.listManagedGateways();
|
|
146
|
+
if (!listResponse.success || !listResponse.gateways || listResponse.gateways.length === 0) {
|
|
147
|
+
console.log(chalk_1.default.yellow('⚠ No managed gateways found'));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const choices = listResponse.gateways.map((gateway) => ({
|
|
151
|
+
name: `${gateway.name} (${gateway.id})`,
|
|
152
|
+
value: gateway.id,
|
|
153
|
+
}));
|
|
154
|
+
const answer = await inquirer_1.default.prompt([
|
|
155
|
+
{
|
|
156
|
+
type: 'list',
|
|
157
|
+
name: 'gatewayId',
|
|
158
|
+
message: 'Select managed gateway:',
|
|
159
|
+
choices,
|
|
160
|
+
},
|
|
161
|
+
]);
|
|
162
|
+
gatewayId = answer.gatewayId;
|
|
163
|
+
}
|
|
164
|
+
logger.info('Getting managed gateway details', { gatewayId });
|
|
165
|
+
const response = await edgibleService.getManagedGateway(gatewayId);
|
|
166
|
+
if (!response.success || !response.gateway) {
|
|
167
|
+
console.log(chalk_1.default.red('✗ Managed gateway not found'));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const gateway = response.gateway;
|
|
171
|
+
console.log(chalk_1.default.blue('\n📋 Managed Gateway Details:'));
|
|
172
|
+
console.log(chalk_1.default.white(` ID: ${gateway.id}`));
|
|
173
|
+
console.log(chalk_1.default.white(` Name: ${gateway.name}`));
|
|
174
|
+
if (gateway.description) {
|
|
175
|
+
console.log(chalk_1.default.gray(` Description: ${gateway.description}`));
|
|
176
|
+
}
|
|
177
|
+
console.log(chalk_1.default.white(` IP Address: ${gateway.ipAddress || 'N/A'}`));
|
|
178
|
+
console.log(chalk_1.default.white(` Status: ${gateway.status || 'N/A'}`));
|
|
179
|
+
console.log(chalk_1.default.white(` Last Seen: ${gateway.lastSeen ? new Date(gateway.lastSeen).toLocaleString() : 'N/A'}`));
|
|
180
|
+
console.log(chalk_1.default.white(` Created: ${new Date(gateway.createdAt).toLocaleString()}`));
|
|
181
|
+
console.log(chalk_1.default.white(` Organization ID: ${gateway.organizationId}`));
|
|
182
|
+
if (gateway.capacity) {
|
|
183
|
+
console.log(chalk_1.default.blue('\n📊 Capacity:'));
|
|
184
|
+
console.log(chalk_1.default.white(` Current Applications: ${gateway.capacity.currentApps}`));
|
|
185
|
+
console.log(chalk_1.default.white(` Max Applications: ${gateway.capacity.maxApps}`));
|
|
186
|
+
const usagePercent = (gateway.capacity.currentApps / gateway.capacity.maxApps) * 100;
|
|
187
|
+
console.log(chalk_1.default.white(` Usage: ${usagePercent.toFixed(1)}%`));
|
|
188
|
+
}
|
|
189
|
+
if (gateway.health) {
|
|
190
|
+
console.log(chalk_1.default.blue('\n🏥 Health:'));
|
|
191
|
+
console.log(chalk_1.default.white(` Healthy: ${gateway.health.healthy ? chalk_1.default.green('Yes') : chalk_1.default.red('No')}`));
|
|
192
|
+
console.log(chalk_1.default.white(` Last Seen: ${gateway.health.lastSeen ? new Date(gateway.health.lastSeen).toLocaleString() : 'N/A'}`));
|
|
193
|
+
console.log(chalk_1.default.white(` Application Count: ${gateway.health.applicationCount}`));
|
|
194
|
+
}
|
|
195
|
+
}, {
|
|
196
|
+
configRepository: (0, container_1.getContainer)().get(types_1.TYPES.ConfigRepository),
|
|
197
|
+
requireAuth: true,
|
|
198
|
+
}));
|
|
199
|
+
managedGatewayCommand
|
|
200
|
+
.command('delete')
|
|
201
|
+
.description('Delete a managed gateway')
|
|
202
|
+
.option('-i, --id <id>', 'Gateway ID to delete')
|
|
203
|
+
.option('-f, --force', 'Force delete even if applications exist')
|
|
204
|
+
.alias('rm')
|
|
205
|
+
.action((0, command_wrapper_1.wrapCommand)(async (options) => {
|
|
206
|
+
const container = (0, container_1.getContainer)();
|
|
207
|
+
const logger = container.get(types_1.TYPES.Logger);
|
|
208
|
+
const configRepository = container.get(types_1.TYPES.ConfigRepository);
|
|
209
|
+
const edgibleService = container.get(types_1.TYPES.EdgibleService);
|
|
210
|
+
(0, config_validator_1.validateConfig)(configRepository, {
|
|
211
|
+
requireAuth: true,
|
|
212
|
+
});
|
|
213
|
+
let gatewayId = options.id;
|
|
214
|
+
if (!gatewayId) {
|
|
215
|
+
// List gateways first to allow selection
|
|
216
|
+
const listResponse = await edgibleService.listManagedGateways();
|
|
217
|
+
if (!listResponse.success || !listResponse.gateways || listResponse.gateways.length === 0) {
|
|
218
|
+
console.log(chalk_1.default.yellow('⚠ No managed gateways found'));
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const choices = listResponse.gateways.map((gateway) => ({
|
|
222
|
+
name: `${gateway.name} (${gateway.id})`,
|
|
223
|
+
value: gateway.id,
|
|
224
|
+
}));
|
|
225
|
+
const answer = await inquirer_1.default.prompt([
|
|
226
|
+
{
|
|
227
|
+
type: 'list',
|
|
228
|
+
name: 'gatewayId',
|
|
229
|
+
message: 'Select managed gateway to delete:',
|
|
230
|
+
choices,
|
|
231
|
+
},
|
|
232
|
+
]);
|
|
233
|
+
gatewayId = answer.gatewayId;
|
|
234
|
+
}
|
|
235
|
+
// Confirm deletion
|
|
236
|
+
const confirm = await inquirer_1.default.prompt([
|
|
237
|
+
{
|
|
238
|
+
type: 'confirm',
|
|
239
|
+
name: 'confirm',
|
|
240
|
+
message: `Are you sure you want to delete managed gateway ${gatewayId}?`,
|
|
241
|
+
default: false,
|
|
242
|
+
},
|
|
243
|
+
]);
|
|
244
|
+
if (!confirm.confirm) {
|
|
245
|
+
logger.info('Managed gateway deletion cancelled');
|
|
246
|
+
console.log(chalk_1.default.gray('Deletion cancelled'));
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
logger.info('Deleting managed gateway', { gatewayId, force: options.force || false });
|
|
250
|
+
await edgibleService.deleteManagedGateway(gatewayId, options.force || false);
|
|
251
|
+
console.log(chalk_1.default.green('✓ Managed gateway deleted successfully!'));
|
|
252
|
+
}, {
|
|
253
|
+
configRepository: (0, container_1.getContainer)().get(types_1.TYPES.ConfigRepository),
|
|
254
|
+
requireAuth: true,
|
|
255
|
+
}));
|
|
256
|
+
managedGatewayCommand
|
|
257
|
+
.command('resync')
|
|
258
|
+
.description('Resync agent code on a managed gateway')
|
|
259
|
+
.option('-i, --id <id>', 'Gateway ID to resync')
|
|
260
|
+
.option('-v, --version <version>', 'Agent version to deploy')
|
|
261
|
+
.option('--local', 'Upload agent from local dist directory instead of downloading from S3')
|
|
262
|
+
.option('--install-from-local', 'Upload agent from local dist directory instead of downloading from S3')
|
|
263
|
+
.option('--reboot', 'Reboot the gateway after resync completes')
|
|
264
|
+
.option('--wipe-logs', 'Wipe agent logs before resync')
|
|
265
|
+
.option('--debug', 'Set agent log level to debug')
|
|
266
|
+
.action((0, command_wrapper_1.wrapCommand)(async (options) => {
|
|
267
|
+
// Map --local to installFromLocal for backward compatibility
|
|
268
|
+
const installFromLocal = options.local || options.installFromLocal;
|
|
269
|
+
const container = (0, container_1.getContainer)();
|
|
270
|
+
const logger = container.get(types_1.TYPES.Logger);
|
|
271
|
+
const configRepository = container.get(types_1.TYPES.ConfigRepository);
|
|
272
|
+
const edgibleService = container.get(types_1.TYPES.EdgibleService);
|
|
273
|
+
(0, config_validator_1.validateConfig)(configRepository, {
|
|
274
|
+
requireAuth: true,
|
|
275
|
+
});
|
|
276
|
+
let gatewayId = options.id;
|
|
277
|
+
if (!gatewayId) {
|
|
278
|
+
// List gateways first to allow selection
|
|
279
|
+
const listResponse = await edgibleService.listManagedGateways();
|
|
280
|
+
if (!listResponse.success || !listResponse.gateways || listResponse.gateways.length === 0) {
|
|
281
|
+
console.log(chalk_1.default.yellow('⚠ No managed gateways found'));
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const choices = listResponse.gateways.map((gateway) => ({
|
|
285
|
+
name: `${gateway.name} (${gateway.id})`,
|
|
286
|
+
value: gateway.id,
|
|
287
|
+
}));
|
|
288
|
+
const answer = await inquirer_1.default.prompt([
|
|
289
|
+
{
|
|
290
|
+
type: 'list',
|
|
291
|
+
name: 'gatewayId',
|
|
292
|
+
message: 'Select managed gateway to resync:',
|
|
293
|
+
choices,
|
|
294
|
+
},
|
|
295
|
+
]);
|
|
296
|
+
gatewayId = answer.gatewayId;
|
|
297
|
+
}
|
|
298
|
+
logger.info('Resyncing agent on managed gateway', {
|
|
299
|
+
gatewayId,
|
|
300
|
+
version: options.version,
|
|
301
|
+
installFromLocal,
|
|
302
|
+
reboot: options.reboot,
|
|
303
|
+
wipeLogs: options.wipeLogs,
|
|
304
|
+
debug: options.debug
|
|
305
|
+
});
|
|
306
|
+
const result = await edgibleService.resyncManagedGatewayAgent(gatewayId, options.version, installFromLocal, options.reboot, options.wipeLogs, options.debug);
|
|
307
|
+
console.log(chalk_1.default.green('\n✓ Agent resynced successfully!'));
|
|
308
|
+
console.log(chalk_1.default.blue('\n📋 Resync Details:'));
|
|
309
|
+
console.log(chalk_1.default.white(` Gateway ID: ${gatewayId}`));
|
|
310
|
+
if (result.agentVersion) {
|
|
311
|
+
console.log(chalk_1.default.white(` Agent Version: ${result.agentVersion}`));
|
|
312
|
+
}
|
|
313
|
+
if (result.syncTimestamp) {
|
|
314
|
+
console.log(chalk_1.default.white(` Sync Time: ${new Date(result.syncTimestamp).toLocaleString()}`));
|
|
315
|
+
}
|
|
316
|
+
if (options.debug) {
|
|
317
|
+
console.log(chalk_1.default.cyan(` Log Level: Debug (enabled)`));
|
|
318
|
+
}
|
|
319
|
+
if (options.wipeLogs && result.logsWiped) {
|
|
320
|
+
console.log(chalk_1.default.yellow(` Logs: Wiped before resync`));
|
|
321
|
+
}
|
|
322
|
+
if (options.reboot && result.rebooted) {
|
|
323
|
+
console.log(chalk_1.default.yellow(` Reboot: Command sent (gateway is rebooting)`));
|
|
324
|
+
}
|
|
325
|
+
}, {
|
|
326
|
+
configRepository: (0, container_1.getContainer)().get(types_1.TYPES.ConfigRepository),
|
|
327
|
+
requireAuth: true,
|
|
328
|
+
}));
|
|
329
|
+
managedGatewayCommand
|
|
330
|
+
.command('logs')
|
|
331
|
+
.description('Retrieve agent logs from a managed gateway')
|
|
332
|
+
.option('-i, --id <id>', 'Gateway ID to get logs from')
|
|
333
|
+
.option('-n, --lines <number>', 'Number of log lines', '50')
|
|
334
|
+
.option('-f, --follow', 'Follow logs in real-time')
|
|
335
|
+
.option('-l, --level <level>', 'Log level filter', 'all')
|
|
336
|
+
.option('-m, --module <module>', 'Filter logs by module name (comma-separated for multiple modules, e.g., "agent,caddy")')
|
|
337
|
+
.option('-c, --comprehensive', 'Show comprehensive diagnostics (status, system info, WireGuard, Caddy, etc.)')
|
|
338
|
+
.option('--single-line', 'Exclude data and error traces from output (single line per log entry)')
|
|
339
|
+
.action((0, command_wrapper_1.wrapCommand)(async (options) => {
|
|
340
|
+
const container = (0, container_1.getContainer)();
|
|
341
|
+
const logger = container.get(types_1.TYPES.Logger);
|
|
342
|
+
const configRepository = container.get(types_1.TYPES.ConfigRepository);
|
|
343
|
+
const edgibleService = container.get(types_1.TYPES.EdgibleService);
|
|
344
|
+
(0, config_validator_1.validateConfig)(configRepository, {
|
|
345
|
+
requireAuth: true,
|
|
346
|
+
});
|
|
347
|
+
let gatewayId = options.id;
|
|
348
|
+
if (!gatewayId) {
|
|
349
|
+
// List gateways first to allow selection
|
|
350
|
+
const listResponse = await edgibleService.listManagedGateways();
|
|
351
|
+
if (!listResponse.success || !listResponse.gateways || listResponse.gateways.length === 0) {
|
|
352
|
+
console.log(chalk_1.default.yellow('⚠ No managed gateways found'));
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const choices = listResponse.gateways.map((gateway) => ({
|
|
356
|
+
name: `${gateway.name} (${gateway.id})`,
|
|
357
|
+
value: gateway.id,
|
|
358
|
+
}));
|
|
359
|
+
const answer = await inquirer_1.default.prompt([
|
|
360
|
+
{
|
|
361
|
+
type: 'list',
|
|
362
|
+
name: 'gatewayId',
|
|
363
|
+
message: 'Select managed gateway:',
|
|
364
|
+
choices,
|
|
365
|
+
},
|
|
366
|
+
]);
|
|
367
|
+
gatewayId = answer.gatewayId;
|
|
368
|
+
}
|
|
369
|
+
const lines = parseInt(options.lines || '50') || 50;
|
|
370
|
+
const follow = options.follow || false;
|
|
371
|
+
const level = options.level || 'all';
|
|
372
|
+
const module = options.module;
|
|
373
|
+
const comprehensive = options.comprehensive || false;
|
|
374
|
+
logger.info('Retrieving managed gateway logs', {
|
|
375
|
+
gatewayId,
|
|
376
|
+
lines: follow ? undefined : lines,
|
|
377
|
+
follow,
|
|
378
|
+
level,
|
|
379
|
+
module,
|
|
380
|
+
comprehensive,
|
|
381
|
+
});
|
|
382
|
+
// Use the dedicated getManagedGatewayLogs method
|
|
383
|
+
try {
|
|
384
|
+
if (!gatewayId) {
|
|
385
|
+
console.log(chalk_1.default.red('✗ Gateway ID is required'));
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const result = await edgibleService.getManagedGatewayLogs(gatewayId, {
|
|
389
|
+
lines: follow ? undefined : lines,
|
|
390
|
+
follow: follow,
|
|
391
|
+
level: level,
|
|
392
|
+
comprehensive: comprehensive,
|
|
393
|
+
});
|
|
394
|
+
if (result.success) {
|
|
395
|
+
// For comprehensive mode, just output raw logs
|
|
396
|
+
if (comprehensive) {
|
|
397
|
+
console.log(result.logs);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
// Parse and format JSON logs nicely
|
|
401
|
+
const formattedLogs = (0, log_formatter_1.processLogs)(result.logs, {
|
|
402
|
+
module: module,
|
|
403
|
+
level: level,
|
|
404
|
+
singleLine: options.singleLine || false
|
|
405
|
+
});
|
|
406
|
+
if (formattedLogs.trim()) {
|
|
407
|
+
console.log(formattedLogs);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
if (module) {
|
|
411
|
+
console.log(chalk_1.default.yellow(`No logs found for module(s): ${module}`));
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
console.log(chalk_1.default.yellow('No logs found'));
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
logger.error('Failed to retrieve logs');
|
|
421
|
+
console.log(chalk_1.default.red('✗ Failed to retrieve logs'));
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
logger.error('Error retrieving managed gateway logs', error);
|
|
426
|
+
console.log(chalk_1.default.red('✗ Error retrieving logs'));
|
|
427
|
+
}
|
|
428
|
+
}, {
|
|
429
|
+
configRepository: (0, container_1.getContainer)().get(types_1.TYPES.ConfigRepository),
|
|
430
|
+
requireAuth: true,
|
|
431
|
+
}));
|
|
432
|
+
managedGatewayCommand
|
|
433
|
+
.command('wireguard')
|
|
434
|
+
.description('Show WireGuard status on a managed gateway')
|
|
435
|
+
.alias('wg')
|
|
436
|
+
.option('-i, --id <id>', 'Gateway ID to show WireGuard status for')
|
|
437
|
+
.action((0, command_wrapper_1.wrapCommand)(async (options) => {
|
|
438
|
+
const container = (0, container_1.getContainer)();
|
|
439
|
+
const logger = container.get(types_1.TYPES.Logger);
|
|
440
|
+
const configRepository = container.get(types_1.TYPES.ConfigRepository);
|
|
441
|
+
const edgibleService = container.get(types_1.TYPES.EdgibleService);
|
|
442
|
+
(0, config_validator_1.validateConfig)(configRepository, {
|
|
443
|
+
requireAuth: true,
|
|
444
|
+
});
|
|
445
|
+
let gatewayId = options.id;
|
|
446
|
+
if (!gatewayId) {
|
|
447
|
+
// List gateways first to allow selection
|
|
448
|
+
const listResponse = await edgibleService.listManagedGateways();
|
|
449
|
+
if (!listResponse.success || !listResponse.gateways || listResponse.gateways.length === 0) {
|
|
450
|
+
console.log(chalk_1.default.yellow('⚠ No managed gateways found'));
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const choices = listResponse.gateways.map((gateway) => ({
|
|
454
|
+
name: `${gateway.name} (${gateway.id})`,
|
|
455
|
+
value: gateway.id,
|
|
456
|
+
}));
|
|
457
|
+
const answer = await inquirer_1.default.prompt([
|
|
458
|
+
{
|
|
459
|
+
type: 'list',
|
|
460
|
+
name: 'gatewayId',
|
|
461
|
+
message: 'Select managed gateway:',
|
|
462
|
+
choices,
|
|
463
|
+
},
|
|
464
|
+
]);
|
|
465
|
+
gatewayId = answer.gatewayId;
|
|
466
|
+
}
|
|
467
|
+
logger.info('Retrieving WireGuard status', { gatewayId });
|
|
468
|
+
try {
|
|
469
|
+
if (!gatewayId) {
|
|
470
|
+
console.log(chalk_1.default.red('✗ Gateway ID is required'));
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const result = await edgibleService.executeManagedGatewayCommand(gatewayId, 'sudo wg show');
|
|
474
|
+
if (result.success) {
|
|
475
|
+
if (result.output.trim()) {
|
|
476
|
+
console.log(result.output);
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
console.log(chalk_1.default.yellow('No WireGuard interfaces found'));
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
logger.error('Failed to retrieve WireGuard status', { error: result.error });
|
|
484
|
+
console.log(chalk_1.default.red('✗ Failed to retrieve WireGuard status'));
|
|
485
|
+
if (result.error) {
|
|
486
|
+
console.log(chalk_1.default.red(` Error: ${result.error}`));
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
catch (error) {
|
|
491
|
+
logger.error('Error retrieving WireGuard status', error);
|
|
492
|
+
console.log(chalk_1.default.red('✗ Error retrieving WireGuard status'));
|
|
493
|
+
console.log(chalk_1.default.red(` ${error instanceof Error ? error.message : String(error)}`));
|
|
494
|
+
}
|
|
495
|
+
}, {
|
|
496
|
+
configRepository: (0, container_1.getContainer)().get(types_1.TYPES.ConfigRepository),
|
|
497
|
+
requireAuth: true,
|
|
498
|
+
}));
|
|
499
|
+
managedGatewayCommand
|
|
500
|
+
.command('reboot')
|
|
501
|
+
.description('Reboot a managed gateway')
|
|
502
|
+
.option('-i, --id <id>', 'Gateway ID to reboot')
|
|
503
|
+
.option('-f, --force', 'Force reboot without confirmation')
|
|
504
|
+
.action((0, command_wrapper_1.wrapCommand)(async (options) => {
|
|
505
|
+
const container = (0, container_1.getContainer)();
|
|
506
|
+
const logger = container.get(types_1.TYPES.Logger);
|
|
507
|
+
const configRepository = container.get(types_1.TYPES.ConfigRepository);
|
|
508
|
+
const edgibleService = container.get(types_1.TYPES.EdgibleService);
|
|
509
|
+
(0, config_validator_1.validateConfig)(configRepository, {
|
|
510
|
+
requireAuth: true,
|
|
511
|
+
});
|
|
512
|
+
let gatewayId = options.id;
|
|
513
|
+
if (!gatewayId) {
|
|
514
|
+
// List gateways first to allow selection
|
|
515
|
+
const listResponse = await edgibleService.listManagedGateways();
|
|
516
|
+
if (!listResponse.success || !listResponse.gateways || listResponse.gateways.length === 0) {
|
|
517
|
+
console.log(chalk_1.default.yellow('⚠ No managed gateways found'));
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
const choices = listResponse.gateways.map((gateway) => ({
|
|
521
|
+
name: `${gateway.name} (${gateway.id})`,
|
|
522
|
+
value: gateway.id,
|
|
523
|
+
}));
|
|
524
|
+
const answer = await inquirer_1.default.prompt([
|
|
525
|
+
{
|
|
526
|
+
type: 'list',
|
|
527
|
+
name: 'gatewayId',
|
|
528
|
+
message: 'Select managed gateway to reboot:',
|
|
529
|
+
choices,
|
|
530
|
+
},
|
|
531
|
+
]);
|
|
532
|
+
gatewayId = answer.gatewayId;
|
|
533
|
+
}
|
|
534
|
+
// Confirm reboot unless force flag is set
|
|
535
|
+
if (!options.force) {
|
|
536
|
+
const confirm = await inquirer_1.default.prompt([
|
|
537
|
+
{
|
|
538
|
+
type: 'confirm',
|
|
539
|
+
name: 'confirm',
|
|
540
|
+
message: `Are you sure you want to reboot managed gateway ${gatewayId}?`,
|
|
541
|
+
default: false,
|
|
542
|
+
},
|
|
543
|
+
]);
|
|
544
|
+
if (!confirm.confirm) {
|
|
545
|
+
logger.info('Gateway reboot cancelled');
|
|
546
|
+
console.log(chalk_1.default.gray('Reboot cancelled'));
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
logger.info('Rebooting managed gateway', { gatewayId });
|
|
551
|
+
try {
|
|
552
|
+
if (!gatewayId) {
|
|
553
|
+
console.log(chalk_1.default.red('✗ Gateway ID is required'));
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
console.log(chalk_1.default.blue(`Rebooting gateway ${gatewayId}...`));
|
|
557
|
+
// Execute reboot command (this will disconnect SSH, which is expected)
|
|
558
|
+
const result = await edgibleService.executeManagedGatewayCommand(gatewayId, 'sudo reboot');
|
|
559
|
+
// Note: The command may not return successfully because the gateway reboots
|
|
560
|
+
// and disconnects the SSH session. We check if we got an error that suggests
|
|
561
|
+
// the connection was lost (which is expected during reboot)
|
|
562
|
+
if (result.success || (result.error && result.error.includes('ECONNRESET'))) {
|
|
563
|
+
console.log(chalk_1.default.green('✓ Reboot command sent successfully'));
|
|
564
|
+
console.log(chalk_1.default.yellow('⚠ Gateway is rebooting. SSH connection will be lost.'));
|
|
565
|
+
console.log(chalk_1.default.gray(' The gateway should be back online in a few minutes.'));
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
logger.error('Failed to reboot gateway', { error: result.error });
|
|
569
|
+
console.log(chalk_1.default.red('✗ Failed to send reboot command'));
|
|
570
|
+
if (result.error) {
|
|
571
|
+
console.log(chalk_1.default.red(` Error: ${result.error}`));
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
catch (error) {
|
|
576
|
+
// If the error is a connection reset, that's expected during reboot
|
|
577
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
578
|
+
if (errorMessage.includes('ECONNRESET') || errorMessage.includes('connection')) {
|
|
579
|
+
console.log(chalk_1.default.green('✓ Reboot command sent successfully'));
|
|
580
|
+
console.log(chalk_1.default.yellow('⚠ Gateway is rebooting. SSH connection was lost (expected).'));
|
|
581
|
+
console.log(chalk_1.default.gray(' The gateway should be back online in a few minutes.'));
|
|
582
|
+
}
|
|
583
|
+
else {
|
|
584
|
+
logger.error('Error rebooting gateway', error);
|
|
585
|
+
console.log(chalk_1.default.red('✗ Error rebooting gateway'));
|
|
586
|
+
console.log(chalk_1.default.red(` ${errorMessage}`));
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}, {
|
|
590
|
+
configRepository: (0, container_1.getContainer)().get(types_1.TYPES.ConfigRepository),
|
|
591
|
+
requireAuth: true,
|
|
592
|
+
}));
|
|
593
|
+
managedGatewayCommand
|
|
594
|
+
.command('ssh')
|
|
595
|
+
.description('Connect to a managed gateway via SSH (interactive shell)')
|
|
596
|
+
.option('-i, --id <id>', 'Gateway ID to connect to')
|
|
597
|
+
.action((0, command_wrapper_1.wrapCommand)(async (options) => {
|
|
598
|
+
const container = (0, container_1.getContainer)();
|
|
599
|
+
const logger = container.get(types_1.TYPES.Logger);
|
|
600
|
+
const configRepository = container.get(types_1.TYPES.ConfigRepository);
|
|
601
|
+
const edgibleService = container.get(types_1.TYPES.EdgibleService);
|
|
602
|
+
(0, config_validator_1.validateConfig)(configRepository, {
|
|
603
|
+
requireAuth: true,
|
|
604
|
+
});
|
|
605
|
+
let gatewayId = options.id;
|
|
606
|
+
if (!gatewayId) {
|
|
607
|
+
// List gateways first to allow selection
|
|
608
|
+
const listResponse = await edgibleService.listManagedGateways();
|
|
609
|
+
if (!listResponse.success || !listResponse.gateways || listResponse.gateways.length === 0) {
|
|
610
|
+
console.log(chalk_1.default.yellow('⚠ No managed gateways found'));
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
const choices = listResponse.gateways.map((gateway) => ({
|
|
614
|
+
name: `${gateway.name} (${gateway.id})`,
|
|
615
|
+
value: gateway.id,
|
|
616
|
+
}));
|
|
617
|
+
const answer = await inquirer_1.default.prompt([
|
|
618
|
+
{
|
|
619
|
+
type: 'list',
|
|
620
|
+
name: 'gatewayId',
|
|
621
|
+
message: 'Select managed gateway:',
|
|
622
|
+
choices,
|
|
623
|
+
},
|
|
624
|
+
]);
|
|
625
|
+
gatewayId = answer.gatewayId;
|
|
626
|
+
}
|
|
627
|
+
logger.info('Connecting to managed gateway via SSH', { gatewayId });
|
|
628
|
+
// Get managed gateway details
|
|
629
|
+
const gatewayDetails = await edgibleService.getManagedGateway(gatewayId);
|
|
630
|
+
if (!gatewayDetails.success || !gatewayDetails.gateway) {
|
|
631
|
+
console.log(chalk_1.default.red('✗ Managed gateway not found'));
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
const gateway = gatewayDetails.gateway;
|
|
635
|
+
const ipAddress = gateway.ipAddress;
|
|
636
|
+
if (!ipAddress) {
|
|
637
|
+
console.log(chalk_1.default.red('✗ Gateway IP address not available'));
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
// Get SSH key from backend
|
|
641
|
+
console.log(chalk_1.default.gray('Fetching SSH key from backend...'));
|
|
642
|
+
const sshKeyResponse = await edgibleService.apiClient.getManagedGatewaySSHKey({ gatewayId });
|
|
643
|
+
if (!sshKeyResponse.success || !sshKeyResponse.sshPrivateKey) {
|
|
644
|
+
console.log(chalk_1.default.red('✗ Failed to retrieve SSH key for managed gateway'));
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
const sshPrivateKey = sshKeyResponse.sshPrivateKey;
|
|
648
|
+
// Create temporary SSH key file
|
|
649
|
+
const os = require('os');
|
|
650
|
+
const path = require('path');
|
|
651
|
+
const fs = require('fs');
|
|
652
|
+
const tempKeyPath = path.join(os.tmpdir(), `edgible-mgw-ssh-${gatewayId}-${Date.now()}.pem`);
|
|
653
|
+
try {
|
|
654
|
+
// Write SSH key to temp file with proper permissions
|
|
655
|
+
fs.writeFileSync(tempKeyPath, sshPrivateKey, { mode: 0o600 });
|
|
656
|
+
console.log(chalk_1.default.blue(`\nConnecting to managed gateway: ${gatewayId}`));
|
|
657
|
+
console.log(chalk_1.default.gray(`Public IP: ${ipAddress}`));
|
|
658
|
+
console.log(chalk_1.default.gray(`Region: ${gateway.organizationId || 'N/A'}`));
|
|
659
|
+
console.log(chalk_1.default.yellow('\nOpening SSH connection...\n'));
|
|
660
|
+
// Build SSH command
|
|
661
|
+
const sshCommand = `ssh -i "${tempKeyPath}" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@${ipAddress}`;
|
|
662
|
+
console.log(chalk_1.default.green('✓ Opening interactive SSH session...'));
|
|
663
|
+
console.log(chalk_1.default.gray('─'.repeat(80)));
|
|
664
|
+
console.log(chalk_1.default.gray('Tip: Type "exit" to disconnect from the gateway\n'));
|
|
665
|
+
// Execute SSH using child_process
|
|
666
|
+
const { spawn } = require('child_process');
|
|
667
|
+
const sshProcess = spawn('sh', ['-c', sshCommand], {
|
|
668
|
+
stdio: 'inherit',
|
|
669
|
+
shell: false,
|
|
670
|
+
});
|
|
671
|
+
sshProcess.on('error', (error) => {
|
|
672
|
+
logger.error('SSH connection error', error);
|
|
673
|
+
console.error(chalk_1.default.red('✗ SSH connection error:'), error.message);
|
|
674
|
+
console.log(chalk_1.default.yellow('\nMake sure SSH is installed and the key file has correct permissions'));
|
|
675
|
+
throw error;
|
|
676
|
+
});
|
|
677
|
+
sshProcess.on('exit', (code) => {
|
|
678
|
+
if (code === 0) {
|
|
679
|
+
logger.debug('SSH session ended normally');
|
|
680
|
+
console.log(chalk_1.default.gray('\nSSH session ended'));
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
logger.warn('SSH session ended with non-zero code', { code });
|
|
684
|
+
console.log(chalk_1.default.yellow(`\nSSH session ended with code: ${code}`));
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
// Wait for process to exit
|
|
688
|
+
await new Promise((resolve, reject) => {
|
|
689
|
+
sshProcess.on('exit', (code) => {
|
|
690
|
+
if (code === 0 || code === null) {
|
|
691
|
+
resolve();
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
reject(new Error(`SSH session exited with code ${code}`));
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
sshProcess.on('error', reject);
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
logger.error('Error connecting to managed gateway via SSH', error);
|
|
702
|
+
console.error(chalk_1.default.red('✗ Error connecting to managed gateway:'), error instanceof Error ? error.message : String(error));
|
|
703
|
+
throw error;
|
|
704
|
+
}
|
|
705
|
+
finally {
|
|
706
|
+
// Clean up temp key file
|
|
707
|
+
try {
|
|
708
|
+
if (fs.existsSync(tempKeyPath)) {
|
|
709
|
+
fs.unlinkSync(tempKeyPath);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
catch (cleanupError) {
|
|
713
|
+
// Ignore cleanup errors
|
|
714
|
+
logger.debug('Failed to cleanup temp SSH key file', cleanupError);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}, {
|
|
718
|
+
configRepository: (0, container_1.getContainer)().get(types_1.TYPES.ConfigRepository),
|
|
719
|
+
requireAuth: true,
|
|
720
|
+
}));
|
|
721
|
+
managedGatewayCommand
|
|
722
|
+
.command('wipe-logs')
|
|
723
|
+
.description('Clear agent log file on a managed gateway')
|
|
724
|
+
.option('-i, --id <id>', 'Gateway ID to wipe logs for')
|
|
725
|
+
.action((0, command_wrapper_1.wrapCommand)(async (options) => {
|
|
726
|
+
const container = (0, container_1.getContainer)();
|
|
727
|
+
const logger = container.get(types_1.TYPES.Logger);
|
|
728
|
+
const configRepository = container.get(types_1.TYPES.ConfigRepository);
|
|
729
|
+
const edgibleService = container.get(types_1.TYPES.EdgibleService);
|
|
730
|
+
(0, config_validator_1.validateConfig)(configRepository, {
|
|
731
|
+
requireAuth: true,
|
|
732
|
+
});
|
|
733
|
+
let gatewayId = options.id;
|
|
734
|
+
if (!gatewayId) {
|
|
735
|
+
// List gateways first to allow selection
|
|
736
|
+
const listResponse = await edgibleService.listManagedGateways();
|
|
737
|
+
if (!listResponse.success || !listResponse.gateways || listResponse.gateways.length === 0) {
|
|
738
|
+
console.log(chalk_1.default.yellow('⚠ No managed gateways found'));
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
const choices = listResponse.gateways.map((gateway) => ({
|
|
742
|
+
name: `${gateway.name} (${gateway.id})`,
|
|
743
|
+
value: gateway.id,
|
|
744
|
+
}));
|
|
745
|
+
const answer = await inquirer_1.default.prompt([
|
|
746
|
+
{
|
|
747
|
+
type: 'list',
|
|
748
|
+
name: 'gatewayId',
|
|
749
|
+
message: 'Select managed gateway:',
|
|
750
|
+
choices,
|
|
751
|
+
},
|
|
752
|
+
]);
|
|
753
|
+
gatewayId = answer.gatewayId;
|
|
754
|
+
}
|
|
755
|
+
logger.info('Wiping managed gateway logs', { gatewayId });
|
|
756
|
+
// Confirm action
|
|
757
|
+
const confirm = await inquirer_1.default.prompt([
|
|
758
|
+
{
|
|
759
|
+
type: 'confirm',
|
|
760
|
+
name: 'confirm',
|
|
761
|
+
message: `Are you sure you want to clear all logs on managed gateway ${gatewayId}?`,
|
|
762
|
+
default: false,
|
|
763
|
+
},
|
|
764
|
+
]);
|
|
765
|
+
if (!confirm.confirm) {
|
|
766
|
+
logger.info('Log wipe cancelled');
|
|
767
|
+
console.log(chalk_1.default.gray('Log wipe cancelled'));
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
// Get managed gateway logs and wipe them
|
|
771
|
+
const result = await edgibleService.wipeManagedGatewayLogs(gatewayId);
|
|
772
|
+
if (result.success) {
|
|
773
|
+
console.log(chalk_1.default.green('✓ Managed gateway logs cleared successfully!'));
|
|
774
|
+
console.log(chalk_1.default.gray(` Log file: ${result.logFile || 'agent.log'}`));
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
console.log(chalk_1.default.red('✗ Failed to clear logs'));
|
|
778
|
+
if (result.message) {
|
|
779
|
+
console.log(chalk_1.default.yellow(result.message));
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}, {
|
|
783
|
+
configRepository: (0, container_1.getContainer)().get(types_1.TYPES.ConfigRepository),
|
|
784
|
+
requireAuth: true,
|
|
785
|
+
}));
|
|
786
|
+
}
|
|
787
|
+
//# sourceMappingURL=managedGateway.js.map
|