Skip to content

Commit e0fc210

Browse files
committed
[Bugfix] fix didi#887 解除jmx的SSL和密码认证默认耦合
1 parent 41b5f35 commit e0fc210

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

km-console/packages/layout-clusters-fe/src/constants/reg.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ export const regTemplateName = /^[a-z0-9\._-]*$/; // 仅支持小写字母、数
2222
export const regIp = /((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/g; // ip
2323

2424
export const regKafkaPassword = /^[A-Za-z0-9_\-!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]*$/;
25+
26+
export const regJmxPassword = /^[_a-zA-Z0-9-]*$/; // JMX密码:支持大小写字母、数字、下划线、短划线

km-console/packages/layout-clusters-fe/src/pages/MutliClusterPage/AccessCluster.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Button, Divider, Drawer, Form, Input, InputNumber, Radio, Select, Spin, Space, Utils, Tabs, Collapse, Empty } from 'knowdesign';
1+
import { Button, Divider, Drawer, Form, Input, InputNumber, Radio, Select, Spin, Space, Utils, Tabs, Collapse, Empty, Checkbox } from 'knowdesign';
22
import message from '@src/components/Message';
33
import React, { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from 'react';
44
import { useIntl } from 'react-intl';
55
import api from '@src/api';
6-
import { regClusterName, regIpAndPort, regUsername } from '@src/constants/reg';
6+
import { regClusterName, regIpAndPort, regUsername, regJmxPassword } from '@src/constants/reg';
77
import { bootstrapServersErrCodes, jmxErrCodes, zkErrCodes } from './config';
88
import CodeMirrorFormItem from '@src/components/CodeMirrorFormItem';
99
import { IconFont } from '@knowdesign/icons';
@@ -169,7 +169,16 @@ const ClusterTabContent = forwardRef((props: any, ref): JSX.Element => {
169169
const originValue = obj?.jmxProperties;
170170
if (originValue) {
171171
const jmxProperties = JSON.parse(originValue);
172-
typeof jmxProperties === 'object' && jmxProperties !== null && Object.assign(res, jmxProperties);
172+
if (typeof jmxProperties === 'object' && jmxProperties !== null) {
173+
Object.assign(res, jmxProperties);
174+
// 根据是否有 username/token 判断是否启用密码认证
175+
const hasPasswordAuth = !!(jmxProperties.username && jmxProperties.token);
176+
res.hasPasswordAuth = hasPasswordAuth;
177+
// 如果没有密码认证,确保 openSSL 为 false
178+
if (!hasPasswordAuth) {
179+
res.openSSL = false;
180+
}
181+
}
173182
}
174183
} catch (err) {
175184
console.error('jmxProperties not JSON: ', err);
@@ -257,8 +266,8 @@ const ClusterTabContent = forwardRef((props: any, ref): JSX.Element => {
257266
if (!value) {
258267
return Promise.reject('密码不能为空');
259268
}
260-
if (!new RegExp(regUsername).test(value)) {
261-
return Promise.reject('密码只能由大小写、下划线、短划线(-)组成');
269+
if (!new RegExp(regJmxPassword).test(value)) {
270+
return Promise.reject('密码只能由大小写字母、数字、下划线、短划线(-)组成');
262271
}
263272
if (value.length < 6 || value.length > 32) {
264273
return Promise.reject('密码长度限制在6~32字符');
@@ -360,15 +369,15 @@ const ClusterTabContent = forwardRef((props: any, ref): JSX.Element => {
360369
<InputNumber addonAfter="个" min={0} max={99999} style={{ width: 124 }} />
361370
</Form.Item>
362371
</div>
363-
<Form.Item name="openSSL" label="Security :">
372+
<Form.Item name="hasPasswordAuth" label="Security :">
364373
<Radio.Group>
365374
<Radio value={false}>None</Radio>
366375
<Radio value={true}>Password Authentication</Radio>
367376
</Radio.Group>
368377
</Form.Item>
369-
<Form.Item dependencies={['openSSL']} noStyle>
378+
<Form.Item dependencies={['hasPasswordAuth']} noStyle>
370379
{({ getFieldValue }) => {
371-
return getFieldValue('openSSL') ? (
380+
return getFieldValue('hasPasswordAuth') ? (
372381
<div className="user-info-form-items">
373382
<Form.Item className="user-info-label" label="User Info :" required />
374383
<div className="inline-items">
@@ -379,6 +388,7 @@ const ClusterTabContent = forwardRef((props: any, ref): JSX.Element => {
379388
validator: validators.securityUserName,
380389
},
381390
]}
391+
style={{ width: '140px', marginRight: '8px' }}
382392
>
383393
<Input placeholder="请输入用户名" />
384394
</Form.Item>
@@ -390,9 +400,13 @@ const ClusterTabContent = forwardRef((props: any, ref): JSX.Element => {
390400
validator: validators.securityToken,
391401
},
392402
]}
403+
style={{ width: '140px', marginRight: '8px' }}
393404
>
394405
<Input placeholder="请输入密码" />
395406
</Form.Item>
407+
<Form.Item name="openSSL" valuePropName="checked" style={{ marginBottom: 0, alignSelf: 'center' }}>
408+
<Checkbox>启用 SSL</Checkbox>
409+
</Form.Item>
396410
</div>
397411
</div>
398412
) : null;
@@ -759,9 +773,9 @@ const AccessClusterDrawer = (props: AccessClusterDrawerProps) => {
759773
jmxProperties: {
760774
jmxPort: res.jmxPort,
761775
maxConn: res.maxConn,
762-
openSSL: res.openSSL || false,
763-
token: res.token,
764-
username: res.username,
776+
openSSL: res.hasPasswordAuth ? (res.openSSL || false) : false,
777+
token: res.hasPasswordAuth ? res.token : '',
778+
username: res.hasPasswordAuth ? res.username : '',
765779
},
766780
kafkaVersion: res.kafkaVersion,
767781
name: res.name,

0 commit comments

Comments
 (0)