From 9e5cda59ceb53f4f1f1eab034c5d6f9a0d82223c Mon Sep 17 00:00:00 2001 From: Hoang Nguyen Date: Wed, 6 Jul 2022 13:46:09 +0700 Subject: [PATCH] UI: Add authmethod field allowing to choose password or ssh key when adding host (#6525) * add authmethod to addhost in zone wizard * add a condition for hiding password field * set default value when switch hypervisor * add more value for authmethod --- ui/src/views/infra/zone/StaticInputsForm.vue | 57 +++++++++++++++++-- .../infra/zone/ZoneWizardAddResources.vue | 30 +++++++++- .../views/infra/zone/ZoneWizardLaunchZone.vue | 3 +- 3 files changed, 84 insertions(+), 6 deletions(-) diff --git a/ui/src/views/infra/zone/StaticInputsForm.vue b/ui/src/views/infra/zone/StaticInputsForm.vue index 0c23a3ad083..6604ba32c88 100644 --- a/ui/src/views/infra/zone/StaticInputsForm.vue +++ b/ui/src/views/infra/zone/StaticInputsForm.vue @@ -67,6 +67,26 @@ v-model:value="form[field.key]" v-focus="index === 0" /> + + + + {{ $t(radioItem.label) }} + + + + + + { @@ -236,6 +264,27 @@ export default { return false } return true + }, + isDisplayItem (conditions) { + if (!conditions || Object.keys(conditions).length === 0) { + return true + } + let isShow = true + Object.keys(conditions).forEach(key => { + if (!isShow) return false + + const condition = conditions[key] + const fieldVal = this.form[key] + ? this.form[key] + : (this.prefillContent?.[key] || null) + if (Array.isArray(condition) && !condition.includes(fieldVal)) { + isShow = false + } else if (!Array.isArray(condition) && fieldVal !== condition) { + isShow = false + } + }) + + return isShow } } } diff --git a/ui/src/views/infra/zone/ZoneWizardAddResources.vue b/ui/src/views/infra/zone/ZoneWizardAddResources.vue index 8a52ec91007..ad16ef30aa1 100644 --- a/ui/src/views/infra/zone/ZoneWizardAddResources.vue +++ b/ui/src/views/infra/zone/ZoneWizardAddResources.vue @@ -284,6 +284,33 @@ export default { hypervisor: ['VMware', 'BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator'] } }, + { + title: 'label.authentication.method', + key: 'authmethod', + placeHolder: 'message.error.authmethod', + required: false, + radioGroup: true, + defaultValue: 'password', + radioOption: [{ + label: 'label.password', + value: 'password' + }, { + label: 'label.authentication.sshkey', + value: 'sshkey', + condition: { + hypervisor: ['KVM'] + } + }], + display: { + hypervisor: ['BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator'] + }, + alert: { + message: 'message.add.host.sshkey', + display: { + authmethod: 'sshkey' + } + } + }, { title: 'label.password', key: 'hostPassword', @@ -291,7 +318,8 @@ export default { required: true, password: true, display: { - hypervisor: ['VMware', 'BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator'] + hypervisor: ['VMware', 'BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator'], + authmethod: 'password' } }, { diff --git a/ui/src/views/infra/zone/ZoneWizardLaunchZone.vue b/ui/src/views/infra/zone/ZoneWizardLaunchZone.vue index 432523c901a..7f23c3b643a 100644 --- a/ui/src/views/infra/zone/ZoneWizardLaunchZone.vue +++ b/ui/src/views/infra/zone/ZoneWizardLaunchZone.vue @@ -1211,6 +1211,7 @@ export default { this.addStep('message.adding.host', 'hostResource') const hostData = {} + const hostPassword = this.prefillContent?.authmethod !== 'password' ? '' : (this.prefillContent?.hostPassword || null) hostData.zoneid = this.stepData.zoneReturned.id hostData.podid = this.stepData.podReturned.id hostData.clusterid = this.stepData.clusterReturned.id @@ -1218,7 +1219,7 @@ export default { hostData.clustertype = this.stepData.clusterReturned.clustertype hostData.hosttags = this.prefillContent?.hostTags || null hostData.username = this.prefillContent?.hostUserName || null - hostData.password = this.prefillContent?.hostPassword || null + hostData.password = hostPassword const hostname = this.prefillContent?.hostName || null let url = null if (hostname.indexOf('http://') === -1) {