Skip to content

Commit

Permalink
The host name needs to fully comply with the naming convention of she…
Browse files Browse the repository at this point in the history
…ll variables (#168)

* cvm name standard

Signed-off-by: liu deyi <[email protected]>

* cvm name standard

Signed-off-by: liu deyi <[email protected]>

* cvm name standard

Signed-off-by: liu deyi <[email protected]>

* modify regular expression

Signed-off-by: liu deyi <[email protected]>

* modify regular expression

Signed-off-by: liu deyi <[email protected]>
  • Loading branch information
dyliu authored Aug 12, 2021
1 parent aeb15b8 commit 2edded4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/microservice/aslan/config/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ var (
// RenderTemplateAlias ...
RenderTemplateAlias = regexp.MustCompile(`{{\s?\.\w+\s?}}`)
ServiceNameAlias = regexp.MustCompile(`\$Service\$`)

NameSpaceRegex = regexp.MustCompile(NameSpaceRegexString)
NameSpaceRegex = regexp.MustCompile(NameSpaceRegexString)
)

const (
ServiceNameRegexString = "^[a-zA-Z0-9-_]+$"
ConfigNameRegexString = "^[a-zA-Z0-9-]+$"
ImageRegexString = "^[a-zA-Z0-9.:\\/-]+$"
CVMNameRegexString = "^[a-zA-Z_]\\w+$"

EnvRecyclePolicyAlways = "always"
EnvRecyclePolicyTaskStatus = "success"
Expand All @@ -46,6 +46,7 @@ var (
ServiceNameRegex = regexp.MustCompile(ServiceNameRegexString)
ConfigNameRegex = regexp.MustCompile(ConfigNameRegexString)
ImageRegex = regexp.MustCompile(ImageRegexString)
CVMNameRegex = regexp.MustCompile(CVMNameRegexString)
)

// ScheduleType 触发模式
Expand Down
6 changes: 6 additions & 0 deletions pkg/microservice/aslan/core/system/service/private_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package service
import (
"go.uber.org/zap"

"github.com/koderover/zadig/pkg/microservice/aslan/config"
commonmodels "github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/models"
commonrepo "github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/mongodb"
e "github.com/koderover/zadig/pkg/tool/errors"
Expand All @@ -43,9 +44,14 @@ func GetPrivateKey(id string, log *zap.SugaredLogger) (*commonmodels.PrivateKey,
}

func CreatePrivateKey(args *commonmodels.PrivateKey, log *zap.SugaredLogger) error {
if !config.CVMNameRegex.MatchString(args.Name) {
return e.ErrCreatePrivateKey.AddDesc("主机名称仅支持字母,数字和下划线且首个字符不以数字开头")
}

if privateKeys, _ := commonrepo.NewPrivateKeyColl().List(&commonrepo.PrivateKeyArgs{Name: args.Name}); len(privateKeys) > 0 {
return e.ErrCreatePrivateKey.AddDesc("Name already exists")
}

err := commonrepo.NewPrivateKeyColl().Create(args)
if err != nil {
log.Errorf("PrivateKey.Create error: %v", err)
Expand Down

0 comments on commit 2edded4

Please sign in to comment.