plugin-workflow-portainer 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/client/127.09e6675863ac8138.js +10 -0
  2. package/dist/client/57.67f04a547ead06b8.js +10 -0
  3. package/dist/client/981.e38099c59bf992f0.js +10 -0
  4. package/dist/client/index.js +1 -1
  5. package/dist/client-v2/127.9f65dc2e3d0df10a.js +10 -0
  6. package/dist/client-v2/57.a60e16e4b4e4fa28.js +10 -0
  7. package/dist/client-v2/981.8627062881ad83d1.js +10 -0
  8. package/dist/client-v2/index.js +1 -1
  9. package/dist/locale/en-US.json +43 -1
  10. package/dist/locale/vi-VN.json +43 -1
  11. package/dist/locale/zh-CN.json +43 -1
  12. package/dist/node_modules/joi/package.json +1 -1
  13. package/dist/server/actions/portainer.js +125 -0
  14. package/dist/server/plugin.js +8 -1
  15. package/dist/server/services/PortainerClient.js +177 -5
  16. package/dist/shared/env.js +19 -2
  17. package/package.json +2 -2
  18. package/src/client-v2/__tests__/workflow-registration.test.tsx +111 -1
  19. package/src/client-v2/components/PortainerSettingsPage.tsx +38 -2
  20. package/src/client-v2/components/PortainerTargetFields.tsx +10 -18
  21. package/src/client-v2/components/RedeployFieldset.tsx +2 -1
  22. package/src/client-v2/components/StackDetailDrawer.tsx +790 -0
  23. package/src/locale/en-US.json +43 -1
  24. package/src/locale/vi-VN.json +43 -1
  25. package/src/locale/zh-CN.json +43 -1
  26. package/src/server/__tests__/portainer-workflow.test.ts +105 -1
  27. package/src/server/actions/portainer.ts +167 -2
  28. package/src/server/plugin.ts +8 -1
  29. package/src/server/services/PortainerClient.ts +259 -2
  30. package/src/shared/env.ts +15 -0
  31. package/src/shared/types.ts +59 -0
  32. package/dist/client/127.5012da93825a6e5c.js +0 -10
  33. package/dist/client/57.ace9538136438718.js +0 -10
  34. package/dist/client/65.ec4a55173511c06d.js +0 -10
  35. package/dist/client-v2/127.0ec4dce7b13750e9.js +0 -10
  36. package/dist/client-v2/57.e7cfc50fb651ac14.js +0 -10
  37. package/dist/client-v2/65.9c745ea32ac96e98.js +0 -10
@@ -147,5 +147,47 @@
147
147
  "Failed to update status": "Failed to update status",
148
148
  "Portainer instance deleted": "Portainer instance deleted",
149
149
  "Failed to delete Portainer instance": "Failed to delete Portainer instance",
