remote-task-excutor-cli/pkg/models/validator.go

34 lines
798 B
Go

package models
import (
"errors"
"regexp"
)
// ValidateConfig 验证配置参数
func ValidateConfig(config *RunConfig) error {
// 验证镜像
if config.Image == 0 {
return errors.New("image is required")
}
// 验证命令
if config.Command == "" {
return errors.New("command is required")
}
return nil
}
// isValidCodeConfig 验证代码配置格式
func isValidCodeConfig(input string) bool {
// 检查 SSH 格式 (git@github.com:user/repo.git)
sshPattern := `^git@[a-zA-Z0-9.-]+:[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+\.git$`
// 检查 HTTPS 格式 (https://github.com/user/repo.git)
httpsPattern := `^https?://[a-zA-Z0-9.-]+/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+\.git$`
return regexp.MustCompile(sshPattern).MatchString(input) ||
regexp.MustCompile(httpsPattern).MatchString(input)
}