@attraccess/plugin-rabbitmq 0.1.0-nightly.1140.3 → 0.1.0-nightly.1161.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -33,14 +33,18 @@ __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
39
|
// backend/detection/service.ts
|
|
40
40
|
var import_plugins_backend_sdk = require("@attraccess/plugins-backend-sdk");
|
|
41
41
|
var import_common = require("@nestjs/common");
|
|
42
42
|
var import_node_crypto2 = require("node:crypto");
|
|
43
43
|
|
|
44
|
+
// backend/permissions.ts
|
|
45
|
+
var RABBITMQ_VIEW_PERMISSION = "resources.update";
|
|
46
|
+
var RABBITMQ_MANAGE_PERMISSION = "system.settings.manage";
|
|
47
|
+
|
|
44
48
|
// backend/management/transport.ts
|
|
45
49
|
var import_node_crypto = require("node:crypto");
|
|
46
50
|
var import_node_https = require("node:https");
|
|
@@ -85,8 +89,8 @@ function trustOptions(config) {
|
|
|
85
89
|
...servername != null ? { servername } : {}
|
|
86
90
|
};
|
|
87
91
|
}
|
|
88
|
-
async function managementRequest(config, url, method, body, timeoutMs) {
|
|
89
|
-
const headers = { accept: "application/json" };
|
|
92
|
+
async function managementRequest(config, url, method, body, timeoutMs, extraHeaders) {
|
|
93
|
+
const headers = { accept: "application/json", ...extraHeaders };
|
|
90
94
|
if (config.username !== null) {
|
|
91
95
|
headers.authorization = `Basic ${Buffer.from(`${config.username}:${config.password ?? ""}`, "utf8").toString("base64")}`;
|
|
92
96
|
}
|
|
@@ -315,7 +319,7 @@ __decorateClass([
|
|
|
315
319
|
__decorateParam(1, (0, import_common.Query)("refresh"))
|
|
316
320
|
], RabbitmqDetectionController.prototype, "detect", 1);
|
|
317
321
|
RabbitmqDetectionController = __decorateClass([
|
|
318
|
-
(0, import_plugins_backend_sdk.Auth)(
|
|
322
|
+
(0, import_plugins_backend_sdk.Auth)(RABBITMQ_VIEW_PERMISSION),
|
|
319
323
|
(0, import_common.Controller)("rabbitmq"),
|
|
320
324
|
__decorateParam(0, (0, import_common.Inject)(RabbitmqDetectionService))
|
|
321
325
|
], RabbitmqDetectionController);
|
|
@@ -323,6 +327,7 @@ RabbitmqDetectionController = __decorateClass([
|
|
|
323
327
|
// backend/management/client.ts
|
|
324
328
|
var import_common2 = require("@nestjs/common");
|
|
325
329
|
var REQUEST_TIMEOUT_MS = 1e4;
|
|
330
|
+
var MISSING_PRIVILEGE_ERROR = "not_authorised";
|
|
326
331
|
var RabbitmqManagementClient = class {
|
|
327
332
|
// Builds the management API base URL from the generic MQTT config (same
|
|
328
333
|
// convention as RabbitmqDetectionService).
|
|
@@ -332,11 +337,11 @@ var RabbitmqManagementClient = class {
|
|
|
332
337
|
// Performs one management API request. `path` is relative to `/api`, with
|
|
333
338
|
// every variable segment already URL-encoded by the caller. Returns the
|
|
334
339
|
// parsed JSON body (or null for empty responses, e.g. 201/204).
|
|
335
|
-
async request(config, method, path, body) {
|
|
340
|
+
async request(config, method, path, body, headers) {
|
|
336
341
|
const base = this.managementApiBase(config);
|
|
337
342
|
let response;
|
|
338
343
|
try {
|
|
339
|
-
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);
|
|
340
345
|
} catch (error) {
|
|
341
346
|
throw new import_common2.HttpException(
|
|
342
347
|
`Cannot reach the RabbitMQ management API at ${base}: ${describeManagementError(error, REQUEST_TIMEOUT_MS)}`,
|
|
@@ -354,15 +359,16 @@ var RabbitmqManagementClient = class {
|
|
|
354
359
|
async toHttpException(response) {
|
|
355
360
|
const upstream = await this.parseErrorBody(response);
|
|
356
361
|
const reason = upstream?.reason || upstream?.error || "";
|
|
357
|
-
|
|
362
|
+
const missingPrivilege = upstream?.error === MISSING_PRIVILEGE_ERROR;
|
|
363
|
+
if (response.status === 401 && !missingPrivilege) {
|
|
358
364
|
return new import_common2.HttpException(
|
|
359
365
|
"The RabbitMQ management API rejected the configured MQTT server credentials (401). Check the username/password configured for this MQTT server.",
|
|
360
366
|
import_common2.HttpStatus.BAD_GATEWAY
|
|
361
367
|
);
|
|
362
368
|
}
|
|
363
|
-
if (response.status === 403 || /not.?authori[sz]ed/i.test(reason)) {
|
|
369
|
+
if (response.status === 403 || missingPrivilege || /not.?authori[sz]ed/i.test(reason)) {
|
|
364
370
|
return new import_common2.HttpException(
|
|
365
|
-
'The configured MQTT server user lacks management privileges on RabbitMQ.
|
|
371
|
+
'The configured MQTT server user lacks management privileges on RabbitMQ. Viewing requires the "monitoring" tag; managing users and closing connections requires "administrator".',
|
|
366
372
|
import_common2.HttpStatus.BAD_GATEWAY
|
|
367
373
|
);
|
|
368
374
|
}
|
|
@@ -405,7 +411,31 @@ RabbitmqManagementClient = __decorateClass([
|
|
|
405
411
|
|
|
406
412
|
// backend/users/service.ts
|
|
407
413
|
var import_plugins_backend_sdk2 = require("@attraccess/plugins-backend-sdk");
|
|
414
|
+
var import_common4 = require("@nestjs/common");
|
|
415
|
+
|
|
416
|
+
// backend/management/config.ts
|
|
408
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
|
|
409
439
|
var PLUGIN_CONTEXT2 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
410
440
|
var RabbitmqUsersService = class {
|
|
411
441
|
constructor(context, client) {
|
|
@@ -415,7 +445,7 @@ var RabbitmqUsersService = class {
|
|
|
415
445
|
// Lists all users with their per-vhost permissions, plus the vhost list for
|
|
416
446
|
// the UI's vhost choices. Three management calls, joined here.
|
|
417
447
|
async listUsers(mqttServerId) {
|
|
418
|
-
const config = await this.
|
|
448
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
419
449
|
const [rawUsers, rawPermissions, rawVhosts] = await Promise.all([
|
|
420
450
|
this.client.request(config, "GET", "/users"),
|
|
421
451
|
this.client.request(config, "GET", "/permissions"),
|
|
@@ -423,14 +453,14 @@ var RabbitmqUsersService = class {
|
|
|
423
453
|
]);
|
|
424
454
|
const permissionsByUser = /* @__PURE__ */ new Map();
|
|
425
455
|
for (const permission of rawPermissions ?? []) {
|
|
426
|
-
const
|
|
427
|
-
|
|
456
|
+
const list2 = permissionsByUser.get(permission.user) ?? [];
|
|
457
|
+
list2.push({
|
|
428
458
|
vhost: permission.vhost,
|
|
429
459
|
configure: permission.configure,
|
|
430
460
|
write: permission.write,
|
|
431
461
|
read: permission.read
|
|
432
462
|
});
|
|
433
|
-
permissionsByUser.set(permission.user,
|
|
463
|
+
permissionsByUser.set(permission.user, list2);
|
|
434
464
|
}
|
|
435
465
|
const users = (rawUsers ?? []).map((user) => ({
|
|
436
466
|
name: user.name,
|
|
@@ -448,11 +478,11 @@ var RabbitmqUsersService = class {
|
|
|
448
478
|
// the same operation (used by the create form's "default MQTT permissions").
|
|
449
479
|
async upsertUser(mqttServerId, username, dto) {
|
|
450
480
|
this.assertValidName(username, "Username");
|
|
451
|
-
const config = await this.
|
|
481
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
452
482
|
const existing = await this.findUser(config, username);
|
|
453
483
|
const password = dto.password?.length ? dto.password : void 0;
|
|
454
484
|
if (!existing && !password) {
|
|
455
|
-
throw new
|
|
485
|
+
throw new import_common4.HttpException("Password is required when creating a new user.", import_common4.HttpStatus.BAD_REQUEST);
|
|
456
486
|
}
|
|
457
487
|
const body = { tags: (dto.tags ?? this.normalizeTags(existing?.tags)).join(",") };
|
|
458
488
|
if (password) {
|
|
@@ -470,11 +500,11 @@ var RabbitmqUsersService = class {
|
|
|
470
500
|
}
|
|
471
501
|
async deleteUser(mqttServerId, username) {
|
|
472
502
|
this.assertValidName(username, "Username");
|
|
473
|
-
const config = await this.
|
|
503
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
474
504
|
if (config.username !== null && config.username === username) {
|
|
475
|
-
throw new
|
|
505
|
+
throw new import_common4.HttpException(
|
|
476
506
|
"Refusing to delete the user the MQTT server connection is configured with.",
|
|
477
|
-
|
|
507
|
+
import_common4.HttpStatus.BAD_REQUEST
|
|
478
508
|
);
|
|
479
509
|
}
|
|
480
510
|
await this.client.request(config, "DELETE", `/users/${encodeURIComponent(username)}`);
|
|
@@ -482,13 +512,13 @@ var RabbitmqUsersService = class {
|
|
|
482
512
|
async setPermissions(mqttServerId, username, dto) {
|
|
483
513
|
this.assertValidName(username, "Username");
|
|
484
514
|
this.assertValidName(dto.vhost, "Vhost");
|
|
485
|
-
const config = await this.
|
|
515
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
486
516
|
await this.putPermission(config, username, dto);
|
|
487
517
|
}
|
|
488
518
|
async clearPermissions(mqttServerId, username, vhost) {
|
|
489
519
|
this.assertValidName(username, "Username");
|
|
490
520
|
this.assertValidName(vhost, "Vhost");
|
|
491
|
-
const config = await this.
|
|
521
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
492
522
|
await this.client.request(
|
|
493
523
|
config,
|
|
494
524
|
"DELETE",
|
|
@@ -512,19 +542,12 @@ var RabbitmqUsersService = class {
|
|
|
512
542
|
try {
|
|
513
543
|
return await this.client.request(config, "GET", `/users/${encodeURIComponent(username)}`);
|
|
514
544
|
} catch (error) {
|
|
515
|
-
if (error instanceof
|
|
545
|
+
if (error instanceof import_common4.HttpException && error.getStatus() === import_common4.HttpStatus.NOT_FOUND) {
|
|
516
546
|
return null;
|
|
517
547
|
}
|
|
518
548
|
throw error;
|
|
519
549
|
}
|
|
520
550
|
}
|
|
521
|
-
async requireConfig(mqttServerId) {
|
|
522
|
-
const config = await this.context.getMqttServerConfig(mqttServerId);
|
|
523
|
-
if (!config) {
|
|
524
|
-
throw new import_common3.HttpException("MQTT server not found.", import_common3.HttpStatus.NOT_FOUND);
|
|
525
|
-
}
|
|
526
|
-
return config;
|
|
527
|
-
}
|
|
528
551
|
normalizeTags(tags) {
|
|
529
552
|
if (Array.isArray(tags)) {
|
|
530
553
|
return tags.filter((tag) => tag.length > 0);
|
|
@@ -536,17 +559,17 @@ var RabbitmqUsersService = class {
|
|
|
536
559
|
}
|
|
537
560
|
assertValidName(value, label) {
|
|
538
561
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
539
|
-
throw new
|
|
562
|
+
throw new import_common4.HttpException(`${label} must not be empty.`, import_common4.HttpStatus.BAD_REQUEST);
|
|
540
563
|
}
|
|
541
564
|
if (value.length > 255) {
|
|
542
|
-
throw new
|
|
565
|
+
throw new import_common4.HttpException(`${label} must be at most 255 characters.`, import_common4.HttpStatus.BAD_REQUEST);
|
|
543
566
|
}
|
|
544
567
|
}
|
|
545
568
|
};
|
|
546
569
|
RabbitmqUsersService = __decorateClass([
|
|
547
|
-
(0,
|
|
548
|
-
__decorateParam(0, (0,
|
|
549
|
-
__decorateParam(1, (0,
|
|
570
|
+
(0, import_common4.Injectable)(),
|
|
571
|
+
__decorateParam(0, (0, import_common4.Inject)(PLUGIN_CONTEXT2)),
|
|
572
|
+
__decorateParam(1, (0, import_common4.Inject)(RabbitmqManagementClient))
|
|
550
573
|
], RabbitmqUsersService);
|
|
551
574
|
var RabbitmqUsersController = class {
|
|
552
575
|
// esbuild does not emit decorator metadata, so Nest cannot infer constructor
|
|
@@ -565,52 +588,56 @@ var RabbitmqUsersController = class {
|
|
|
565
588
|
}
|
|
566
589
|
setPermissions(mqttServerId, username, dto) {
|
|
567
590
|
if (!dto || typeof dto.vhost !== "string") {
|
|
568
|
-
throw new
|
|
591
|
+
throw new import_common4.HttpException("A vhost is required.", import_common4.HttpStatus.BAD_REQUEST);
|
|
569
592
|
}
|
|
570
593
|
return this.users.setPermissions(mqttServerId, username, dto);
|
|
571
594
|
}
|
|
572
595
|
clearPermissions(mqttServerId, username, vhost) {
|
|
573
596
|
if (typeof vhost !== "string" || vhost.length === 0) {
|
|
574
|
-
throw new
|
|
597
|
+
throw new import_common4.HttpException("A vhost query parameter is required.", import_common4.HttpStatus.BAD_REQUEST);
|
|
575
598
|
}
|
|
576
599
|
return this.users.clearPermissions(mqttServerId, username, vhost);
|
|
577
600
|
}
|
|
578
601
|
};
|
|
579
602
|
__decorateClass([
|
|
580
|
-
(0,
|
|
581
|
-
|
|
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))
|
|
582
606
|
], RabbitmqUsersController.prototype, "list", 1);
|
|
583
607
|
__decorateClass([
|
|
584
|
-
(0,
|
|
585
|
-
|
|
586
|
-
__decorateParam(
|
|
587
|
-
__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)())
|
|
588
613
|
], RabbitmqUsersController.prototype, "upsert", 1);
|
|
589
614
|
__decorateClass([
|
|
590
|
-
(0,
|
|
591
|
-
|
|
592
|
-
__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"))
|
|
593
619
|
], RabbitmqUsersController.prototype, "remove", 1);
|
|
594
620
|
__decorateClass([
|
|
595
|
-
(0,
|
|
596
|
-
|
|
597
|
-
__decorateParam(
|
|
598
|
-
__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)())
|
|
599
626
|
], RabbitmqUsersController.prototype, "setPermissions", 1);
|
|
600
627
|
__decorateClass([
|
|
601
|
-
(0,
|
|
602
|
-
|
|
603
|
-
__decorateParam(
|
|
604
|
-
__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"))
|
|
605
633
|
], RabbitmqUsersController.prototype, "clearPermissions", 1);
|
|
606
634
|
RabbitmqUsersController = __decorateClass([
|
|
607
|
-
(0,
|
|
608
|
-
(0,
|
|
609
|
-
__decorateParam(0, (0, import_common3.Inject)(RabbitmqUsersService))
|
|
635
|
+
(0, import_common4.Controller)("rabbitmq"),
|
|
636
|
+
__decorateParam(0, (0, import_common4.Inject)(RabbitmqUsersService))
|
|
610
637
|
], RabbitmqUsersController);
|
|
611
638
|
|
|
612
639
|
// backend/credentials/provider.ts
|
|
613
|
-
var
|
|
640
|
+
var import_common5 = require("@nestjs/common");
|
|
614
641
|
|
|
615
642
|
// ../../../node_modules/.pnpm/async-mutex@0.5.0/node_modules/async-mutex/index.mjs
|
|
616
643
|
var E_TIMEOUT = new Error("timeout while waiting for mutex to become available");
|
|
@@ -854,22 +881,22 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
854
881
|
}
|
|
855
882
|
assertNotManagementUser(config, username) {
|
|
856
883
|
if (config.username === username) {
|
|
857
|
-
throw new
|
|
884
|
+
throw new import_common5.BadRequestException("Refusing to modify the MQTT server management identity.");
|
|
858
885
|
}
|
|
859
886
|
}
|
|
860
887
|
assertName(value, label) {
|
|
861
888
|
if (typeof value !== "string" || value.trim().length === 0 || value.length > 255) {
|
|
862
|
-
throw new
|
|
889
|
+
throw new import_common5.BadRequestException(`${label} must be a non-empty string no longer than 255 characters.`);
|
|
863
890
|
}
|
|
864
891
|
}
|
|
865
892
|
assertTopicFilter(filter) {
|
|
866
893
|
if (filter.includes(".")) {
|
|
867
|
-
throw new
|
|
894
|
+
throw new import_common5.BadRequestException("RabbitMQ MQTT topic policies cannot contain dots.");
|
|
868
895
|
}
|
|
869
896
|
const segments = filter.split("/");
|
|
870
897
|
for (const [index, segment] of segments.entries()) {
|
|
871
898
|
if (segment.includes("+") && segment !== "+" || segment.includes("#") && (segment !== "#" || index !== segments.length - 1)) {
|
|
872
|
-
throw new
|
|
899
|
+
throw new import_common5.BadRequestException(
|
|
873
900
|
"MQTT wildcards must occupy a complete topic level, and # must be the final level."
|
|
874
901
|
);
|
|
875
902
|
}
|
|
@@ -880,11 +907,11 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
880
907
|
this.assertName(request2.username, "Username");
|
|
881
908
|
this.assertName(request2.vhost, "Vhost");
|
|
882
909
|
if (!Array.isArray(request2.topicPolicy.publish) || !Array.isArray(request2.topicPolicy.subscribe)) {
|
|
883
|
-
throw new
|
|
910
|
+
throw new import_common5.BadRequestException("Publish and subscribe topic policies must be arrays.");
|
|
884
911
|
}
|
|
885
912
|
for (const filter of [...request2.topicPolicy.publish, ...request2.topicPolicy.subscribe]) {
|
|
886
913
|
if (typeof filter !== "string" || filter.length === 0 || filter.length > 1024) {
|
|
887
|
-
throw new
|
|
914
|
+
throw new import_common5.BadRequestException("MQTT topic filters must be non-empty strings no longer than 1024 characters.");
|
|
888
915
|
}
|
|
889
916
|
this.assertTopicFilter(filter);
|
|
890
917
|
}
|
|
@@ -892,7 +919,7 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
892
919
|
async requireConfig(mqttServerId) {
|
|
893
920
|
const config = await this.context.getMqttServerConfig(mqttServerId);
|
|
894
921
|
if (!config) {
|
|
895
|
-
throw new
|
|
922
|
+
throw new import_common5.BadRequestException("MQTT server not found.");
|
|
896
923
|
}
|
|
897
924
|
return config;
|
|
898
925
|
}
|
|
@@ -921,7 +948,7 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
921
948
|
try {
|
|
922
949
|
return await this.client.request(config, "GET", path);
|
|
923
950
|
} catch (error) {
|
|
924
|
-
if (error instanceof
|
|
951
|
+
if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) {
|
|
925
952
|
return null;
|
|
926
953
|
}
|
|
927
954
|
throw error;
|
|
@@ -938,7 +965,7 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
938
965
|
await this.client.request(config, "GET", path);
|
|
939
966
|
return true;
|
|
940
967
|
} catch (error) {
|
|
941
|
-
if (error instanceof
|
|
968
|
+
if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) {
|
|
942
969
|
return false;
|
|
943
970
|
}
|
|
944
971
|
throw error;
|
|
@@ -1023,7 +1050,7 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
1023
1050
|
try {
|
|
1024
1051
|
await this.client.request(config, "DELETE", `/users/${encodeURIComponent(request2.username)}`);
|
|
1025
1052
|
} catch (error) {
|
|
1026
|
-
if (error instanceof
|
|
1053
|
+
if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) return;
|
|
1027
1054
|
throw error;
|
|
1028
1055
|
}
|
|
1029
1056
|
}
|
|
@@ -1040,8 +1067,245 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
1040
1067
|
__publicField(_RabbitmqCredentialProvisioningProvider, "vhostLocks", /* @__PURE__ */ new Map());
|
|
1041
1068
|
var RabbitmqCredentialProvisioningProvider = _RabbitmqCredentialProvisioningProvider;
|
|
1042
1069
|
|
|
1043
|
-
// backend/
|
|
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 };
|
|
1076
|
+
}
|
|
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");
|
|
1044
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);
|
|
1136
|
+
}
|
|
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);
|
|
1153
|
+
}
|
|
1154
|
+
if (name === "." || name === "..") {
|
|
1155
|
+
throw new import_common7.HttpException("Invalid connection name.", import_common7.HttpStatus.BAD_REQUEST);
|
|
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);
|
|
1162
|
+
}
|
|
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);
|
|
1174
|
+
}
|
|
1175
|
+
list(mqttServerId) {
|
|
1176
|
+
return this.connections.listConnections(mqttServerId);
|
|
1177
|
+
}
|
|
1178
|
+
close(mqttServerId, name, reason) {
|
|
1179
|
+
return this.connections.closeConnection(mqttServerId, name, reason);
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
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);
|
|
1224
|
+
}
|
|
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);
|
|
1306
|
+
|
|
1307
|
+
// backend/plugin.ts
|
|
1308
|
+
var PLUGIN_CONTEXT5 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
1045
1309
|
var RabbitmqService = class {
|
|
1046
1310
|
constructor(context) {
|
|
1047
1311
|
__publicField(this, "context", context);
|
|
@@ -1054,8 +1318,8 @@ var RabbitmqService = class {
|
|
|
1054
1318
|
}
|
|
1055
1319
|
};
|
|
1056
1320
|
RabbitmqService = __decorateClass([
|
|
1057
|
-
(0,
|
|
1058
|
-
__decorateParam(0, (0,
|
|
1321
|
+
(0, import_common9.Injectable)(),
|
|
1322
|
+
__decorateParam(0, (0, import_common9.Inject)(PLUGIN_CONTEXT5))
|
|
1059
1323
|
], RabbitmqService);
|
|
1060
1324
|
var RabbitmqController = class {
|
|
1061
1325
|
// esbuild does not emit decorator metadata, so Nest cannot infer constructor
|
|
@@ -1068,12 +1332,12 @@ var RabbitmqController = class {
|
|
|
1068
1332
|
}
|
|
1069
1333
|
};
|
|
1070
1334
|
__decorateClass([
|
|
1071
|
-
(0,
|
|
1335
|
+
(0, import_common9.Get)("status")
|
|
1072
1336
|
], RabbitmqController.prototype, "status", 1);
|
|
1073
1337
|
RabbitmqController = __decorateClass([
|
|
1074
|
-
(0,
|
|
1075
|
-
(0,
|
|
1076
|
-
__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))
|
|
1077
1341
|
], RabbitmqController);
|
|
1078
1342
|
var RabbitmqPluginModule = class {
|
|
1079
1343
|
};
|
|
@@ -1084,13 +1348,22 @@ var plugin = {
|
|
|
1084
1348
|
register(context) {
|
|
1085
1349
|
return {
|
|
1086
1350
|
module: RabbitmqPluginModule,
|
|
1087
|
-
controllers: [
|
|
1351
|
+
controllers: [
|
|
1352
|
+
RabbitmqController,
|
|
1353
|
+
RabbitmqCapabilitiesController,
|
|
1354
|
+
RabbitmqDetectionController,
|
|
1355
|
+
RabbitmqUsersController,
|
|
1356
|
+
RabbitmqConnectionsController,
|
|
1357
|
+
RabbitmqStatsController
|
|
1358
|
+
],
|
|
1088
1359
|
providers: [
|
|
1089
|
-
{ provide:
|
|
1360
|
+
{ provide: PLUGIN_CONTEXT5, useValue: context },
|
|
1090
1361
|
RabbitmqService,
|
|
1091
1362
|
RabbitmqDetectionService,
|
|
1092
1363
|
RabbitmqManagementClient,
|
|
1093
|
-
RabbitmqUsersService
|
|
1364
|
+
RabbitmqUsersService,
|
|
1365
|
+
RabbitmqConnectionsService,
|
|
1366
|
+
RabbitmqStatsService
|
|
1094
1367
|
]
|
|
1095
1368
|
};
|
|
1096
1369
|
}
|