150
- "Failed to load environments and stacks from Portainer": "Failed to load environments and stacks from Portainer"
150
+ "Failed to load environments and stacks from Portainer": "Failed to load environments and stacks from Portainer",
151
+ "Detail": "Detail",
152
+ "Stack Detail": "Stack Detail",
153
+ "Auto-refresh (5s)": "Auto-refresh (5s)",
154
+ "Auto-refresh live metrics (5s)": "Auto-refresh live metrics (5s)",
155
+ "Stop this Stack on Portainer?": "Stop this Stack on Portainer?",
156
+ "Stack started": "Stack started",
157
+ "Stack stopped": "Stack stopped",
158
+ "Failed to control Stack": "Failed to control Stack",
159
+ "Operation must be start or stop": "Operation must be start or stop",
160
+ "Failed to load Stack details from Portainer": "Failed to load Stack details from Portainer",
161
+ "Containers Health": "Containers Health",
162
+ "Live CPU Usage": "Live CPU Usage",
163
+ "Live Memory Usage": "Live Memory Usage",
164
+ "Network I/O (RX / TX)": "Network I/O (RX / TX)",
165
+ "Containers & Live Metrics": "Containers & Live Metrics",
166
+ "Stack containers and live metrics": "Stack containers and live metrics",
167
+ "No containers found for this Stack": "No containers found for this Stack",
168
+ "Container / Service": "Container / Service",
169
+ "State & Uptime": "State & Uptime",
170
+ "Ports & IP": "Ports & IP",
171
+ "CPU": "CPU",
172
+ "Memory": "Memory",
173
+ "Network / PIDs": "Network / PIDs",
174
+ "Logs": "Logs",
175
+ "Container Logs": "Container Logs",
176
+ "Tail lines": "Tail lines",
177
+ "Close": "Close",
178
+ "No log output": "No log output",
179
+ "Failed to fetch container logs": "Failed to fetch container logs",
180
+ "Stack Metadata": "Stack Metadata",
181
+ "Entry point": "Entry point",
182
+ "Created at": "Created at",
183
+ "Last updated": "Last updated",
184
+ "Git commit / config": "Git commit / config",
185
+ "Project path": "Project path",
186
+ "Deployment History": "Deployment History",
187
+ "Time": "Time",
188
+ "Message": "Message",
189
+ "Value": "Value",
190
+ "No environment variables configured": "No environment variables configured",
191
+ "Compose File": "Compose File",
192
+ "Compose file content is unavailable": "Compose file content is unavailable"
151
193
  }
@@ -147,5 +147,47 @@
147
147
  "Failed to update status": "Cập nhật trạng thái thất bại",
148
148
  "Portainer instance deleted": "Đã xóa kết nối Portainer",
149
149
  "Failed to delete Portainer instance": "Xóa kết nối Portainer thất bại",
150
- "Failed to load environments and stacks from Portainer": "Không thể tải danh sách môi trường và Stack từ Portainer"
150
+ "Failed to load environments and stacks from Portainer": "Không thể tải danh sách môi trường và Stack từ Portainer",
151
+ "Detail": "Chi tiết",
152
+ "Stack Detail": "Chi tiết Stack",
153
+ "Auto-refresh (5s)": "Tự làm mới (5s)",
154
+ "Auto-refresh live metrics (5s)": "Tự làm mới thông số trực tiếp (5s)",
155
+ "Stop this Stack on Portainer?": "Dừng Stack này trên Portainer?",
156
+ "Stack started": "Đã khởi động Stack",
157
+ "Stack stopped": "Đã dừng Stack",
158
+ "Failed to control Stack": "Điều khiển Stack thất bại",
159
+ "Operation must be start or stop": "Thao tác phải là start hoặc stop",
160
+ "Failed to load Stack details from Portainer": "Không thể tải chi tiết Stack từ Portainer",
161
+ "Containers Health": "Sức khỏe Container",
162
+ "Live CPU Usage": "CPU trực tiếp",
163
+ "Live Memory Usage": "Bộ nhớ RAM trực tiếp",
164
+ "Network I/O (RX / TX)": "Lưu lượng mạng (RX / TX)",
165
+ "Containers & Live Metrics": "Container & Thông số trực tiếp",
166
+ "Stack containers and live metrics": "Danh sách container và thông số trực tiếp của Stack",
167
+ "No containers found for this Stack": "Không có container nào thuộc Stack này",
168
+ "Container / Service": "Container / Dịch vụ",
169
+ "State & Uptime": "Trạng thái & Thời gian chạy",
170
+ "Ports & IP": "Cổng & Địa chỉ IP",
171
+ "CPU": "CPU",
172
+ "Memory": "Bộ nhớ",
173
+ "Network / PIDs": "Mạng / PIDs",
174
+ "Logs": "Nhật ký",
175
+ "Container Logs": "Nhật ký Container",
176
+ "Tail lines": "Số dòng cuối",
177
+ "Close": "Đóng",
178
+ "No log output": "Chưa có dữ liệu nhật ký",
179
+ "Failed to fetch container logs": "Không thể tải nhật ký container",
180
+ "Stack Metadata": "Thông tin cấu hình Stack",
181
+ "Entry point": "Tệp khởi chạy",
182
+ "Created at": "Thời gian tạo",
183
+ "Last updated": "Cập nhật gần nhất",
184
+ "Git commit / config": "Mã commit / Tệp cấu hình Git",
185
+ "Project path": "Đường dẫn dự án",
186
+ "Deployment History": "Lịch sử triển khai",
187
+ "Time": "Thời gian",
188
+ "Message": "Thông điệp",
189
+ "Value": "Giá trị",
190
+ "No environment variables configured": "Chưa cấu hình biến môi trường nào",
191
+ "Compose File": "Tệp Compose",
192
+ "Compose file content is unavailable": "Không đọc được nội dung tệp Compose"
151
193
  }
