feat: add Agent Credential to Register Cluster (#40)

Co-authored-by: yaojiping <yaojiping@infini.ltd>
This commit is contained in:
yaojp123 2024-12-16 17:03:21 +08:00 committed by GitHub
parent ffda990228
commit 0fe48abcfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 100 additions and 12 deletions

View File

@ -151,6 +151,14 @@ const ClusterStep = ({ dispatch, history, query }) => {
username: clusterConfig.username || "", username: clusterConfig.username || "",
password: clusterConfig.password || "", password: clusterConfig.password || "",
}, },
agent_credential_id:
values.agent_credential_id !== MANUAL_VALUE
? values.agent_credential_id
: undefined,
agent_basic_auth: {
username: values.agent_username,
password: values.agent_password,
},
description: values.description, description: values.description,
enabled: true, enabled: true,
monitored: values.monitored, monitored: values.monitored,
@ -196,7 +204,7 @@ const ClusterStep = ({ dispatch, history, query }) => {
if (current === 0) { if (current === 0) {
return <InitialStep ref={formRef} initialValue={clusterConfig} />; return <InitialStep ref={formRef} initialValue={clusterConfig} />;
} else if (current === 1) { } else if (current === 1) {
return <ExtraStep initialValue={clusterConfig} ref={formRef} />; return <ExtraStep initialValue={clusterConfig} ref={formRef} dispatch={dispatch}/>;
} else if (current === 2) { } else if (current === 2) {
return ( return (
<ResultStep <ResultStep

View File

@ -6,6 +6,7 @@ import {
InputNumber, InputNumber,
Divider, Divider,
Descriptions, Descriptions,
message,
} from "antd"; } from "antd";
import { HealthStatusView } from "@/components/infini/health_status_view"; import { HealthStatusView } from "@/components/infini/health_status_view";
import { formatMessage } from "umi/locale"; import { formatMessage } from "umi/locale";
@ -13,18 +14,91 @@ import TagEditor from "@/components/infini/TagEditor";
import MonitorConfigsForm from "../MonitorConfigsForm"; import MonitorConfigsForm from "../MonitorConfigsForm";
import MetadataConfigsForm from "../MetadataConfigsForm"; import MetadataConfigsForm from "../MetadataConfigsForm";
import "../Form.scss"; import "../Form.scss";
import AgentCredentialForm from "../AgentCredentialForm";
import { MANUAL_VALUE } from "./initial_step";
@Form.create() @Form.create()
export class ExtraStep extends React.Component { export class ExtraStep extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { monitored: true }; this.state = {
monitored: true,
btnLoadingAgent: false,
agentCredentialRequired: false,
isManual: false,
needAuth: false,
};
} }
componentDidMount() { componentDidMount() {
const { initialValue } = this.props
const needAuth = initialValue?.credential_id ? true : false
this.setState({ this.setState({
monitored: this.props?.initialValue?.monitored ?? true, monitored: initialValue?.monitored ?? true,
needAuth,
isManual: needAuth ? !!initialValue?.username : false
}); });
} }
tryConnect = async () => {
const { dispatch, form, initialValue } = this.props;
if (this.state.needAuth) {
this.setState({
...this.state,
agentCredentialRequired: true,
});
}
const fieldNames = [
"agent_credential_id",
"agent_username",
"agent_password",
];
setTimeout(() => {
form.validateFields(
fieldNames,
{ force: true },
async (errors, values) => {
if (errors) {
return false;
}
if (!initialValue) {
return;
}
let newVals = {
host: initialValue.host,
schema: initialValue.isTLS === true ? "https" : "http",
};
newVals = {
...newVals,
...{
credential_id:
values.agent_credential_id !== MANUAL_VALUE
? values.agent_credential_id
: undefined,
basic_auth: {
username: values.agent_username,
password: values.agent_password,
},
},
};
this.setState({ btnLoadingAgent: true });
const res = await dispatch({
type: "clusterConfig/doTryConnect",
payload: newVals,
});
if (res) {
message.success(
formatMessage({
id: "app.message.connect.success",
})
);
}
this.setState({ btnLoadingAgent: false });
}
);
}, 200);
};
render() { render() {
const { const {
form: { getFieldDecorator }, form: { getFieldDecorator },
@ -141,15 +215,21 @@ export class ExtraStep extends React.Component {
initialValue: "", initialValue: "",
})(<Input.TextArea placeholder="Cluster description" />)} })(<Input.TextArea placeholder="Cluster description" />)}
</Form.Item> </Form.Item>
{/* <Form.Item label=""> <AgentCredentialForm
{getFieldDecorator('enabled', { btnLoading={this.state.btnLoadingAgent}
valuePropName: 'checked', needAuth={this.state.needAuth}
initialValue: true, form={this.props.form}
})(<Switch initialValue={{
checkedChildren={<Icon type="check" />} ...(initialValue || {}),
unCheckedChildren={<Icon type="close" />} agent_credential_id: initialValue?.credential_id,
/>)} username: initialValue?.username,
</Form.Item> */} password: initialValue?.password,
}}
isManual={this.state.isManual}
isEdit={true}
tryConnect={this.tryConnect}
credentialRequired={this.state.agentCredentialRequired}
/>
<Form.Item <Form.Item
label={formatMessage({ label={formatMessage({
id: "cluster.manage.table.column.discovery.enabled", id: "cluster.manage.table.column.discovery.enabled",