From f241ea6752b9305bf6bb20b3d7037fb6c4022a95 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 29 Mar 2019 14:47:27 +0800 Subject: [PATCH] fix: Add regex for helm appName (#1077) --- src/locales/zh/deploy.json | 1 + src/pages/Dashboard/Apps/Deploy/index.jsx | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/locales/zh/deploy.json b/src/locales/zh/deploy.json index 1c1a4eaf..9fbdbff1 100644 --- a/src/locales/zh/deploy.json +++ b/src/locales/zh/deploy.json @@ -13,6 +13,7 @@ "STEPPER_FOOTER_APP_DEPLOY_1": "部署完成的实例将会出现在「我的实例」列表中", "STEPPER_TITLE_APP_DEPLOY_TEST_1": "部署测试实例", "STEPPER_FOOTER_APP_DEPLOY_TEST_1": "部署完成的测试实例将会出现在「测试实例/沙盒实例」列表中", + "HELM_APP_NAME_ERROR": "实例名称必须是$t(HELM_APP_NAME_TIP)", "HELM_APP_NAME_TIP": "小写字母开头,最长14个字符(支持数字/小写字母/连字符)", "No available version": "没有可用版本" } diff --git a/src/pages/Dashboard/Apps/Deploy/index.jsx b/src/pages/Dashboard/Apps/Deploy/index.jsx index 15b8e5ce..9279325d 100644 --- a/src/pages/Dashboard/Apps/Deploy/index.jsx +++ b/src/pages/Dashboard/Apps/Deploy/index.jsx @@ -31,6 +31,7 @@ const keysShouldBeNumber = [ 'instance_class', 'count' ]; +const appNameRegex = /^[a-z][a-z0-9-]{0,13}$/; @withTranslation() @inject(({ rootStore }) => ({ @@ -179,6 +180,9 @@ export default class AppDeploy extends Component { if (!name) { return appDeployStore.error(t('Name should not be empty')); } + if (!appNameRegex.test(name)) { + return appDeployStore.error(t('HELM_APP_NAME_ERROR')); + } let conf; if (isK8s) {