Skip to content

Commit 7534196

Browse files
authored
UI: Fix Userdata registration from UI (#8791)
* UI: Fix Userdata registration from UI * add isbase64 checkbox
1 parent a10eee2 commit 7534196

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

ui/public/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@
11101110
"label.ipv6.subnets": "IPv6 Subnets",
11111111
"label.ip.addresses": "IP Addresses",
11121112
"label.iqn": "Target IQN",
1113+
"label.is.base64.encoded": "Base64 encoded",
11131114
"label.is.in.progress": "is in progress",
11141115
"label.is.shared": "Is shared",
11151116
"label.is2faenabled": "Is 2FA enabled",

ui/src/utils/plugins.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,15 @@ export const fileSizeUtilPlugin = {
486486
}
487487
}
488488

489+
function isBase64 (str) {
490+
try {
491+
const decoded = new TextDecoder().decode(Uint8Array.from(atob(str), c => c.charCodeAt(0)))
492+
return btoa(decoded) === str
493+
} catch (err) {
494+
return false
495+
}
496+
}
497+
489498
export const genericUtilPlugin = {
490499
install (app) {
491500
app.config.globalProperties.$isValidUuid = function (uuid) {
@@ -494,8 +503,7 @@ export const genericUtilPlugin = {
494503
}
495504

496505
app.config.globalProperties.$toBase64AndURIEncoded = function (text) {
497-
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
498-
if (base64regex.test(text)) {
506+
if (isBase64(text)) {
499507
return text
500508
}
501509
return encodeURIComponent(btoa(unescape(encodeURIComponent(text))))

ui/src/views/compute/RegisterUserData.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
v-model:value="form.userdata"
4444
:placeholder="apiParams.userdata.description"/>
4545
</a-form-item>
46+
<a-form-item name="isbase64" ref="isbase64" :label="$t('label.is.base64.encoded')">
47+
<a-checkbox v-model:checked="form.isbase64"></a-checkbox>
48+
</a-form-item>
4649
<a-form-item name="params" ref="params">
4750
<template #label>
4851
<tooltip-label :title="$t('label.userdataparams')" :tooltip="apiParams.params.description"/>
@@ -147,7 +150,9 @@ export default {
147150
methods: {
148151
initForm () {
149152
this.formRef = ref()
150-
this.form = reactive({})
153+
this.form = reactive({
154+
isbase64: false
155+
})
151156
this.rules = reactive({
152157
name: [{ required: true, message: this.$t('message.error.name') }],
153158
userdata: [{ required: true, message: this.$t('message.error.userdata') }]
@@ -204,7 +209,7 @@ export default {
204209
if (this.isValidValueForKey(values, 'account') && values.account.length > 0) {
205210
params.account = values.account
206211
}
207-
params.userdata = this.$toBase64AndURIEncoded(values.userdata)
212+
params.userdata = values.isbase64 ? values.userdata : this.$toBase64AndURIEncoded(values.userdata)
208213
209214
if (values.params != null && values.params.length > 0) {
210215
var userdataparams = values.params.join(',')

0 commit comments

Comments
 (0)