From 0fe48abcfa71bb3e8b31283230ae5aad631fdc7c Mon Sep 17 00:00:00 2001 From: yaojp123 <15989103230@163.com> Date: Mon, 16 Dec 2024 17:03:21 +0800 Subject: [PATCH] feat: add Agent Credential to Register Cluster (#40) Co-authored-by: yaojiping --- web/src/pages/System/Cluster/Step.js | 10 +- .../pages/System/Cluster/steps/extra_step.js | 102 ++++++++++++++++-- 2 files changed, 100 insertions(+), 12 deletions(-) diff --git a/web/src/pages/System/Cluster/Step.js b/web/src/pages/System/Cluster/Step.js index df2dac03..ff2b36f4 100644 --- a/web/src/pages/System/Cluster/Step.js +++ b/web/src/pages/System/Cluster/Step.js @@ -151,6 +151,14 @@ const ClusterStep = ({ dispatch, history, query }) => { username: clusterConfig.username || "", 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, enabled: true, monitored: values.monitored, @@ -196,7 +204,7 @@ const ClusterStep = ({ dispatch, history, query }) => { if (current === 0) { return ; } else if (current === 1) { - return ; + return ; } else if (current === 2) { return ( { + 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() { const { form: { getFieldDecorator }, @@ -141,15 +215,21 @@ export class ExtraStep extends React.Component { initialValue: "", })()} - {/* - {getFieldDecorator('enabled', { - valuePropName: 'checked', - initialValue: true, - })(} - unCheckedChildren={} - />)} - */} +