fix: Fix the convert shell code to base64 errors

Control input must be ASCII code to match StringIO function in cloud-init

Change-Id: I9dd468847043ed1c3e936c6a9605c10367cff21a
This commit is contained in:
xusongfu 2021-11-03 16:19:58 +08:00
parent 6dc359f4a2
commit a612794349
4 changed files with 15 additions and 1 deletions

View File

@ -1137,6 +1137,7 @@
"Placement service:": "Placement service:",
"Platform Info": "Platform Info",
"Please confirm your password!": "Please confirm your password!",
"Please enter a valid ASCII code": "Please enter a valid ASCII code",
"Please enter a valid Email Address!": "Please enter a valid Email Address!",
"Please enter a valid Phone Number": "Please enter a valid Phone Number",
"Please enter complete key value!": "Please enter complete key value!",

View File

@ -1137,6 +1137,7 @@
"Placement service:": "放置服务(placement):",
"Platform Info": "平台概况",
"Please confirm your password!": "请确认您的密码",
"Please enter a valid ASCII code": "请输入有效的ASCII码",
"Please enter a valid Email Address!": "请输入一个有效的邮箱地址",
"Please enter a valid Phone Number": "请输入一个有效的手机号",
"Please enter complete key value!": "请输入完整的键值!",

View File

@ -19,7 +19,7 @@ import globalHypervisorStore from 'stores/nova/hypervisor';
import globalServerGroupStore from 'stores/nova/server-group';
import policyType from 'resources/server-group';
import Base from 'components/Form';
import { getPasswordOtherRule } from 'utils/validate';
import { getPasswordOtherRule, asciiValidator } from 'utils/validate';
import { hypervisorColumns, hypervisorFilters } from 'resources/hypervisor';
import { physicalNodeTypes } from 'resources/instance';
@ -330,6 +330,7 @@ export class SystemStep extends Base {
name: 'userData',
label: t('User Data'),
type: 'textarea-from-file',
validator: asciiValidator,
hidden: !more,
extra: t(
'The user needs to ensure that the input is a shell script that can run completely and normally.'

View File

@ -53,6 +53,7 @@ const instanceNameRegex =
/^[a-zA-Z\u4e00-\u9fa5][\u4e00-\u9fa5\w"'._-]{0,127}$/;
const ipv6CidrOnly =
/^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9-]*[A-Za-z0-9])$|^\s*((([0-9A-F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,2})$/;
const asciiRegex = /^[\x00-\x7f]*$/; // eslint-disable-line
export const regex = {
cidr,
@ -71,6 +72,7 @@ export const regex = {
imageNameRegex,
instanceNameRegex,
ipv6CidrOnly,
asciiRegex,
};
export const isPhoneNumber = (value) => phone(value).isValid;
@ -335,6 +337,8 @@ export const macAddressMessage = t(
'Invalid Mac Address. Please Use ":" as separator.'
);
const asciiMessage = t('Please enter a valid ASCII code');
export const phoneNumberValidate = (rule, value) => {
if (!rule.required && !value) {
return Promise.resolve(true);
@ -588,3 +592,10 @@ export const jsonValidator = (item, value) => {
}
return Promise.resolve(true);
};
export const asciiValidator = (rule, value) => {
if (asciiRegex.test(value)) {
return Promise.resolve(true);
}
return Promise.reject(new Error(`${t('Invalid: ')}${asciiMessage}`));
};