-
Notifications
You must be signed in to change notification settings - Fork 771
feat(wren-ui): Added FE Support for MySQL SSL Connection #1072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d5baadc
e52ba38
bb6c6c4
9286f32
5b18731
ceaaedc
b5f2899
9a78f61
2f5fd8f
0a81674
a4a9319
8d1db64
a7ded75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum SSLMode { | ||
DISABLED = 'disabled', | ||
ENABLED = 'enabled', | ||
VERIFY_CA = 'verify_ca', | ||
} | ||
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,15 +1,73 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Form, Input } from 'antd'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { useEffect, useState } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Form, Input, Select, Button, Upload } from 'antd'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import UploadOutlined from '@ant-design/icons/UploadOutlined'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { UploadFile } from 'antd/lib/upload/interface'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { ERROR_TEXTS } from '@/utils/error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { FORM_MODE } from '@/utils/enum'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { hostValidator } from '@/utils/validator'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { SSLMode } from '@/apollo/server/types'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
interface Props { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mode?: FORM_MODE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
10
to
13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update Props interface with SSL-related properties. The Props interface should be extended to include SSL-related properties for better type safety. interface Props {
mode?: FORM_MODE;
+ sslMode?: SSLMode;
+ onSSLModeChange?: (mode: SSLMode) => void;
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const UploadSSL = (props) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { onChange, value } = props; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add TypeScript interface for component props The Add a props interface: interface UploadSSLProps {
onChange?: (value: string | undefined) => void;
value?: string;
}
const UploadSSL = (props: UploadSSLProps) => { |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const [fileList, setFileList] = useState<UploadFile[]>([]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!value) setFileList([]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, [value]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const readFileContent = (file: any, callback: (value: string) => void) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const reader = new FileReader(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
reader.onloadend = (_e) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const result = reader.result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const fileContent = String(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
callback(fileContent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
reader.readAsText(file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+23
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve type safety in file handling. The file parameter is typed as - const readFileContent = (file: any, callback: (value: string) => void) => {
+ const readFileContent = (file: File, callback: (value: string) => void) => {
+ const validFileTypes = ['.pem', '.crt', '.key'];
+ const fileExtension = file.name.toLowerCase().slice(file.name.lastIndexOf('.'));
+
+ if (!validFileTypes.includes(fileExtension)) {
+ console.error('Invalid file type');
+ return;
+ }
+
const reader = new FileReader();
reader.onloadend = (_e) => {
const result = reader.result; 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const onUploadChange = (info) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { file, fileList } = info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (fileList.length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const uploadFile = fileList[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readFileContent(file.originFileObj, (fileContent: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onChange && onChange(fileContent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
setFileList([uploadFile]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+37
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve error handling and type safety in upload handling. The upload handler should include error handling and proper TypeScript types. - const onUploadChange = (info) => {
+ const onUploadChange = (info: { file: UploadFile; fileList: UploadFile[] }) => {
const { file, fileList } = info;
+
+ if (file.status === 'error') {
+ console.error('File upload failed:', file.error);
+ return;
+ }
+
if (fileList.length) {
const uploadFile = fileList[0];
- readFileContent(file.originFileObj, (fileContent: string) => {
- onChange && onChange(fileContent);
- });
+ if (file.originFileObj) {
+ readFileContent(file.originFileObj, (fileContent: string) => {
+ onChange?.(fileContent);
+ });
+ }
setFileList([uploadFile]);
}
}; 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (1.9.4)[error] 42-42: Change to an optional chain. Unsafe fix: Change to an optional chain. (lint/complexity/useOptionalChain) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const onRemove = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
setFileList([]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onChange && onChange(undefined); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Upload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
accept=".pem,.crt,.key" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fileList={fileList} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onChange={onUploadChange} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onRemove={onRemove} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
maxCount={1} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Button icon={<UploadOutlined />}>Click to upload SSL cert file</Button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</Upload> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default function MySQLProperties(props: Props) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { mode } = props; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const isEditMode = mode === FORM_MODE.EDIT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const [sslMode, setSSLMode] = useState<string>(SSLMode.DISABLED); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const onSSLModeChange = (value: string) => setSSLMode(value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Form.Item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -89,6 +147,34 @@ export default function MySQLProperties(props: Props) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Input placeholder="MySQL database name" disabled={isEditMode} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</Form.Item> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Form.Item label="SSL mode" name="sslMode" initialValue={SSLMode.DISABLED}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Select | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
style={{ width: 120 }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onChange={onSSLModeChange} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
disabled={isEditMode} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options={[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ value: SSLMode.DISABLED, label: 'Disabled' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ value: SSLMode.ENABLED, label: 'Enabled' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ value: SSLMode.VERIFY_CA, label: 'Verify CA' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</Form.Item> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sslMode === SSLMode.VERIFY_CA && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<Form.Item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label="SSL CA file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name="sslCA" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rules={[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
message: ERROR_TEXTS.CONNECTION.SSL_CERT.REQUIRED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<UploadSSL /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</Form.Item> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Uh oh!
There was an error while loading. Please reload this page.