@attraccess/plugin-rabbitmq 0.1.0-nightly.990.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 -248
- 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
|
}
|
|
@@ -403,30 +404,38 @@ var RabbitmqManagementClient = class {
|
|
|
403
404
|
return null;
|
|
404
405
|
}
|
|
405
406
|
}
|
|
406
|
-
describeNetworkError(error) {
|
|
407
|
-
if (error instanceof Error) {
|
|
408
|
-
if (error.name === "AbortError") {
|
|
409
|
-
return `no response within ${REQUEST_TIMEOUT_MS}ms`;
|
|
410
|
-
}
|
|
411
|
-
const cause = error.cause;
|
|
412
|
-
if (cause instanceof Error && cause.message) {
|
|
413
|
-
return cause.message;
|
|
414
|
-
}
|
|
415
|
-
return error.message;
|
|
416
|
-
}
|
|
417
|
-
return "unknown network error";
|
|
418
|
-
}
|
|
419
407
|
};
|
|
420
408
|
RabbitmqManagementClient = __decorateClass([
|
|
421
|
-
(0,
|
|
409
|
+
(0, import_common2.Injectable)()
|
|
422
410
|
], RabbitmqManagementClient);
|
|
423
411
|
|
|
424
|
-
// backend/
|
|
412
|
+
// backend/users/service.ts
|
|
425
413
|
var import_plugins_backend_sdk2 = require("@attraccess/plugins-backend-sdk");
|
|
426
|
-
var import_common5 = require("@nestjs/common");
|
|
427
|
-
|
|
428
|
-
// backend/rabbitmq-users.service.ts
|
|
429
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
|
|
430
439
|
var PLUGIN_CONTEXT2 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
431
440
|
var RabbitmqUsersService = class {
|
|
432
441
|
constructor(context, client) {
|
|
@@ -436,7 +445,7 @@ var RabbitmqUsersService = class {
|
|
|
436
445
|
// Lists all users with their per-vhost permissions, plus the vhost list for
|
|
437
446
|
// the UI's vhost choices. Three management calls, joined here.
|
|
438
447
|
async listUsers(mqttServerId) {
|
|
439
|
-
const config = await this.
|
|
448
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
440
449
|
const [rawUsers, rawPermissions, rawVhosts] = await Promise.all([
|
|
441
450
|
this.client.request(config, "GET", "/users"),
|
|
442
451
|
this.client.request(config, "GET", "/permissions"),
|
|
@@ -444,14 +453,14 @@ var RabbitmqUsersService = class {
|
|
|
444
453
|
]);
|
|
445
454
|
const permissionsByUser = /* @__PURE__ */ new Map();
|
|
446
455
|
for (const permission of rawPermissions ?? []) {
|
|
447
|
-
const
|
|
448
|
-
|
|
456
|
+
const list2 = permissionsByUser.get(permission.user) ?? [];
|
|
457
|
+
list2.push({
|
|
449
458
|
vhost: permission.vhost,
|
|
450
459
|
configure: permission.configure,
|
|
451
460
|
write: permission.write,
|
|
452
461
|
read: permission.read
|
|
453
462
|
});
|
|
454
|
-
permissionsByUser.set(permission.user,
|
|
463
|
+
permissionsByUser.set(permission.user, list2);
|
|
455
464
|
}
|
|
456
465
|
const users = (rawUsers ?? []).map((user) => ({
|
|
457
466
|
name: user.name,
|
|
@@ -469,7 +478,7 @@ var RabbitmqUsersService = class {
|
|
|
469
478
|
// the same operation (used by the create form's "default MQTT permissions").
|
|
470
479
|
async upsertUser(mqttServerId, username, dto) {
|
|
471
480
|
this.assertValidName(username, "Username");
|
|
472
|
-
const config = await this.
|
|
481
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
473
482
|
const existing = await this.findUser(config, username);
|
|
474
483
|
const password = dto.password?.length ? dto.password : void 0;
|
|
475
484
|
if (!existing && !password) {
|
|
@@ -491,7 +500,7 @@ var RabbitmqUsersService = class {
|
|
|
491
500
|
}
|
|
492
501
|
async deleteUser(mqttServerId, username) {
|
|
493
502
|
this.assertValidName(username, "Username");
|
|
494
|
-
const config = await this.
|
|
503
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
495
504
|
if (config.username !== null && config.username === username) {
|
|
496
505
|
throw new import_common4.HttpException(
|
|
497
506
|
"Refusing to delete the user the MQTT server connection is configured with.",
|
|
@@ -503,13 +512,13 @@ var RabbitmqUsersService = class {
|
|
|
503
512
|
async setPermissions(mqttServerId, username, dto) {
|
|
504
513
|
this.assertValidName(username, "Username");
|
|
505
514
|
this.assertValidName(dto.vhost, "Vhost");
|
|
506
|
-
const config = await this.
|
|
515
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
507
516
|
await this.putPermission(config, username, dto);
|
|
508
517
|
}
|
|
509
518
|
async clearPermissions(mqttServerId, username, vhost) {
|
|
510
519
|
this.assertValidName(username, "Username");
|
|
511
520
|
this.assertValidName(vhost, "Vhost");
|
|
512
|
-
const config = await this.
|
|
521
|
+
const config = await requireMqttServerConfig(this.context, mqttServerId);
|
|
513
522
|
await this.client.request(
|
|
514
523
|
config,
|
|
515
524
|
"DELETE",
|
|
@@ -539,13 +548,6 @@ var RabbitmqUsersService = class {
|
|
|
539
548
|
throw error;
|
|
540
549
|
}
|
|
541
550
|
}
|
|
542
|
-
async requireConfig(mqttServerId) {
|
|
543
|
-
const config = await this.context.getMqttServerConfig(mqttServerId);
|
|
544
|
-
if (!config) {
|
|
545
|
-
throw new import_common4.HttpException("MQTT server not found.", import_common4.HttpStatus.NOT_FOUND);
|
|
546
|
-
}
|
|
547
|
-
return config;
|
|
548
|
-
}
|
|
549
551
|
normalizeTags(tags) {
|
|
550
552
|
if (Array.isArray(tags)) {
|
|
551
553
|
return tags.filter((tag) => tag.length > 0);
|
|
@@ -569,8 +571,6 @@ RabbitmqUsersService = __decorateClass([
|
|
|
569
571
|
__decorateParam(0, (0, import_common4.Inject)(PLUGIN_CONTEXT2)),
|
|
570
572
|
__decorateParam(1, (0, import_common4.Inject)(RabbitmqManagementClient))
|
|
571
573
|
], RabbitmqUsersService);
|
|
572
|
-
|
|
573
|
-
// backend/rabbitmq-users.controller.ts
|
|
574
574
|
var RabbitmqUsersController = class {
|
|
575
575
|
// esbuild does not emit decorator metadata, so Nest cannot infer constructor
|
|
576
576
|
// types for injection — always inject by an explicit token.
|
|
@@ -588,53 +588,56 @@ var RabbitmqUsersController = class {
|
|
|
588
588
|
}
|
|
589
589
|
setPermissions(mqttServerId, username, dto) {
|
|
590
590
|
if (!dto || typeof dto.vhost !== "string") {
|
|
591
|
-
throw new
|
|
591
|
+
throw new import_common4.HttpException("A vhost is required.", import_common4.HttpStatus.BAD_REQUEST);
|
|
592
592
|
}
|
|
593
593
|
return this.users.setPermissions(mqttServerId, username, dto);
|
|
594
594
|
}
|
|
595
595
|
clearPermissions(mqttServerId, username, vhost) {
|
|
596
596
|
if (typeof vhost !== "string" || vhost.length === 0) {
|
|
597
|
-
throw new
|
|
597
|
+
throw new import_common4.HttpException("A vhost query parameter is required.", import_common4.HttpStatus.BAD_REQUEST);
|
|
598
598
|
}
|
|
599
599
|
return this.users.clearPermissions(mqttServerId, username, vhost);
|
|
600
600
|
}
|
|
601
601
|
};
|
|
602
602
|
__decorateClass([
|
|
603
|
-
(0,
|
|
604
|
-
|
|
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))
|
|
605
606
|
], RabbitmqUsersController.prototype, "list", 1);
|
|
606
607
|
__decorateClass([
|
|
607
|
-
(0,
|
|
608
|
-
|
|
609
|
-
__decorateParam(
|
|
610
|
-
__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)())
|
|
611
613
|
], RabbitmqUsersController.prototype, "upsert", 1);
|
|
612
614
|
__decorateClass([
|
|
613
|
-
(0,
|
|
614
|
-
|
|
615
|
-
__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"))
|
|
616
619
|
], RabbitmqUsersController.prototype, "remove", 1);
|
|
617
620
|
__decorateClass([
|
|
618
|
-
(0,
|
|
619
|
-
|
|
620
|
-
__decorateParam(
|
|
621
|
-
__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)())
|
|
622
626
|
], RabbitmqUsersController.prototype, "setPermissions", 1);
|
|
623
627
|
__decorateClass([
|
|
624
|
-
(0,
|
|
625
|
-
|
|
626
|
-
__decorateParam(
|
|
627
|
-
__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"))
|
|
628
633
|
], RabbitmqUsersController.prototype, "clearPermissions", 1);
|
|
629
634
|
RabbitmqUsersController = __decorateClass([
|
|
630
|
-
(0,
|
|
631
|
-
(0,
|
|
632
|
-
__decorateParam(0, (0, import_common5.Inject)(RabbitmqUsersService))
|
|
635
|
+
(0, import_common4.Controller)("rabbitmq"),
|
|
636
|
+
__decorateParam(0, (0, import_common4.Inject)(RabbitmqUsersService))
|
|
633
637
|
], RabbitmqUsersController);
|
|
634
638
|
|
|
635
|
-
// backend/
|
|
636
|
-
var
|
|
637
|
-
var import_common6 = require("@nestjs/common");
|
|
639
|
+
// backend/credentials/provider.ts
|
|
640
|
+
var import_common5 = require("@nestjs/common");
|
|
638
641
|
|
|
639
642
|
// ../../../node_modules/.pnpm/async-mutex@0.5.0/node_modules/async-mutex/index.mjs
|
|
640
643
|
var E_TIMEOUT = new Error("timeout while waiting for mutex to become available");
|
|
@@ -842,7 +845,31 @@ var Mutex = class {
|
|
|
842
845
|
}
|
|
843
846
|
};
|
|
844
847
|
|
|
845
|
-
// 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
|
+
}
|
|
846
873
|
var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvisioningProvider {
|
|
847
874
|
constructor(context) {
|
|
848
875
|
__publicField(this, "context", context);
|
|
@@ -852,46 +879,114 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
852
879
|
__publicField(this, "detection");
|
|
853
880
|
this.detection = new RabbitmqDetectionService(context);
|
|
854
881
|
}
|
|
855
|
-
|
|
856
|
-
|
|
882
|
+
assertNotManagementUser(config, username) {
|
|
883
|
+
if (config.username === username) {
|
|
884
|
+
throw new import_common5.BadRequestException("Refusing to modify the MQTT server management identity.");
|
|
885
|
+
}
|
|
857
886
|
}
|
|
858
|
-
|
|
859
|
-
|
|
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
|
+
}
|
|
860
891
|
}
|
|
861
|
-
|
|
862
|
-
|
|
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
|
+
}
|
|
863
904
|
}
|
|
864
|
-
|
|
905
|
+
assertRequest(request2) {
|
|
906
|
+
this.assertName(request2.identity, "Identity");
|
|
865
907
|
this.assertName(request2.username, "Username");
|
|
866
|
-
|
|
867
|
-
|
|
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) {
|
|
868
948
|
try {
|
|
869
|
-
await this.client.request(config, "
|
|
949
|
+
return await this.client.request(config, "GET", path);
|
|
870
950
|
} catch (error) {
|
|
871
|
-
if (error instanceof
|
|
951
|
+
if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) {
|
|
952
|
+
return null;
|
|
953
|
+
}
|
|
872
954
|
throw error;
|
|
873
955
|
}
|
|
874
956
|
}
|
|
875
|
-
async
|
|
876
|
-
this.
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
lock = { mutex: new Mutex(), users: 0 };
|
|
883
|
-
_RabbitmqCredentialProvisioningProvider.vhostLocks.set(lockKey, lock);
|
|
884
|
-
}
|
|
885
|
-
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) {
|
|
886
964
|
try {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
if (
|
|
891
|
-
|
|
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;
|
|
892
970
|
}
|
|
971
|
+
throw error;
|
|
893
972
|
}
|
|
894
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
|
+
}
|
|
895
990
|
async writeCredentialLocked(request2, config) {
|
|
896
991
|
const password = (0, import_crypto.randomBytes)(24).toString("base64url");
|
|
897
992
|
const vhost = encodeURIComponent(request2.vhost);
|
|
@@ -928,143 +1023,289 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
|
|
|
928
1023
|
password
|
|
929
1024
|
};
|
|
930
1025
|
}
|
|
931
|
-
async
|
|
932
|
-
|
|
933
|
-
await this.
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
async userExists(config, username) {
|
|
945
|
-
return this.exists(config, `/users/${username}`);
|
|
946
|
-
}
|
|
947
|
-
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;
|
|
948
1037
|
try {
|
|
949
|
-
await
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
if (
|
|
953
|
-
|
|
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);
|
|
954
1043
|
}
|
|
955
|
-
throw error;
|
|
956
1044
|
}
|
|
957
1045
|
}
|
|
958
|
-
async
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
return this.getOptional(config, `/topic-permissions/${vhost}/${username}`);
|
|
963
|
-
}
|
|
964
|
-
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);
|
|
965
1050
|
try {
|
|
966
|
-
|
|
1051
|
+
await this.client.request(config, "DELETE", `/users/${encodeURIComponent(request2.username)}`);
|
|
967
1052
|
} catch (error) {
|
|
968
|
-
if (error instanceof
|
|
969
|
-
return null;
|
|
970
|
-
}
|
|
1053
|
+
if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) return;
|
|
971
1054
|
throw error;
|
|
972
1055
|
}
|
|
973
1056
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
this.restorePermission(config, `/permissions/${vhost}/${username}`, permissions),
|
|
977
|
-
this.restorePermission(config, `/topic-permissions/${vhost}/${username}`, topicPermissions)
|
|
978
|
-
]);
|
|
979
|
-
const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
980
|
-
if (failures.length > 0) {
|
|
981
|
-
throw new AggregateError(failures, "Failed to restore RabbitMQ permissions.");
|
|
982
|
-
}
|
|
1057
|
+
rotate(request2) {
|
|
1058
|
+
return this.writeCredential(request2);
|
|
983
1059
|
}
|
|
984
|
-
|
|
985
|
-
|
|
1060
|
+
provision(request2) {
|
|
1061
|
+
return this.writeCredential(request2);
|
|
986
1062
|
}
|
|
987
|
-
async
|
|
988
|
-
|
|
989
|
-
const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
990
|
-
if (failures.length > 0) {
|
|
991
|
-
throw new AggregateError([error, ...failures], "Credential provisioning failed and rollback was incomplete.");
|
|
992
|
-
}
|
|
993
|
-
throw error;
|
|
1063
|
+
async supports(config) {
|
|
1064
|
+
return (await this.detection.detect(config.id)).isRabbitMQ;
|
|
994
1065
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
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 };
|
|
1001
1076
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
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);
|
|
1015
1136
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
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);
|
|
1019
1153
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
if (segment.includes("+") && segment !== "+" || segment.includes("#") && (segment !== "#" || index !== segments.length - 1)) {
|
|
1023
|
-
throw new import_common6.BadRequestException(
|
|
1024
|
-
"MQTT wildcards must occupy a complete topic level, and # must be the final level."
|
|
1025
|
-
);
|
|
1026
|
-
}
|
|
1154
|
+
if (name === "." || name === "..") {
|
|
1155
|
+
throw new import_common7.HttpException("Invalid connection name.", import_common7.HttpStatus.BAD_REQUEST);
|
|
1027
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);
|
|
1028
1162
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
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);
|
|
1033
1174
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1175
|
+
list(mqttServerId) {
|
|
1176
|
+
return this.connections.listConnections(mqttServerId);
|
|
1177
|
+
}
|
|
1178
|
+
close(mqttServerId, name, reason) {
|
|
1179
|
+
return this.connections.closeConnection(mqttServerId, name, reason);
|
|
1038
1180
|
}
|
|
1039
1181
|
};
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
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);
|
|
1045
1224
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
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);
|
|
1065
1306
|
|
|
1066
1307
|
// backend/plugin.ts
|
|
1067
|
-
var
|
|
1308
|
+
var PLUGIN_CONTEXT5 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
1068
1309
|
var RabbitmqService = class {
|
|
1069
1310
|
constructor(context) {
|
|
1070
1311
|
__publicField(this, "context", context);
|
|
@@ -1077,8 +1318,8 @@ var RabbitmqService = class {
|
|
|
1077
1318
|
}
|
|
1078
1319
|
};
|
|
1079
1320
|
RabbitmqService = __decorateClass([
|
|
1080
|
-
(0,
|
|
1081
|
-
__decorateParam(0, (0,
|
|
1321
|
+
(0, import_common9.Injectable)(),
|
|
1322
|
+
__decorateParam(0, (0, import_common9.Inject)(PLUGIN_CONTEXT5))
|
|
1082
1323
|
], RabbitmqService);
|
|
1083
1324
|
var RabbitmqController = class {
|
|
1084
1325
|
// esbuild does not emit decorator metadata, so Nest cannot infer constructor
|
|
@@ -1091,12 +1332,12 @@ var RabbitmqController = class {
|
|
|
1091
1332
|
}
|
|
1092
1333
|
};
|
|
1093
1334
|
__decorateClass([
|
|
1094
|
-
(0,
|
|
1335
|
+
(0, import_common9.Get)("status")
|
|
1095
1336
|
], RabbitmqController.prototype, "status", 1);
|
|
1096
1337
|
RabbitmqController = __decorateClass([
|
|
1097
|
-
(0,
|
|
1098
|
-
(0,
|
|
1099
|
-
__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))
|
|
1100
1341
|
], RabbitmqController);
|
|
1101
1342
|
var RabbitmqPluginModule = class {
|
|
1102
1343
|
};
|
|
@@ -1107,13 +1348,22 @@ var plugin = {
|
|
|
1107
1348
|
register(context) {
|
|
1108
1349
|
return {
|
|
1109
1350
|
module: RabbitmqPluginModule,
|
|
1110
|
-
controllers: [
|
|
1351
|
+
controllers: [
|
|
1352
|
+
RabbitmqController,
|
|
1353
|
+
RabbitmqCapabilitiesController,
|
|
1354
|
+
RabbitmqDetectionController,
|
|
1355
|
+
RabbitmqUsersController,
|
|
1356
|
+
RabbitmqConnectionsController,
|
|
1357
|
+
RabbitmqStatsController
|
|
1358
|
+
],
|
|
1111
1359
|
providers: [
|
|
1112
|
-
{ provide:
|
|
1360
|
+
{ provide: PLUGIN_CONTEXT5, useValue: context },
|
|
1113
1361
|
RabbitmqService,
|
|
1114
1362
|
RabbitmqDetectionService,
|
|
1115
1363
|
RabbitmqManagementClient,
|
|
1116
|
-
RabbitmqUsersService
|
|
1364
|
+
RabbitmqUsersService,
|
|
1365
|
+
RabbitmqConnectionsService,
|
|
1366
|
+
RabbitmqStatsService
|
|
1117
1367
|
]
|
|
1118
1368
|
};
|
|
1119
1369
|
}
|