Compare commits

...

3 Commits

3 changed files with 45 additions and 7 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "t42-sso-manager", "name": "t42-sso-manager",
"version": "1.19.0", "version": "1.19.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "t42-sso-manager", "name": "t42-sso-manager",
"version": "1.19.0", "version": "1.19.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^7.3.0", "@fortawesome/fontawesome-free": "^7.3.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "t42-sso-manager", "name": "t42-sso-manager",
"version": "1.19.0", "version": "1.19.2",
"description": "A very simple LDAP management and SSO system", "description": "A very simple LDAP management and SSO system",
"author": [ "author": [
{ {
+42 -4
View File
@@ -9,6 +9,7 @@ class DiscoveryReconciler {
for (const res of resources) { for (const res of resources) {
if (!res.metadata) res.metadata = {}; if (!res.metadata) res.metadata = {};
res._originalSlug = res.slug; // Keep track for edge mapping
let existing = null; let existing = null;
@@ -94,10 +95,11 @@ class DiscoveryReconciler {
metadata: mergedMeta, metadata: mergedMeta,
updated_on: Math.floor(Date.now() / 1000) updated_on: Math.floor(Date.now() / 1000)
}); });
res._actualId = existing.id;
} else { } else {
// Create new // Create new
const sources = [sourceName]; const sources = new Set([sourceName]);
res.metadata.discovery_sources = sources; res.metadata.discovery_sources = [...sources];
res.metadata.last_seen = Date.now(); res.metadata.last_seen = Date.now();
const slug = res.slug || `${res.kind}-${crypto.randomBytes(4).toString('hex')}`; const slug = res.slug || `${res.kind}-${crypto.randomBytes(4).toString('hex')}`;
@@ -112,12 +114,48 @@ class DiscoveryReconciler {
}); });
newDevices++; newDevices++;
res._actualId = created.id; // Map original slug to actual ID
WebhookEmitter.emit('discovery.new_device', created.toJSON()); WebhookEmitter.emit('discovery.new_device', created.toJSON());
} }
} }
// We can handle edges similarly if needed, but for simplicity we assume edges are managed elsewhere // Now process edges
// or we just trust the plugins to give us explicit parent-child mappings by slug. const allRes = await Resource.list();
const existingEdges = await ResourceEdge.list();
for (const edge of edges) {
// Find parent ID. It might be in the current payload (mapped to _actualId) or in DB by slug
let parentId = null;
const parentResInPayload = resources.find(r => r._originalSlug === edge.parentSlug);
if (parentResInPayload && parentResInPayload._actualId) {
parentId = parentResInPayload._actualId;
} else {
const parentResInDb = allRes.find(r => r.slug === edge.parentSlug);
if (parentResInDb) parentId = parentResInDb.id;
}
// Find child ID
let childId = null;
const childResInPayload = resources.find(r => r._originalSlug === edge.childSlug);
if (childResInPayload && childResInPayload._actualId) {
childId = childResInPayload._actualId;
} else {
const childResInDb = allRes.find(r => r.slug === edge.childSlug);
if (childResInDb) childId = childResInDb.id;
}
if (parentId && childId) {
const edgeExists = existingEdges.find(e => e.parentId === parentId && e.childId === childId && e.relation === edge.relation);
if (!edgeExists) {
await ResourceEdge.create({
id: crypto.randomUUID(),
parentId,
childId,
relation: edge.relation
});
}
}
}
if (newDevices > 0) { if (newDevices > 0) {
console.log(`[DiscoveryReconciler] Source ${sourceName} discovered ${newDevices} new devices.`); console.log(`[DiscoveryReconciler] Source ${sourceName} discovered ${newDevices} new devices.`);