From c1f39b866f0c70c85f3ae364949c8b3b226ec4dd Mon Sep 17 00:00:00 2001 From: Sheen Date: Sat, 15 Apr 2023 15:50:06 +0800 Subject: [PATCH] [Feature][Sheen] added never expire service token --- backend/src/controllers/v2/serviceTokenDataController.ts | 7 +++++-- .../ServiceTokenSection/ServiceTokenSection.tsx | 9 +++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/src/controllers/v2/serviceTokenDataController.ts b/backend/src/controllers/v2/serviceTokenDataController.ts index 6b3d24dfb..328749472 100644 --- a/backend/src/controllers/v2/serviceTokenDataController.ts +++ b/backend/src/controllers/v2/serviceTokenDataController.ts @@ -75,8 +75,11 @@ export const createServiceTokenData = async (req: Request, res: Response) => { const secret = crypto.randomBytes(16).toString('hex'); const secretHash = await bcrypt.hash(secret, getSaltRounds()); - const expiresAt = new Date(); - expiresAt.setSeconds(expiresAt.getSeconds() + expiresIn); + let expiresAt; + if (!!expiresIn) { + expiresAt = new Date() + expiresAt.setSeconds(expiresAt.getSeconds() + expiresIn); + } let user, serviceAccount; diff --git a/frontend/src/views/Settings/ProjectSettingsPage/components/ServiceTokenSection/ServiceTokenSection.tsx b/frontend/src/views/Settings/ProjectSettingsPage/components/ServiceTokenSection/ServiceTokenSection.tsx index b857a3224..10c95ee55 100644 --- a/frontend/src/views/Settings/ProjectSettingsPage/components/ServiceTokenSection/ServiceTokenSection.tsx +++ b/frontend/src/views/Settings/ProjectSettingsPage/components/ServiceTokenSection/ServiceTokenSection.tsx @@ -37,13 +37,14 @@ const apiTokenExpiry = [ { label: '7 Days', value: 604800 }, { label: '1 Month', value: 2592000 }, { label: '6 months', value: 15552000 }, - { label: '12 months', value: 31104000 } + { label: '12 months', value: 31104000 }, + { label: 'Never', value: null }, ]; const createServiceTokenSchema = yup.object({ name: yup.string().required().label('Service Token Name'), environment: yup.string().required().label('Environment'), - expiresIn: yup.string().required().label('Service Token Expiration'), + expiresIn: yup.string().optional().label('Service Token Expiration'), permissions: yup.object().shape({ read: yup.boolean().required(), write: yup.boolean().required() @@ -213,7 +214,7 @@ export const ServiceTokenSection = ({ className="w-full" > {apiTokenExpiry.map(({ label, value }) => ( - + {label} ))} @@ -332,7 +333,7 @@ export const ServiceTokenSection = ({ {row.name} {row.environment} - {new Date(row.expiresAt).toUTCString()} + {row.expiresAt && new Date(row.expiresAt).toUTCString()}