feat(rabbitmq): add message queue management support
This commit is contained in:
1 parent
503d6748d4
commit
39e554369f
76 files changed
+14915
-707
No files matched your search
@@ -0,0 +1,480 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import type { MqChannelInfo, MqClientConnectionInfo, NamespaceRef } from "@/types/mq";
|
||||
import { mqCloseClientConnection, mqListClientChannels, mqListClientConnections } from "@/lib/backend/api";
|
||||
import { isAllVhostsNamespace, RABBITMQ_MQ_TENANT, resolveMqRowNamespace } from "@/lib/mq/mqConsoleDefaults";
|
||||
import { formatError } from "@/lib/backend/errorUtils";
|
||||
import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
|
||||
|
||||
interface Props {
|
||||
connectionId: string;
|
||||
/** RabbitMQ virtual host; undefined lists connections across all vhosts. */
|
||||
namespace?: string;
|
||||
readOnly?: boolean;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const { t } = useI18n();
|
||||
|
||||
const connections = ref<MqClientConnectionInfo[]>([]);
|
||||
const loading = ref(false);
|
||||
const error = ref<string>();
|
||||
const connectionSearch = ref("");
|
||||
|
||||
const expandedNames = ref<Set<string>>(new Set());
|
||||
const channelsByConnection = ref<Record<string, MqChannelInfo[]>>({});
|
||||
const channelsLoading = ref<Record<string, boolean>>({});
|
||||
const channelsError = ref<Record<string, string | undefined>>({});
|
||||
|
||||
const showCloseDialog = ref(false);
|
||||
const closeTarget = ref<MqClientConnectionInfo>();
|
||||
const closing = ref(false);
|
||||
|
||||
const filteredConnections = computed(() => {
|
||||
const query = connectionSearch.value.trim().toLowerCase();
|
||||
if (!query) return connections.value;
|
||||
return connections.value.filter((connection) => {
|
||||
return connection.name.toLowerCase().includes(query) || connection.user.toLowerCase().includes(query) || connection.peerHost.toLowerCase().includes(query);
|
||||
});
|
||||
});
|
||||
|
||||
// RabbitMQ "all vhosts" mode: rows carry their own vhost in `namespace`, and
|
||||
// row-level operations must target that vhost rather than the "*" selection.
|
||||
const showNamespaceColumn = computed(() => isAllVhostsNamespace(props.namespace));
|
||||
|
||||
// RabbitMQ namespace is the vhost; the tenant is always the synthetic one.
|
||||
function nsRef(namespace?: string): NamespaceRef {
|
||||
return { tenant: RABBITMQ_MQ_TENANT, namespace: namespace ?? "" };
|
||||
}
|
||||
|
||||
function guardWritable() {
|
||||
if (props.readOnly) {
|
||||
error.value = t("mqClientConnections.readOnly");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function loadConnections() {
|
||||
loading.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
connections.value = await mqListClientConnections(props.connectionId, nsRef(props.namespace));
|
||||
// Drop cached channels for connections that went away.
|
||||
const liveNames = new Set(connections.value.map((connection) => connection.name));
|
||||
expandedNames.value = new Set([...expandedNames.value].filter((name) => liveNames.has(name)));
|
||||
for (const name of Object.keys(channelsByConnection.value)) {
|
||||
if (!liveNames.has(name)) {
|
||||
delete channelsByConnection.value[name];
|
||||
delete channelsLoading.value[name];
|
||||
delete channelsError.value[name];
|
||||
}
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadChannels(connection: MqClientConnectionInfo) {
|
||||
const connectionName = connection.name;
|
||||
const namespace = resolveMqRowNamespace(connection, props.namespace);
|
||||
if (!namespace) {
|
||||
channelsError.value = { ...channelsError.value, [connectionName]: t("mqAdmin.selectNamespaceToWrite") };
|
||||
return;
|
||||
}
|
||||
channelsLoading.value = { ...channelsLoading.value, [connectionName]: true };
|
||||
channelsError.value = { ...channelsError.value, [connectionName]: undefined };
|
||||
try {
|
||||
const channels = await mqListClientChannels(props.connectionId, nsRef(namespace), connectionName);
|
||||
channelsByConnection.value = { ...channelsByConnection.value, [connectionName]: channels };
|
||||
} catch (e: unknown) {
|
||||
channelsError.value = { ...channelsError.value, [connectionName]: formatError(e) };
|
||||
} finally {
|
||||
channelsLoading.value = { ...channelsLoading.value, [connectionName]: false };
|
||||
}
|
||||
}
|
||||
|
||||
function toggleExpanded(connection: MqClientConnectionInfo) {
|
||||
const next = new Set(expandedNames.value);
|
||||
if (next.has(connection.name)) {
|
||||
next.delete(connection.name);
|
||||
expandedNames.value = next;
|
||||
return;
|
||||
}
|
||||
next.add(connection.name);
|
||||
expandedNames.value = next;
|
||||
if (!channelsByConnection.value[connection.name]) {
|
||||
void loadChannels(connection);
|
||||
}
|
||||
}
|
||||
|
||||
function openCloseDialog(connection: MqClientConnectionInfo) {
|
||||
if (!guardWritable()) return;
|
||||
closeTarget.value = connection;
|
||||
showCloseDialog.value = true;
|
||||
}
|
||||
|
||||
async function confirmClose() {
|
||||
const target = closeTarget.value;
|
||||
if (!target) return;
|
||||
const namespace = resolveMqRowNamespace(target, props.namespace);
|
||||
if (!namespace) {
|
||||
error.value = t("mqAdmin.selectNamespaceToWrite");
|
||||
return;
|
||||
}
|
||||
closing.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
await mqCloseClientConnection(props.connectionId, nsRef(namespace), target.name);
|
||||
showCloseDialog.value = false;
|
||||
await loadConnections();
|
||||
} catch (e: unknown) {
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
closing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function formatRate(value: number | undefined): string {
|
||||
if (value === undefined) return "-";
|
||||
if (!value) return "0 B/s";
|
||||
const units = ["B/s", "KB/s", "MB/s", "GB/s"];
|
||||
const index = Math.min(Math.floor(Math.log(value) / Math.log(1024)), units.length - 1);
|
||||
return `${(value / 1024 ** index).toFixed(2)} ${units[index]}`;
|
||||
}
|
||||
|
||||
function formatConnectedAt(value: number | undefined): string {
|
||||
if (value === undefined) return "-";
|
||||
return new Date(value).toLocaleString();
|
||||
}
|
||||
|
||||
function formatOptionalNumber(value: number | undefined): string {
|
||||
return value === undefined ? "-" : String(value);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.namespace,
|
||||
() => {
|
||||
expandedNames.value = new Set();
|
||||
channelsByConnection.value = {};
|
||||
channelsLoading.value = {};
|
||||
channelsError.value = {};
|
||||
loadConnections();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="clients-panel">
|
||||
<div class="panel-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<input v-model="connectionSearch" type="search" class="connection-search" :placeholder="t('mqClientConnections.searchPlaceholder')" :disabled="loading && !connections.length" />
|
||||
<span v-if="connections.length" class="connection-count">{{ filteredConnections.length }} / {{ connections.length }}</span>
|
||||
</div>
|
||||
<div class="toolbar-actions">
|
||||
<button @click="loadConnections" :disabled="loading" class="btn-secondary">
|
||||
{{ loading ? t("mqClientConnections.refreshing") : t("mqClientConnections.refresh") }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="panel-error">{{ error }}</div>
|
||||
|
||||
<div v-else-if="loading && !connections.length" class="panel-loading">{{ t("mqClientConnections.loading") }}</div>
|
||||
|
||||
<div v-else-if="!connections.length" class="panel-placeholder">{{ t("mqClientConnections.noConnections") }}</div>
|
||||
|
||||
<div v-else-if="!filteredConnections.length" class="panel-placeholder">{{ t("mqClientConnections.noMatches") }}</div>
|
||||
|
||||
<div v-else class="connections-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="expand-col"></th>
|
||||
<th>{{ t("mqClientConnections.name") }}</th>
|
||||
<th v-if="showNamespaceColumn">{{ t("mqAdmin.namespace") }}</th>
|
||||
<th>{{ t("mqClientConnections.user") }}</th>
|
||||
<th>{{ t("mqClientConnections.peerAddress") }}</th>
|
||||
<th>{{ t("mqClientConnections.state") }}</th>
|
||||
<th>{{ t("mqClientConnections.channels") }}</th>
|
||||
<th>{{ t("mqClientConnections.recvRate") }}</th>
|
||||
<th>{{ t("mqClientConnections.sendRate") }}</th>
|
||||
<th>{{ t("mqClientConnections.connectedAt") }}</th>
|
||||
<th>{{ t("mqClientConnections.actions") }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody v-for="connection in filteredConnections" :key="connection.name">
|
||||
<tr :class="{ expanded: expandedNames.has(connection.name) }" @click="toggleExpanded(connection)">
|
||||
<td class="expand-col">
|
||||
<span class="expand-icon">{{ expandedNames.has(connection.name) ? "▾" : "▸" }}</span>
|
||||
</td>
|
||||
<td class="connection-name" :title="connection.name">{{ connection.name }}</td>
|
||||
<td v-if="showNamespaceColumn">{{ connection.namespace || "-" }}</td>
|
||||
<td>{{ connection.user || "-" }}</td>
|
||||
<td>{{ connection.peerHost ? `${connection.peerHost}:${connection.peerPort}` : "-" }}</td>
|
||||
<td>
|
||||
<span class="badge" :class="connection.state === 'running' ? 'badge-info' : 'badge-warning'">{{ connection.state || "-" }}</span>
|
||||
</td>
|
||||
<td>{{ connection.channels }}</td>
|
||||
<td>{{ formatRate(connection.recvRate) }}</td>
|
||||
<td>{{ formatRate(connection.sendRate) }}</td>
|
||||
<td>{{ formatConnectedAt(connection.connectedAt) }}</td>
|
||||
<td class="actions" @click.stop>
|
||||
<button class="btn-sm btn-danger" :disabled="readOnly || (showNamespaceColumn && !connection.namespace)" :title="showNamespaceColumn && !connection.namespace ? t('mqAdmin.selectNamespaceToWrite') : undefined" @click="openCloseDialog(connection)">
|
||||
{{ t("mqClientConnections.closeConnection") }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="expandedNames.has(connection.name)" class="channels-row">
|
||||
<td :colspan="showNamespaceColumn ? 11 : 10">
|
||||
<div v-if="channelsError[connection.name]" class="panel-error">{{ channelsError[connection.name] }}</div>
|
||||
<div v-else-if="channelsLoading[connection.name] && !channelsByConnection[connection.name]?.length" class="panel-loading">{{ t("mqClientConnections.loading") }}</div>
|
||||
<div v-else-if="!channelsByConnection[connection.name]?.length" class="panel-placeholder">{{ t("mqClientConnections.noChannels") }}</div>
|
||||
<table v-else class="channels-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t("mqClientConnections.channelName") }}</th>
|
||||
<th>{{ t("mqClientConnections.state") }}</th>
|
||||
<th>{{ t("mqClientConnections.prefetch") }}</th>
|
||||
<th>{{ t("mqClientConnections.unacked") }}</th>
|
||||
<th>{{ t("mqClientConnections.consumers") }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="channel in channelsByConnection[connection.name]" :key="channel.name">
|
||||
<td class="connection-name" :title="channel.name">{{ channel.name }}</td>
|
||||
<td>{{ channel.state || "-" }}</td>
|
||||
<td>{{ formatOptionalNumber(channel.prefetch) }}</td>
|
||||
<td>{{ formatOptionalNumber(channel.messagesUnacked) }}</td>
|
||||
<td>{{ formatOptionalNumber(channel.consumerCount) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Close Connection Confirm -->
|
||||
<DangerConfirmDialog
|
||||
v-model:open="showCloseDialog"
|
||||
:title="t('mqClientConnections.closeConnection')"
|
||||
:message="t('mqClientConnections.confirmClose', { name: closeTarget?.name ?? '' })"
|
||||
:confirm-label="t('mqClientConnections.closeConnection')"
|
||||
:loading="closing"
|
||||
:close-on-confirm="false"
|
||||
@confirm="confirmClose"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.clients-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
overflow: auto;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.panel-toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.toolbar-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.toolbar-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.connection-search {
|
||||
width: min(320px, 32vw);
|
||||
min-width: 180px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.connection-search:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 2px var(--color-primary-alpha);
|
||||
}
|
||||
|
||||
.connection-count {
|
||||
flex: 0 0 auto;
|
||||
color: var(--color-text-tertiary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.panel-placeholder,
|
||||
.panel-error,
|
||||
.panel-loading {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.panel-error {
|
||||
color: var(--color-error);
|
||||
}
|
||||
|
||||
.connections-table {
|
||||
overflow: auto;
|
||||
background: var(--color-background);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
th {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: var(--color-text-secondary);
|
||||
background: var(--color-background-secondary);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.connections-table tbody tr {
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.connections-table tbody tr:hover {
|
||||
background: var(--color-hover);
|
||||
}
|
||||
|
||||
.connections-table tbody tr.expanded {
|
||||
background: var(--color-primary-alpha);
|
||||
}
|
||||
|
||||
.expand-col {
|
||||
width: 24px;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
color: var(--color-text-tertiary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.connection-name {
|
||||
font-weight: 500;
|
||||
max-width: 320px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.channels-row {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.channels-row:hover {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.channels-row td {
|
||||
background: var(--color-background-secondary);
|
||||
padding: 8px 12px 12px 36px;
|
||||
}
|
||||
|
||||
.channels-table {
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
background: var(--color-background);
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.badge-info {
|
||||
background: var(--color-info-alpha);
|
||||
color: var(--color-info);
|
||||
}
|
||||
|
||||
.badge-warning {
|
||||
background: var(--color-warning-alpha);
|
||||
color: var(--color-warning);
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.btn-secondary,
|
||||
.btn-sm {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: var(--color-hover);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
color: var(--color-error);
|
||||
border-color: var(--color-error);
|
||||
}
|
||||
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: var(--color-error);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 4px 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,437 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import type { MqNodeInfo, MqOverviewInfo } from "@/types/mq";
|
||||
import { mqGetOverview, mqListNodes } from "@/lib/backend/api";
|
||||
import { formatError } from "@/lib/backend/errorUtils";
|
||||
|
||||
interface Props {
|
||||
connectionId: string;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const { t } = useI18n();
|
||||
|
||||
const overview = ref<MqOverviewInfo>();
|
||||
const nodes = ref<MqNodeInfo[]>([]);
|
||||
const loading = ref(false);
|
||||
const error = ref<string>();
|
||||
const autoRefresh = ref(true);
|
||||
const refreshInterval = ref(5); // seconds
|
||||
|
||||
let refreshTimer: number | undefined;
|
||||
|
||||
function isDocumentHidden(): boolean {
|
||||
return typeof document !== "undefined" && document.hidden;
|
||||
}
|
||||
|
||||
async function loadStats(options: { skipWhenHidden?: boolean } = {}) {
|
||||
if (options.skipWhenHidden && isDocumentHidden()) return;
|
||||
loading.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
const [overviewData, nodeData] = await Promise.all([mqGetOverview(props.connectionId), mqListNodes(props.connectionId)]);
|
||||
overview.value = overviewData;
|
||||
nodes.value = nodeData;
|
||||
} catch (e: unknown) {
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function refreshNow() {
|
||||
void loadStats();
|
||||
}
|
||||
|
||||
function startAutoRefresh() {
|
||||
stopAutoRefresh();
|
||||
if (autoRefresh.value && !isDocumentHidden()) {
|
||||
refreshTimer = window.setInterval(() => {
|
||||
void loadStats({ skipWhenHidden: true });
|
||||
}, refreshInterval.value * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function stopAutoRefresh() {
|
||||
if (refreshTimer !== undefined) {
|
||||
clearInterval(refreshTimer);
|
||||
refreshTimer = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function handleVisibilityChange() {
|
||||
if (isDocumentHidden()) {
|
||||
stopAutoRefresh();
|
||||
return;
|
||||
}
|
||||
startAutoRefresh();
|
||||
void loadStats();
|
||||
}
|
||||
|
||||
function formatNumber(value: number | undefined): string {
|
||||
return value === undefined ? "-" : value.toLocaleString();
|
||||
}
|
||||
|
||||
function formatRate(value: number | undefined): string {
|
||||
return value === undefined ? "-" : `${value.toFixed(2)} msg/s`;
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number | undefined): string {
|
||||
if (bytes === undefined) return "-";
|
||||
if (bytes === 0) return "0 B";
|
||||
const k = 1024;
|
||||
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + " " + sizes[i];
|
||||
}
|
||||
|
||||
function formatUsage(used: number | undefined, total: number | undefined): string {
|
||||
if (used === undefined) return "-";
|
||||
return total === undefined ? formatNumber(used) : `${formatNumber(used)} / ${formatNumber(total)}`;
|
||||
}
|
||||
|
||||
function formatMemory(node: MqNodeInfo): string {
|
||||
if (node.memUsed === undefined) return "-";
|
||||
if (node.memLimit === undefined || node.memLimit <= 0) return formatBytes(node.memUsed);
|
||||
const percent = Math.round((node.memUsed / node.memLimit) * 100);
|
||||
return `${formatBytes(node.memUsed)} / ${formatBytes(node.memLimit)} (${percent}%)`;
|
||||
}
|
||||
|
||||
function formatUptime(uptimeMs: number | undefined): string {
|
||||
if (uptimeMs === undefined) return "-";
|
||||
const totalSeconds = Math.floor(uptimeMs / 1000);
|
||||
const days = Math.floor(totalSeconds / 86400);
|
||||
const hours = Math.floor((totalSeconds % 86400) / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
if (days > 0) return `${days}d ${hours}h ${minutes}m`;
|
||||
if (hours > 0) return `${hours}h ${minutes}m`;
|
||||
return `${minutes}m`;
|
||||
}
|
||||
|
||||
watch(autoRefresh, () => {
|
||||
startAutoRefresh();
|
||||
});
|
||||
|
||||
watch(refreshInterval, () => {
|
||||
if (autoRefresh.value) {
|
||||
startAutoRefresh();
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.connectionId,
|
||||
() => {
|
||||
overview.value = undefined;
|
||||
nodes.value = [];
|
||||
void loadStats();
|
||||
startAutoRefresh();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||||
startAutoRefresh();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
||||
stopAutoRefresh();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="rabbitmq-monitoring-panel">
|
||||
<div class="panel-toolbar">
|
||||
<h3 class="section-title">{{ t("mqRabbitMqMonitoring.title") }}</h3>
|
||||
<div class="toolbar-actions">
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" v-model="autoRefresh" />
|
||||
<span>{{ t("mqMonitoring.autoRefresh") }}</span>
|
||||
</label>
|
||||
<select v-model.number="refreshInterval" :disabled="!autoRefresh" class="refresh-interval">
|
||||
<option :value="5">{{ t("mqMonitoring.refreshInterval5s") }}</option>
|
||||
<option :value="10">{{ t("mqMonitoring.refreshInterval10s") }}</option>
|
||||
<option :value="30">{{ t("mqMonitoring.refreshInterval30s") }}</option>
|
||||
<option :value="60">{{ t("mqMonitoring.refreshInterval60s") }}</option>
|
||||
</select>
|
||||
<button @click="refreshNow" :disabled="loading" class="btn-secondary">
|
||||
{{ loading ? t("mqMonitoring.refreshing") : t("mqMonitoring.refreshNow") }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="panel-error">{{ error }}</div>
|
||||
<div v-else-if="loading && !overview" class="panel-loading">{{ t("mqRabbitMqMonitoring.loading") }}</div>
|
||||
|
||||
<template v-else>
|
||||
<!-- Overview cards -->
|
||||
<div class="panel-section">
|
||||
<h4 class="section-subtitle">{{ t("mqRabbitMqMonitoring.overviewTitle") }}</h4>
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">{{ t("mqRabbitMqMonitoring.messagesReady") }}</div>
|
||||
<div class="stat-value">{{ formatNumber(overview?.messagesReady) }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">{{ t("mqRabbitMqMonitoring.messagesUnacked") }}</div>
|
||||
<div class="stat-value">{{ formatNumber(overview?.messagesUnacked) }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">{{ t("mqRabbitMqMonitoring.publishRate") }}</div>
|
||||
<div class="stat-value">{{ formatRate(overview?.publishRate) }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">{{ t("mqRabbitMqMonitoring.deliverRate") }}</div>
|
||||
<div class="stat-value">{{ formatRate(overview?.deliverRate) }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">{{ t("mqRabbitMqMonitoring.ackRate") }}</div>
|
||||
<div class="stat-value">{{ formatRate(overview?.ackRate) }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">{{ t("mqRabbitMqMonitoring.totalQueues") }}</div>
|
||||
<div class="stat-value">{{ formatNumber(overview?.totalQueues) }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">{{ t("mqRabbitMqMonitoring.totalExchanges") }}</div>
|
||||
<div class="stat-value">{{ formatNumber(overview?.totalExchanges) }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">{{ t("mqRabbitMqMonitoring.totalConnections") }}</div>
|
||||
<div class="stat-value">{{ formatNumber(overview?.totalConnections) }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">{{ t("mqRabbitMqMonitoring.totalChannels") }}</div>
|
||||
<div class="stat-value">{{ formatNumber(overview?.totalChannels) }}</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">{{ t("mqRabbitMqMonitoring.totalConsumers") }}</div>
|
||||
<div class="stat-value">{{ formatNumber(overview?.totalConsumers) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Node table -->
|
||||
<div class="panel-section">
|
||||
<h4 class="section-subtitle">{{ t("mqRabbitMqMonitoring.nodesTitle") }}</h4>
|
||||
<div v-if="!nodes.length" class="panel-placeholder">{{ t("mqRabbitMqMonitoring.noNodes") }}</div>
|
||||
<div v-else class="data-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t("mqRabbitMqMonitoring.nodeName") }}</th>
|
||||
<th>{{ t("mqRabbitMqMonitoring.status") }}</th>
|
||||
<th>{{ t("mqRabbitMqMonitoring.memory") }}</th>
|
||||
<th>{{ t("mqRabbitMqMonitoring.diskFree") }}</th>
|
||||
<th>{{ t("mqRabbitMqMonitoring.fileDescriptors") }}</th>
|
||||
<th>{{ t("mqRabbitMqMonitoring.sockets") }}</th>
|
||||
<th>{{ t("mqRabbitMqMonitoring.uptime") }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="node in nodes" :key="node.name">
|
||||
<td class="node-name" :title="node.name">{{ node.name }}</td>
|
||||
<td>
|
||||
<span :class="['status-badge', node.running ? 'running' : 'stopped']">
|
||||
{{ node.running ? t("mqRabbitMqMonitoring.running") : t("mqRabbitMqMonitoring.stopped") }}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{ formatMemory(node) }}</td>
|
||||
<td>{{ formatBytes(node.diskFree) }}</td>
|
||||
<td>{{ formatUsage(node.fdUsed, node.fdTotal) }}</td>
|
||||
<td>{{ formatUsage(node.socketsUsed, node.socketsTotal) }}</td>
|
||||
<td>{{ formatUptime(node.uptimeMs) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.rabbitmq-monitoring-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
padding: 12px 16px;
|
||||
overflow: auto;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.section-subtitle {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.panel-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.panel-toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.toolbar-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--color-text-secondary);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.refresh-interval {
|
||||
padding: 4px 8px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.panel-placeholder,
|
||||
.panel-error,
|
||||
.panel-loading {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.panel-error {
|
||||
color: var(--color-error);
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
padding: 12px 14px;
|
||||
background: var(--color-background);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 12px;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.data-table {
|
||||
overflow: auto;
|
||||
background: var(--color-background);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
th {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: var(--color-text-secondary);
|
||||
background: var(--color-background-secondary);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.data-table tbody tr {
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.data-table tbody tr:hover {
|
||||
background: var(--color-hover);
|
||||
}
|
||||
|
||||
.node-name {
|
||||
font-family: var(--font-mono, monospace);
|
||||
font-size: 12px;
|
||||
max-width: 280px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status-badge.running {
|
||||
background: var(--color-success-alpha);
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
.status-badge.stopped {
|
||||
background: var(--color-error-alpha);
|
||||
color: var(--color-error);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: var(--color-hover);
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,780 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import type { MqUserInfo, MqVhostPermission } from "@/types/mq";
|
||||
import { mqCreateUser, mqDeleteUser, mqGrantUserPermission, mqListNamespaces, mqListUserPermissions, mqListUsers, mqRevokeUserPermission } from "@/lib/backend/api";
|
||||
import { isAllVhostsNamespace, RABBITMQ_MQ_TENANT } from "@/lib/mq/mqConsoleDefaults";
|
||||
import { formatError } from "@/lib/backend/errorUtils";
|
||||
import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
|
||||
|
||||
interface Props {
|
||||
connectionId: string;
|
||||
/** Selected RabbitMQ virtual host; "*" lists permissions across all vhosts. */
|
||||
namespace?: string;
|
||||
readOnly?: boolean;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const { t } = useI18n();
|
||||
|
||||
const users = ref<MqUserInfo[]>([]);
|
||||
const usersLoading = ref(false);
|
||||
const error = ref<string>();
|
||||
const userSearch = ref("");
|
||||
/** Clicking a user row filters the permission matrix to that user. */
|
||||
const selectedUser = ref<string>();
|
||||
|
||||
const permissions = ref<MqVhostPermission[]>([]);
|
||||
const permissionsLoading = ref(false);
|
||||
|
||||
/** Virtual hosts for the grant dialog dropdown. */
|
||||
const vhosts = ref<string[]>([]);
|
||||
|
||||
const dialogError = ref<string>();
|
||||
const showCreateDialog = ref(false);
|
||||
const createForm = ref({ name: "", password: "", tagsText: "" });
|
||||
const creating = ref(false);
|
||||
|
||||
const showDeleteDialog = ref(false);
|
||||
const deleteTarget = ref<MqUserInfo>();
|
||||
const deleting = ref(false);
|
||||
|
||||
const showGrantDialog = ref(false);
|
||||
const grantForm = ref({ user: "", virtualHost: "", configure: ".*", write: ".*", read: ".*" });
|
||||
const granting = ref(false);
|
||||
|
||||
const showRevokeDialog = ref(false);
|
||||
const revokeTarget = ref<MqVhostPermission>();
|
||||
const revoking = ref(false);
|
||||
|
||||
const filteredUsers = computed(() => {
|
||||
const query = userSearch.value.trim().toLowerCase();
|
||||
if (!query) return users.value;
|
||||
return users.value.filter((user) => user.name.toLowerCase().includes(query));
|
||||
});
|
||||
|
||||
const filteredPermissions = computed(() => {
|
||||
if (!selectedUser.value) return permissions.value;
|
||||
return permissions.value.filter((permission) => permission.user === selectedUser.value);
|
||||
});
|
||||
|
||||
function guardWritable(): boolean {
|
||||
if (props.readOnly) {
|
||||
error.value = t("mqUserPermissions.readOnly");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
usersLoading.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
users.value = await mqListUsers(props.connectionId);
|
||||
if (selectedUser.value && !users.value.some((user) => user.name === selectedUser.value)) {
|
||||
selectedUser.value = undefined;
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
usersLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPermissions() {
|
||||
permissionsLoading.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
// "*" is a listing sentinel: translate it into the all-vhosts listing.
|
||||
if (isAllVhostsNamespace(props.namespace)) {
|
||||
permissions.value = await mqListUserPermissions(props.connectionId, { allVhosts: true });
|
||||
} else if (props.namespace) {
|
||||
permissions.value = await mqListUserPermissions(props.connectionId, { virtualHost: props.namespace });
|
||||
} else {
|
||||
permissions.value = await mqListUserPermissions(props.connectionId);
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
permissionsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadVhosts() {
|
||||
try {
|
||||
const namespaces = await mqListNamespaces(props.connectionId, RABBITMQ_MQ_TENANT);
|
||||
vhosts.value = namespaces.map((ns) => ns.namespace);
|
||||
} catch (e: unknown) {
|
||||
console.warn("[DBX] Failed to load RabbitMQ vhosts:", e);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleUserFilter(user: MqUserInfo) {
|
||||
selectedUser.value = selectedUser.value === user.name ? undefined : user.name;
|
||||
}
|
||||
|
||||
function openCreateDialog() {
|
||||
if (!guardWritable()) return;
|
||||
createForm.value = { name: "", password: "", tagsText: "" };
|
||||
dialogError.value = undefined;
|
||||
showCreateDialog.value = true;
|
||||
}
|
||||
|
||||
function parseTags(text: string): string[] | undefined {
|
||||
const tags = text
|
||||
.split(",")
|
||||
.map((tag) => tag.trim())
|
||||
.filter((tag) => tag.length > 0);
|
||||
return tags.length ? tags : undefined;
|
||||
}
|
||||
|
||||
async function handleCreateUser() {
|
||||
const name = createForm.value.name.trim();
|
||||
const password = createForm.value.password;
|
||||
if (!name) {
|
||||
dialogError.value = t("mqUserPermissions.nameRequired");
|
||||
return;
|
||||
}
|
||||
if (!password) {
|
||||
dialogError.value = t("mqUserPermissions.passwordRequired");
|
||||
return;
|
||||
}
|
||||
creating.value = true;
|
||||
dialogError.value = undefined;
|
||||
try {
|
||||
await mqCreateUser(props.connectionId, name, password, parseTags(createForm.value.tagsText));
|
||||
showCreateDialog.value = false;
|
||||
await loadUsers();
|
||||
} catch (e: unknown) {
|
||||
dialogError.value = formatError(e);
|
||||
} finally {
|
||||
creating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openDeleteDialog(user: MqUserInfo) {
|
||||
if (!guardWritable()) return;
|
||||
deleteTarget.value = user;
|
||||
showDeleteDialog.value = true;
|
||||
}
|
||||
|
||||
async function confirmDelete() {
|
||||
const target = deleteTarget.value;
|
||||
if (!target) return;
|
||||
deleting.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
await mqDeleteUser(props.connectionId, target.name);
|
||||
showDeleteDialog.value = false;
|
||||
await Promise.all([loadUsers(), loadPermissions()]);
|
||||
} catch (e: unknown) {
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
deleting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openGrantDialog() {
|
||||
if (!guardWritable()) return;
|
||||
const currentVhost = props.namespace && !isAllVhostsNamespace(props.namespace) ? props.namespace : "";
|
||||
grantForm.value = {
|
||||
user: selectedUser.value ?? users.value[0]?.name ?? "",
|
||||
virtualHost: currentVhost || vhosts.value[0] || "",
|
||||
configure: ".*",
|
||||
write: ".*",
|
||||
read: ".*",
|
||||
};
|
||||
dialogError.value = undefined;
|
||||
showGrantDialog.value = true;
|
||||
}
|
||||
|
||||
function patternOrDefault(value: string): string | undefined {
|
||||
const trimmed = value.trim();
|
||||
return trimmed ? trimmed : undefined;
|
||||
}
|
||||
|
||||
async function handleGrant() {
|
||||
const user = grantForm.value.user.trim();
|
||||
const virtualHost = grantForm.value.virtualHost.trim();
|
||||
if (!user) {
|
||||
dialogError.value = t("mqUserPermissions.userRequired");
|
||||
return;
|
||||
}
|
||||
if (!virtualHost || isAllVhostsNamespace(virtualHost)) {
|
||||
dialogError.value = t("mqUserPermissions.vhostRequired");
|
||||
return;
|
||||
}
|
||||
granting.value = true;
|
||||
dialogError.value = undefined;
|
||||
try {
|
||||
await mqGrantUserPermission(props.connectionId, user, virtualHost, {
|
||||
configure: patternOrDefault(grantForm.value.configure),
|
||||
write: patternOrDefault(grantForm.value.write),
|
||||
read: patternOrDefault(grantForm.value.read),
|
||||
});
|
||||
showGrantDialog.value = false;
|
||||
await loadPermissions();
|
||||
} catch (e: unknown) {
|
||||
dialogError.value = formatError(e);
|
||||
} finally {
|
||||
granting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openRevokeDialog(permission: MqVhostPermission) {
|
||||
if (!guardWritable()) return;
|
||||
revokeTarget.value = permission;
|
||||
showRevokeDialog.value = true;
|
||||
}
|
||||
|
||||
async function confirmRevoke() {
|
||||
const target = revokeTarget.value;
|
||||
if (!target) return;
|
||||
revoking.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
await mqRevokeUserPermission(props.connectionId, target.user, target.vhost);
|
||||
showRevokeDialog.value = false;
|
||||
await loadPermissions();
|
||||
} catch (e: unknown) {
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
revoking.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.namespace,
|
||||
() => {
|
||||
loadPermissions();
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.connectionId,
|
||||
() => {
|
||||
selectedUser.value = undefined;
|
||||
loadUsers();
|
||||
loadPermissions();
|
||||
loadVhosts();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="user-permissions-panel">
|
||||
<!-- Users -->
|
||||
<div class="panel-section">
|
||||
<div class="panel-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<h3 class="section-title">{{ t("mqUserPermissions.usersTitle") }}</h3>
|
||||
<input v-model="userSearch" type="search" class="user-search" :placeholder="t('mqUserPermissions.searchUsers')" :disabled="usersLoading && !users.length" />
|
||||
<span v-if="users.length" class="row-count">{{ filteredUsers.length }} / {{ users.length }}</span>
|
||||
</div>
|
||||
<div class="toolbar-actions">
|
||||
<button @click="openCreateDialog" :disabled="readOnly" class="btn-secondary">{{ t("mqUserPermissions.createUser") }}</button>
|
||||
<button @click="loadUsers" :disabled="usersLoading" class="btn-secondary">
|
||||
{{ usersLoading ? t("mqUserPermissions.refreshing") : t("mqUserPermissions.refresh") }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="usersLoading && !users.length" class="panel-loading">{{ t("mqUserPermissions.loading") }}</div>
|
||||
<div v-else-if="!users.length" class="panel-placeholder">{{ t("mqUserPermissions.noUsers") }}</div>
|
||||
<div v-else-if="!filteredUsers.length" class="panel-placeholder">{{ t("mqUserPermissions.noUserMatches") }}</div>
|
||||
<div v-else class="data-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t("mqUserPermissions.name") }}</th>
|
||||
<th>{{ t("mqUserPermissions.tags") }}</th>
|
||||
<th>{{ t("mqUserPermissions.actions") }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="user in filteredUsers" :key="user.name" :class="{ selected: selectedUser === user.name }" @click="toggleUserFilter(user)">
|
||||
<td class="user-name" :title="user.name">{{ user.name }}</td>
|
||||
<td>
|
||||
<span v-if="user.tags.length" class="tag-list">
|
||||
<span v-for="tag in user.tags" :key="tag" class="badge badge-info">{{ tag }}</span>
|
||||
</span>
|
||||
<span v-else>-</span>
|
||||
</td>
|
||||
<td class="actions" @click.stop>
|
||||
<button class="btn-sm btn-danger" :disabled="readOnly" @click="openDeleteDialog(user)">{{ t("mqUserPermissions.delete") }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Permission matrix -->
|
||||
<div class="panel-section">
|
||||
<div class="panel-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<h3 class="section-title">{{ t("mqUserPermissions.permissionsTitle") }}</h3>
|
||||
<span v-if="selectedUser" class="filter-chip">
|
||||
{{ selectedUser }}
|
||||
<button class="chip-clear" @click="selectedUser = undefined">×</button>
|
||||
</span>
|
||||
</div>
|
||||
<div class="toolbar-actions">
|
||||
<button @click="openGrantDialog" :disabled="readOnly" class="btn-secondary">{{ t("mqUserPermissions.grantPermission") }}</button>
|
||||
<button @click="loadPermissions" :disabled="permissionsLoading" class="btn-secondary">
|
||||
{{ permissionsLoading ? t("mqUserPermissions.refreshing") : t("mqUserPermissions.refresh") }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="panel-error">{{ error }}</div>
|
||||
<div v-else-if="permissionsLoading && !permissions.length" class="panel-loading">{{ t("mqUserPermissions.loading") }}</div>
|
||||
<div v-else-if="!filteredPermissions.length" class="panel-placeholder">{{ t("mqUserPermissions.noPermissions") }}</div>
|
||||
<div v-else class="data-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t("mqUserPermissions.user") }}</th>
|
||||
<th>{{ t("mqUserPermissions.vhost") }}</th>
|
||||
<th>{{ t("mqUserPermissions.configure") }}</th>
|
||||
<th>{{ t("mqUserPermissions.write") }}</th>
|
||||
<th>{{ t("mqUserPermissions.read") }}</th>
|
||||
<th>{{ t("mqUserPermissions.actions") }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="permission in filteredPermissions" :key="`${permission.user}@${permission.vhost}`">
|
||||
<td class="user-name" :title="permission.user">{{ permission.user }}</td>
|
||||
<td>{{ permission.vhost }}</td>
|
||||
<td class="pattern-cell" :title="permission.configure">{{ permission.configure }}</td>
|
||||
<td class="pattern-cell" :title="permission.write">{{ permission.write }}</td>
|
||||
<td class="pattern-cell" :title="permission.read">{{ permission.read }}</td>
|
||||
<td class="actions">
|
||||
<button class="btn-sm btn-danger" :disabled="readOnly" @click="openRevokeDialog(permission)">{{ t("mqUserPermissions.revoke") }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Create User Dialog -->
|
||||
<div v-if="showCreateDialog" class="dialog-overlay" @click="showCreateDialog = false">
|
||||
<div class="dialog" @click.stop>
|
||||
<div class="dialog-header">
|
||||
<h3>{{ t("mqUserPermissions.createUser") }}</h3>
|
||||
<button @click="showCreateDialog = false" class="btn-close">×</button>
|
||||
</div>
|
||||
<div class="dialog-body">
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqUserPermissions.name") }}</label>
|
||||
<input v-model="createForm.name" type="text" :disabled="readOnly" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqUserPermissions.password") }}</label>
|
||||
<input v-model="createForm.password" type="password" :disabled="readOnly" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqUserPermissions.tags") }}</label>
|
||||
<input v-model="createForm.tagsText" type="text" :placeholder="t('mqUserPermissions.tagsPlaceholder')" :disabled="readOnly" />
|
||||
</div>
|
||||
<div v-if="dialogError" class="form-error">{{ dialogError }}</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button @click="showCreateDialog = false" class="btn-secondary">{{ t("mqUserPermissions.cancel") }}</button>
|
||||
<button @click="handleCreateUser" :disabled="creating || readOnly" class="btn-primary">{{ t("mqUserPermissions.create") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Grant Permission Dialog -->
|
||||
<div v-if="showGrantDialog" class="dialog-overlay" @click="showGrantDialog = false">
|
||||
<div class="dialog" @click.stop>
|
||||
<div class="dialog-header">
|
||||
<h3>{{ t("mqUserPermissions.grantPermission") }}</h3>
|
||||
<button @click="showGrantDialog = false" class="btn-close">×</button>
|
||||
</div>
|
||||
<div class="dialog-body">
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqUserPermissions.user") }}</label>
|
||||
<select v-model="grantForm.user" :disabled="readOnly">
|
||||
<option value="" disabled>{{ t("mqUserPermissions.selectUser") }}</option>
|
||||
<option v-for="user in users" :key="user.name" :value="user.name">{{ user.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqUserPermissions.vhost") }}</label>
|
||||
<select v-model="grantForm.virtualHost" :disabled="readOnly">
|
||||
<option value="" disabled>{{ t("mqUserPermissions.selectVhost") }}</option>
|
||||
<option v-for="vhost in vhosts" :key="vhost" :value="vhost">{{ vhost }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqUserPermissions.configure") }}</label>
|
||||
<input v-model="grantForm.configure" type="text" placeholder=".*" :disabled="readOnly" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqUserPermissions.write") }}</label>
|
||||
<input v-model="grantForm.write" type="text" placeholder=".*" :disabled="readOnly" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqUserPermissions.read") }}</label>
|
||||
<input v-model="grantForm.read" type="text" placeholder=".*" :disabled="readOnly" />
|
||||
</div>
|
||||
<div class="form-hint">{{ t("mqUserPermissions.patternHint") }}</div>
|
||||
<div v-if="dialogError" class="form-error">{{ dialogError }}</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button @click="showGrantDialog = false" class="btn-secondary">{{ t("mqUserPermissions.cancel") }}</button>
|
||||
<button @click="handleGrant" :disabled="granting || readOnly" class="btn-primary">{{ t("mqUserPermissions.grant") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete User Confirm -->
|
||||
<DangerConfirmDialog
|
||||
v-model:open="showDeleteDialog"
|
||||
:title="t('mqUserPermissions.delete')"
|
||||
:message="t('mqUserPermissions.confirmDeleteUser', { name: deleteTarget?.name ?? '' })"
|
||||
:confirm-label="t('mqUserPermissions.delete')"
|
||||
:loading="deleting"
|
||||
:close-on-confirm="false"
|
||||
@confirm="confirmDelete"
|
||||
/>
|
||||
|
||||
<!-- Revoke Permission Confirm -->
|
||||
<DangerConfirmDialog
|
||||
v-model:open="showRevokeDialog"
|
||||
:title="t('mqUserPermissions.revoke')"
|
||||
:message="t('mqUserPermissions.confirmRevoke', { user: revokeTarget?.user ?? '', vhost: revokeTarget?.vhost ?? '' })"
|
||||
:confirm-label="t('mqUserPermissions.revoke')"
|
||||
:loading="revoking"
|
||||
:close-on-confirm="false"
|
||||
@confirm="confirmRevoke"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.user-permissions-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
padding: 12px 16px;
|
||||
overflow: auto;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.panel-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.panel-toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.toolbar-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.toolbar-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.user-search {
|
||||
width: min(280px, 28vw);
|
||||
min-width: 160px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.user-search:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 2px var(--color-primary-alpha);
|
||||
}
|
||||
|
||||
.row-count {
|
||||
flex: 0 0 auto;
|
||||
color: var(--color-text-tertiary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.filter-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
background: var(--color-primary-alpha);
|
||||
color: var(--color-primary);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.chip-clear {
|
||||
border: none;
|
||||
background: none;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.panel-placeholder,
|
||||
.panel-error,
|
||||
.panel-loading {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.panel-error {
|
||||
color: var(--color-error);
|
||||
}
|
||||
|
||||
.data-table {
|
||||
overflow: auto;
|
||||
background: var(--color-background);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
th {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: var(--color-text-secondary);
|
||||
background: var(--color-background-secondary);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.data-table tbody tr {
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.data-table tbody tr:hover {
|
||||
background: var(--color-hover);
|
||||
}
|
||||
|
||||
.data-table tbody tr.selected {
|
||||
background: var(--color-primary-alpha);
|
||||
}
|
||||
|
||||
.user-name {
|
||||
font-weight: 500;
|
||||
max-width: 280px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.pattern-cell {
|
||||
font-family: var(--font-mono, monospace);
|
||||
font-size: 12px;
|
||||
max-width: 220px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tag-list {
|
||||
display: inline-flex;
|
||||
gap: 4px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.badge-info {
|
||||
background: var(--color-info-alpha);
|
||||
color: var(--color-info);
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.btn-primary,
|
||||
.btn-secondary,
|
||||
.btn-sm {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: var(--color-hover);
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--color-primary);
|
||||
color: white;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
color: var(--color-error);
|
||||
border-color: var(--color-error);
|
||||
}
|
||||
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: var(--color-error);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 4px 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Dialogs */
|
||||
.dialog-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.dialog {
|
||||
background: var(--color-background);
|
||||
border-radius: 8px;
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.dialog-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.dialog-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.btn-close {
|
||||
border: none;
|
||||
background: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: var(--color-text-secondary);
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.dialog-body {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
padding: 16px 20px;
|
||||
border-top: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-weight: 500;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.form-group input[type="text"],
|
||||
.form-group input[type="password"],
|
||||
.form-group select {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
box-sizing: border-box;
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
color: var(--color-text-tertiary);
|
||||
font-size: 12px;
|
||||
margin-top: -8px;
|
||||
}
|
||||
|
||||
.form-error {
|
||||
color: var(--color-error);
|
||||
font-size: 13px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,626 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import type { MqPolicyInfo, MqPolicyUpsertRequest } from "@/types/mq";
|
||||
import { mqDeletePolicy, mqListNamespaces, mqListPolicies, mqSetPolicy } from "@/lib/backend/api";
|
||||
import { isAllVhostsNamespace, RABBITMQ_MQ_TENANT } from "@/lib/mq/mqConsoleDefaults";
|
||||
import { formatError } from "@/lib/backend/errorUtils";
|
||||
import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
|
||||
|
||||
interface Props {
|
||||
connectionId: string;
|
||||
/** Selected RabbitMQ virtual host; "*" lists policies across all vhosts. */
|
||||
namespace?: string;
|
||||
readOnly?: boolean;
|
||||
}
|
||||
|
||||
interface DefinitionEntry {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const { t } = useI18n();
|
||||
|
||||
/** Well-known policy definition keys offered in the editor dropdown. */
|
||||
const COMMON_DEFINITION_KEYS = ["message-ttl", "expires", "max-length", "max-length-bytes", "dead-letter-exchange", "dead-letter-routing-key", "max-age"];
|
||||
/** Definition keys whose values are numeric. */
|
||||
const NUMERIC_DEFINITION_KEYS = new Set(["message-ttl", "expires", "max-length", "max-length-bytes"]);
|
||||
const APPLY_TO_OPTIONS = ["queues", "exchanges", "all"];
|
||||
|
||||
const policies = ref<MqPolicyInfo[]>([]);
|
||||
const loading = ref(false);
|
||||
const error = ref<string>();
|
||||
|
||||
/** Virtual hosts for the create/edit dialog dropdown. */
|
||||
const vhosts = ref<string[]>([]);
|
||||
|
||||
const dialogError = ref<string>();
|
||||
const showEditDialog = ref(false);
|
||||
/** When set the dialog edits this policy; name and vhost stay fixed. */
|
||||
const editingPolicy = ref<MqPolicyInfo>();
|
||||
const editForm = ref({ name: "", virtualHost: "", pattern: "", applyTo: "queues", priority: 0 });
|
||||
const definitionEntries = ref<DefinitionEntry[]>([]);
|
||||
const saving = ref(false);
|
||||
|
||||
const showDeleteDialog = ref(false);
|
||||
const deleteTarget = ref<MqPolicyInfo>();
|
||||
const deleting = ref(false);
|
||||
|
||||
function guardWritable(): boolean {
|
||||
if (props.readOnly) {
|
||||
error.value = t("mqRabbitMqPolicies.readOnly");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function loadPolicies() {
|
||||
loading.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
// "*" is a listing sentinel: translate it into the all-vhosts listing.
|
||||
if (isAllVhostsNamespace(props.namespace)) {
|
||||
policies.value = await mqListPolicies(props.connectionId, { allVhosts: true });
|
||||
} else if (props.namespace) {
|
||||
policies.value = await mqListPolicies(props.connectionId, { virtualHost: props.namespace });
|
||||
} else {
|
||||
policies.value = await mqListPolicies(props.connectionId);
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadVhosts() {
|
||||
try {
|
||||
const namespaces = await mqListNamespaces(props.connectionId, RABBITMQ_MQ_TENANT);
|
||||
vhosts.value = namespaces.map((ns) => ns.namespace);
|
||||
} catch (e: unknown) {
|
||||
console.warn("[DBX] Failed to load RabbitMQ vhosts:", e);
|
||||
}
|
||||
}
|
||||
|
||||
function definitionEntriesFrom(policy: MqPolicyInfo): DefinitionEntry[] {
|
||||
return Object.entries(policy.definition).map(([key, value]) => ({ key, value: String(value) }));
|
||||
}
|
||||
|
||||
function openCreateDialog() {
|
||||
if (!guardWritable()) return;
|
||||
const currentVhost = props.namespace && !isAllVhostsNamespace(props.namespace) ? props.namespace : "";
|
||||
editingPolicy.value = undefined;
|
||||
editForm.value = { name: "", virtualHost: currentVhost || vhosts.value[0] || "", pattern: "", applyTo: "queues", priority: 0 };
|
||||
definitionEntries.value = [];
|
||||
dialogError.value = undefined;
|
||||
showEditDialog.value = true;
|
||||
}
|
||||
|
||||
function openEditDialog(policy: MqPolicyInfo) {
|
||||
if (!guardWritable()) return;
|
||||
editingPolicy.value = policy;
|
||||
editForm.value = { name: policy.name, virtualHost: policy.vhost, pattern: policy.pattern, applyTo: policy.applyTo || "queues", priority: policy.priority };
|
||||
definitionEntries.value = definitionEntriesFrom(policy);
|
||||
dialogError.value = undefined;
|
||||
showEditDialog.value = true;
|
||||
}
|
||||
|
||||
function addDefinitionEntry() {
|
||||
definitionEntries.value = [...definitionEntries.value, { key: "", value: "" }];
|
||||
}
|
||||
|
||||
function removeDefinitionEntry(index: number) {
|
||||
definitionEntries.value = definitionEntries.value.filter((_, i) => i !== index);
|
||||
}
|
||||
|
||||
function buildDefinition(): Record<string, unknown> {
|
||||
const definition: Record<string, unknown> = {};
|
||||
for (const entry of definitionEntries.value) {
|
||||
const key = entry.key.trim();
|
||||
if (!key) continue;
|
||||
const raw = entry.value.trim();
|
||||
if (NUMERIC_DEFINITION_KEYS.has(key) && raw !== "" && Number.isFinite(Number(raw))) {
|
||||
definition[key] = Number(raw);
|
||||
} else {
|
||||
definition[key] = raw;
|
||||
}
|
||||
}
|
||||
return definition;
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
const name = editForm.value.name.trim();
|
||||
const virtualHost = editForm.value.virtualHost.trim();
|
||||
const pattern = editForm.value.pattern.trim();
|
||||
if (!name) {
|
||||
dialogError.value = t("mqRabbitMqPolicies.nameRequired");
|
||||
return;
|
||||
}
|
||||
// "*" is a listing sentinel and must never reach a write operation.
|
||||
if (!virtualHost || isAllVhostsNamespace(virtualHost)) {
|
||||
dialogError.value = t("mqRabbitMqPolicies.vhostRequired");
|
||||
return;
|
||||
}
|
||||
if (!pattern) {
|
||||
dialogError.value = t("mqRabbitMqPolicies.patternRequired");
|
||||
return;
|
||||
}
|
||||
const request: MqPolicyUpsertRequest = {
|
||||
name,
|
||||
pattern,
|
||||
applyTo: editForm.value.applyTo || undefined,
|
||||
priority: Number.isFinite(editForm.value.priority) ? editForm.value.priority : undefined,
|
||||
definition: buildDefinition(),
|
||||
};
|
||||
saving.value = true;
|
||||
dialogError.value = undefined;
|
||||
try {
|
||||
await mqSetPolicy(props.connectionId, virtualHost, request);
|
||||
showEditDialog.value = false;
|
||||
await loadPolicies();
|
||||
} catch (e: unknown) {
|
||||
dialogError.value = formatError(e);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openDeleteDialog(policy: MqPolicyInfo) {
|
||||
if (!guardWritable()) return;
|
||||
deleteTarget.value = policy;
|
||||
showDeleteDialog.value = true;
|
||||
}
|
||||
|
||||
async function confirmDelete() {
|
||||
const target = deleteTarget.value;
|
||||
if (!target) return;
|
||||
deleting.value = true;
|
||||
error.value = undefined;
|
||||
try {
|
||||
await mqDeletePolicy(props.connectionId, target.vhost, target.name);
|
||||
showDeleteDialog.value = false;
|
||||
await loadPolicies();
|
||||
} catch (e: unknown) {
|
||||
error.value = formatError(e);
|
||||
} finally {
|
||||
deleting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function formatDefinitionValue(value: unknown): string {
|
||||
return typeof value === "string" ? value : JSON.stringify(value);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.namespace,
|
||||
() => {
|
||||
loadPolicies();
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.connectionId,
|
||||
() => {
|
||||
loadPolicies();
|
||||
loadVhosts();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="policies-panel">
|
||||
<div class="panel-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<h3 class="section-title">{{ t("mqRabbitMqPolicies.title") }}</h3>
|
||||
<span v-if="policies.length" class="row-count">{{ policies.length }}</span>
|
||||
</div>
|
||||
<div class="toolbar-actions">
|
||||
<button @click="openCreateDialog" :disabled="readOnly" class="btn-secondary">{{ t("mqRabbitMqPolicies.createPolicy") }}</button>
|
||||
<button @click="loadPolicies" :disabled="loading" class="btn-secondary">
|
||||
{{ loading ? t("mqRabbitMqPolicies.refreshing") : t("mqRabbitMqPolicies.refresh") }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="panel-error">{{ error }}</div>
|
||||
<div v-else-if="loading && !policies.length" class="panel-loading">{{ t("mqRabbitMqPolicies.loading") }}</div>
|
||||
<div v-else-if="!policies.length" class="panel-placeholder">{{ t("mqRabbitMqPolicies.noPolicies") }}</div>
|
||||
<div v-else class="data-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t("mqRabbitMqPolicies.name") }}</th>
|
||||
<th>{{ t("mqRabbitMqPolicies.vhost") }}</th>
|
||||
<th>{{ t("mqRabbitMqPolicies.pattern") }}</th>
|
||||
<th>{{ t("mqRabbitMqPolicies.applyTo") }}</th>
|
||||
<th>{{ t("mqRabbitMqPolicies.priority") }}</th>
|
||||
<th>{{ t("mqRabbitMqPolicies.definition") }}</th>
|
||||
<th>{{ t("mqRabbitMqPolicies.actions") }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="policy in policies" :key="`${policy.vhost}/${policy.name}`">
|
||||
<td class="policy-name" :title="policy.name">{{ policy.name }}</td>
|
||||
<td>{{ policy.vhost }}</td>
|
||||
<td class="pattern-cell" :title="policy.pattern">{{ policy.pattern }}</td>
|
||||
<td>{{ policy.applyTo }}</td>
|
||||
<td>{{ policy.priority }}</td>
|
||||
<td class="definition-cell">
|
||||
<div v-for="(value, key) in policy.definition" :key="key" class="definition-item">
|
||||
<span class="definition-key">{{ key }}</span>
|
||||
<span class="definition-value">{{ formatDefinitionValue(value) }}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="actions">
|
||||
<button class="btn-sm" :disabled="readOnly" @click="openEditDialog(policy)">{{ t("mqRabbitMqPolicies.edit") }}</button>
|
||||
<button class="btn-sm btn-danger" :disabled="readOnly" @click="openDeleteDialog(policy)">{{ t("mqRabbitMqPolicies.delete") }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Create / Edit Policy Dialog -->
|
||||
<div v-if="showEditDialog" class="dialog-overlay" @click="showEditDialog = false">
|
||||
<div class="dialog" @click.stop>
|
||||
<div class="dialog-header">
|
||||
<h3>{{ editingPolicy ? t("mqRabbitMqPolicies.editPolicy") : t("mqRabbitMqPolicies.createPolicy") }}</h3>
|
||||
<button @click="showEditDialog = false" class="btn-close">×</button>
|
||||
</div>
|
||||
<div class="dialog-body">
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqRabbitMqPolicies.name") }}</label>
|
||||
<input v-model="editForm.name" type="text" :disabled="readOnly || !!editingPolicy" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqRabbitMqPolicies.vhost") }}</label>
|
||||
<select v-model="editForm.virtualHost" :disabled="readOnly || !!editingPolicy">
|
||||
<option value="" disabled>{{ t("mqRabbitMqPolicies.selectVhost") }}</option>
|
||||
<option v-for="vhost in vhosts" :key="vhost" :value="vhost">{{ vhost }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqRabbitMqPolicies.pattern") }}</label>
|
||||
<input v-model="editForm.pattern" type="text" placeholder="^dbx-" :disabled="readOnly" />
|
||||
</div>
|
||||
<div class="form-hint">{{ t("mqRabbitMqPolicies.patternHint") }}</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqRabbitMqPolicies.applyTo") }}</label>
|
||||
<select v-model="editForm.applyTo" :disabled="readOnly">
|
||||
<option v-for="option in APPLY_TO_OPTIONS" :key="option" :value="option">{{ option }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqRabbitMqPolicies.priority") }}</label>
|
||||
<input v-model.number="editForm.priority" type="number" :disabled="readOnly" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ t("mqRabbitMqPolicies.definition") }}</label>
|
||||
<div v-for="(entry, index) in definitionEntries" :key="index" class="definition-row">
|
||||
<input v-model="entry.key" type="text" list="rabbitmq-policy-definition-keys" :placeholder="t('mqRabbitMqPolicies.definitionKey')" :disabled="readOnly" />
|
||||
<input v-model="entry.value" type="text" :placeholder="t('mqRabbitMqPolicies.definitionValue')" :disabled="readOnly" />
|
||||
<button class="btn-sm btn-danger" :disabled="readOnly" @click="removeDefinitionEntry(index)">×</button>
|
||||
</div>
|
||||
<datalist id="rabbitmq-policy-definition-keys">
|
||||
<option v-for="key in COMMON_DEFINITION_KEYS" :key="key" :value="key" />
|
||||
</datalist>
|
||||
<button class="btn-sm" :disabled="readOnly" @click="addDefinitionEntry">{{ t("mqRabbitMqPolicies.addDefinition") }}</button>
|
||||
</div>
|
||||
<div v-if="dialogError" class="form-error">{{ dialogError }}</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button @click="showEditDialog = false" class="btn-secondary">{{ t("mqRabbitMqPolicies.cancel") }}</button>
|
||||
<button @click="handleSave" :disabled="saving || readOnly" class="btn-primary">{{ t("mqRabbitMqPolicies.save") }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete Policy Confirm -->
|
||||
<DangerConfirmDialog
|
||||
v-model:open="showDeleteDialog"
|
||||
:title="t('mqRabbitMqPolicies.delete')"
|
||||
:message="t('mqRabbitMqPolicies.confirmDelete', { name: deleteTarget?.name ?? '', vhost: deleteTarget?.vhost ?? '' })"
|
||||
:confirm-label="t('mqRabbitMqPolicies.delete')"
|
||||
:loading="deleting"
|
||||
:close-on-confirm="false"
|
||||
@confirm="confirmDelete"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.policies-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
overflow: auto;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.panel-toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.toolbar-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.toolbar-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.row-count {
|
||||
flex: 0 0 auto;
|
||||
color: var(--color-text-tertiary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.panel-placeholder,
|
||||
.panel-error,
|
||||
.panel-loading {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.panel-error {
|
||||
color: var(--color-error);
|
||||
}
|
||||
|
||||
.data-table {
|
||||
overflow: auto;
|
||||
background: var(--color-background);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
th {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: var(--color-text-secondary);
|
||||
background: var(--color-background-secondary);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.data-table tbody tr {
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.data-table tbody tr:hover {
|
||||
background: var(--color-hover);
|
||||
}
|
||||
|
||||
.policy-name {
|
||||
font-weight: 500;
|
||||
max-width: 220px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.pattern-cell {
|
||||
font-family: var(--font-mono, monospace);
|
||||
font-size: 12px;
|
||||
max-width: 220px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.definition-cell {
|
||||
max-width: 320px;
|
||||
}
|
||||
|
||||
.definition-item {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
font-family: var(--font-mono, monospace);
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.definition-key {
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.definition-value {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.btn-primary,
|
||||
.btn-secondary,
|
||||
.btn-sm {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: var(--color-hover);
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--color-primary);
|
||||
color: white;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
color: var(--color-error);
|
||||
border-color: var(--color-error);
|
||||
}
|
||||
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: var(--color-error);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 4px 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Dialog */
|
||||
.dialog-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.dialog {
|
||||
background: var(--color-background);
|
||||
border-radius: 8px;
|
||||
width: 90%;
|
||||
max-width: 560px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.dialog-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.dialog-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.btn-close {
|
||||
border: none;
|
||||
background: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: var(--color-text-secondary);
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.dialog-body {
|
||||
padding: 20px;
|
||||
max-height: 70vh;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
padding: 16px 20px;
|
||||
border-top: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-weight: 500;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.form-group input[type="text"],
|
||||
.form-group input[type="number"],
|
||||
.form-group select {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
box-sizing: border-box;
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.definition-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.definition-row input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.definition-row .btn-sm {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
color: var(--color-text-tertiary);
|
||||
font-size: 12px;
|
||||
margin-top: -8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.form-error {
|
||||
color: var(--color-error);
|
||||
font-size: 13px;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user