n8n
Version:
n8n Workflow Automation Tool
68 lines • 2.96 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HostIdClashCheck = void 0;
const decorators_1 = require("@n8n/decorators");
const CHECK_CODE = 'cluster.hostid-clash';
const AUDIT_DETECTED = 'n8n.audit.cluster.hostid-clash.detected';
const AUDIT_RESOLVED = 'n8n.audit.cluster.hostid-clash.resolved';
function computeFingerprint(instances) {
const byHost = new Map();
for (const instance of instances) {
const keys = byHost.get(instance.hostId) ?? [];
keys.push(instance.instanceKey);
byHost.set(instance.hostId, keys);
}
const clashing = Array.from(byHost.entries())
.filter(([, keys]) => keys.length > 1)
.map(([hostId, keys]) => ({ hostId, instanceKeys: [...keys].sort() }))
.sort((a, b) => a.hostId.localeCompare(b.hostId));
return {
hasClash: clashing.length > 0,
fingerprint: clashing.map((c) => c.hostId).join('|'),
clashing,
};
}
let HostIdClashCheck = class HostIdClashCheck {
constructor() {
this.checkDescription = {
name: 'hostid-clash',
displayName: 'Host ID clash',
};
}
async run(context) {
const current = computeFingerprint(context.currentState.values());
const previous = computeFingerprint(context.previousState.values());
if (!current.hasClash) {
if (previous.hasClash) {
return { auditEvents: [{ eventName: AUDIT_RESOLVED, payload: {} }] };
}
return {};
}
const hostIds = current.clashing.map((c) => c.hostId);
const result = {
warnings: [
{
code: CHECK_CODE,
message: `Detected multiple instances sharing the same hostId: ${hostIds.join(', ')}`,
severity: 'warning',
context: { clashing: current.clashing },
},
],
};
if (current.fingerprint !== previous.fingerprint) {
result.auditEvents = [{ eventName: AUDIT_DETECTED, payload: { clashing: current.clashing } }];
}
return result;
}
};
exports.HostIdClashCheck = HostIdClashCheck;
exports.HostIdClashCheck = HostIdClashCheck = __decorate([
(0, decorators_1.ClusterCheck)()
], HostIdClashCheck);
//# sourceMappingURL=hostid-clash.check.js.map