mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-04 09:46:40 +00:00
Switch to update
This commit is contained in:
@@ -86,3 +86,33 @@ export async function removeRemoteSubnets(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateRemoteSubnets(
|
||||||
|
clientId: number,
|
||||||
|
siteId: number,
|
||||||
|
remoteSubnets: {
|
||||||
|
oldRemoteSubnets: string[],
|
||||||
|
newRemoteSubnets: string[]
|
||||||
|
},
|
||||||
|
olmId?: string
|
||||||
|
) {
|
||||||
|
if (!olmId) {
|
||||||
|
const [olm] = await db
|
||||||
|
.select()
|
||||||
|
.from(olms)
|
||||||
|
.where(eq(olms.clientId, clientId))
|
||||||
|
.limit(1);
|
||||||
|
if (!olm) {
|
||||||
|
throw new Error(`Olm with ID ${clientId} not found`);
|
||||||
|
}
|
||||||
|
olmId = olm.olmId;
|
||||||
|
}
|
||||||
|
|
||||||
|
await sendToClient(olmId, {
|
||||||
|
type: `olm/wg/peer/update-remote-subnets`,
|
||||||
|
data: {
|
||||||
|
siteId: siteId,
|
||||||
|
...remoteSubnets
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,11 +18,13 @@ import { fromError } from "zod-validation-error";
|
|||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { OpenAPITags, registry } from "@server/openApi";
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
import {
|
import {
|
||||||
addRemoteSubnets,
|
updateRemoteSubnets,
|
||||||
removeRemoteSubnets,
|
|
||||||
updateTargets
|
updateTargets
|
||||||
} from "@server/routers/client/targets";
|
} from "@server/routers/client/targets";
|
||||||
import { generateRemoteSubnets, generateSubnetProxyTargets } from "@server/lib/ip";
|
import {
|
||||||
|
generateRemoteSubnets,
|
||||||
|
generateSubnetProxyTargets
|
||||||
|
} from "@server/lib/ip";
|
||||||
import {
|
import {
|
||||||
getClientSiteResourceAccess,
|
getClientSiteResourceAccess,
|
||||||
rebuildClientAssociations
|
rebuildClientAssociations
|
||||||
@@ -261,19 +263,20 @@ export async function updateSiteResource(
|
|||||||
});
|
});
|
||||||
|
|
||||||
let olmJobs: Promise<void>[] = [];
|
let olmJobs: Promise<void>[] = [];
|
||||||
for (const client of mergedAllClients) { // we also need to update the remote subnets on the olms for each client that has access to this site
|
for (const client of mergedAllClients) {
|
||||||
|
// we also need to update the remote subnets on the olms for each client that has access to this site
|
||||||
olmJobs.push(
|
olmJobs.push(
|
||||||
removeRemoteSubnets(
|
updateRemoteSubnets(
|
||||||
client.clientId,
|
client.clientId,
|
||||||
updatedSiteResource.siteId,
|
updatedSiteResource.siteId,
|
||||||
generateRemoteSubnets([existingSiteResource])
|
{
|
||||||
)
|
oldRemoteSubnets: generateRemoteSubnets([
|
||||||
);
|
existingSiteResource
|
||||||
olmJobs.push(
|
]),
|
||||||
addRemoteSubnets(
|
newRemoteSubnets: generateRemoteSubnets([
|
||||||
client.clientId,
|
updatedSiteResource
|
||||||
updatedSiteResource.siteId,
|
])
|
||||||
generateRemoteSubnets([updatedSiteResource])
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user