Skip to content

Commit

Permalink
fix: ensure license issuance fields are of number type (#4873)
Browse files Browse the repository at this point in the history
zjy365 authored Jul 9, 2024
1 parent aec5fac commit 9ef2a3e
Showing 4 changed files with 46 additions and 17 deletions.
43 changes: 27 additions & 16 deletions frontend/desktop/src/components/desktop_content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { getGlobalNotification } from '@/api/platform';
import AppWindow from '@/components/app_window';
// import useDriver from '@/hooks/useDriver';
import { LicenseFrontendKey } from '@/constants/account';
import useAppStore from '@/stores/app';
import { useConfigStore } from '@/stores/config';
import { useDesktopConfigStore } from '@/stores/desktopConfig';
import { TApp, WindowSize } from '@/types';
import { Box, Center, Flex, Text } from '@chakra-ui/react';
import { WarnTriangleIcon, useMessage } from '@sealos/ui';
import { useQuery } from '@tanstack/react-query';
import { Box, Flex } from '@chakra-ui/react';
import { useMessage } from '@sealos/ui';
import { useTranslation } from 'next-i18next';
import dynamic from 'next/dynamic';
import { MouseEvent, useCallback, useEffect, useState } from 'react';
@@ -20,8 +21,6 @@ import IframeWindow from './iframe_window';
import styles from './index.module.scss';
import Monitor from './monitor';
import SearchBox from './searchBox';
import { EmptyIcon } from '../icons';
import { useDesktopConfigStore } from '@/stores/desktopConfig';
import Warn from './warn';

const AppDock = dynamic(() => import('../AppDock'), { ssr: false });
@@ -106,22 +105,34 @@ export default function Desktop(props: any) {

// const { UserGuide, showGuide } = useDriver({ openDesktopApp });

useQuery(['getGlobalNotification'], getGlobalNotification, {
onSuccess(data) {
useEffect(() => {
const globalNotification = async () => {
const data = await getGlobalNotification();
const newID = data.data?.metadata?.uid;
if (!newID || newID === localStorage.getItem('GlobalNotification')) return;
localStorage.setItem('GlobalNotification', newID);

const title =
i18n.language === 'zh' && data.data?.spec?.i18ns?.zh?.message
? data.data?.spec?.i18ns?.zh?.message
: data.data?.spec?.message;
message({
title: title,
status: 'info',
duration: null
});
}
});

if (data.data?.metadata?.labels?.[LicenseFrontendKey]) {
message({
title: title,
status: 'info',
duration: null
});
} else {
if (!newID || newID === localStorage.getItem('GlobalNotification')) return;
localStorage.setItem('GlobalNotification', newID);
message({
title: title,
status: 'info',
duration: null
});
}
};
globalNotification();
}, []);

return (
<Box
1 change: 1 addition & 0 deletions frontend/desktop/src/constants/account.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const GUIDE_DESKTOP_INDEX_KEY = 'frontend.guide.desktop.index';
export const LicenseFrontendKey = 'cloud.sealos.io/license-frontend';
2 changes: 2 additions & 0 deletions frontend/desktop/src/types/crd.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { KubeConfig } from '@kubernetes/client-node';
import { APPTYPE, displayType } from './app';
import { LicenseFrontendKey } from '@/constants/account';

export type CRDMeta = {
group: string; // group
@@ -102,6 +103,7 @@ export type NotificationItem = {
creationTimestamp: string;
labels: {
isRead: string;
[LicenseFrontendKey]?: string;
};
name: string;
namespace: string;
17 changes: 16 additions & 1 deletion service/license/src/services/backend/db/license.ts
Original file line number Diff line number Diff line change
@@ -118,7 +118,22 @@ export function generateLicenseToken(payload: LicenseToken, time: number) {
iss: 'Sealos',
iat: nowInSeconds,
exp: expirationTime,
...payload
type: payload.type,
clusterID: payload.clusterID,
data: {
totalCPU:
typeof payload.data.totalCPU === 'number'
? payload.data.totalCPU
: parseInt(payload.data.totalCPU),
totalMemory:
typeof payload.data.totalMemory === 'number'
? payload.data.totalMemory
: parseInt(payload.data.totalMemory),
nodeCount:
typeof payload.data.nodeCount === 'number'
? payload.data.nodeCount
: parseInt(payload.data.nodeCount)
}
};

const token = sign(_payload, base64Decode(privateKey), { algorithm: 'RS256' });

0 comments on commit 9ef2a3e

Please sign in to comment.