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