From 96edc9204c04f9a7368f53417a35a0d50b565c0f Mon Sep 17 00:00:00 2001 From: Sachin Date: Fri, 29 Sep 2023 09:02:42 +0000 Subject: [PATCH] env validation moved inside function on github modlues api --- radlab-ui/webapp/src/pages/api/github/index.ts | 9 +++++---- radlab-ui/webapp/src/pages/api/github/modules.ts | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/radlab-ui/webapp/src/pages/api/github/index.ts b/radlab-ui/webapp/src/pages/api/github/index.ts index 200a9fe7..4da6f54e 100644 --- a/radlab-ui/webapp/src/pages/api/github/index.ts +++ b/radlab-ui/webapp/src/pages/api/github/index.ts @@ -4,14 +4,15 @@ import { withAuth } from "@/utils/middleware" import { AuthedNextApiHandler } from "@/utils/types" import { NextApiResponse } from "next" -const GIT_TOKEN_SECRET_KEY_NAME = envOrFail( - "GIT_TOKEN_SECRET_KEY_NAME", - process.env.GIT_TOKEN_SECRET_KEY_NAME, -) const getModuleDataFromGitHub = async ( req: AuthedNextApiHandler, res: NextApiResponse, ) => { + const GIT_TOKEN_SECRET_KEY_NAME = envOrFail( + "GIT_TOKEN_SECRET_KEY_NAME", + process.env.GIT_TOKEN_SECRET_KEY_NAME, + ) + const { path } = req.body const secret = await getSecretKeyValue(GIT_TOKEN_SECRET_KEY_NAME) try { diff --git a/radlab-ui/webapp/src/pages/api/github/modules.ts b/radlab-ui/webapp/src/pages/api/github/modules.ts index bad328ea..30d8504f 100644 --- a/radlab-ui/webapp/src/pages/api/github/modules.ts +++ b/radlab-ui/webapp/src/pages/api/github/modules.ts @@ -4,14 +4,14 @@ import { withAuth } from "@/utils/middleware" import { AuthedNextApiHandler } from "@/utils/types" import { NextApiResponse } from "next" -const GIT_TOKEN_SECRET_KEY_NAME = envOrFail( - "GIT_TOKEN_SECRET_KEY_NAME", - process.env.GIT_TOKEN_SECRET_KEY_NAME, -) const getModulesFromGitHub = async ( _req: AuthedNextApiHandler, res: NextApiResponse, ) => { + const GIT_TOKEN_SECRET_KEY_NAME = envOrFail( + "GIT_TOKEN_SECRET_KEY_NAME", + process.env.GIT_TOKEN_SECRET_KEY_NAME, + ) const secret = await getSecretKeyValue(GIT_TOKEN_SECRET_KEY_NAME) const modules = await getGitHubModules(secret) return res.status(200).json(modules)