@@ -147,5 +147,47 @@
147
147
  "Failed to update status": "更新状态失败",
148
148
  "Portainer instance deleted": "Portainer 实例已删除",
149
149
  "Failed to delete Portainer instance": "删除 Portainer 实例失败",
150
- "Failed to load environments and stacks from Portainer": "从 Portainer 加载环境与 Stack 列表失败"
150
+ "Failed to load environments and stacks from Portainer": "从 Portainer 加载环境与 Stack 列表失败",
151
+ "Detail": "详情",
152
+ "Stack Detail": "Stack 详情",
153
+ "Auto-refresh (5s)": "自动刷新 (5s)",
154
+ "Auto-refresh live metrics (5s)": "自动刷新实时指标 (5s)",
155
+ "Stop this Stack on Portainer?": "确定在 Portainer 上停止此 Stack 吗?",
156
+ "Stack started": "Stack 已启动",
157
+ "Stack stopped": "Stack 已停止",
158
+ "Failed to control Stack": "控制 Stack 失败",
159
+ "Operation must be start or stop": "操作必须为 start 或 stop",
160
+ "Failed to load Stack details from Portainer": "从 Portainer 加载 Stack 详情失败",
161
+ "Containers Health": "容器健康度",
162
+ "Live CPU Usage": "实时 CPU 使用率",
163
+ "Live Memory Usage": "实时内存使用",
164
+ "Network I/O (RX / TX)": "网络流量 (RX / TX)",
165
+ "Containers & Live Metrics": "容器与实时指标",
166
+ "Stack containers and live metrics": "Stack 容器与实时指标",
167
+ "No containers found for this Stack": "未找到该 Stack 的容器",
168
+ "Container / Service": "容器 / 服务",
169
+ "State & Uptime": "状态与运行时长",
170
+ "Ports & IP": "端口与 IP",
171
+ "CPU": "CPU",
172
+ "Memory": "内存",
173
+ "Network / PIDs": "网络 / PIDs",
174
+ "Logs": "日志",
175
+ "Container Logs": "容器日志",
176
+ "Tail lines": "末尾行数",
177
+ "Close": "关闭",
178
+ "No log output": "暂无日志输出",
179
+ "Failed to fetch container logs": "获取容器日志失败",
180
+ "Stack Metadata": "Stack 元数据",
181
+ "Entry point": "入口文件",
182
+ "Created at": "创建时间",
183
+ "Last updated": "最后更新",
184
+ "Git commit / config": "Git 提交 / 配置文件",
185
+ "Project path": "项目路径",
186
+ "Deployment History": "部署历史",
187
+ "Time": "时间",
188
+ "Message": "消息",
189
+ "Value": "值",
190
+ "No environment variables configured": "未配置环境变量",
191
+ "Compose File": "Compose 文件",
192
+ "Compose file content is unavailable": "无法获取 Compose 文件内容"
151
193
  }
@@ -9,13 +9,22 @@
9
9
 
10
10
  import http from 'node:http';
11
11
  import type { AddressInfo } from 'node:net';
12
+ import type { Context } from '@nocobase/actions';
12
13
  import type Application from '@nocobase/server';
13
14
  import { SECRET_MASK } from '../../shared/constants';
