mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
UI: Fix Userdata registration from UI (#8791)
* UI: Fix Userdata registration from UI * add isbase64 checkbox
This commit is contained in:
parent
a10eee25b3
commit
7534196361
@ -1110,6 +1110,7 @@
|
||||
"label.ipv6.subnets": "IPv6 Subnets",
|
||||
"label.ip.addresses": "IP Addresses",
|
||||
"label.iqn": "Target IQN",
|
||||
"label.is.base64.encoded": "Base64 encoded",
|
||||
"label.is.in.progress": "is in progress",
|
||||
"label.is.shared": "Is shared",
|
||||
"label.is2faenabled": "Is 2FA enabled",
|
||||
|
||||
@ -486,6 +486,15 @@ export const fileSizeUtilPlugin = {
|
||||
}
|
||||
}
|
||||
|
||||
function isBase64 (str) {
|
||||
try {
|
||||
const decoded = new TextDecoder().decode(Uint8Array.from(atob(str), c => c.charCodeAt(0)))
|
||||
return btoa(decoded) === str
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export const genericUtilPlugin = {
|
||||
install (app) {
|
||||
app.config.globalProperties.$isValidUuid = function (uuid) {
|
||||
@ -494,8 +503,7 @@ export const genericUtilPlugin = {
|
||||
}
|
||||
|
||||
app.config.globalProperties.$toBase64AndURIEncoded = function (text) {
|
||||
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
|
||||
if (base64regex.test(text)) {
|
||||
if (isBase64(text)) {
|
||||
return text
|
||||
}
|
||||
return encodeURIComponent(btoa(unescape(encodeURIComponent(text))))
|
||||
|
||||
@ -43,6 +43,9 @@
|
||||
v-model:value="form.userdata"
|
||||
:placeholder="apiParams.userdata.description"/>
|
||||
</a-form-item>
|
||||
<a-form-item name="isbase64" ref="isbase64" :label="$t('label.is.base64.encoded')">
|
||||
<a-checkbox v-model:checked="form.isbase64"></a-checkbox>
|
||||
</a-form-item>
|
||||
<a-form-item name="params" ref="params">
|
||||
<template #label>
|
||||
<tooltip-label :title="$t('label.userdataparams')" :tooltip="apiParams.params.description"/>
|
||||
@ -147,7 +150,9 @@ export default {
|
||||
methods: {
|
||||
initForm () {
|
||||
this.formRef = ref()
|
||||
this.form = reactive({})
|
||||
this.form = reactive({
|
||||
isbase64: false
|
||||
})
|
||||
this.rules = reactive({
|
||||
name: [{ required: true, message: this.$t('message.error.name') }],
|
||||
userdata: [{ required: true, message: this.$t('message.error.userdata') }]
|
||||
@ -204,7 +209,7 @@ export default {
|
||||
if (this.isValidValueForKey(values, 'account') && values.account.length > 0) {
|
||||
params.account = values.account
|
||||
}
|
||||
params.userdata = this.$toBase64AndURIEncoded(values.userdata)
|
||||
params.userdata = values.isbase64 ? values.userdata : this.$toBase64AndURIEncoded(values.userdata)
|
||||
|
||||
if (values.params != null && values.params.length > 0) {
|
||||
var userdataparams = values.params.join(',')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user