mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-12 17:02:08 +02:00
Standardize db rebuildClientAssociationsFromClient
This commit is contained in:
@@ -42,7 +42,7 @@ function runQueuedClientAssociationRebuilds(
|
|||||||
void (async () => {
|
void (async () => {
|
||||||
for (const client of uniqueClientsById.values()) {
|
for (const client of uniqueClientsById.values()) {
|
||||||
try {
|
try {
|
||||||
await rebuildClientAssociationsFromClient(client, db);
|
await rebuildClientAssociationsFromClient(client);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`Failed rebuilding associations for client ${client.clientId} (user ${userId}): ${String(error)}`
|
`Failed rebuilding associations for client ${client.clientId} (user ${userId}): ${String(error)}`
|
||||||
|
|||||||
@@ -1043,9 +1043,9 @@ async function handleSubnetProxyTargetUpdates(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function rebuildClientAssociationsFromClient(
|
export async function rebuildClientAssociationsFromClient(
|
||||||
client: Client,
|
client: Client
|
||||||
trx: Transaction | typeof db = db
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const trx = primaryDb;
|
||||||
try {
|
try {
|
||||||
return await lockManager.withLock(
|
return await lockManager.withLock(
|
||||||
`rebuild-client-associations:client:${client.clientId}`,
|
`rebuild-client-associations:client:${client.clientId}`,
|
||||||
@@ -2137,7 +2137,7 @@ export function startRebuildQueueProcessor(): void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await rebuildClientAssociationsFromClient(client, primaryDb);
|
await rebuildClientAssociationsFromClient(client);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,13 +163,11 @@ export async function addUserRole(
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const orgClient of orgClientsToRebuild) {
|
for (const orgClient of orgClientsToRebuild) {
|
||||||
rebuildClientAssociationsFromClient(orgClient, primaryDb).catch(
|
rebuildClientAssociationsFromClient(orgClient).catch((e) => {
|
||||||
(e) => {
|
logger.error(
|
||||||
logger.error(
|
`Failed to rebuild client associations for client ${orgClient.clientId} after adding role: ${e}`
|
||||||
`Failed to rebuild client associations for client ${orgClient.clientId} after adding role: ${e}`
|
);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response(res, {
|
return response(res, {
|
||||||
|
|||||||
@@ -170,13 +170,11 @@ export async function removeUserRole(
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const orgClient of orgClientsToRebuild) {
|
for (const orgClient of orgClientsToRebuild) {
|
||||||
rebuildClientAssociationsFromClient(orgClient, primaryDb).catch(
|
rebuildClientAssociationsFromClient(orgClient).catch((e) => {
|
||||||
(e) => {
|
logger.error(
|
||||||
logger.error(
|
`Failed to rebuild client associations for client ${orgClient.clientId} after removing role: ${e}`
|
||||||
`Failed to rebuild client associations for client ${orgClient.clientId} after removing role: ${e}`
|
);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response(res, {
|
return response(res, {
|
||||||
|
|||||||
@@ -150,13 +150,11 @@ export async function setUserOrgRoles(
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const orgClient of orgClientsToRebuild) {
|
for (const orgClient of orgClientsToRebuild) {
|
||||||
rebuildClientAssociationsFromClient(orgClient, primaryDb).catch(
|
rebuildClientAssociationsFromClient(orgClient).catch((e) => {
|
||||||
(e) => {
|
logger.error(
|
||||||
logger.error(
|
`Failed to rebuild client associations for client ${orgClient.clientId} after setting roles: ${e}`
|
||||||
`Failed to rebuild client associations for client ${orgClient.clientId} after setting roles: ${e}`
|
);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response(res, {
|
return response(res, {
|
||||||
|
|||||||
@@ -280,13 +280,11 @@ export async function createClient(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (newClient) {
|
if (newClient) {
|
||||||
rebuildClientAssociationsFromClient(newClient, primaryDb).catch(
|
rebuildClientAssociationsFromClient(newClient).catch((e) => {
|
||||||
(e) => {
|
logger.error(
|
||||||
logger.error(
|
`Failed to rebuild client associations after creating client: ${e}`
|
||||||
`Failed to rebuild client associations after creating client: ${e}`
|
);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response<CreateClientResponse>(res, {
|
return response<CreateClientResponse>(res, {
|
||||||
|
|||||||
@@ -255,13 +255,11 @@ export async function createUserClient(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (newClient) {
|
if (newClient) {
|
||||||
rebuildClientAssociationsFromClient(newClient, primaryDb).catch(
|
rebuildClientAssociationsFromClient(newClient).catch((e) => {
|
||||||
(e) => {
|
logger.error(
|
||||||
logger.error(
|
`Failed to rebuild client associations after creating user client: ${e}`
|
||||||
`Failed to rebuild client associations after creating user client: ${e}`
|
);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response<CreateClientAndOlmResponse>(res, {
|
return response<CreateClientAndOlmResponse>(res, {
|
||||||
|
|||||||
@@ -109,13 +109,11 @@ export async function deleteClient(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (deletedClient) {
|
if (deletedClient) {
|
||||||
rebuildClientAssociationsFromClient(deletedClient, primaryDb).catch(
|
rebuildClientAssociationsFromClient(deletedClient).catch((e) => {
|
||||||
(e) => {
|
logger.error(
|
||||||
logger.error(
|
`Failed to rebuild client associations after deleting client ${clientId}: ${e}`
|
||||||
`Failed to rebuild client associations after deleting client ${clientId}: ${e}`
|
);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
if (olm) {
|
if (olm) {
|
||||||
sendTerminateClient(
|
sendTerminateClient(
|
||||||
deletedClient.clientId,
|
deletedClient.clientId,
|
||||||
|
|||||||
@@ -60,13 +60,17 @@ export async function rebuildClientAssociationsCacheRoute(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await rebuildClientAssociationsFromClient(client);
|
rebuildClientAssociationsFromClient(client).catch((e) => {
|
||||||
|
logger.error(
|
||||||
|
`Failed to rebuild client associations for client ${clientId}: ${e}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return response(res, {
|
return response(res, {
|
||||||
data: null,
|
data: null,
|
||||||
success: true,
|
success: true,
|
||||||
error: false,
|
error: false,
|
||||||
message: "Client association cache rebuilt successfully",
|
message: "Client association cache queued successfully",
|
||||||
status: HttpCode.OK
|
status: HttpCode.OK
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -86,13 +86,11 @@ export async function deleteUserOlm(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (deletedClient) {
|
if (deletedClient) {
|
||||||
rebuildClientAssociationsFromClient(deletedClient, primaryDb).catch(
|
rebuildClientAssociationsFromClient(deletedClient).catch((e) => {
|
||||||
(e) => {
|
logger.error(
|
||||||
logger.error(
|
`Failed to rebuild client-site associations after deleting OLM ${olmId}: ${e}`
|
||||||
`Failed to rebuild client-site associations after deleting OLM ${olmId}: ${e}`
|
);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
sendTerminateClient(
|
sendTerminateClient(
|
||||||
deletedClient.clientId,
|
deletedClient.clientId,
|
||||||
OlmErrorCodes.TERMINATED_DELETED,
|
OlmErrorCodes.TERMINATED_DELETED,
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ export async function batchAddClientToSiteResources(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
rebuildClientAssociationsFromClient(client, primaryDb).catch((e) => {
|
rebuildClientAssociationsFromClient(client).catch((e) => {
|
||||||
logger.error(
|
logger.error(
|
||||||
`Failed to rebuild client associations after batch adding site resources for client ${clientId}: ${e}`
|
`Failed to rebuild client associations after batch adding site resources for client ${clientId}: ${e}`
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -159,13 +159,11 @@ export async function addUserRoleLegacy(
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const orgClient of orgClientsToRebuild) {
|
for (const orgClient of orgClientsToRebuild) {
|
||||||
rebuildClientAssociationsFromClient(orgClient, primaryDb).catch(
|
rebuildClientAssociationsFromClient(orgClient).catch((e) => {
|
||||||
(e) => {
|
logger.error(
|
||||||
logger.error(
|
`Failed to rebuild client associations for client ${orgClient.clientId} after adding role: ${e}`
|
||||||
`Failed to rebuild client associations for client ${orgClient.clientId} after adding role: ${e}`
|
);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response(res, {
|
return response(res, {
|
||||||
|
|||||||
Reference in New Issue
Block a user