14
15
  import { buildEffectiveStackEnv, normalizeGitReference, parseDotEnvText } from '../../shared/env';
16
+ import { createPortainerResourceActions } from '../actions/portainer';
15
17
  import { executePortainerControl } from '../instructions/PortainerStackControlInstruction';
16
18
  import { executePortainerRedeploy } from '../instructions/PortainerStackRedeployInstruction';
17
19
  import { PluginWorkflowPortainerServer } from '../plugin';
18
- import { assertValidPortainerUrl, PortainerApiError, PortainerClient } from '../services/PortainerClient';
20
+ import {
21
+ assertValidContainerId,
22
+ assertValidPortainerUrl,
23
+ computeDockerContainerStats,
24
+ demuxDockerLogBuffer,
25
+ PortainerApiError,
26
+ PortainerClient,
27
+ } from '../services/PortainerClient';
19
28
 
20
29
  interface RecordedRequest {
21
30
  method: string;
@@ -451,5 +460,100 @@ describe('plugin-workflow-portainer shared env & server instructions', () => {
451
460
  const maskedRow = (ctx.body as { data: Array<Record<string, string>> }).data[0];
452
461
  expect(maskedRow.apiKey).toBe(SECRET_MASK);
453
462
  expect(maskedRow.gitAccessToken).toBe(SECRET_MASK);
463
+ expect(allowRules.has('getStackOverview')).toBe(true);
464
+ expect(allowRules.has('getContainerLogs')).toBe(true);
465
+ expect(allowRules.has('controlStack')).toBe(false);
466
+ });
467
+
468
+ it('computes live Docker container stats, demuxes binary log frames, and builds getStackOverview', async () => {
469
+ const stats = computeDockerContainerStats({
470
+ cpu_stats: {
471
+ cpu_usage: { total_usage: 250_000_000 },
472
+ system_cpu_usage: 2_000_000_000,
473
+ online_cpus: 2,
474
+ },
475
+ precpu_stats: {
476
+ cpu_usage: { total_usage: 150_000_000 },
477
+ system_cpu_usage: 1_000_000_000,
478
+ },
479
+ memory_stats: {
480
+ usage: 120 * 1024 * 1024,
481
+ limit: 1024 * 1024 * 1024,
482
+ stats: { inactive_file: 20 * 1024 * 1024 },
483
+ },
484
+ networks: {
485
+ eth0: { rx_bytes: 4096, tx_bytes: 2048 },
486
+ eth1: { rx_bytes: 1024, tx_bytes: 512 },
487
+ },
488
+ blkio_stats: {
489
+ io_service_bytes_recursive: [
490
+ { op: 'Read', value: 8192 },
491
+ { op: 'Write', value: 4096 },
492
+ ],
493
+ },
494
+ pids_stats: { current: 7 },
495
+ });
496
+
497
+ expect(stats.cpuPercent).toBe(20);
498
+ expect(stats.memUsageBytes).toBe(100 * 1024 * 1024);
499
+ expect(stats.memLimitBytes).toBe(1024 * 1024 * 1024);
500
+ expect(stats.memPercent).toBe(9.77);
501
+ expect(stats.netRxBytes).toBe(5120);
502
+ expect(stats.netTxBytes).toBe(2560);
503
+ expect(stats.blockReadBytes).toBe(8192);
504
+ expect(stats.blockWriteBytes).toBe(4096);
505
+ expect(stats.pids).toBe(7);
506
+
507
+ const line1 = Buffer.from('2026-11-26T16:25:00Z nginx ready\n', 'utf8');
508
+ const hdr1 = Buffer.alloc(8);
509
+ hdr1[0] = 1;
510
+ hdr1.writeUInt32BE(line1.length, 4);
511
+ const line2 = Buffer.from('2026-11-26T16:25:01Z worker started\n', 'utf8');
512
+ const hdr2 = Buffer.alloc(8);
513
+ hdr2[0] = 2;
514
+ hdr2.writeUInt32BE(line2.length, 4);
515
+ const muxBuf = Buffer.concat([hdr1, line1, hdr2, line2]);
516
+
517
+ expect(demuxDockerLogBuffer(muxBuf)).toBe(
518
+ '2026-11-26T16:25:00Z nginx ready\n2026-11-26T16:25:01Z worker started\n',
519
+ );
520
+ expect(demuxDockerLogBuffer(Buffer.from('plain tty log\n', 'utf8'))).toBe('plain tty log\n');
521
+ expect(() => assertValidContainerId('../bad-path')).toThrow(PortainerApiError);
522
+ expect(assertValidContainerId('afb6265776d5')).toBe('afb6265776d5');
523
+
524
+ const app = createFakeApp({
525
+ id: 1,
526
+ name: 'Primary Portainer',
527
+ baseUrl,
528
+ apiKey: 'enc:ptr_test_key_123',
529
+ enabled: true,
530
+ defaultTimeoutMs: 10_000,
531
+ });
532
+
533
+ vi.spyOn(PortainerClient.prototype, 'getContainerLiveStats').mockResolvedValueOnce(stats);
534
+
535
+ const actions = createPortainerResourceActions(app);
536
+ const ctx = {
537
+ action: { params: { instanceId: 1, stackId: 10 } },
538
+ t: (k: string) => k,
539
+ throw: (code: number, msg: string) => {
540
+ throw new Error(`${code}:${msg}`);
541
+ },
542
+ body: undefined as unknown,
543
+ } as unknown as Context;
544
+
545
+ await actions.getStackOverview(ctx, async () => {});
546
+ const overview = ctx.body as {
547
+ detail: { env: Array<{ name: string; value: string; sensitive: boolean }> };
548
+ summary: { totalCpuPercent: number; runningCount: number };
549
+ };
550
+ expect(overview.summary.totalCpuPercent).toBe(20);
551
+ expect(overview.summary.runningCount).toBe(1);
552
+ const dbSecret = overview.detail.env.find((item) => item.name === 'DB_PASSWORD');
553
+ const existingFlag = overview.detail.env.find((item) => item.name === 'EXISTING_FLAG');
554
+ expect(dbSecret?.sensitive).toBe(true);
555
+ expect(dbSecret?.value).toBe(SECRET_MASK);
556
+ expect(existingFlag?.sensitive).toBe(false);
557
+ expect(existingFlag?.value).toBe('keep-me');
454
558
  });
455
559
  });
