mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-28 01:10:54 +01:00
Co-authored-by: Meier Lukas <meierschlumpf@gmail.com> Co-authored-by: deepsource-io[bot] <42547082+deepsource-io[bot]@users.noreply.github.com>
216 lines
7.8 KiB
TypeScript
216 lines
7.8 KiB
TypeScript
import { observable } from "@trpc/server/observable";
|
|
|
|
import type { Modify } from "@homarr/common/types";
|
|
import type { Integration } from "@homarr/db/schema";
|
|
import type { IntegrationKindByCategory } from "@homarr/definitions";
|
|
import { getIntegrationKindsByCategory } from "@homarr/definitions";
|
|
import type {
|
|
FirewallCpuSummary,
|
|
FirewallInterfacesSummary,
|
|
FirewallMemorySummary,
|
|
FirewallVersionSummary,
|
|
} from "@homarr/integrations";
|
|
import {
|
|
firewallCpuRequestHandler,
|
|
firewallInterfacesRequestHandler,
|
|
firewallMemoryRequestHandler,
|
|
firewallVersionRequestHandler,
|
|
} from "@homarr/request-handler/firewall";
|
|
|
|
import { createManyIntegrationMiddleware } from "../../middlewares/integration";
|
|
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
|
|
|
export const firewallRouter = createTRPCRouter({
|
|
getFirewallCpuStatus: publicProcedure
|
|
.concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("firewall")))
|
|
.query(async ({ ctx }) => {
|
|
const results = await Promise.all(
|
|
ctx.integrations.map(async (integration) => {
|
|
const innerHandler = firewallCpuRequestHandler.handler(integration, {});
|
|
const { data, timestamp } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
|
|
|
|
return {
|
|
integration: {
|
|
id: integration.id,
|
|
name: integration.name,
|
|
kind: integration.kind,
|
|
updatedAt: timestamp,
|
|
},
|
|
summary: data,
|
|
};
|
|
}),
|
|
);
|
|
return results;
|
|
}),
|
|
subscribeFirewallCpuStatus: publicProcedure
|
|
.concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("firewall")))
|
|
.subscription(({ ctx }) => {
|
|
return observable<{
|
|
integration: Modify<Integration, { kind: IntegrationKindByCategory<"firewall"> }>;
|
|
summary: FirewallCpuSummary;
|
|
}>((emit) => {
|
|
const unsubscribes: (() => void)[] = [];
|
|
for (const integrationWithSecrets of ctx.integrations) {
|
|
const { decryptedSecrets: _, ...integration } = integrationWithSecrets;
|
|
const innerHandler = firewallCpuRequestHandler.handler(integrationWithSecrets, {});
|
|
const unsubscribe = innerHandler.subscribe((summary) => {
|
|
emit.next({
|
|
integration,
|
|
summary,
|
|
});
|
|
});
|
|
unsubscribes.push(unsubscribe);
|
|
}
|
|
return () => {
|
|
unsubscribes.forEach((unsubscribe) => {
|
|
unsubscribe();
|
|
});
|
|
};
|
|
});
|
|
}),
|
|
|
|
getFirewallInterfacesStatus: publicProcedure
|
|
.concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("firewall")))
|
|
.query(async ({ ctx }) => {
|
|
const results = await Promise.all(
|
|
ctx.integrations.map(async (integration) => {
|
|
const innerHandler = firewallInterfacesRequestHandler.handler(integration, {});
|
|
const { data, timestamp } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
|
|
|
|
return {
|
|
integration: {
|
|
id: integration.id,
|
|
name: integration.name,
|
|
kind: integration.kind,
|
|
updatedAt: timestamp,
|
|
},
|
|
summary: data,
|
|
};
|
|
}),
|
|
);
|
|
return results;
|
|
}),
|
|
subscribeFirewallInterfacesStatus: publicProcedure
|
|
.concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("firewall")))
|
|
.subscription(({ ctx }) => {
|
|
return observable<{
|
|
integration: Modify<Integration, { kind: IntegrationKindByCategory<"firewall"> }>;
|
|
summary: FirewallInterfacesSummary[];
|
|
}>((emit) => {
|
|
const unsubscribes: (() => void)[] = [];
|
|
for (const integrationWithSecrets of ctx.integrations) {
|
|
const { decryptedSecrets: _, ...integration } = integrationWithSecrets;
|
|
const innerHandler = firewallInterfacesRequestHandler.handler(integrationWithSecrets, {});
|
|
const unsubscribe = innerHandler.subscribe((summary) => {
|
|
emit.next({
|
|
integration,
|
|
summary,
|
|
});
|
|
});
|
|
unsubscribes.push(unsubscribe);
|
|
}
|
|
return () => {
|
|
unsubscribes.forEach((unsubscribe) => {
|
|
unsubscribe();
|
|
});
|
|
};
|
|
});
|
|
}),
|
|
|
|
getFirewallVersionStatus: publicProcedure
|
|
.concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("firewall")))
|
|
.query(async ({ ctx }) => {
|
|
const results = await Promise.all(
|
|
ctx.integrations.map(async (integration) => {
|
|
const innerHandler = firewallVersionRequestHandler.handler(integration, {});
|
|
const { data, timestamp } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
|
|
|
|
return {
|
|
integration: {
|
|
id: integration.id,
|
|
name: integration.name,
|
|
kind: integration.kind,
|
|
updatedAt: timestamp,
|
|
},
|
|
summary: data,
|
|
};
|
|
}),
|
|
);
|
|
return results;
|
|
}),
|
|
subscribeFirewallVersionStatus: publicProcedure
|
|
.concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("firewall")))
|
|
.subscription(({ ctx }) => {
|
|
return observable<{
|
|
integration: Modify<Integration, { kind: IntegrationKindByCategory<"firewall"> }>;
|
|
summary: FirewallVersionSummary;
|
|
}>((emit) => {
|
|
const unsubscribes: (() => void)[] = [];
|
|
for (const integrationWithSecrets of ctx.integrations) {
|
|
const { decryptedSecrets: _, ...integration } = integrationWithSecrets;
|
|
const innerHandler = firewallVersionRequestHandler.handler(integrationWithSecrets, {});
|
|
const unsubscribe = innerHandler.subscribe((summary) => {
|
|
emit.next({
|
|
integration,
|
|
summary,
|
|
});
|
|
});
|
|
unsubscribes.push(unsubscribe);
|
|
}
|
|
return () => {
|
|
unsubscribes.forEach((unsubscribe) => {
|
|
unsubscribe();
|
|
});
|
|
};
|
|
});
|
|
}),
|
|
|
|
getFirewallMemoryStatus: publicProcedure
|
|
.concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("firewall")))
|
|
.query(async ({ ctx }) => {
|
|
const results = await Promise.all(
|
|
ctx.integrations.map(async (integration) => {
|
|
const innerHandler = firewallMemoryRequestHandler.handler(integration, {});
|
|
const { data, timestamp } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
|
|
|
|
return {
|
|
integration: {
|
|
id: integration.id,
|
|
name: integration.name,
|
|
kind: integration.kind,
|
|
updatedAt: timestamp,
|
|
},
|
|
summary: data,
|
|
};
|
|
}),
|
|
);
|
|
return results;
|
|
}),
|
|
subscribeFirewallMemoryStatus: publicProcedure
|
|
.concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("firewall")))
|
|
.subscription(({ ctx }) => {
|
|
return observable<{
|
|
integration: Modify<Integration, { kind: IntegrationKindByCategory<"firewall"> }>;
|
|
summary: FirewallMemorySummary;
|
|
}>((emit) => {
|
|
const unsubscribes: (() => void)[] = [];
|
|
for (const integrationWithSecrets of ctx.integrations) {
|
|
const { decryptedSecrets: _, ...integration } = integrationWithSecrets;
|
|
const innerHandler = firewallMemoryRequestHandler.handler(integrationWithSecrets, {});
|
|
const unsubscribe = innerHandler.subscribe((summary) => {
|
|
emit.next({
|
|
integration,
|
|
summary,
|
|
});
|
|
});
|
|
unsubscribes.push(unsubscribe);
|
|
}
|
|
return () => {
|
|
unsubscribes.forEach((unsubscribe) => {
|
|
unsubscribe();
|
|
});
|
|
};
|
|
});
|
|
}),
|
|
});
|