Skip to content

Commit 9e5cda5

Browse files
author
Hoang Nguyen
authored
UI: Add authmethod field allowing to choose password or ssh key when adding host (apache#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
1 parent c6b6114 commit 9e5cda5

File tree

3 files changed

+84
-6
lines changed

3 files changed

+84
-6
lines changed

ui/src/views/infra/zone/StaticInputsForm.vue

+53-4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@
6767
v-model:value="form[field.key]"
6868
v-focus="index === 0"
6969
/>
70+
<a-radio-group
71+
v-else-if="field.radioGroup"
72+
v-model:value="form[field.key]"
73+
buttonStyle="solid">
74+
<span
75+
style="margin-right: 5px;"
76+
v-for="(radioItem, idx) in field.radioOption"
77+
:key="idx">
78+
<a-radio-button
79+
:value="radioItem.value"
80+
v-if="isDisplayItem(radioItem.condition)">
81+
{{ $t(radioItem.label) }}
82+
</a-radio-button>
83+
</span>
84+
<a-alert style="margin-top: 5px" type="warning" v-if="field.alert && isDisplayItem(field.alert.display)">
85+
<template #message>
86+
<span v-html="$t(field.alert.message)" />
87+
</template>
88+
</a-alert>
89+
</a-radio-group>
7090
<a-input
7191
v-else
7292
v-model:value="form[field.key]"
@@ -118,6 +138,11 @@ export default {
118138
created () {
119139
this.initForm()
120140
},
141+
computed: {
142+
hypervisor () {
143+
return this.prefillContent?.hypervisor || null
144+
}
145+
},
121146
mounted () {
122147
this.fillValue()
123148
},
@@ -152,13 +177,13 @@ export default {
152177
if (!fieldExists) {
153178
return
154179
}
155-
if (field.key === 'agentUserName' && !this.getPrefilled(field.key)) {
180+
if (field.key === 'agentUserName' && !this.getPrefilled(field)) {
156181
this.form[field.key] = 'Oracle'
157182
} else {
158183
if (field.switch) {
159184
this.form[field.key] = this.isChecked(field)
160185
} else {
161-
this.form[field.key] = this.getPrefilled(field.key)
186+
this.form[field.key] = this.getPrefilled(field)
162187
}
163188
}
164189
})
@@ -179,8 +204,11 @@ export default {
179204
})
180205
}
181206
},
182-
getPrefilled (key) {
183-
return this.prefillContent?.[key] || null
207+
getPrefilled (field) {
208+
if (field.key === 'authmethod' && this.hypervisor !== 'KVM') {
209+
return field.value || field.defaultValue || 'password'
210+
}
211+
return this.prefillContent?.[field.key] || field.value || field.defaultValue || null
184212
},
185213
handleSubmit () {
186214
this.formRef.value.validate().then(() => {
@@ -236,6 +264,27 @@ export default {
236264
return false
237265
}
238266
return true
267+
},
268+
isDisplayItem (conditions) {
269+
if (!conditions || Object.keys(conditions).length === 0) {
270+
return true
271+
}
272+
let isShow = true
273+
Object.keys(conditions).forEach(key => {
274+
if (!isShow) return false
275+
276+
const condition = conditions[key]
277+
const fieldVal = this.form[key]
278+
? this.form[key]
279+
: (this.prefillContent?.[key] || null)
280+
if (Array.isArray(condition) && !condition.includes(fieldVal)) {
281+
isShow = false
282+
} else if (!Array.isArray(condition) && fieldVal !== condition) {
283+
isShow = false
284+
}
285+
})
286+
287+
return isShow
239288
}
240289
}
241290
}

ui/src/views/infra/zone/ZoneWizardAddResources.vue

+29-1
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,42 @@ export default {
284284
hypervisor: ['VMware', 'BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator']
285285
}
286286
},
287+
{
288+
title: 'label.authentication.method',
289+
key: 'authmethod',
290+
placeHolder: 'message.error.authmethod',
291+
required: false,
292+
radioGroup: true,
293+
defaultValue: 'password',
294+
radioOption: [{
295+
label: 'label.password',
296+
value: 'password'
297+
}, {
298+
label: 'label.authentication.sshkey',
299+
value: 'sshkey',
300+
condition: {
301+
hypervisor: ['KVM']
302+
}
303+
}],
304+
display: {
305+
hypervisor: ['BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator']
306+
},
307+
alert: {
308+
message: 'message.add.host.sshkey',
309+
display: {
310+
authmethod: 'sshkey'
311+
}
312+
}
313+
},
287314
{
288315
title: 'label.password',
289316
key: 'hostPassword',
290317
placeHolder: 'message.error.host.password',
291318
required: true,
292319
password: true,
293320
display: {
294-
hypervisor: ['VMware', 'BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator']
321+
hypervisor: ['VMware', 'BareMetal', 'Ovm', 'Hyperv', 'KVM', 'XenServer', 'LXC', 'Simulator'],
322+
authmethod: 'password'
295323
}
296324
},
297325
{

ui/src/views/infra/zone/ZoneWizardLaunchZone.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -1211,14 +1211,15 @@ export default {
12111211
this.addStep('message.adding.host', 'hostResource')
12121212
12131213
const hostData = {}
1214+
const hostPassword = this.prefillContent?.authmethod !== 'password' ? '' : (this.prefillContent?.hostPassword || null)
12141215
hostData.zoneid = this.stepData.zoneReturned.id
12151216
hostData.podid = this.stepData.podReturned.id
12161217
hostData.clusterid = this.stepData.clusterReturned.id
12171218
hostData.hypervisor = this.stepData.clusterReturned.hypervisortype
12181219
hostData.clustertype = this.stepData.clusterReturned.clustertype
12191220
hostData.hosttags = this.prefillContent?.hostTags || null
12201221
hostData.username = this.prefillContent?.hostUserName || null
1221-
hostData.password = this.prefillContent?.hostPassword || null
1222+
hostData.password = hostPassword
12221223
const hostname = this.prefillContent?.hostName || null
12231224
let url = null
12241225
if (hostname.indexOf('http://') === -1) {

0 commit comments

Comments
 (0)