@@ -11,9 +11,21 @@ import type { Context, Next } from '@nocobase/actions';
11
11
  import type Application from '@nocobase/server';
12
12
  import { PLUGIN_NAMESPACE, PORTAINER_INSTANCES_COLLECTION, SECRET_MASK } from '../../shared/constants';
13
13
  import { isLikelySensitiveKey } from '../../shared/env';
14
- import type { ID, PortainerInstanceSummary } from '../../shared/types';
14
+ import type {
15
+ ID,
16
+ PortainerContainerSummary,
17
+ PortainerInstanceSummary,
18
+ PortainerStackOverview,
19
+ } from '../../shared/types';
15
20
  import { decryptIfNeeded, resolvePortainerInstance } from '../instructions/helpers';
16
- import { assertPositiveInt, clampTimeoutMs, PortainerApiError, PortainerClient } from '../services/PortainerClient';
21
+ import {
22
+ assertPositiveInt,
23
+ assertValidContainerId,
24
+ clampTimeoutMs,
25
+ PortainerApiError,
26
+ PortainerClient,
27
+ summarizeContainersHealth,
28
+ } from '../services/PortainerClient';
17
29
 
18
30
  function getRequestParam(ctx: Context, key: string): unknown {
19
31
  const params = (ctx.action?.params ?? {}) as Record<string, unknown>;
@@ -192,5 +204,158 @@ export function createPortainerResourceActions(app: Application) {
192
204
  }
193
205
  await next();
194
206
  },
