@attraccess/plugin-rabbitmq 0.1.0-nightly.991.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.
- package/LICENSE.md +14 -0
- package/dist/index.js +535 -237
- package/frontend/__federation_expose_Plugin--VB44ZV_.js +1942 -0
- package/frontend/__federation_fn_import-BHGw2mzr.js +1 -0
- package/frontend/{_virtual___federation_fn_import-BXODRNto.js → _virtual___federation_fn_import-D2E5es2p.js} +2 -4
- package/frontend/host-shared-placeholder-BvRk9kiK.js +0 -0
- package/frontend/remoteEntry.js +3 -5
- package/frontend/style.css +41 -38
- package/package.json +12 -9
- package/frontend/__federation_expose_Plugin-ytcRKNWl.js +0 -1001
- package/frontend/__federation_fn_import-DAGm_xmC.js +0 -2
- package/frontend/jsx-runtime-B9Qmn8k7.js +0 -42
- package/frontend/preload-helper-DxWiKyOd.js +0 -68
- package/frontend/react-D5kF5LxZ.js +0 -383
- package/frontend/rolldown-runtime-EAsCxrDo.js +0 -14
package/dist/index.js
CHANGED
|
@@ -33,18 +33,52 @@ __export(plugin_exports, {
|
|
|
33
33
|
default: () => plugin_default
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(plugin_exports);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
// backend/rabbitmq-detection.controller.ts
|
|
40
|
-
var import_plugins_backend_sdk = require("@attraccess/plugins-backend-sdk");
|
|
41
|
-
var import_common2 = require("@nestjs/common");
|
|
36
|
+
var import_plugins_backend_sdk7 = require("@attraccess/plugins-backend-sdk");
|
|
37
|
+
var import_common9 = require("@nestjs/common");
|
|
42
38
|
|
|
43
|
-
// backend/
|
|
39
|
+
// backend/detection/service.ts
|
|
40
|
+
var import_plugins_backend_sdk2 = require("@attraccess/plugins-backend-sdk");
|
|
44
41
|
var import_common = require("@nestjs/common");
|
|
45
42
|
var import_node_crypto2 = require("node:crypto");
|
|
46
43
|
|
|
47
|
-
// backend/
|
|
44
|
+
// backend/permissions.ts
|
|
45
|
+
var import_plugins_backend_sdk = require("@attraccess/plugins-backend-sdk");
|
|
46
|
+
|
|
47
|
+
// backend/permission-keys.ts
|
|
48
|
+
var RABBITMQ_BROKER_READ = "rabbitmq.broker.read";
|
|
49
|
+
var RABBITMQ_BROKER_MANAGE = "rabbitmq.broker.manage";
|
|
50
|
+
|
|
51
|
+
// backend/permissions.ts
|
|
52
|
+
var RABBITMQ_PERMISSIONS = (0, import_plugins_backend_sdk.definePluginPermissions)({
|
|
53
|
+
category: { en: "RabbitMQ", de: "RabbitMQ" },
|
|
54
|
+
permissions: [
|
|
55
|
+
{
|
|
56
|
+
// View tier — detection/status, user list, connections list and broker stats.
|
|
57
|
+
key: RABBITMQ_BROKER_READ,
|
|
58
|
+
label: { en: "View RabbitMQ broker", de: "RabbitMQ-Broker anzeigen" },
|
|
59
|
+
description: {
|
|
60
|
+
en: "View the RabbitMQ detection, broker users, connections and statistics",
|
|
61
|
+
de: "RabbitMQ-Erkennung, Broker-Benutzer, Verbindungen und Statistiken anzeigen"
|
|
62
|
+
},
|
|
63
|
+
defaultRoles: ["administrator", "resource-manager", "system-admin"]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
// Manage tier — everything that changes the broker: user create/update/delete, permissions and closing
|
|
67
|
+
// connections. The live MQTT message explorer is not part of the plugin: it is a core feature for every broker.
|
|
68
|
+
key: RABBITMQ_BROKER_MANAGE,
|
|
69
|
+
label: { en: "Manage RabbitMQ broker", de: "RabbitMQ-Broker verwalten" },
|
|
70
|
+
description: {
|
|
71
|
+
en: "Create, change and delete broker users and their permissions, and close connections",
|
|
72
|
+
de: "Broker-Benutzer und deren Berechtigungen anlegen, \xE4ndern und l\xF6schen sowie Verbindungen schlie\xDFen"
|
|
73
|
+
},
|
|
74
|
+
defaultRoles: ["administrator", "system-admin"]
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
var RABBITMQ_VIEW_PERMISSION = RABBITMQ_PERMISSIONS.keys[RABBITMQ_BROKER_READ];
|
|
79
|
+
var RABBITMQ_MANAGE_PERMISSION = RABBITMQ_PERMISSIONS.keys[RABBITMQ_BROKER_MANAGE];
|
|
80
|
+
|
|
81
|
+
// backend/management/transport.ts
|
|
48
82
|
var import_node_crypto = require("node:crypto");
|
|
49
83
|
var import_node_https = require("node:https");
|
|
50
84
|
var import_node_net = require("node:net");
|
|
@@ -88,8 +122,8 @@ function trustOptions(config) {
|
|
|
88
122
|
...servername != null ? { servername } : {}
|
|
89
123
|
};
|
|
90
124
|
}
|
|
91
|
-
async function managementRequest(config, url, method, body, timeoutMs) {
|
|
92
|
-
const headers = { accept: "application/json" };
|
|
125
|
+
async function managementRequest(config, url, method, body, timeoutMs, extraHeaders) {
|
|
126
|
+
const headers = { accept: "application/json", ...extraHeaders };
|
|
93
127
|
if (config.username !== null) {
|
|
94
128
|
headers.authorization = `Basic ${Buffer.from(`${config.username}:${config.password ?? ""}`, "utf8").toString("base64")}`;
|
|
95
129
|
}
|
|
@@ -175,7 +209,7 @@ function describeManagementError(error, timeoutMs) {
|
|
|
175
209
|
}
|
|
176
210
|
}
|
|
177
211
|
|
|
178
|
-
// backend/
|
|
212
|
+
// backend/detection/service.ts
|
|
179
213
|
var PLUGIN_CONTEXT = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
180
214
|
var CACHE_TTL_MS = 6e4;
|
|
181
215
|
var PROBE_TIMEOUT_MS = 5e3;
|
|
@@ -302,8 +336,6 @@ RabbitmqDetectionService = __decorateClass([
|
|
|
302
336
|
(0, import_common.Injectable)(),
|
|
303
337
|
__decorateParam(0, (0, import_common.Inject)(PLUGIN_CONTEXT))
|
|
304
338
|
], RabbitmqDetectionService);
|
|
305
|
-
|
|
306
|
-
// backend/rabbitmq-detection.controller.ts
|
|
307
339
|
var RabbitmqDetectionController = class {
|
|
308
340
|
// esbuild does not emit decorator metadata, so Nest cannot infer constructor
|
|
309
341
|
// types for injection — always inject by an explicit token.
|
|
@@ -315,19 +347,20 @@ var RabbitmqDetectionController = class {
|
|
|
315
347
|
}
|
|
316
348
|
};
|
|
317
349
|
__decorateClass([
|
|
318
|
-
(0,
|
|
319
|
-
__decorateParam(0, (0,
|
|
320
|
-
__decorateParam(1, (0,
|
|
350
|
+
(0, import_common.Get)("detection/:mqttServerId"),
|
|
351
|
+
__decorateParam(0, (0, import_common.Param)("mqttServerId", import_common.ParseIntPipe)),
|
|
352
|
+
__decorateParam(1, (0, import_common.Query)("refresh"))
|
|
321
353
|
], RabbitmqDetectionController.prototype, "detect", 1);
|
|
322
354
|
RabbitmqDetectionController = __decorateClass([
|
|
323
|
-
(0,
|
|
324
|
-
(0,
|
|
325
|
-
__decorateParam(0, (0,
|
|
355
|
+
(0, import_plugins_backend_sdk2.Auth)(RABBITMQ_VIEW_PERMISSION),
|
|
356
|
+
(0, import_common.Controller)("rabbitmq"),
|
|
357
|
+
__decorateParam(0, (0, import_common.Inject)(RabbitmqDetectionService))
|
|
326
358
|
], RabbitmqDetectionController);
|
|
327
359
|
|
|
328
|
-
// backend/
|
|
329
|
-
var
|
|
360
|
+
// backend/management/client.ts
|
|
361
|
+
var import_common2 = require("@nestjs/common");
|
|
330
362
|
var REQUEST_TIMEOUT_MS = 1e4;
|
|
363
|
+
var MISSING_PRIVILEGE_ERROR = "not_authorised";
|
|
331
364
|
var RabbitmqManagementClient = class {
|
|
332
365
|
// Builds the management API base URL from the generic MQTT config (same
|
|
333
366
|
// convention as RabbitmqDetectionService).
|
|
@@ -337,15 +370,15 @@ var RabbitmqManagementClient = class {
|
|
|
337
370
|
// Performs one management API request. `path` is relative to `/api`, with
|
|
338
371
|
// every variable segment already URL-encoded by the caller. Returns the
|
|
339
372
|
// parsed JSON body (or null for empty responses, e.g. 201/204).
|
|
340
|
-
async request(config, method, path, body) {
|
|
373
|
+
async request(config, method, path, body, headers) {
|
|
341
374
|
const base = this.managementApiBase(config);
|
|
342
375
|
let response;
|
|
343
376
|
try {
|
|
344
|
-
response = await managementRequest(config, `${base}/api${path}`, method, body, REQUEST_TIMEOUT_MS);
|
|
377
|
+
response = await managementRequest(config, `${base}/api${path}`, method, body, REQUEST_TIMEOUT_MS, headers);
|
|
345
378
|
} catch (error) {
|
|
346
|
-
throw new
|
|
379
|
+
throw new import_common2.HttpException(
|
|
347
380
|
`Cannot reach the RabbitMQ management API at ${base}: ${describeManagementError(error, REQUEST_TIMEOUT_MS)}`,
|
|
348
|
-
|
|
381
|
+
import_common2.HttpStatus.BAD_GATEWAY
|
|
349
382
|
);
|
|
350
383
|
}
|
|
351
384
|
if (!response.ok) {
|
|
@@ -359,27 +392,28 @@ var RabbitmqManagementClient = class {
|
|
|
359
392
|
async toHttpException(response) {
|
|
360
393
|
const upstream = await this.parseErrorBody(response);
|
|
361
394
|
const reason = upstream?.reason || upstream?.error || "";
|
|
362
|
-
|
|
363
|
-
|
|
395
|
+
const missingPrivilege = upstream?.error === MISSING_PRIVILEGE_ERROR;
|
|
396
|
+
if (response.status === 401 && !missingPrivilege) {
|
|
397
|
+
return new import_common2.HttpException(
|
|
364
398
|
"The RabbitMQ management API rejected the configured MQTT server credentials (401). Check the username/password configured for this MQTT server.",
|
|
365
|
-
|
|
399
|
+
import_common2.HttpStatus.BAD_GATEWAY
|
|
366
400
|
);
|
|
367
401
|
}
|
|
368
|
-
if (response.status === 403 || /not.?authori[sz]ed/i.test(reason)) {
|
|
369
|
-
return new
|
|
370
|
-
'The configured MQTT server user lacks management privileges on RabbitMQ.
|
|
371
|
-
|
|
402
|
+
if (response.status === 403 || missingPrivilege || /not.?authori[sz]ed/i.test(reason)) {
|
|
403
|
+
return new import_common2.HttpException(
|
|
404
|
+
'The configured MQTT server user lacks management privileges on RabbitMQ. Viewing requires the "monitoring" tag; managing users and closing connections requires "administrator".',
|
|
405
|
+
import_common2.HttpStatus.BAD_GATEWAY
|
|
372
406
|
);
|
|
373
407
|
}
|
|
374
408
|
if (response.status === 404) {
|
|
375
|
-
return new
|
|
409
|
+
return new import_common2.HttpException("Not found on the RabbitMQ side.", import_common2.HttpStatus.NOT_FOUND);
|
|
376
410
|
}
|
|
377
411
|
if (response.status === 400) {
|
|
378
|
-
return new
|
|
412
|
+
return new import_common2.HttpException("RabbitMQ rejected the request.", import_common2.HttpStatus.BAD_REQUEST);
|
|
379
413
|
}
|
|
380
|
-
return new
|
|
414
|
+
return new import_common2.HttpException(
|
|
381
415
|
`RabbitMQ management API request failed (HTTP ${response.status}).`,
|
|
382
|
-
|
|
416
|
+
import_common2.HttpStatus.BAD_GATEWAY
|
|
383
417
|
);
|
|
384
418
|
}
|
|
385
419
|
async parseBody(response) {
|
|
@@ -390,9 +424,9 @@ var RabbitmqManagementClient = class {
|
|
|
390
424
|
try {
|
|
391
425
|
return JSON.parse(text);
|
|
392
426
|
} catch {
|
|
393
|
-
throw new
|
|
427
|
+
throw new import_common2.HttpException(
|
|
394
428
|
"The RabbitMQ management API returned a response that is not valid JSON.",
|
|
395
|
-
|
|
429
|
+
import_common2.HttpStatus.BAD_GATEWAY
|
|
396
430
|
);
|
|
397
431
|
}
|
|
398
432
|
}
|
|
@@ -405,15 +439,36 @@ var RabbitmqManagementClient = class {
|
|
|
405
439
|
}
|
|
406
440
|
};
|
|
407
441
|
RabbitmqManagementClient = __decorateClass([
|
|
408
|
-
(0,
|
|
442
|
+
(0, import_common2.Injectable)()
|
|
409
443
|
], RabbitmqManagementClient);
|
|
410
444
|
|
|
411
|
-
// backend/
|
|
412
|
-
var
|
|
413
|
-
var import_common5 = require("@nestjs/common");
|
|
414
|
-
|
|
415
|
-
// backend/rabbitmq-users.service.ts
|
|
445
|
+
// backend/users/service.ts
|
|
446
|
+
var import_plugins_backend_sdk3 = require("@attraccess/plugins-backend-sdk");
|
|
416
447
|
var import_common4 = require("@nestjs/common");
|
|
448
|
+
|
|
449
|
+
// backend/management/config.ts
|
|
450
|
+
var import_common3 = require("@nestjs/common");
|
|
451
|
+
async function requireMqttServerConfig(context, mqttServerId) {
|
|
452
|
+
const config = await context.getMqttServerConfig(mqttServerId);
|
|
453
|
+
if (!config) {
|
|
454
|
+
throw new import_common3.HttpException("MQTT server not found.", import_common3.HttpStatus.NOT_FOUND);
|
|
455
|
+
}
|
|
456
|
+
return config;
|
|
457
|
+
}
|
|
458
|
+
function num(value) {
|
|
459
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
460
|
+
}
|
|
461
|
+
function str(value) {
|
|
462
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
463
|
+
}
|
|
464
|
+
function rec(value) {
|
|
465
|
+
return value !== null && typeof value === "object" ? value : {};
|
|
466
|
+
}
|
|
467
|
+
function list(value) {
|
|
468
|
+
return Array.isArray(value) ? value.map(rec) : [];
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// backend/users/service.ts
|
|
417
472
|
var PLUGIN_CONTEXT2 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
418
473
|
var RabbitmqUsersService = class {
|
|
419
474
|
constructor(context, client) {
|
|
@@ -423,7 +478,7 @@ var RabbitmqUsersService = class {
|
|
|
423
478
|
// Lists all users with their per-vhost permissions, plus the vhost list for
|
|
424
479
|
// the UI's vhost choices. Three management calls, joined here.
|
|
425
480
|
async listUsers(mqttServerId) {
|
|
426
|
-
const config = await this.
|
|
481
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
427
482
|
const [rawUsers, rawPermissions, rawVhosts] = await Promise.all([
|
|
428
483
|
this.client.request(config, "GET", "/users"),
|
|
429
484
|
this.client.request(config, "GET", "/permissions"),
|
|
@@ -431,14 +486,14 @@ var RabbitmqUsersService = class {
|
|
|
431
486
|
]);
|
|
432
487
|
const permissionsByUser = /* @__PURE__ */ new Map();
|
|
433
488
|
for (const permission of rawPermissions ?? []) {
|
|
434
|
-
const
|
|
435
|
-
|
|
489
|
+
const list2 = permissionsByUser.get(permission.user) ?? [];
|
|
490
|
+
list2.push({
|
|
436
491
|
vhost: permission.vhost,
|
|
437
492
|
configure: permission.configure,
|
|
438
493
|
write: permission.write,
|
|
439
494
|
read: permission.read
|
|
440
495
|
});
|
|
441
|
-
permissionsByUser.set(permission.user,
|
|
496
|
+
permissionsByUser.set(permission.user, list2);
|
|
442
497
|
}
|
|
443
498
|
const users = (rawUsers ?? []).map((user) => ({
|
|
444
499
|
name: user.name,
|
|
@@ -456,7 +511,7 @@ var RabbitmqUsersService = class {
|
|
|
456
511
|
// the same operation (used by the create form's "default MQTT permissions").
|
|
457
512
|
async upsertUser(mqttServerId, username, dto) {
|
|
458
513
|
this.assertValidName(username, "Username");
|
|
459
|
-
const config = await this.
|
|
514
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
460
515
|
const existing = await this.findUser(config, username);
|
|
461
516
|
const password = dto.password?.length ? dto.password : void 0;
|
|
462
517
|
if (!existing && !password) {
|
|
@@ -478,7 +533,7 @@ var RabbitmqUsersService = class {
|
|
|
478
533
|
}
|
|
479
534
|
async deleteUser(mqttServerId, username) {
|
|
480
535
|
this.assertValidName(username, "Username");
|
|
481
|
-
const config = await this.
|
|
536
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
482
537
|
if (config.username !== null && config.username === username) {
|
|
483
538
|
throw new import_common4.HttpException(
|
|
484
539
|
"Refusing to delete the user the MQTT server connection is configured with.",
|
|
@@ -490,13 +545,13 @@ var RabbitmqUsersService = class {
|
|
|
490
545
|
async setPermissions(mqttServerId, username, dto) {
|
|
491
546
|
this.assertValidName(username, "Username");
|
|
492
547
|
this.assertValidName(dto.vhost, "Vhost");
|
|
493
|
-
const config = await this.
|
|
548
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
494
549
|
await this.putPermission(config, username, dto);
|
|
495
550
|
}
|
|
496
551
|
async clearPermissions(mqttServerId, username, vhost) {
|
|
497
552
|
this.assertValidName(username, "Username");
|
|
498
553
|
this.assertValidName(vhost, "Vhost");
|
|
499
|
-
const config = await this.
|
|
554
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
500
555
|
await this.client.request(
|
|
501
556
|
config,
|
|
502
557
|
"DELETE",
|
|
@@ -526,13 +581,6 @@ var RabbitmqUsersService = class {
|
|
|
526
581
|
throw error;
|
|
527
582
|
}
|
|
528
583
|
}
|
|
529
|
-
async requireConfig(mqttServerId) {
|
|
530
|
-
const config = await this.context.getMqttServerConfig(mqttServerId);
|
|
531
|
-
if (!config) {
|
|
532
|
-
throw new import_common4.HttpException("MQTT server not found.", import_common4.HttpStatus.NOT_FOUND);
|
|
533
|
-
}
|
|
534
|
-
return config;
|
|
535
|
-
}
|
|
536
584
|
normalizeTags(tags) {
|
|
537
585
|
if (Array.isArray(tags)) {
|
|
538
586
|
return tags.filter((tag) => tag.length > 0);
|
|
@@ -556,8 +604,6 @@ RabbitmqUsersService = __decorateClass([
|
|
|
556
604
|
__decorateParam(0, (0, import_common4.Inject)(PLUGIN_CONTEXT2)),
|
|
557
605
|
__decorateParam(1, (0, import_common4.Inject)(RabbitmqManagementClient))
|
|
558
606
|
], RabbitmqUsersService);
|
|
559
|
-
|
|
560
|
-
// backend/rabbitmq-users.controller.ts
|
|
561
607
|
var RabbitmqUsersController = class {
|
|
562
608
|
// esbuild does not emit decorator metadata, so Nest cannot infer constructor
|
|
563
609
|
// types for injection — always inject by an explicit token.
|
|
@@ -575,53 +621,56 @@ var RabbitmqUsersController = class {
|
|
|
575
621
|
}
|
|
576
622
|
setPermissions(mqttServerId, username, dto) {
|
|
577
623
|
if (!dto || typeof dto.vhost !== "string") {
|
|
578
|
-
throw new
|
|
624
|
+
throw new import_common4.HttpException("A vhost is required.", import_common4.HttpStatus.BAD_REQUEST);
|
|
579
625
|
}
|
|
580
626
|
return this.users.setPermissions(mqttServerId, username, dto);
|
|
581
627
|
}
|
|
582
628
|
clearPermissions(mqttServerId, username, vhost) {
|
|
583
629
|
if (typeof vhost !== "string" || vhost.length === 0) {
|
|
584
|
-
throw new
|
|
630
|
+
throw new import_common4.HttpException("A vhost query parameter is required.", import_common4.HttpStatus.BAD_REQUEST);
|
|
585
631
|
}
|
|
586
632
|
return this.users.clearPermissions(mqttServerId, username, vhost);
|
|
587
633
|
}
|
|
588
634
|
};
|
|
589
635
|
__decorateClass([
|
|
590
|
-
(0,
|
|
591
|
-
|
|
636
|
+
(0, import_plugins_backend_sdk3.Auth)(RABBITMQ_VIEW_PERMISSION),
|
|
637
|
+
(0, import_common4.Get)("users/:mqttServerId"),
|
|
638
|
+
__decorateParam(0, (0, import_common4.Param)("mqttServerId", import_common4.ParseIntPipe))
|
|
592
639
|
], RabbitmqUsersController.prototype, "list", 1);
|
|
593
640
|
__decorateClass([
|
|
594
|
-
(0,
|
|
595
|
-
|
|
596
|
-
__decorateParam(
|
|
597
|
-
__decorateParam(
|
|
641
|
+
(0, import_plugins_backend_sdk3.Auth)(RABBITMQ_MANAGE_PERMISSION),
|
|
642
|
+
(0, import_common4.Put)("users/:mqttServerId/:username"),
|
|
643
|
+
__decorateParam(0, (0, import_common4.Param)("mqttServerId", import_common4.ParseIntPipe)),
|
|
644
|
+
__decorateParam(1, (0, import_common4.Param)("username")),
|
|
645
|
+
__decorateParam(2, (0, import_common4.Body)())
|
|
598
646
|
], RabbitmqUsersController.prototype, "upsert", 1);
|
|
599
647
|
__decorateClass([
|
|
600
|
-
(0,
|
|
601
|
-
|
|
602
|
-
__decorateParam(
|
|
648
|
+
(0, import_plugins_backend_sdk3.Auth)(RABBITMQ_MANAGE_PERMISSION),
|
|
649
|
+
(0, import_common4.Delete)("users/:mqttServerId/:username"),
|
|
650
|
+
__decorateParam(0, (0, import_common4.Param)("mqttServerId", import_common4.ParseIntPipe)),
|
|
651
|
+
__decorateParam(1, (0, import_common4.Param)("username"))
|
|
603
652
|
], RabbitmqUsersController.prototype, "remove", 1);
|
|
604
653
|
__decorateClass([
|
|
605
|
-
(0,
|
|
606
|
-
|
|
607
|
-
__decorateParam(
|
|
608
|
-
__decorateParam(
|
|
654
|
+
(0, import_plugins_backend_sdk3.Auth)(RABBITMQ_MANAGE_PERMISSION),
|
|
655
|
+
(0, import_common4.Put)("users/:mqttServerId/:username/permissions"),
|
|
656
|
+
__decorateParam(0, (0, import_common4.Param)("mqttServerId", import_common4.ParseIntPipe)),
|
|
657
|
+
__decorateParam(1, (0, import_common4.Param)("username")),
|
|
658
|
+
__decorateParam(2, (0, import_common4.Body)())
|
|
609
659
|
], RabbitmqUsersController.prototype, "setPermissions", 1);
|
|
610
660
|
__decorateClass([
|
|
611
|
-
(0,
|
|
612
|
-
|
|
613
|
-
__decorateParam(
|
|
614
|
-
__decorateParam(
|
|
661
|
+
(0, import_plugins_backend_sdk3.Auth)(RABBITMQ_MANAGE_PERMISSION),
|
|
662
|
+
(0, import_common4.Delete)("users/:mqttServerId/:username/permissions"),
|
|
663
|
+
__decorateParam(0, (0, import_common4.Param)("mqttServerId", import_common4.ParseIntPipe)),
|
|
664
|
+
__decorateParam(1, (0, import_common4.Param)("username")),
|
|
665
|
+
__decorateParam(2, (0, import_common4.Query)("vhost"))
|
|
615
666
|
], RabbitmqUsersController.prototype, "clearPermissions", 1);
|
|
616
667
|
RabbitmqUsersController = __decorateClass([
|
|
617
|
-
(0,
|
|
618
|
-
(0,
|
|
619
|
-
__decorateParam(0, (0, import_common5.Inject)(RabbitmqUsersService))
|
|
668
|
+
(0, import_common4.Controller)("rabbitmq"),
|
|
669
|
+
__decorateParam(0, (0, import_common4.Inject)(RabbitmqUsersService))
|
|
620
670
|
], RabbitmqUsersController);
|
|
621
671
|
|
|
622
|
-
// backend/
|
|
623
|
-
var
|
|
624
|
-
var import_common6 = require("@nestjs/common");
|
|
672
|
+
// backend/credentials/provider.ts
|
|
673
|
+
var import_common5 = require("@nestjs/common");
|
|
625
674
|
|
|
626
675
|
// ../../../node_modules/.pnpm/async-mutex@0.5.0/node_modules/async-mutex/index.mjs
|
|
627
676
|
var E_TIMEOUT = new Error("timeout while waiting for mutex to become available");
|
|
@@ -829,7 +878,31 @@ var Mutex = class {
|
|
|
829
878
|
}
|
|
830
879
|
};
|
|
831
880
|
|
|
832
|
-
// backend/
|
|
881
|
+
// backend/credentials/provider.ts
|
|
882
|
+
var import_crypto = require("crypto");
|
|
883
|
+
function escapeRegex(value) {
|
|
884
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
885
|
+
}
|
|
886
|
+
function mqttFilterToRegex(filter) {
|
|
887
|
+
const terminalMultiLevel = filter.endsWith("/#");
|
|
888
|
+
const prefix = terminalMultiLevel ? filter.slice(0, -2) : filter;
|
|
889
|
+
const translated = prefix.split("/").map((segment) => {
|
|
890
|
+
if (segment === "+") {
|
|
891
|
+
return "[^.]+";
|
|
892
|
+
}
|
|
893
|
+
if (segment === "#") {
|
|
894
|
+
return ".*";
|
|
895
|
+
}
|
|
896
|
+
return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
897
|
+
}).join("\\.");
|
|
898
|
+
return terminalMultiLevel ? `${translated}(?:\\..*)?` : translated;
|
|
899
|
+
}
|
|
900
|
+
function mqttFiltersToRegex(filters) {
|
|
901
|
+
if (filters.length === 0) {
|
|
902
|
+
return "$(?!)";
|
|
903
|
+
}
|
|
904
|
+
return `^(?:${filters.map(mqttFilterToRegex).join("|")})$`;
|
|
905
|
+
}
|
|
833
906
|
var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvisioningProvider {
|
|
834
907
|
constructor(context) {
|
|
835
908
|
__publicField(this, "context", context);
|
|
@@ -839,46 +912,114 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
839
912
|
__publicField(this, "detection");
|
|
840
913
|
this.detection = new RabbitmqDetectionService(context);
|
|
841
914
|
}
|
|
842
|
-
|
|
843
|
-
|
|
915
|
+
assertNotManagementUser(config, username) {
|
|
916
|
+
if (config.username === username) {
|
|
917
|
+
throw new import_common5.BadRequestException("Refusing to modify the MQTT server management identity.");
|
|
918
|
+
}
|
|
844
919
|
}
|
|
845
|
-
|
|
846
|
-
|
|
920
|
+
assertName(value, label) {
|
|
921
|
+
if (typeof value !== "string" || value.trim().length === 0 || value.length > 255) {
|
|
922
|
+
throw new import_common5.BadRequestException(`${label} must be a non-empty string no longer than 255 characters.`);
|
|
923
|
+
}
|
|
847
924
|
}
|
|
848
|
-
|
|
849
|
-
|
|
925
|
+
assertTopicFilter(filter) {
|
|
926
|
+
if (filter.includes(".")) {
|
|
927
|
+
throw new import_common5.BadRequestException("RabbitMQ MQTT topic policies cannot contain dots.");
|
|
928
|
+
}
|
|
929
|
+
const segments = filter.split("/");
|
|
930
|
+
for (const [index, segment] of segments.entries()) {
|
|
931
|
+
if (segment.includes("+") && segment !== "+" || segment.includes("#") && (segment !== "#" || index !== segments.length - 1)) {
|
|
932
|
+
throw new import_common5.BadRequestException(
|
|
933
|
+
"MQTT wildcards must occupy a complete topic level, and # must be the final level."
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
850
937
|
}
|
|
851
|
-
|
|
938
|
+
assertRequest(request2) {
|
|
939
|
+
this.assertName(request2.identity, "Identity");
|
|
852
940
|
this.assertName(request2.username, "Username");
|
|
853
|
-
|
|
854
|
-
|
|
941
|
+
this.assertName(request2.vhost, "Vhost");
|
|
942
|
+
if (!Array.isArray(request2.topicPolicy.publish) || !Array.isArray(request2.topicPolicy.subscribe)) {
|
|
943
|
+
throw new import_common5.BadRequestException("Publish and subscribe topic policies must be arrays.");
|
|
944
|
+
}
|
|
945
|
+
for (const filter of [...request2.topicPolicy.publish, ...request2.topicPolicy.subscribe]) {
|
|
946
|
+
if (typeof filter !== "string" || filter.length === 0 || filter.length > 1024) {
|
|
947
|
+
throw new import_common5.BadRequestException("MQTT topic filters must be non-empty strings no longer than 1024 characters.");
|
|
948
|
+
}
|
|
949
|
+
this.assertTopicFilter(filter);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
async requireConfig(mqttServerId) {
|
|
953
|
+
const config = await this.context.getMqttServerConfig(mqttServerId);
|
|
954
|
+
if (!config) {
|
|
955
|
+
throw new import_common5.BadRequestException("MQTT server not found.");
|
|
956
|
+
}
|
|
957
|
+
return config;
|
|
958
|
+
}
|
|
959
|
+
async failAfterRollback(error, rollback) {
|
|
960
|
+
const results = await Promise.allSettled(rollback.map((operation) => operation()));
|
|
961
|
+
const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
962
|
+
if (failures.length > 0) {
|
|
963
|
+
throw new AggregateError([error, ...failures], "Credential provisioning failed and rollback was incomplete.");
|
|
964
|
+
}
|
|
965
|
+
throw error;
|
|
966
|
+
}
|
|
967
|
+
async restorePermission(config, path, permissions) {
|
|
968
|
+
await this.client.request(config, permissions ? "PUT" : "DELETE", path, permissions ?? void 0);
|
|
969
|
+
}
|
|
970
|
+
async restorePermissions(config, vhost, username, permissions, topicPermissions) {
|
|
971
|
+
const results = await Promise.allSettled([
|
|
972
|
+
this.restorePermission(config, `/permissions/${vhost}/${username}`, permissions),
|
|
973
|
+
this.restorePermission(config, `/topic-permissions/${vhost}/${username}`, topicPermissions)
|
|
974
|
+
]);
|
|
975
|
+
const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
976
|
+
if (failures.length > 0) {
|
|
977
|
+
throw new AggregateError(failures, "Failed to restore RabbitMQ permissions.");
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
async getOptional(config, path) {
|
|
855
981
|
try {
|
|
856
|
-
await this.client.request(config, "
|
|
982
|
+
return await this.client.request(config, "GET", path);
|
|
857
983
|
} catch (error) {
|
|
858
|
-
if (error instanceof
|
|
984
|
+
if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) {
|
|
985
|
+
return null;
|
|
986
|
+
}
|
|
859
987
|
throw error;
|
|
860
988
|
}
|
|
861
989
|
}
|
|
862
|
-
async
|
|
863
|
-
this.
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
lock = { mutex: new Mutex(), users: 0 };
|
|
870
|
-
_RabbitmqCredentialProvisioningProvider.vhostLocks.set(lockKey, lock);
|
|
871
|
-
}
|
|
872
|
-
lock.users += 1;
|
|
990
|
+
async getTopicPermissions(config, vhost, username) {
|
|
991
|
+
return this.getOptional(config, `/topic-permissions/${vhost}/${username}`);
|
|
992
|
+
}
|
|
993
|
+
async getPermissions(config, vhost, username) {
|
|
994
|
+
return this.getOptional(config, `/permissions/${vhost}/${username}`);
|
|
995
|
+
}
|
|
996
|
+
async exists(config, path) {
|
|
873
997
|
try {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
if (
|
|
878
|
-
|
|
998
|
+
await this.client.request(config, "GET", path);
|
|
999
|
+
return true;
|
|
1000
|
+
} catch (error) {
|
|
1001
|
+
if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) {
|
|
1002
|
+
return false;
|
|
879
1003
|
}
|
|
1004
|
+
throw error;
|
|
880
1005
|
}
|
|
881
1006
|
}
|
|
1007
|
+
async userExists(config, username) {
|
|
1008
|
+
return this.exists(config, `/users/${username}`);
|
|
1009
|
+
}
|
|
1010
|
+
async writePermissions(config, request2, vhost, username) {
|
|
1011
|
+
const subscriptionQueue = `mqtt-subscription-${escapeRegex(request2.identity)}.*`;
|
|
1012
|
+
await this.client.request(config, "PUT", `/permissions/${vhost}/${username}`, {
|
|
1013
|
+
configure: `^${subscriptionQueue}$`,
|
|
1014
|
+
write: `^(amq\\.topic|${subscriptionQueue})$`,
|
|
1015
|
+
read: `^(amq\\.topic|${subscriptionQueue})$`
|
|
1016
|
+
});
|
|
1017
|
+
await this.client.request(config, "PUT", `/topic-permissions/${vhost}/${username}`, {
|
|
1018
|
+
exchange: "amq.topic",
|
|
1019
|
+
write: mqttFiltersToRegex(request2.topicPolicy.publish),
|
|
1020
|
+
read: mqttFiltersToRegex(request2.topicPolicy.subscribe)
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
882
1023
|
async writeCredentialLocked(request2, config) {
|
|
883
1024
|
const password = (0, import_crypto.randomBytes)(24).toString("base64url");
|
|
884
1025
|
const vhost = encodeURIComponent(request2.vhost);
|
|
@@ -915,143 +1056,289 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
915
1056
|
password
|
|
916
1057
|
};
|
|
917
1058
|
}
|
|
918
|
-
async
|
|
919
|
-
|
|
920
|
-
await this.
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
async userExists(config, username) {
|
|
932
|
-
return this.exists(config, `/users/${username}`);
|
|
933
|
-
}
|
|
934
|
-
async exists(config, path) {
|
|
1059
|
+
async writeCredential(request2) {
|
|
1060
|
+
this.assertRequest(request2);
|
|
1061
|
+
const config = await this.requireConfig(request2.mqttServerId);
|
|
1062
|
+
this.assertNotManagementUser(config, request2.username);
|
|
1063
|
+
const lockKey = `${config.id}:${request2.vhost}`;
|
|
1064
|
+
let lock = _RabbitmqCredentialProvisioningProvider.vhostLocks.get(lockKey);
|
|
1065
|
+
if (!lock) {
|
|
1066
|
+
lock = { mutex: new Mutex(), users: 0 };
|
|
1067
|
+
_RabbitmqCredentialProvisioningProvider.vhostLocks.set(lockKey, lock);
|
|
1068
|
+
}
|
|
1069
|
+
lock.users += 1;
|
|
935
1070
|
try {
|
|
936
|
-
await
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
if (
|
|
940
|
-
|
|
1071
|
+
return await lock.mutex.runExclusive(() => this.writeCredentialLocked(request2, config));
|
|
1072
|
+
} finally {
|
|
1073
|
+
lock.users -= 1;
|
|
1074
|
+
if (lock.users === 0 && _RabbitmqCredentialProvisioningProvider.vhostLocks.get(lockKey) === lock) {
|
|
1075
|
+
_RabbitmqCredentialProvisioningProvider.vhostLocks.delete(lockKey);
|
|
941
1076
|
}
|
|
942
|
-
throw error;
|
|
943
1077
|
}
|
|
944
1078
|
}
|
|
945
|
-
async
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
return this.getOptional(config, `/topic-permissions/${vhost}/${username}`);
|
|
950
|
-
}
|
|
951
|
-
async getOptional(config, path) {
|
|
1079
|
+
async revoke(request2) {
|
|
1080
|
+
this.assertName(request2.username, "Username");
|
|
1081
|
+
const config = await this.requireConfig(request2.mqttServerId);
|
|
1082
|
+
this.assertNotManagementUser(config, request2.username);
|
|
952
1083
|
try {
|
|
953
|
-
|
|
1084
|
+
await this.client.request(config, "DELETE", `/users/${encodeURIComponent(request2.username)}`);
|
|
954
1085
|
} catch (error) {
|
|
955
|
-
if (error instanceof
|
|
956
|
-
return null;
|
|
957
|
-
}
|
|
1086
|
+
if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) return;
|
|
958
1087
|
throw error;
|
|
959
1088
|
}
|
|
960
1089
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
this.restorePermission(config, `/permissions/${vhost}/${username}`, permissions),
|
|
964
|
-
this.restorePermission(config, `/topic-permissions/${vhost}/${username}`, topicPermissions)
|
|
965
|
-
]);
|
|
966
|
-
const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
967
|
-
if (failures.length > 0) {
|
|
968
|
-
throw new AggregateError(failures, "Failed to restore RabbitMQ permissions.");
|
|
969
|
-
}
|
|
1090
|
+
rotate(request2) {
|
|
1091
|
+
return this.writeCredential(request2);
|
|
970
1092
|
}
|
|
971
|
-
|
|
972
|
-
|
|
1093
|
+
provision(request2) {
|
|
1094
|
+
return this.writeCredential(request2);
|
|
973
1095
|
}
|
|
974
|
-
async
|
|
975
|
-
|
|
976
|
-
const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
977
|
-
if (failures.length > 0) {
|
|
978
|
-
throw new AggregateError([error, ...failures], "Credential provisioning failed and rollback was incomplete.");
|
|
979
|
-
}
|
|
980
|
-
throw error;
|
|
1096
|
+
async supports(config) {
|
|
1097
|
+
return (await this.detection.detect(config.id)).isRabbitMQ;
|
|
981
1098
|
}
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1099
|
+
};
|
|
1100
|
+
__publicField(_RabbitmqCredentialProvisioningProvider, "vhostLocks", /* @__PURE__ */ new Map());
|
|
1101
|
+
var RabbitmqCredentialProvisioningProvider = _RabbitmqCredentialProvisioningProvider;
|
|
1102
|
+
|
|
1103
|
+
// backend/capabilities.ts
|
|
1104
|
+
var import_plugins_backend_sdk4 = require("@attraccess/plugins-backend-sdk");
|
|
1105
|
+
var import_common6 = require("@nestjs/common");
|
|
1106
|
+
var RabbitmqCapabilitiesController = class {
|
|
1107
|
+
capabilities(request2) {
|
|
1108
|
+
return { canManage: request2.user.effectivePermissions?.has(RABBITMQ_MANAGE_PERMISSION) === true };
|
|
988
1109
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1110
|
+
};
|
|
1111
|
+
__decorateClass([
|
|
1112
|
+
(0, import_plugins_backend_sdk4.Auth)(RABBITMQ_VIEW_PERMISSION),
|
|
1113
|
+
(0, import_common6.Get)("capabilities"),
|
|
1114
|
+
__decorateParam(0, (0, import_common6.Req)())
|
|
1115
|
+
], RabbitmqCapabilitiesController.prototype, "capabilities", 1);
|
|
1116
|
+
RabbitmqCapabilitiesController = __decorateClass([
|
|
1117
|
+
(0, import_common6.Controller)("rabbitmq")
|
|
1118
|
+
], RabbitmqCapabilitiesController);
|
|
1119
|
+
|
|
1120
|
+
// backend/connections/service.ts
|
|
1121
|
+
var import_plugins_backend_sdk5 = require("@attraccess/plugins-backend-sdk");
|
|
1122
|
+
var import_common7 = require("@nestjs/common");
|
|
1123
|
+
var PLUGIN_CONTEXT3 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
1124
|
+
var MAX_CONNECTIONS = 1e3;
|
|
1125
|
+
var MAX_REASON_LENGTH = 200;
|
|
1126
|
+
var CONNECTION_COLUMNS = [
|
|
1127
|
+
"name",
|
|
1128
|
+
"client_properties",
|
|
1129
|
+
"user",
|
|
1130
|
+
"vhost",
|
|
1131
|
+
"peer_host",
|
|
1132
|
+
"peer_port",
|
|
1133
|
+
"protocol",
|
|
1134
|
+
"state",
|
|
1135
|
+
"ssl",
|
|
1136
|
+
"connected_at",
|
|
1137
|
+
"channels",
|
|
1138
|
+
"recv_oct",
|
|
1139
|
+
"send_oct",
|
|
1140
|
+
"recv_oct_details",
|
|
1141
|
+
"send_oct_details"
|
|
1142
|
+
].join(",");
|
|
1143
|
+
function toConnection(row) {
|
|
1144
|
+
const name = str(row.name);
|
|
1145
|
+
if (!name) return null;
|
|
1146
|
+
const properties = rec(row.client_properties);
|
|
1147
|
+
return {
|
|
1148
|
+
name,
|
|
1149
|
+
clientId: str(properties.connection_name) ?? str(properties.client_id),
|
|
1150
|
+
user: str(row.user),
|
|
1151
|
+
vhost: str(row.vhost),
|
|
1152
|
+
peerHost: str(row.peer_host),
|
|
1153
|
+
peerPort: num(row.peer_port),
|
|
1154
|
+
protocol: str(row.protocol),
|
|
1155
|
+
state: str(row.state),
|
|
1156
|
+
ssl: row.ssl === true,
|
|
1157
|
+
connectedAt: num(row.connected_at),
|
|
1158
|
+
channels: num(row.channels),
|
|
1159
|
+
recvBytes: num(row.recv_oct),
|
|
1160
|
+
sendBytes: num(row.send_oct),
|
|
1161
|
+
recvRate: num(rec(row.recv_oct_details).rate),
|
|
1162
|
+
sendRate: num(rec(row.send_oct_details).rate)
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
var RabbitmqConnectionsService = class {
|
|
1166
|
+
constructor(context, client) {
|
|
1167
|
+
__publicField(this, "context", context);
|
|
1168
|
+
__publicField(this, "client", client);
|
|
1002
1169
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1170
|
+
async listConnections(mqttServerId) {
|
|
1171
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
1172
|
+
const raw = await this.client.request(config, "GET", `/connections?columns=${CONNECTION_COLUMNS}`);
|
|
1173
|
+
const all = list(raw).map(toConnection).filter((row) => row !== null).sort((a, b) => (a.clientId ?? a.name).localeCompare(b.clientId ?? b.name));
|
|
1174
|
+
return {
|
|
1175
|
+
mqttServerId,
|
|
1176
|
+
total: all.length,
|
|
1177
|
+
truncated: all.length > MAX_CONNECTIONS,
|
|
1178
|
+
connections: all.slice(0, MAX_CONNECTIONS)
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
// Query values arrive as arrays when repeated (`?reason=a&reason=b`), so both
|
|
1182
|
+
// parameters are checked at runtime rather than trusted to be strings.
|
|
1183
|
+
async closeConnection(mqttServerId, name, reason) {
|
|
1184
|
+
if (typeof name !== "string" || name.length === 0 || name.length > 1024) {
|
|
1185
|
+
throw new import_common7.HttpException("A connection name is required.", import_common7.HttpStatus.BAD_REQUEST);
|
|
1006
1186
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
if (segment.includes("+") && segment !== "+" || segment.includes("#") && (segment !== "#" || index !== segments.length - 1)) {
|
|
1010
|
-
throw new import_common6.BadRequestException(
|
|
1011
|
-
"MQTT wildcards must occupy a complete topic level, and # must be the final level."
|
|
1012
|
-
);
|
|
1013
|
-
}
|
|
1187
|
+
if (name === "." || name === "..") {
|
|
1188
|
+
throw new import_common7.HttpException("Invalid connection name.", import_common7.HttpStatus.BAD_REQUEST);
|
|
1014
1189
|
}
|
|
1190
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
1191
|
+
const headers = {};
|
|
1192
|
+
const cleaned = (typeof reason === "string" ? reason : "").normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/[^\x20-\x7e]/g, "?").trim().slice(0, MAX_REASON_LENGTH);
|
|
1193
|
+
if (cleaned.length > 0) headers["x-reason"] = cleaned;
|
|
1194
|
+
await this.client.request(config, "DELETE", `/connections/${encodeURIComponent(name)}`, void 0, headers);
|
|
1015
1195
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1196
|
+
};
|
|
1197
|
+
RabbitmqConnectionsService = __decorateClass([
|
|
1198
|
+
(0, import_common7.Injectable)(),
|
|
1199
|
+
__decorateParam(0, (0, import_common7.Inject)(PLUGIN_CONTEXT3)),
|
|
1200
|
+
__decorateParam(1, (0, import_common7.Inject)(RabbitmqManagementClient))
|
|
1201
|
+
], RabbitmqConnectionsService);
|
|
1202
|
+
var RabbitmqConnectionsController = class {
|
|
1203
|
+
// esbuild does not emit decorator metadata, so Nest cannot infer constructor
|
|
1204
|
+
// types for injection — always inject by an explicit token.
|
|
1205
|
+
constructor(connections) {
|
|
1206
|
+
__publicField(this, "connections", connections);
|
|
1020
1207
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1208
|
+
list(mqttServerId) {
|
|
1209
|
+
return this.connections.listConnections(mqttServerId);
|
|
1210
|
+
}
|
|
1211
|
+
close(mqttServerId, name, reason) {
|
|
1212
|
+
return this.connections.closeConnection(mqttServerId, name, reason);
|
|
1025
1213
|
}
|
|
1026
1214
|
};
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1215
|
+
__decorateClass([
|
|
1216
|
+
(0, import_plugins_backend_sdk5.Auth)(RABBITMQ_VIEW_PERMISSION),
|
|
1217
|
+
(0, import_common7.Get)("connections/:mqttServerId"),
|
|
1218
|
+
__decorateParam(0, (0, import_common7.Param)("mqttServerId", import_common7.ParseIntPipe))
|
|
1219
|
+
], RabbitmqConnectionsController.prototype, "list", 1);
|
|
1220
|
+
__decorateClass([
|
|
1221
|
+
(0, import_plugins_backend_sdk5.Auth)(RABBITMQ_MANAGE_PERMISSION),
|
|
1222
|
+
(0, import_common7.Delete)("connections/:mqttServerId"),
|
|
1223
|
+
__decorateParam(0, (0, import_common7.Param)("mqttServerId", import_common7.ParseIntPipe)),
|
|
1224
|
+
__decorateParam(1, (0, import_common7.Query)("name")),
|
|
1225
|
+
__decorateParam(2, (0, import_common7.Query)("reason"))
|
|
1226
|
+
], RabbitmqConnectionsController.prototype, "close", 1);
|
|
1227
|
+
RabbitmqConnectionsController = __decorateClass([
|
|
1228
|
+
(0, import_common7.Controller)("rabbitmq"),
|
|
1229
|
+
__decorateParam(0, (0, import_common7.Inject)(RabbitmqConnectionsService))
|
|
1230
|
+
], RabbitmqConnectionsController);
|
|
1231
|
+
|
|
1232
|
+
// backend/stats/service.ts
|
|
1233
|
+
var import_plugins_backend_sdk6 = require("@attraccess/plugins-backend-sdk");
|
|
1234
|
+
var import_common8 = require("@nestjs/common");
|
|
1235
|
+
var PLUGIN_CONTEXT4 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
1236
|
+
var MAX_QUEUES = 1e3;
|
|
1237
|
+
var NODE_COLUMNS = [
|
|
1238
|
+
"name",
|
|
1239
|
+
"running",
|
|
1240
|
+
"mem_used",
|
|
1241
|
+
"mem_limit",
|
|
1242
|
+
"mem_alarm",
|
|
1243
|
+
"disk_free",
|
|
1244
|
+
"disk_free_limit",
|
|
1245
|
+
"disk_free_alarm",
|
|
1246
|
+
"fd_used",
|
|
1247
|
+
"fd_total",
|
|
1248
|
+
"sockets_used",
|
|
1249
|
+
"sockets_total",
|
|
1250
|
+
"uptime"
|
|
1251
|
+
].join(",");
|
|
1252
|
+
var bool = (value) => typeof value === "boolean" ? value : null;
|
|
1253
|
+
var RabbitmqStatsService = class {
|
|
1254
|
+
constructor(context, client) {
|
|
1255
|
+
__publicField(this, "context", context);
|
|
1256
|
+
__publicField(this, "client", client);
|
|
1032
1257
|
}
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1258
|
+
async getStats(mqttServerId) {
|
|
1259
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
1260
|
+
const [rawOverview, rawNodes, rawQueues] = await Promise.all([
|
|
1261
|
+
this.client.request(config, "GET", "/overview"),
|
|
1262
|
+
this.client.request(config, "GET", `/nodes?columns=${NODE_COLUMNS}`),
|
|
1263
|
+
this.client.request(
|
|
1264
|
+
config,
|
|
1265
|
+
"GET",
|
|
1266
|
+
"/queues?columns=vhost,name,type,state,messages_ready,messages_unacknowledged,consumers"
|
|
1267
|
+
)
|
|
1268
|
+
]);
|
|
1269
|
+
const overview = rec(rawOverview);
|
|
1270
|
+
const totals = rec(overview.object_totals);
|
|
1271
|
+
const queueTotals = rec(overview.queue_totals);
|
|
1272
|
+
const messageStats = rec(overview.message_stats);
|
|
1273
|
+
const queues = list(rawQueues).map((row) => ({
|
|
1274
|
+
vhost: str(row.vhost) ?? "/",
|
|
1275
|
+
name: str(row.name) ?? "",
|
|
1276
|
+
type: str(row.type),
|
|
1277
|
+
state: str(row.state),
|
|
1278
|
+
messagesReady: num(row.messages_ready),
|
|
1279
|
+
messagesUnacknowledged: num(row.messages_unacknowledged),
|
|
1280
|
+
consumers: num(row.consumers)
|
|
1281
|
+
})).sort((a, b) => a.vhost.localeCompare(b.vhost) || a.name.localeCompare(b.name));
|
|
1282
|
+
return {
|
|
1283
|
+
mqttServerId,
|
|
1284
|
+
overview: {
|
|
1285
|
+
rabbitmqVersion: str(overview.rabbitmq_version),
|
|
1286
|
+
erlangVersion: str(overview.erlang_version),
|
|
1287
|
+
clusterName: str(overview.cluster_name),
|
|
1288
|
+
connections: num(totals.connections),
|
|
1289
|
+
channels: num(totals.channels),
|
|
1290
|
+
queues: num(totals.queues),
|
|
1291
|
+
consumers: num(totals.consumers),
|
|
1292
|
+
messagesReady: num(queueTotals.messages_ready),
|
|
1293
|
+
messagesUnacknowledged: num(queueTotals.messages_unacknowledged),
|
|
1294
|
+
publishRate: num(rec(messageStats.publish_details).rate),
|
|
1295
|
+
deliverRate: num(rec(messageStats.deliver_get_details).rate)
|
|
1296
|
+
},
|
|
1297
|
+
nodes: list(rawNodes).map((row) => ({
|
|
1298
|
+
name: str(row.name) ?? "",
|
|
1299
|
+
running: bool(row.running),
|
|
1300
|
+
memUsed: num(row.mem_used),
|
|
1301
|
+
memLimit: num(row.mem_limit),
|
|
1302
|
+
memAlarm: bool(row.mem_alarm),
|
|
1303
|
+
diskFree: num(row.disk_free),
|
|
1304
|
+
diskFreeLimit: num(row.disk_free_limit),
|
|
1305
|
+
diskFreeAlarm: bool(row.disk_free_alarm),
|
|
1306
|
+
fdUsed: num(row.fd_used),
|
|
1307
|
+
fdTotal: num(row.fd_total),
|
|
1308
|
+
socketsUsed: num(row.sockets_used),
|
|
1309
|
+
socketsTotal: num(row.sockets_total),
|
|
1310
|
+
uptime: num(row.uptime)
|
|
1311
|
+
})).sort((a, b) => a.name.localeCompare(b.name)),
|
|
1312
|
+
queues: queues.slice(0, MAX_QUEUES),
|
|
1313
|
+
totalQueues: queues.length
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
};
|
|
1317
|
+
RabbitmqStatsService = __decorateClass([
|
|
1318
|
+
(0, import_common8.Injectable)(),
|
|
1319
|
+
__decorateParam(0, (0, import_common8.Inject)(PLUGIN_CONTEXT4)),
|
|
1320
|
+
__decorateParam(1, (0, import_common8.Inject)(RabbitmqManagementClient))
|
|
1321
|
+
], RabbitmqStatsService);
|
|
1322
|
+
var RabbitmqStatsController = class {
|
|
1323
|
+
constructor(stats) {
|
|
1324
|
+
__publicField(this, "stats", stats);
|
|
1325
|
+
}
|
|
1326
|
+
get(mqttServerId) {
|
|
1327
|
+
return this.stats.getStats(mqttServerId);
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
__decorateClass([
|
|
1331
|
+
(0, import_common8.Get)("stats/:mqttServerId"),
|
|
1332
|
+
__decorateParam(0, (0, import_common8.Param)("mqttServerId", import_common8.ParseIntPipe))
|
|
1333
|
+
], RabbitmqStatsController.prototype, "get", 1);
|
|
1334
|
+
RabbitmqStatsController = __decorateClass([
|
|
1335
|
+
(0, import_plugins_backend_sdk6.Auth)(RABBITMQ_VIEW_PERMISSION),
|
|
1336
|
+
(0, import_common8.Controller)("rabbitmq"),
|
|
1337
|
+
__decorateParam(0, (0, import_common8.Inject)(RabbitmqStatsService))
|
|
1338
|
+
], RabbitmqStatsController);
|
|
1052
1339
|
|
|
1053
1340
|
// backend/plugin.ts
|
|
1054
|
-
var
|
|
1341
|
+
var PLUGIN_CONTEXT5 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
1055
1342
|
var RabbitmqService = class {
|
|
1056
1343
|
constructor(context) {
|
|
1057
1344
|
__publicField(this, "context", context);
|
|
@@ -1064,8 +1351,8 @@ var RabbitmqService = class {
|
|
|
1064
1351
|
}
|
|
1065
1352
|
};
|
|
1066
1353
|
RabbitmqService = __decorateClass([
|
|
1067
|
-
(0,
|
|
1068
|
-
__decorateParam(0, (0,
|
|
1354
|
+
(0, import_common9.Injectable)(),
|
|
1355
|
+
__decorateParam(0, (0, import_common9.Inject)(PLUGIN_CONTEXT5))
|
|
1069
1356
|
], RabbitmqService);
|
|
1070
1357
|
var RabbitmqController = class {
|
|
1071
1358
|
// esbuild does not emit decorator metadata, so Nest cannot infer constructor
|
|
@@ -1078,29 +1365,40 @@ var RabbitmqController = class {
|
|
|
1078
1365
|
}
|
|
1079
1366
|
};
|
|
1080
1367
|
__decorateClass([
|
|
1081
|
-
(0,
|
|
1368
|
+
(0, import_common9.Get)("status")
|
|
1082
1369
|
], RabbitmqController.prototype, "status", 1);
|
|
1083
1370
|
RabbitmqController = __decorateClass([
|
|
1084
|
-
(0,
|
|
1085
|
-
(0,
|
|
1086
|
-
__decorateParam(0, (0,
|
|
1371
|
+
(0, import_plugins_backend_sdk7.Auth)(RABBITMQ_VIEW_PERMISSION),
|
|
1372
|
+
(0, import_common9.Controller)("rabbitmq"),
|
|
1373
|
+
__decorateParam(0, (0, import_common9.Inject)(RabbitmqService))
|
|
1087
1374
|
], RabbitmqController);
|
|
1088
1375
|
var RabbitmqPluginModule = class {
|
|
1089
1376
|
};
|
|
1090
1377
|
var plugin = {
|
|
1378
|
+
// ATT-1003: the plugin's own view and manage keys (see ./permissions).
|
|
1379
|
+
permissions: RABBITMQ_PERMISSIONS,
|
|
1091
1380
|
credentialProvisioningProvider(context) {
|
|
1092
1381
|
return new RabbitmqCredentialProvisioningProvider(context);
|
|
1093
1382
|
},
|
|
1094
1383
|
register(context) {
|
|
1095
1384
|
return {
|
|
1096
1385
|
module: RabbitmqPluginModule,
|
|
1097
|
-
controllers: [
|
|
1386
|
+
controllers: [
|
|
1387
|
+
RabbitmqController,
|
|
1388
|
+
RabbitmqCapabilitiesController,
|
|
1389
|
+
RabbitmqDetectionController,
|
|
1390
|
+
RabbitmqUsersController,
|
|
1391
|
+
RabbitmqConnectionsController,
|
|
1392
|
+
RabbitmqStatsController
|
|
1393
|
+
],
|
|
1098
1394
|
providers: [
|
|
1099
|
-
{ provide:
|
|
1395
|
+
{ provide: PLUGIN_CONTEXT5, useValue: context },
|
|
1100
1396
|
RabbitmqService,
|
|
1101
1397
|
RabbitmqDetectionService,
|
|
1102
1398
|
RabbitmqManagementClient,
|
|
1103
|
-
RabbitmqUsersService
|
|
1399
|
+
RabbitmqUsersService,
|
|
1400
|
+
RabbitmqConnectionsService,
|
|
1401
|
+
RabbitmqStatsService
|
|
1104
1402
|
]
|
|
1105
1403
|
};
|
|
1106
1404
|
}
|