@tolinax/ayoune-cli 2026.2.0 → 2026.2.2
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/data/defaultActions.js +9 -0
- package/data/modelsAndRights.js +3189 -0
- package/data/modules.js +111 -0
- package/data/operations.js +5 -0
- package/data/services.js +139 -0
- package/index.js +11 -0
- package/lib/api/apiCallHandler.js +68 -0
- package/lib/api/apiClient.js +100 -0
- package/lib/api/auditCallHandler.js +21 -0
- package/lib/api/decodeToken.js +4 -0
- package/lib/api/handleAPIError.js +59 -0
- package/lib/api/login.js +45 -0
- package/lib/commands/createActionsCommand.js +109 -0
- package/lib/commands/createAiCommand.js +188 -0
- package/lib/commands/createAliasCommand.js +106 -0
- package/lib/commands/createAuditCommand.js +49 -0
- package/lib/commands/createCompletionsCommand.js +136 -0
- package/lib/commands/createConfigCommand.js +208 -0
- package/lib/commands/createCopyCommand.js +39 -0
- package/lib/commands/createCreateCommand.js +50 -0
- package/lib/commands/createDeployCommand.js +666 -0
- package/lib/commands/createDescribeCommand.js +42 -0
- package/lib/commands/createEditCommand.js +43 -0
- package/lib/commands/createEventsCommand.js +60 -0
- package/lib/commands/createExecCommand.js +182 -0
- package/lib/commands/createGetCommand.js +47 -0
- package/lib/commands/createListCommand.js +49 -0
- package/lib/commands/createLoginCommand.js +18 -0
- package/lib/commands/createLogoutCommand.js +21 -0
- package/lib/commands/createModulesCommand.js +89 -0
- package/lib/commands/createMonitorCommand.js +283 -0
- package/lib/commands/createProgram.js +163 -0
- package/lib/commands/createServicesCommand.js +228 -0
- package/lib/commands/createStorageCommand.js +54 -0
- package/lib/commands/createStreamCommand.js +50 -0
- package/lib/commands/createWhoAmICommand.js +88 -0
- package/lib/exitCodes.js +6 -0
- package/lib/helpers/addSpacesToCamelCase.js +5 -0
- package/lib/helpers/config.js +6 -0
- package/lib/helpers/configLoader.js +60 -0
- package/lib/helpers/formatDocument.js +176 -0
- package/lib/helpers/handleResponseFormatOptions.js +85 -0
- package/lib/helpers/initializeSettings.js +14 -0
- package/lib/helpers/localStorage.js +4 -0
- package/lib/helpers/makeRandomToken.js +27 -0
- package/lib/helpers/parseInt.js +7 -0
- package/lib/helpers/requireArg.js +9 -0
- package/lib/helpers/saveFile.js +39 -0
- package/lib/models/getCollections.js +15 -0
- package/lib/models/getModelsInModules.js +13 -0
- package/lib/models/getModuleFromCollection.js +7 -0
- package/lib/operations/handleAuditOperation.js +22 -0
- package/lib/operations/handleCollectionOperation.js +91 -0
- package/lib/operations/handleCopySingleOperation.js +22 -0
- package/lib/operations/handleCreateSingleOperation.js +35 -0
- package/lib/operations/handleDeleteSingleOperation.js +14 -0
- package/lib/operations/handleDescribeSingleOperation.js +22 -0
- package/lib/operations/handleEditOperation.js +51 -0
- package/lib/operations/handleEditRawOperation.js +35 -0
- package/lib/operations/handleGetOperation.js +29 -0
- package/lib/operations/handleGetSingleOperation.js +20 -0
- package/lib/operations/handleListOperation.js +63 -0
- package/lib/operations/handleSingleAuditOperation.js +27 -0
- package/lib/prompts/promptAudits.js +15 -0
- package/lib/prompts/promptCollection.js +13 -0
- package/lib/prompts/promptCollectionInModule.js +13 -0
- package/lib/prompts/promptCollectionWithModule.js +15 -0
- package/lib/prompts/promptConfirm.js +12 -0
- package/lib/prompts/promptDefaultAction.js +13 -0
- package/lib/prompts/promptEntry.js +19 -0
- package/lib/prompts/promptFileName.js +12 -0
- package/lib/prompts/promptFilePath.js +18 -0
- package/lib/prompts/promptModule.js +19 -0
- package/lib/prompts/promptName.js +11 -0
- package/lib/prompts/promptOperation.js +13 -0
- package/lib/socket/customerSocketClient.js +13 -0
- package/lib/socket/socketClient.js +12 -0
- package/lib/types.js +1 -0
- package/package.json +2 -2
- package/README.md +0 -505
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { getModuleBaseUrl } from "../api/apiClient.js";
|
|
3
|
+
import { apiCallHandler } from "../api/apiCallHandler.js";
|
|
4
|
+
import { handleResponseFormatOptions } from "../helpers/handleResponseFormatOptions.js";
|
|
5
|
+
import { saveFile } from "../helpers/saveFile.js";
|
|
6
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
7
|
+
import { spinner } from "../../index.js";
|
|
8
|
+
import { EXIT_GENERAL_ERROR } from "../exitCodes.js";
|
|
9
|
+
function getToken() {
|
|
10
|
+
return localStorage.getItem("token") || process.env.AYOUNE_TOKEN || "";
|
|
11
|
+
}
|
|
12
|
+
export function createDeployCommand(program) {
|
|
13
|
+
const deploy = program
|
|
14
|
+
.command("deploy")
|
|
15
|
+
.alias("dp")
|
|
16
|
+
.description("Manage deployments, pods, clusters, pipelines, and plans via DevOps API");
|
|
17
|
+
// ─── DEPLOYMENTS ───────────────────────────────────────
|
|
18
|
+
// ay deploy list
|
|
19
|
+
deploy
|
|
20
|
+
.command("list")
|
|
21
|
+
.alias("ls")
|
|
22
|
+
.description("List deployments across clusters")
|
|
23
|
+
.option("--cluster <name>", "Filter by cluster name")
|
|
24
|
+
.option("--namespace <ns>", "Filter by namespace")
|
|
25
|
+
.option("--health <status>", "Filter: healthy, degraded, crashed, pending")
|
|
26
|
+
.option("-q, --search <term>", "Search by name")
|
|
27
|
+
.option("-l, --limit <number>", "Limit", parseInt, 50)
|
|
28
|
+
.option("-p, --page <number>", "Page", parseInt, 1)
|
|
29
|
+
.action(async (options) => {
|
|
30
|
+
var _a, _b, _c;
|
|
31
|
+
try {
|
|
32
|
+
const opts = { ...program.opts(), ...options };
|
|
33
|
+
spinner.start({ text: "Fetching deployments...", color: "magenta" });
|
|
34
|
+
const params = {
|
|
35
|
+
page: opts.page,
|
|
36
|
+
limit: opts.limit,
|
|
37
|
+
responseFormat: opts.responseFormat,
|
|
38
|
+
verbosity: opts.verbosity,
|
|
39
|
+
hideMeta: opts.hideMeta,
|
|
40
|
+
};
|
|
41
|
+
if (opts.cluster)
|
|
42
|
+
params.cluster = opts.cluster;
|
|
43
|
+
if (opts.namespace)
|
|
44
|
+
params.namespace = opts.namespace;
|
|
45
|
+
if (opts.health)
|
|
46
|
+
params.health = opts.health;
|
|
47
|
+
if (opts.search)
|
|
48
|
+
params.q = opts.search;
|
|
49
|
+
const res = await apiCallHandler("devops", "deployments", "get", null, params);
|
|
50
|
+
handleResponseFormatOptions(opts, res);
|
|
51
|
+
const total = (_c = (_b = (_a = res.meta) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.totalEntries) !== null && _c !== void 0 ? _c : 0;
|
|
52
|
+
spinner.success({ text: `Found ${total} deployments` });
|
|
53
|
+
spinner.stop();
|
|
54
|
+
if (opts.save)
|
|
55
|
+
await saveFile("deploy-list", opts, res);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
spinner.error({ text: e.message || "Failed to list deployments" });
|
|
59
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
// ay deploy get <id>
|
|
63
|
+
deploy
|
|
64
|
+
.command("get <id>")
|
|
65
|
+
.description("Get deployment details by ID")
|
|
66
|
+
.action(async (id, options) => {
|
|
67
|
+
try {
|
|
68
|
+
const opts = { ...program.opts(), ...options };
|
|
69
|
+
spinner.start({ text: `Fetching deployment ${id}...`, color: "magenta" });
|
|
70
|
+
const res = await apiCallHandler("devops", `deployments/${id}`, "get", null, {
|
|
71
|
+
responseFormat: opts.responseFormat,
|
|
72
|
+
verbosity: opts.verbosity,
|
|
73
|
+
});
|
|
74
|
+
handleResponseFormatOptions(opts, res);
|
|
75
|
+
spinner.success({ text: `Deployment ${id} loaded` });
|
|
76
|
+
spinner.stop();
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
spinner.error({ text: e.message || "Failed to get deployment" });
|
|
80
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// ay deploy logs <id>
|
|
84
|
+
deploy
|
|
85
|
+
.command("logs <id>")
|
|
86
|
+
.description("Get deployment logs (supports live streaming)")
|
|
87
|
+
.addHelpText("after", `
|
|
88
|
+
Examples:
|
|
89
|
+
ay deploy logs 64a1b2c3d4e5 Get recent logs
|
|
90
|
+
ay deploy logs 64a1b2c3d4e5 --follow Stream logs in real-time (SSE)
|
|
91
|
+
ay deploy logs 64a1b2c3d4e5 --tail 100 Last 100 log lines`)
|
|
92
|
+
.option("-f, --follow", "Stream logs in real-time (Server-Sent Events)")
|
|
93
|
+
.option("--tail <lines>", "Number of recent log lines", parseInt, 50)
|
|
94
|
+
.action(async (id, options) => {
|
|
95
|
+
try {
|
|
96
|
+
const opts = { ...program.opts(), ...options };
|
|
97
|
+
if (opts.follow) {
|
|
98
|
+
// SSE streaming mode
|
|
99
|
+
spinner.start({ text: `Streaming logs for deployment ${id}...`, color: "magenta" });
|
|
100
|
+
spinner.stop();
|
|
101
|
+
console.error(chalk.dim(` Streaming logs for ${id} (Ctrl+C to stop)\n`));
|
|
102
|
+
const baseUrl = getModuleBaseUrl("devops");
|
|
103
|
+
const url = `${baseUrl}/deployments/${id}/logs?follow=true&tail=${opts.tail}`;
|
|
104
|
+
const https = await import("https");
|
|
105
|
+
const { URL } = await import("url");
|
|
106
|
+
const parsed = new URL(url);
|
|
107
|
+
const req = https.get({
|
|
108
|
+
hostname: parsed.hostname,
|
|
109
|
+
path: `${parsed.pathname}${parsed.search}`,
|
|
110
|
+
headers: {
|
|
111
|
+
Authorization: `Bearer ${getToken()}`,
|
|
112
|
+
Accept: "text/event-stream",
|
|
113
|
+
},
|
|
114
|
+
}, (res) => {
|
|
115
|
+
if (res.statusCode !== 200) {
|
|
116
|
+
console.error(chalk.red(` Error: HTTP ${res.statusCode}`));
|
|
117
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
118
|
+
}
|
|
119
|
+
res.setEncoding("utf-8");
|
|
120
|
+
res.on("data", (chunk) => {
|
|
121
|
+
// Parse SSE: lines starting with "data: "
|
|
122
|
+
const lines = chunk.split("\n");
|
|
123
|
+
for (const line of lines) {
|
|
124
|
+
if (line.startsWith("data: ")) {
|
|
125
|
+
const data = line.slice(6);
|
|
126
|
+
try {
|
|
127
|
+
const parsed = JSON.parse(data);
|
|
128
|
+
if (opts.responseFormat === "json") {
|
|
129
|
+
console.log(JSON.stringify(parsed));
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const ts = parsed.timestamp || "";
|
|
133
|
+
const level = parsed.level || "info";
|
|
134
|
+
const msg = parsed.message || data;
|
|
135
|
+
console.log(`${chalk.dim(ts)} ${chalk.cyan(level)} ${msg}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (_a) {
|
|
139
|
+
console.log(data);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
res.on("end", () => {
|
|
145
|
+
console.error(chalk.dim("\n Stream ended."));
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
req.on("error", (e) => {
|
|
149
|
+
console.error(chalk.red(` Stream error: ${e.message}`));
|
|
150
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
151
|
+
});
|
|
152
|
+
// Keep alive until Ctrl+C
|
|
153
|
+
process.on("SIGINT", () => {
|
|
154
|
+
req.destroy();
|
|
155
|
+
process.exit(0);
|
|
156
|
+
});
|
|
157
|
+
// Prevent Node from exiting
|
|
158
|
+
await new Promise(() => { });
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
// One-shot log fetch
|
|
162
|
+
spinner.start({ text: `Fetching logs for deployment ${id}...`, color: "magenta" });
|
|
163
|
+
const res = await apiCallHandler("devops", `deployments/${id}/logs`, "get", null, {
|
|
164
|
+
tail: opts.tail,
|
|
165
|
+
responseFormat: opts.responseFormat,
|
|
166
|
+
verbosity: opts.verbosity,
|
|
167
|
+
});
|
|
168
|
+
handleResponseFormatOptions(opts, res);
|
|
169
|
+
spinner.success({ text: `Logs loaded for deployment ${id}` });
|
|
170
|
+
spinner.stop();
|
|
171
|
+
if (opts.save)
|
|
172
|
+
await saveFile("deploy-logs", opts, res);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
spinner.error({ text: e.message || "Failed to fetch logs" });
|
|
177
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
// ay deploy scale <deployment> <replicas>
|
|
181
|
+
deploy
|
|
182
|
+
.command("scale <deployment> <replicas>")
|
|
183
|
+
.description("Scale a deployment to N replicas")
|
|
184
|
+
.action(async (deployment, replicas, options) => {
|
|
185
|
+
try {
|
|
186
|
+
const opts = { ...program.opts(), ...options };
|
|
187
|
+
spinner.start({ text: `Scaling ${deployment} to ${replicas} replicas...`, color: "magenta" });
|
|
188
|
+
const res = await apiCallHandler("devops", "deployments/scale", "post", {
|
|
189
|
+
deployment,
|
|
190
|
+
replicas: parseInt(replicas, 10),
|
|
191
|
+
}, { responseFormat: opts.responseFormat });
|
|
192
|
+
handleResponseFormatOptions(opts, res);
|
|
193
|
+
spinner.success({ text: `Scaled ${deployment} to ${replicas} replicas` });
|
|
194
|
+
spinner.stop();
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
spinner.error({ text: e.message || "Failed to scale deployment" });
|
|
198
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
// ay deploy restart <deployment>
|
|
202
|
+
deploy
|
|
203
|
+
.command("restart <deployment>")
|
|
204
|
+
.description("Restart a deployment (rolling restart)")
|
|
205
|
+
.action(async (deployment, options) => {
|
|
206
|
+
try {
|
|
207
|
+
const opts = { ...program.opts(), ...options };
|
|
208
|
+
spinner.start({ text: `Restarting ${deployment}...`, color: "magenta" });
|
|
209
|
+
const res = await apiCallHandler("devops", "deployments/restart", "post", {
|
|
210
|
+
deployment,
|
|
211
|
+
}, { responseFormat: opts.responseFormat });
|
|
212
|
+
handleResponseFormatOptions(opts, res);
|
|
213
|
+
spinner.success({ text: `Restart initiated for ${deployment}` });
|
|
214
|
+
spinner.stop();
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
spinner.error({ text: e.message || "Failed to restart deployment" });
|
|
218
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
// ─── PODS ──────────────────────────────────────────────
|
|
222
|
+
// ay deploy pods
|
|
223
|
+
deploy
|
|
224
|
+
.command("pods")
|
|
225
|
+
.description("List pods across clusters")
|
|
226
|
+
.option("--cluster <name>", "Filter by cluster")
|
|
227
|
+
.option("--namespace <ns>", "Filter by namespace")
|
|
228
|
+
.option("--status <status>", "Filter: Running, Pending, Failed, Succeeded, Unknown")
|
|
229
|
+
.option("--deployment <name>", "Filter by deployment")
|
|
230
|
+
.option("-l, --limit <number>", "Limit", parseInt, 100)
|
|
231
|
+
.action(async (options) => {
|
|
232
|
+
var _a, _b, _c;
|
|
233
|
+
try {
|
|
234
|
+
const opts = { ...program.opts(), ...options };
|
|
235
|
+
spinner.start({ text: "Fetching pods...", color: "magenta" });
|
|
236
|
+
const params = {
|
|
237
|
+
limit: opts.limit,
|
|
238
|
+
responseFormat: opts.responseFormat,
|
|
239
|
+
verbosity: opts.verbosity,
|
|
240
|
+
};
|
|
241
|
+
if (opts.cluster)
|
|
242
|
+
params.cluster = opts.cluster;
|
|
243
|
+
if (opts.namespace)
|
|
244
|
+
params.namespace = opts.namespace;
|
|
245
|
+
if (opts.status)
|
|
246
|
+
params.status = opts.status;
|
|
247
|
+
if (opts.deployment)
|
|
248
|
+
params.deployment = opts.deployment;
|
|
249
|
+
const res = await apiCallHandler("devops", "pods", "get", null, params);
|
|
250
|
+
handleResponseFormatOptions(opts, res);
|
|
251
|
+
const total = (_c = (_b = (_a = res.meta) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.totalEntries) !== null && _c !== void 0 ? _c : 0;
|
|
252
|
+
spinner.success({ text: `Found ${total} pods` });
|
|
253
|
+
spinner.stop();
|
|
254
|
+
if (opts.save)
|
|
255
|
+
await saveFile("deploy-pods", opts, res);
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
spinner.error({ text: e.message || "Failed to list pods" });
|
|
259
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
// ay deploy pod-delete <id>
|
|
263
|
+
deploy
|
|
264
|
+
.command("pod-delete <id>")
|
|
265
|
+
.description("Delete a pod (triggers recreation by controller)")
|
|
266
|
+
.action(async (id, options) => {
|
|
267
|
+
try {
|
|
268
|
+
const opts = { ...program.opts(), ...options };
|
|
269
|
+
spinner.start({ text: `Deleting pod ${id}...`, color: "magenta" });
|
|
270
|
+
const res = await apiCallHandler("devops", `pods/${id}`, "delete", null, {
|
|
271
|
+
responseFormat: opts.responseFormat,
|
|
272
|
+
});
|
|
273
|
+
handleResponseFormatOptions(opts, res);
|
|
274
|
+
spinner.success({ text: `Pod ${id} deleted` });
|
|
275
|
+
spinner.stop();
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
spinner.error({ text: e.message || "Failed to delete pod" });
|
|
279
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
// ─── CLUSTERS ──────────────────────────────────────────
|
|
283
|
+
// ay deploy clusters
|
|
284
|
+
deploy
|
|
285
|
+
.command("clusters")
|
|
286
|
+
.alias("cl")
|
|
287
|
+
.description("List Kubernetes clusters and their health status")
|
|
288
|
+
.addHelpText("after", `
|
|
289
|
+
Examples:
|
|
290
|
+
ay deploy clusters List all clusters
|
|
291
|
+
ay deploy clusters -r table Show clusters in table format`)
|
|
292
|
+
.option("-l, --limit <number>", "Limit", parseInt, 50)
|
|
293
|
+
.action(async (options) => {
|
|
294
|
+
var _a, _b, _c;
|
|
295
|
+
try {
|
|
296
|
+
const opts = { ...program.opts(), ...options };
|
|
297
|
+
spinner.start({ text: "Fetching clusters...", color: "magenta" });
|
|
298
|
+
const res = await apiCallHandler("devops", "clusters", "get", null, {
|
|
299
|
+
limit: opts.limit,
|
|
300
|
+
responseFormat: opts.responseFormat,
|
|
301
|
+
verbosity: opts.verbosity,
|
|
302
|
+
});
|
|
303
|
+
handleResponseFormatOptions(opts, res);
|
|
304
|
+
const total = (_c = (_b = (_a = res.meta) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.totalEntries) !== null && _c !== void 0 ? _c : 0;
|
|
305
|
+
spinner.success({ text: `Found ${total} clusters` });
|
|
306
|
+
spinner.stop();
|
|
307
|
+
if (opts.save)
|
|
308
|
+
await saveFile("deploy-clusters", opts, res);
|
|
309
|
+
}
|
|
310
|
+
catch (e) {
|
|
311
|
+
spinner.error({ text: e.message || "Failed to list clusters" });
|
|
312
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
// ay deploy cluster-sync <id>
|
|
316
|
+
deploy
|
|
317
|
+
.command("cluster-sync <id>")
|
|
318
|
+
.description("Trigger sync for a Kubernetes cluster")
|
|
319
|
+
.action(async (id, options) => {
|
|
320
|
+
try {
|
|
321
|
+
const opts = { ...program.opts(), ...options };
|
|
322
|
+
spinner.start({ text: `Syncing cluster ${id}...`, color: "magenta" });
|
|
323
|
+
const res = await apiCallHandler("devops", `clusters/${id}/sync`, "post", null, {
|
|
324
|
+
responseFormat: opts.responseFormat,
|
|
325
|
+
});
|
|
326
|
+
handleResponseFormatOptions(opts, res);
|
|
327
|
+
spinner.success({ text: `Cluster ${id} sync initiated` });
|
|
328
|
+
spinner.stop();
|
|
329
|
+
}
|
|
330
|
+
catch (e) {
|
|
331
|
+
spinner.error({ text: e.message || "Failed to sync cluster" });
|
|
332
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
// ─── ALERTS ────────────────────────────────────────────
|
|
336
|
+
// ay deploy alerts
|
|
337
|
+
deploy
|
|
338
|
+
.command("alerts")
|
|
339
|
+
.description("List active deployment alerts")
|
|
340
|
+
.option("--severity <level>", "Filter: critical, warning, info")
|
|
341
|
+
.option("--type <type>", "Filter: pod_crash, oom_killed, image_pull_error, deployment_failed, pipeline_failed, cluster_unreachable, high_restart_count, custom")
|
|
342
|
+
.option("-l, --limit <number>", "Limit", parseInt, 50)
|
|
343
|
+
.action(async (options) => {
|
|
344
|
+
var _a, _b, _c;
|
|
345
|
+
try {
|
|
346
|
+
const opts = { ...program.opts(), ...options };
|
|
347
|
+
spinner.start({ text: "Fetching alerts...", color: "magenta" });
|
|
348
|
+
const params = {
|
|
349
|
+
limit: opts.limit,
|
|
350
|
+
responseFormat: opts.responseFormat,
|
|
351
|
+
verbosity: opts.verbosity,
|
|
352
|
+
};
|
|
353
|
+
if (opts.severity)
|
|
354
|
+
params.severity = opts.severity;
|
|
355
|
+
if (opts.type)
|
|
356
|
+
params.type = opts.type;
|
|
357
|
+
const res = await apiCallHandler("devops", "alerts", "get", null, params);
|
|
358
|
+
handleResponseFormatOptions(opts, res);
|
|
359
|
+
const total = (_c = (_b = (_a = res.meta) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.totalEntries) !== null && _c !== void 0 ? _c : 0;
|
|
360
|
+
spinner.success({ text: `Found ${total} alerts` });
|
|
361
|
+
spinner.stop();
|
|
362
|
+
if (opts.save)
|
|
363
|
+
await saveFile("deploy-alerts", opts, res);
|
|
364
|
+
}
|
|
365
|
+
catch (e) {
|
|
366
|
+
spinner.error({ text: e.message || "Failed to fetch alerts" });
|
|
367
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
// ─── PIPELINES ─────────────────────────────────────────
|
|
371
|
+
// ay deploy pipelines
|
|
372
|
+
deploy
|
|
373
|
+
.command("pipelines")
|
|
374
|
+
.alias("pipe")
|
|
375
|
+
.description("List recent CI/CD pipelines")
|
|
376
|
+
.option("--repo <slug>", "Filter by repository slug")
|
|
377
|
+
.option("--result <result>", "Filter: SUCCESSFUL, FAILED, STOPPED, EXPIRED")
|
|
378
|
+
.option("-l, --limit <number>", "Limit", parseInt, 20)
|
|
379
|
+
.action(async (options) => {
|
|
380
|
+
var _a, _b, _c;
|
|
381
|
+
try {
|
|
382
|
+
const opts = { ...program.opts(), ...options };
|
|
383
|
+
spinner.start({ text: "Fetching pipelines...", color: "magenta" });
|
|
384
|
+
const params = {
|
|
385
|
+
limit: opts.limit,
|
|
386
|
+
responseFormat: opts.responseFormat,
|
|
387
|
+
verbosity: opts.verbosity,
|
|
388
|
+
};
|
|
389
|
+
if (opts.repo)
|
|
390
|
+
params.repository = opts.repo;
|
|
391
|
+
if (opts.result)
|
|
392
|
+
params.result = opts.result;
|
|
393
|
+
const res = await apiCallHandler("devops", "pipelines", "get", null, params);
|
|
394
|
+
handleResponseFormatOptions(opts, res);
|
|
395
|
+
const total = (_c = (_b = (_a = res.meta) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.totalEntries) !== null && _c !== void 0 ? _c : 0;
|
|
396
|
+
spinner.success({ text: `Found ${total} pipelines` });
|
|
397
|
+
spinner.stop();
|
|
398
|
+
if (opts.save)
|
|
399
|
+
await saveFile("deploy-pipelines", opts, res);
|
|
400
|
+
}
|
|
401
|
+
catch (e) {
|
|
402
|
+
spinner.error({ text: e.message || "Failed to fetch pipelines" });
|
|
403
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
// ay deploy trigger <repo>
|
|
407
|
+
deploy
|
|
408
|
+
.command("trigger <repo>")
|
|
409
|
+
.description("Trigger a CI/CD pipeline for a repository")
|
|
410
|
+
.addHelpText("after", `
|
|
411
|
+
Examples:
|
|
412
|
+
ay deploy trigger ayoune-cli Trigger pipeline for ayoune-cli
|
|
413
|
+
ay deploy trigger ayoune-cli --branch feature/new Use specific branch
|
|
414
|
+
ay deploy trigger ayoune-cli --target staging Custom pipeline target`)
|
|
415
|
+
.option("--branch <branch>", "Branch to trigger pipeline on", "master")
|
|
416
|
+
.option("--target <target>", "Pipeline target name")
|
|
417
|
+
.action(async (repo, options) => {
|
|
418
|
+
try {
|
|
419
|
+
const opts = { ...program.opts(), ...options };
|
|
420
|
+
spinner.start({ text: `Triggering pipeline for ${repo}...`, color: "magenta" });
|
|
421
|
+
const body = {
|
|
422
|
+
repositorySlug: repo,
|
|
423
|
+
branch: opts.branch,
|
|
424
|
+
};
|
|
425
|
+
if (opts.target)
|
|
426
|
+
body.target = opts.target;
|
|
427
|
+
const res = await apiCallHandler("devops", "pipelines/trigger", "post", body, {
|
|
428
|
+
responseFormat: opts.responseFormat,
|
|
429
|
+
});
|
|
430
|
+
handleResponseFormatOptions(opts, res);
|
|
431
|
+
spinner.success({ text: `Pipeline triggered for ${repo} (branch: ${opts.branch})` });
|
|
432
|
+
spinner.stop();
|
|
433
|
+
}
|
|
434
|
+
catch (e) {
|
|
435
|
+
spinner.error({ text: e.message || "Failed to trigger pipeline" });
|
|
436
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
// ─── DEPLOYMENT PLANS ──────────────────────────────────
|
|
440
|
+
const plans = deploy
|
|
441
|
+
.command("plans")
|
|
442
|
+
.description("Manage multi-step deployment plans");
|
|
443
|
+
// ay deploy plans list
|
|
444
|
+
plans
|
|
445
|
+
.command("list")
|
|
446
|
+
.alias("ls")
|
|
447
|
+
.description("List deployment plans")
|
|
448
|
+
.option("-l, --limit <number>", "Limit", parseInt, 50)
|
|
449
|
+
.option("-p, --page <number>", "Page", parseInt, 1)
|
|
450
|
+
.action(async (options) => {
|
|
451
|
+
var _a, _b, _c;
|
|
452
|
+
try {
|
|
453
|
+
const opts = { ...program.opts(), ...options };
|
|
454
|
+
spinner.start({ text: "Fetching deployment plans...", color: "magenta" });
|
|
455
|
+
const res = await apiCallHandler("devops", "deployment-plans", "get", null, {
|
|
456
|
+
page: opts.page,
|
|
457
|
+
limit: opts.limit,
|
|
458
|
+
responseFormat: opts.responseFormat,
|
|
459
|
+
verbosity: opts.verbosity,
|
|
460
|
+
});
|
|
461
|
+
handleResponseFormatOptions(opts, res);
|
|
462
|
+
const total = (_c = (_b = (_a = res.meta) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.totalEntries) !== null && _c !== void 0 ? _c : 0;
|
|
463
|
+
spinner.success({ text: `Found ${total} deployment plans` });
|
|
464
|
+
spinner.stop();
|
|
465
|
+
if (opts.save)
|
|
466
|
+
await saveFile("deploy-plans", opts, res);
|
|
467
|
+
}
|
|
468
|
+
catch (e) {
|
|
469
|
+
spinner.error({ text: e.message || "Failed to list deployment plans" });
|
|
470
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
// ay deploy plans get <id>
|
|
474
|
+
plans
|
|
475
|
+
.command("get <id>")
|
|
476
|
+
.description("Get deployment plan details")
|
|
477
|
+
.action(async (id, options) => {
|
|
478
|
+
try {
|
|
479
|
+
const opts = { ...program.opts(), ...options };
|
|
480
|
+
spinner.start({ text: `Fetching plan ${id}...`, color: "magenta" });
|
|
481
|
+
const res = await apiCallHandler("devops", `deployment-plans/${id}`, "get", null, {
|
|
482
|
+
responseFormat: opts.responseFormat,
|
|
483
|
+
verbosity: opts.verbosity,
|
|
484
|
+
});
|
|
485
|
+
handleResponseFormatOptions(opts, res);
|
|
486
|
+
spinner.success({ text: `Plan ${id} loaded` });
|
|
487
|
+
spinner.stop();
|
|
488
|
+
}
|
|
489
|
+
catch (e) {
|
|
490
|
+
spinner.error({ text: e.message || "Failed to get plan" });
|
|
491
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
// ay deploy plans create --body '{...}'
|
|
495
|
+
plans
|
|
496
|
+
.command("create")
|
|
497
|
+
.description("Create a new deployment plan")
|
|
498
|
+
.option("--body <json>", "Plan definition as JSON")
|
|
499
|
+
.option("--body-file <path>", "Read plan definition from file")
|
|
500
|
+
.action(async (options) => {
|
|
501
|
+
var _a;
|
|
502
|
+
try {
|
|
503
|
+
const opts = { ...program.opts(), ...options };
|
|
504
|
+
let body = null;
|
|
505
|
+
if (opts.body) {
|
|
506
|
+
try {
|
|
507
|
+
body = JSON.parse(opts.body);
|
|
508
|
+
}
|
|
509
|
+
catch (_b) {
|
|
510
|
+
spinner.error({ text: "Invalid JSON in --body" });
|
|
511
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
else if (opts.bodyFile) {
|
|
515
|
+
const fs = await import("fs");
|
|
516
|
+
const content = fs.readFileSync(opts.bodyFile, "utf-8");
|
|
517
|
+
try {
|
|
518
|
+
body = JSON.parse(content);
|
|
519
|
+
}
|
|
520
|
+
catch (_c) {
|
|
521
|
+
spinner.error({ text: `Invalid JSON in file: ${opts.bodyFile}` });
|
|
522
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (!body) {
|
|
526
|
+
spinner.error({ text: "Provide plan definition via --body or --body-file" });
|
|
527
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
528
|
+
}
|
|
529
|
+
spinner.start({ text: "Creating deployment plan...", color: "magenta" });
|
|
530
|
+
const res = await apiCallHandler("devops", "deployment-plans", "post", body, {
|
|
531
|
+
responseFormat: opts.responseFormat,
|
|
532
|
+
});
|
|
533
|
+
handleResponseFormatOptions(opts, res);
|
|
534
|
+
const planId = ((_a = res.payload) === null || _a === void 0 ? void 0 : _a._id) || "unknown";
|
|
535
|
+
spinner.success({ text: `Deployment plan ${planId} created` });
|
|
536
|
+
spinner.stop();
|
|
537
|
+
}
|
|
538
|
+
catch (e) {
|
|
539
|
+
spinner.error({ text: e.message || "Failed to create plan" });
|
|
540
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
// ay deploy plans execute <id>
|
|
544
|
+
plans
|
|
545
|
+
.command("execute <id>")
|
|
546
|
+
.alias("exec")
|
|
547
|
+
.description("Execute a deployment plan")
|
|
548
|
+
.action(async (id, options) => {
|
|
549
|
+
try {
|
|
550
|
+
const opts = { ...program.opts(), ...options };
|
|
551
|
+
spinner.start({ text: `Executing deployment plan ${id}...`, color: "magenta" });
|
|
552
|
+
const res = await apiCallHandler("devops", `deployment-plans/${id}/execute`, "post", null, {
|
|
553
|
+
responseFormat: opts.responseFormat,
|
|
554
|
+
});
|
|
555
|
+
handleResponseFormatOptions(opts, res);
|
|
556
|
+
spinner.success({ text: `Plan ${id} execution started` });
|
|
557
|
+
spinner.stop();
|
|
558
|
+
}
|
|
559
|
+
catch (e) {
|
|
560
|
+
spinner.error({ text: e.message || "Failed to execute plan" });
|
|
561
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
// ay deploy plans delete <id>
|
|
565
|
+
plans
|
|
566
|
+
.command("delete <id>")
|
|
567
|
+
.alias("rm")
|
|
568
|
+
.description("Delete a deployment plan")
|
|
569
|
+
.action(async (id, options) => {
|
|
570
|
+
try {
|
|
571
|
+
const opts = { ...program.opts(), ...options };
|
|
572
|
+
spinner.start({ text: `Deleting plan ${id}...`, color: "magenta" });
|
|
573
|
+
const res = await apiCallHandler("devops", `deployment-plans/${id}`, "delete", null, {
|
|
574
|
+
responseFormat: opts.responseFormat,
|
|
575
|
+
});
|
|
576
|
+
handleResponseFormatOptions(opts, res);
|
|
577
|
+
spinner.success({ text: `Plan ${id} deleted` });
|
|
578
|
+
spinner.stop();
|
|
579
|
+
}
|
|
580
|
+
catch (e) {
|
|
581
|
+
spinner.error({ text: e.message || "Failed to delete plan" });
|
|
582
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
// ─── REPOSITORIES ──────────────────────────────────────
|
|
586
|
+
const repos = deploy
|
|
587
|
+
.command("repos")
|
|
588
|
+
.description("Manage git repositories");
|
|
589
|
+
// ay deploy repos list
|
|
590
|
+
repos
|
|
591
|
+
.command("list")
|
|
592
|
+
.alias("ls")
|
|
593
|
+
.description("List registered repositories")
|
|
594
|
+
.option("--provider <provider>", "Filter: bitbucket, github")
|
|
595
|
+
.option("-l, --limit <number>", "Limit", parseInt, 50)
|
|
596
|
+
.option("-p, --page <number>", "Page", parseInt, 1)
|
|
597
|
+
.action(async (options) => {
|
|
598
|
+
var _a, _b, _c;
|
|
599
|
+
try {
|
|
600
|
+
const opts = { ...program.opts(), ...options };
|
|
601
|
+
spinner.start({ text: "Fetching repositories...", color: "magenta" });
|
|
602
|
+
const params = {
|
|
603
|
+
page: opts.page,
|
|
604
|
+
limit: opts.limit,
|
|
605
|
+
responseFormat: opts.responseFormat,
|
|
606
|
+
verbosity: opts.verbosity,
|
|
607
|
+
};
|
|
608
|
+
if (opts.provider)
|
|
609
|
+
params.provider = opts.provider;
|
|
610
|
+
const res = await apiCallHandler("devops", "repositories", "get", null, params);
|
|
611
|
+
handleResponseFormatOptions(opts, res);
|
|
612
|
+
const total = (_c = (_b = (_a = res.meta) === null || _a === void 0 ? void 0 : _a.pageInfo) === null || _b === void 0 ? void 0 : _b.totalEntries) !== null && _c !== void 0 ? _c : 0;
|
|
613
|
+
spinner.success({ text: `Found ${total} repositories` });
|
|
614
|
+
spinner.stop();
|
|
615
|
+
if (opts.save)
|
|
616
|
+
await saveFile("deploy-repos", opts, res);
|
|
617
|
+
}
|
|
618
|
+
catch (e) {
|
|
619
|
+
spinner.error({ text: e.message || "Failed to list repositories" });
|
|
620
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
// ay deploy repos sync <id>
|
|
624
|
+
repos
|
|
625
|
+
.command("sync <id>")
|
|
626
|
+
.description("Sync a repository with its remote provider")
|
|
627
|
+
.action(async (id, options) => {
|
|
628
|
+
try {
|
|
629
|
+
const opts = { ...program.opts(), ...options };
|
|
630
|
+
spinner.start({ text: `Syncing repository ${id}...`, color: "magenta" });
|
|
631
|
+
const res = await apiCallHandler("devops", `repositories/${id}/sync`, "post", null, {
|
|
632
|
+
responseFormat: opts.responseFormat,
|
|
633
|
+
});
|
|
634
|
+
handleResponseFormatOptions(opts, res);
|
|
635
|
+
spinner.success({ text: `Repository ${id} sync initiated` });
|
|
636
|
+
spinner.stop();
|
|
637
|
+
}
|
|
638
|
+
catch (e) {
|
|
639
|
+
spinner.error({ text: e.message || "Failed to sync repository" });
|
|
640
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
// ─── DASHBOARD ─────────────────────────────────────────
|
|
644
|
+
// ay deploy dashboard
|
|
645
|
+
deploy
|
|
646
|
+
.command("dashboard")
|
|
647
|
+
.alias("dash")
|
|
648
|
+
.description("Show deployment overview dashboard (clusters, deployments, alerts, pipelines)")
|
|
649
|
+
.action(async (options) => {
|
|
650
|
+
try {
|
|
651
|
+
const opts = { ...program.opts(), ...options };
|
|
652
|
+
spinner.start({ text: "Fetching dashboard...", color: "magenta" });
|
|
653
|
+
const res = await apiCallHandler("devops", "dashboard", "get", null, {
|
|
654
|
+
responseFormat: opts.responseFormat,
|
|
655
|
+
verbosity: opts.verbosity,
|
|
656
|
+
});
|
|
657
|
+
handleResponseFormatOptions(opts, res);
|
|
658
|
+
spinner.success({ text: "Dashboard loaded" });
|
|
659
|
+
spinner.stop();
|
|
660
|
+
}
|
|
661
|
+
catch (e) {
|
|
662
|
+
spinner.error({ text: e.message || "Failed to load dashboard" });
|
|
663
|
+
process.exit(EXIT_GENERAL_ERROR);
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
}
|