207
+
208
+ async getStackOverview(ctx: Context, next: Next) {
209
+ const instanceId = getRequestParam(ctx, 'instanceId') as ID | undefined;
210
+ const rawStackId = getRequestParam(ctx, 'stackId');
211
+ const includeStatsParam = getRequestParam(ctx, 'includeStats');
212
+ const includeFileParam = getRequestParam(ctx, 'includeFile');
213
+ const includeStats = includeStatsParam !== false && includeStatsParam !== 'false';
214
+ const includeFile = includeFileParam !== false && includeFileParam !== 'false';
215
+
216
+ try {
217
+ if (rawStackId === null || typeof rawStackId === 'undefined' || String(rawStackId).trim() === '') {
218
+ ctx.throw(400, ctx.t('Stack ID is required', { ns: PLUGIN_NAMESPACE }));
219
+ }
220
+ const instance = await resolvePortainerInstance(app, instanceId ?? null);
221
+ const stackId = assertPositiveInt(rawStackId as ID, 'Stack ID');
222
+
223
+ const [detail, stackFileContent] = await Promise.all([
224
+ instance.client.getStackDetail(stackId),
225
+ includeFile ? instance.client.getStackFile(stackId).catch(() => '') : Promise.resolve(''),
226
+ ]);
227
+
228
+ const baseContainers = await instance.client
229
+ .listStackContainers(detail.endpointId, detail.name)
230
+ .catch((): PortainerContainerSummary[] => []);
231
+
232
+ const containers: PortainerContainerSummary[] = includeStats
233
+ ? await Promise.all(
234
+ baseContainers.map(async (container) => {
235
+ if (container.state !== 'running') {
236
+ return { ...container, stats: null };
237
+ }
238
+ const stats = await instance.client
239
+ .getContainerLiveStats(detail.endpointId, container.id)
240
+ .catch(() => null);
241
+ return { ...container, stats };
242
+ }),
243
+ )
244
+ : baseContainers;
245
+
246
+ const health = summarizeContainersHealth(containers);
247
+ let totalCpuPercent = 0;
248
+ let totalMemUsageBytes = 0;
249
+ let memLimitBytes = 0;
250
+ let totalNetRxBytes = 0;
251
+ let totalNetTxBytes = 0;
252
+
253
+ for (const item of containers) {
254
+ if (item.stats) {
255
+ totalCpuPercent += item.stats.cpuPercent;
256
+ totalMemUsageBytes += item.stats.memUsageBytes;
257
+ if (item.stats.memLimitBytes > memLimitBytes) {
258
+ memLimitBytes = item.stats.memLimitBytes;
259
+ }
260
+ totalNetRxBytes += item.stats.netRxBytes;
261
+ totalNetTxBytes += item.stats.netTxBytes;
262
+ }
263
+ }
264
+
265
+ const totalMemPercent =
266
+ memLimitBytes > 0 ? Math.round(((totalMemUsageBytes / memLimitBytes) * 100 + Number.EPSILON) * 100) / 100 : 0;
267
+
268
+ const overview: PortainerStackOverview = {
269
+ detail: {
270
+ ...detail,
271
+ env: detail.env.map((pair) => {
272
+ const sensitive = isLikelySensitiveKey(pair.name);
273
+ return {
274
+ name: pair.name,
275
+ value: sensitive ? SECRET_MASK : pair.value,
276
+ hasExistingValue: pair.value.length > 0,
277
+ sensitive,
278
+ };
279
+ }),
280
+ },
281
+ stackFileContent,
282
+ containers,
283
+ summary: {
284
+ ...health,
285
+ totalCpuPercent: Math.round((totalCpuPercent + Number.EPSILON) * 100) / 100,
286
+ totalMemUsageBytes,
287
+ memLimitBytes,
288
+ totalMemPercent,
289
+ totalNetRxBytes,
290
+ totalNetTxBytes,
291
+ },
292
+ sampledAt: new Date().toISOString(),
293
+ };
294
+
295
+ ctx.body = overview;
296
+ } catch (error) {
297
+ sendPortainerError(ctx, error);
298
+ }
299
+ await next();
300
+ },
301
+
302
+ async getContainerLogs(ctx: Context, next: Next) {
303
+ const instanceId = getRequestParam(ctx, 'instanceId') as ID | undefined;
304
+ const rawEndpointId = getRequestParam(ctx, 'endpointId');
305
+ const rawContainerId = getRequestParam(ctx, 'containerId');
306
+ const rawTail = getRequestParam(ctx, 'tail');
307
+
308
+ try {
309
+ const instance = await resolvePortainerInstance(app, instanceId ?? null);
310
+ const endpointId = assertPositiveInt(rawEndpointId as ID, 'Environment (Endpoint) ID');
311
+ const containerId = assertValidContainerId(String(rawContainerId ?? ''));
312
+ const tail = Math.min(1000, Math.max(10, Math.trunc(Number(rawTail) || 100)));
313
+ const logs = await instance.client.getContainerLogs(endpointId, containerId, tail);
314
+ ctx.body = {
315
+ containerId,
316
+ tail,
317
+ logs,
318
+ fetchedAt: new Date().toISOString(),
319
+ };
320
+ } catch (error) {
321
+ sendPortainerError(ctx, error);
322
+ }
323
+ await next();
324
+ },
325
+
326
+ async controlStack(ctx: Context, next: Next) {
327
+ const instanceId = getRequestParam(ctx, 'instanceId') as ID | undefined;
328
+ const rawEndpointId = getRequestParam(ctx, 'endpointId');
329
+ const rawStackId = getRequestParam(ctx, 'stackId');
330
+ const operation = String(getRequestParam(ctx, 'operation') ?? '')
331
+ .trim()
332
+ .toLowerCase();
333
+
334
+ try {
335
+ if (operation !== 'start' && operation !== 'stop') {
336
+ ctx.throw(400, ctx.t('Operation must be start or stop', { ns: PLUGIN_NAMESPACE }));
337
+ }
338
+ const instance = await resolvePortainerInstance(app, instanceId ?? null);
339
+ const endpointId = assertPositiveInt(rawEndpointId as ID, 'Environment (Endpoint) ID');
340
+ const stackId = assertPositiveInt(rawStackId as ID, 'Stack ID');
341
+
342
+ const initial =
343
+ operation === 'start'
344
+ ? await instance.client.startStack(stackId, endpointId)
345
+ : await instance.client.stopStack(stackId, endpointId);
346
+ const settled = await instance.client.waitForStackSettlement(stackId, initial, { timeoutMs: 60_000 });
347
+
348
+ ctx.body = {
349
+ ok: true,
350
+ stackId,
351
+ endpointId,
352
+ operation,
353
+ status: Number(settled?.Status ?? (operation === 'start' ? 1 : 2)),
354
+ };
355
+ } catch (error) {
356
+ sendPortainerError(ctx, error);
357
+ }
358
+ await next();
359
+ },
195
360
  };
196
361
  }
@@ -25,7 +25,14 @@ import { PortainerStackRedeployInstruction } from './instructions/PortainerStack
25
25
  import { assertValidPortainerUrl, clampTimeoutMs } from './services/PortainerClient';
26
26
 
27
27
  const ENCRYPTED_FIELDS = ['apiKey', 'gitAccessToken'] as const;
28
- const METADATA_READ_ACTIONS = ['listInstances', 'listEndpoints', 'listStacks', 'getStackDetail'] as const;
28
+ const METADATA_READ_ACTIONS = [
29
+ 'listInstances',
30
+ 'listEndpoints',
31
+ 'listStacks',
32
+ 'getStackDetail',
33
+ 'getStackOverview',
34
+ 'getContainerLogs',
35
+ ] as const;
29
36
 
30
37
  function maskSecretFields(payload: unknown): unknown {
31
38
  if (!payload || typeof payload !== 'object') {