mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 21:51:56 +00:00
feat: fixed eslint and resolved all eslint issues
This commit is contained in:
@@ -106,9 +106,7 @@ export const injectIdentity = fp(async (server: FastifyZodProvider) => {
|
||||
break;
|
||||
}
|
||||
case AuthMode.SERVICE_TOKEN: {
|
||||
const serviceToken = await server.services.serviceToken.fnValidateServiceToken(
|
||||
token as string
|
||||
);
|
||||
const serviceToken = await server.services.serviceToken.fnValidateServiceToken(token);
|
||||
req.auth = {
|
||||
authMode: AuthMode.SERVICE_TOKEN as const,
|
||||
serviceToken,
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { FastifyRequest } from "fastify";
|
||||
import { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from "fastify";
|
||||
|
||||
import { UnauthorizedError } from "@app/lib/errors";
|
||||
import { ActorType } from "@app/services/auth/auth-type";
|
||||
|
||||
export const verifySuperAdmin = async <T extends FastifyRequest>(req: T) => {
|
||||
export const verifySuperAdmin = <T extends FastifyRequest>(
|
||||
req: T,
|
||||
_res: FastifyReply,
|
||||
done: HookHandlerDoneFunction
|
||||
) => {
|
||||
if (req.auth.actor !== ActorType.USER || !req.auth.user.superAdmin)
|
||||
throw new UnauthorizedError({
|
||||
name: "Unauthorized access",
|
||||
message: "Requires superadmin access"
|
||||
});
|
||||
done();
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { FastifyRequest } from "fastify";
|
||||
import { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from "fastify";
|
||||
|
||||
import { UnauthorizedError } from "@app/lib/errors";
|
||||
import { AuthMode } from "@app/services/auth/auth-type";
|
||||
|
||||
export const verifyAuth =
|
||||
<T extends FastifyRequest>(authStrats: AuthMode[]) =>
|
||||
async (req: T) => {
|
||||
(req: T, _res: FastifyReply, done: HookHandlerDoneFunction) => {
|
||||
if (!Array.isArray(authStrats)) throw new Error("Auth strategy must be array");
|
||||
if (!req.auth)
|
||||
throw new UnauthorizedError({ name: "Unauthorized access", message: "Token missing" });
|
||||
@@ -14,4 +14,5 @@ export const verifyAuth =
|
||||
if (!isAccessAllowed) {
|
||||
throw new UnauthorizedError({ name: `${req.url} Unauthorized Access` });
|
||||
}
|
||||
done();
|
||||
};
|
||||
|
||||
@@ -5,7 +5,6 @@ import { ZodError } from "zod";
|
||||
import {
|
||||
BadRequestError,
|
||||
DatabaseError,
|
||||
ForbiddenRequestError,
|
||||
InternalServerError,
|
||||
UnauthorizedError
|
||||
} from "@app/lib/errors";
|
||||
@@ -14,21 +13,25 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider
|
||||
server.setErrorHandler((error, req, res) => {
|
||||
req.log.error(error);
|
||||
if (error instanceof BadRequestError) {
|
||||
res.status(400).send({ statusCode: 400, message: error.message, error: error.name });
|
||||
void res.status(400).send({ statusCode: 400, message: error.message, error: error.name });
|
||||
} else if (error instanceof UnauthorizedError) {
|
||||
res.status(403).send({ statusCode: 403, message: error.message, error: error.name });
|
||||
void res.status(403).send({ statusCode: 403, message: error.message, error: error.name });
|
||||
} else if (error instanceof DatabaseError || error instanceof InternalServerError) {
|
||||
res.status(500).send({ statusCode: 500, message: "Something went wrong", error: error.name });
|
||||
void res
|
||||
.status(500)
|
||||
.send({ statusCode: 500, message: "Something went wrong", error: error.name });
|
||||
} else if (error instanceof ZodError) {
|
||||
res.status(403).send({ statusCode: 403, error: "ValidationFailure", message: error.issues });
|
||||
void res
|
||||
.status(403)
|
||||
.send({ statusCode: 403, error: "ValidationFailure", message: error.issues });
|
||||
} else if (error instanceof ForbiddenError) {
|
||||
res.status(401).send({
|
||||
void res.status(401).send({
|
||||
statusCode: 401,
|
||||
error: "PermissionDenied",
|
||||
message: `You are not allowed to ${error.action} on ${error.subjectType}`
|
||||
});
|
||||
} else {
|
||||
res.send(error);
|
||||
void res.send(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,17 +20,19 @@ export const registerExternalNextjs = async (
|
||||
if (standaloneMode) {
|
||||
const nextJsBuildPath = path.join(dir, "frontend-build");
|
||||
|
||||
const { default: conf } = await import(
|
||||
const { default: conf } = (await import(
|
||||
path.join(dir, "frontend-build/.next/required-server-files.json"),
|
||||
// @ts-expect-error type
|
||||
{
|
||||
assert: { type: "json" }
|
||||
}
|
||||
);
|
||||
)) as { default: { config: string } };
|
||||
|
||||
/* eslint-disable */
|
||||
const { default: NextServer } = (
|
||||
await import(path.join(dir, "frontend-build/node_modules/next/dist/server/next-server.js"))
|
||||
).default;
|
||||
|
||||
const nextApp = new NextServer({
|
||||
dev: false,
|
||||
dir: nextJsBuildPath,
|
||||
@@ -52,5 +54,6 @@ export const registerExternalNextjs = async (
|
||||
});
|
||||
server.addHook("onClose", () => nextApp.close());
|
||||
await nextApp.prepare();
|
||||
/* eslint-enable */
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { PushEvent } from "@octokit/webhooks-types";
|
||||
import { Probot } from "probot";
|
||||
import SmeeClient from "smee-client";
|
||||
|
||||
@@ -22,7 +23,7 @@ export const registerSecretScannerGhApp = async (server: FastifyZodProvider) =>
|
||||
|
||||
app.on("push", async (context) => {
|
||||
const { payload } = context;
|
||||
await server.services.secretScanning.handleRepoPushEvent(payload as any);
|
||||
await server.services.secretScanning.handleRepoPushEvent(payload as PushEvent);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -49,16 +50,17 @@ export const registerSecretScannerGhApp = async (server: FastifyZodProvider) =>
|
||||
method: "POST",
|
||||
url: "/",
|
||||
handler: async (req, res) => {
|
||||
const eventName = req.headers["x-github-event"] as any;
|
||||
const eventName = req.headers["x-github-event"];
|
||||
const signatureSHA256 = req.headers["x-hub-signature-256"] as string;
|
||||
const id = req.headers["x-github-delivery"] as string;
|
||||
await probot.webhooks.verifyAndReceive({
|
||||
id,
|
||||
// @ts-expect-error type
|
||||
name: eventName,
|
||||
payload: req.body as string,
|
||||
signature: signatureSHA256
|
||||
});
|
||||
res.send("ok");
|
||||
void res.send("ok");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user