mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 16:27:46 +00:00
commented out router
This commit is contained in:
@@ -1,88 +1,87 @@
|
|||||||
import nock, { Definition } from "nock";
|
// import { z } from "zod";
|
||||||
import { z } from "zod";
|
|
||||||
|
|
||||||
import { getConfig } from "@app/lib/config/env";
|
// import { getConfig } from "@app/lib/config/env";
|
||||||
import { ForbiddenRequestError } from "@app/lib/errors";
|
// import { ForbiddenRequestError } from "@app/lib/errors";
|
||||||
import { logger } from "@app/lib/logger";
|
// import { logger } from "@app/lib/logger";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
// import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
// import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
export const registerBddNockRouter = async (server: FastifyZodProvider) => {
|
// export const registerBddNockRouter = async (server: FastifyZodProvider) => {
|
||||||
const checkIfBddNockApiEnabled = () => {
|
// const checkIfBddNockApiEnabled = () => {
|
||||||
const appCfg = getConfig();
|
// const appCfg = getConfig();
|
||||||
// Note: Please note that this API is only available in development mode and only for BDD tests.
|
// // Note: Please note that this API is only available in development mode and only for BDD tests.
|
||||||
// This endpoint should NEVER BE ENABLED IN PRODUCTION!
|
// // This endpoint should NEVER BE ENABLED IN PRODUCTION!
|
||||||
if (appCfg.NODE_ENV !== "development" || !appCfg.isBddNockApiEnabled) {
|
// if (appCfg.NODE_ENV !== "development" || !appCfg.isBddNockApiEnabled) {
|
||||||
throw new ForbiddenRequestError({ message: "BDD Nock API is not enabled" });
|
// throw new ForbiddenRequestError({ message: "BDD Nock API is not enabled" });
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
server.route({
|
// server.route({
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
url: "/define",
|
// url: "/define",
|
||||||
schema: {
|
// schema: {
|
||||||
body: z.object({ definitions: z.unknown().array() }),
|
// body: z.object({ definitions: z.unknown().array() }),
|
||||||
response: {
|
// response: {
|
||||||
200: z.object({ status: z.string() })
|
// 200: z.object({ status: z.string() })
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
onRequest: verifyAuth([AuthMode.JWT]),
|
// onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
handler: async (req) => {
|
// handler: async (req) => {
|
||||||
checkIfBddNockApiEnabled();
|
// checkIfBddNockApiEnabled();
|
||||||
const { body } = req;
|
// const { body } = req;
|
||||||
const { definitions } = body;
|
// const { definitions } = body;
|
||||||
logger.info(definitions, "Defining nock");
|
// logger.info(definitions, "Defining nock");
|
||||||
const processedDefinitions = definitions.map((definition: unknown) => {
|
// const processedDefinitions = definitions.map((definition: unknown) => {
|
||||||
const { path, ...rest } = definition as Definition;
|
// const { path, ...rest } = definition as Definition;
|
||||||
return {
|
// return {
|
||||||
...rest,
|
// ...rest,
|
||||||
path:
|
// path:
|
||||||
path !== undefined && typeof path === "string"
|
// path !== undefined && typeof path === "string"
|
||||||
? path
|
// ? path
|
||||||
: new RegExp((path as unknown as { regex: string }).regex ?? "")
|
// : new RegExp((path as unknown as { regex: string }).regex ?? "")
|
||||||
} as Definition;
|
// } as Definition;
|
||||||
});
|
// });
|
||||||
|
|
||||||
nock.define(processedDefinitions);
|
// nock.define(processedDefinitions);
|
||||||
// Ensure we are activating the nocks, because we could have called `nock.restore()` before this call.
|
// // Ensure we are activating the nocks, because we could have called `nock.restore()` before this call.
|
||||||
if (!nock.isActive()) {
|
// if (!nock.isActive()) {
|
||||||
nock.activate();
|
// nock.activate();
|
||||||
}
|
// }
|
||||||
return { status: "ok" };
|
// return { status: "ok" };
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
server.route({
|
// server.route({
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
url: "/clean-all",
|
// url: "/clean-all",
|
||||||
schema: {
|
// schema: {
|
||||||
response: {
|
// response: {
|
||||||
200: z.object({ status: z.string() })
|
// 200: z.object({ status: z.string() })
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
onRequest: verifyAuth([AuthMode.JWT]),
|
// onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
handler: async () => {
|
// handler: async () => {
|
||||||
checkIfBddNockApiEnabled();
|
// checkIfBddNockApiEnabled();
|
||||||
logger.info("Cleaning all nocks");
|
// logger.info("Cleaning all nocks");
|
||||||
nock.cleanAll();
|
// nock.cleanAll();
|
||||||
return { status: "ok" };
|
// return { status: "ok" };
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
server.route({
|
// server.route({
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
url: "/restore",
|
// url: "/restore",
|
||||||
schema: {
|
// schema: {
|
||||||
response: {
|
// response: {
|
||||||
200: z.object({ status: z.string() })
|
// 200: z.object({ status: z.string() })
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
onRequest: verifyAuth([AuthMode.JWT]),
|
// onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
handler: async () => {
|
// handler: async () => {
|
||||||
checkIfBddNockApiEnabled();
|
// checkIfBddNockApiEnabled();
|
||||||
logger.info("Restore network requests from nock");
|
// logger.info("Restore network requests from nock");
|
||||||
nock.restore();
|
// nock.restore();
|
||||||
return { status: "ok" };
|
// return { status: "ok" };
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
};
|
// };
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { getConfig } from "@app/lib/config/env";
|
|
||||||
import {
|
import {
|
||||||
APP_CONNECTION_REGISTER_ROUTER_MAP,
|
APP_CONNECTION_REGISTER_ROUTER_MAP,
|
||||||
registerAppConnectionRouter
|
registerAppConnectionRouter
|
||||||
@@ -9,7 +8,7 @@ import { registerSecretSyncRouter, SECRET_SYNC_REGISTER_ROUTER_MAP } from "@app/
|
|||||||
|
|
||||||
import { registerAdminRouter } from "./admin-router";
|
import { registerAdminRouter } from "./admin-router";
|
||||||
import { registerAuthRoutes } from "./auth-router";
|
import { registerAuthRoutes } from "./auth-router";
|
||||||
import { registerBddNockRouter } from "./bdd-nock-router";
|
// import { registerBddNockRouter } from "./bdd-nock-router";
|
||||||
import { registerProjectBotRouter } from "./bot-router";
|
import { registerProjectBotRouter } from "./bot-router";
|
||||||
import { registerCaRouter } from "./certificate-authority-router";
|
import { registerCaRouter } from "./certificate-authority-router";
|
||||||
import { CERTIFICATE_AUTHORITY_REGISTER_ROUTER_MAP } from "./certificate-authority-routers";
|
import { CERTIFICATE_AUTHORITY_REGISTER_ROUTER_MAP } from "./certificate-authority-routers";
|
||||||
@@ -242,7 +241,7 @@ export const registerV1Routes = async (server: FastifyZodProvider) => {
|
|||||||
|
|
||||||
// Note: This is a special route for BDD tests. It's only available in development mode and only for BDD tests.
|
// Note: This is a special route for BDD tests. It's only available in development mode and only for BDD tests.
|
||||||
// This route should NEVER BE ENABLED IN PRODUCTION!
|
// This route should NEVER BE ENABLED IN PRODUCTION!
|
||||||
if (getConfig().isBddNockApiEnabled) {
|
// if (getConfig().isBddNockApiEnabled) {
|
||||||
await server.register(registerBddNockRouter, { prefix: "/bdd-nock" });
|
// await server.register(registerBddNockRouter, { prefix: "/bdd-nock" });
|
||||||
}
|
// }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user